Given the coordinates of a centroid, find the nearby pixels with the same color.
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I've got an RGB image with many elements, and a matrix with the coordinates of the centroids of those elements. The elements are of the "almost same" color, lets say centroid pixel is RGB(100,100,100) so almost same color would be RGB(100+-20, 100+-20, 100+-20).
Now I want to find the limits of the elements detected, so I was thinking about going 360° around the centroid in steps of 1° and analyze in a ray pattern starting from the center until the color is not similar, so I store that pixel in some array.
In the end, I should get an array with all the border pixels and I can connect all those pixels with a line and delimitate quite well the element borders with a polygon.
I made an image of what I was thinking... but I need some expert help to determine if this is actually possible or there is some other way to accomplish what I'm looking for.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/158091/image.png)
Thank you, and sorry for my bad english!
0 comentarios
Respuestas (2)
Image Analyst
el 17 de Nov. de 2016
Editada: Image Analyst
el 17 de Nov. de 2016
You can do this with regionprops() in the Image Processing Toolbox. Just make a binary mask and call bwlabel and regionprops. Untested code:
mask = max(rgbImage, [], 3) > 0;
labeledImage = bwlabel(mask);
props = regionprops(labeledImage, 'Area');
allAreas = [props.Area];
This will get both areas. If you want just one of the areas you can segment out just one based on color, shape, size, or whatever property you want to use and get a mask with just that one shape in it.
See my Image Segmentation Tutorial for a well commented, fancy demo: http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862
2 comentarios
Image Analyst
el 18 de Nov. de 2016
If we're done here, then can you "Accept this answer"? Thanks in advance.
Ver también
Categorías
Más información sobre Image Segmentation and Analysis en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!