Given the coordinates of a centroid, find the nearby pixels with the same color.
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(2 个)
Image Analyst
2016-11-17
编辑:Image Analyst
2016-11-17
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Segmentation and Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!