Given the coordinates of a centroid, find the nearby pixels with the same color.
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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.
Thank you, and sorry for my bad english!
0 commentaires
Réponses (2)
Image Analyst
le 17 Nov 2016
Modifié(e) : Image Analyst
le 17 Nov 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 commentaires
Image Analyst
le 18 Nov 2016
If we're done here, then can you "Accept this answer"? Thanks in advance.
Voir également
Catégories
En savoir plus sur Image Segmentation and Analysis dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!