Given the coordinates of a centroid, find the nearby pixels with the same color.

조회 수: 1 (최근 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!

답변 (2개)

Image Analyst
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
Blizki Fernandez
Blizki Fernandez 2016년 11월 17일
Thank you, that really helped!! :D I was overthinking things! bwlabel and regionprops did the trick. Cheers.
PD: You got a lot of nice work in there!
Image Analyst
Image Analyst 2016년 11월 18일
If we're done here, then can you "Accept this answer"? Thanks in advance.

댓글을 달려면 로그인하십시오.


Greg Dionne
Greg Dionne 2016년 11월 17일

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by