How to find distance between boundary pixels and centroid?

4 次查看(过去 30 天)
Hi I'm new in matlab and I want to find the distance between the boundary pixels of each connected component and the centroid. I'm using the following algorithm.I have found centroid but dont know how to find the boundary pixels and distance. Looking forward to your reply.
for i=1:count(boundary pixels)
distance between centroid and boundary pixels
end
sum=sum/count

采纳的回答

Walter Roberson
Walter Roberson 2016-5-10
Once you have a logical mask of ROIs corresponding to each cell, and you have filled the regions, then http://www.mathworks.com/help/images/ref/bwdistgeodesic.html
stats = regionprops(TheBinaryROI, 'Centroid', );
cents = vertcat(stats.Centroid);
mask = logical(size(TheBinaryROI));
cents_ind = sub2ind(size(mask), round(cents(:,2)), round(cents(:,1)));
mask(cents_ind) = true;
dists = bwdistgeodesic(TheBinaryROI, mask);
this will give the distances everywhere inside the ROIs. So you can proceed from there to http://www.mathworks.com/help/images/ref/bwboundaries.html use bwbounaries to trace the boundaries of the cells, and use those to select the information out of dists. Now that I think of it, you could instead use http://www.mathworks.com/help/images/ref/bwmorph.html bwmorph() with 'remove' to get just the outside edges of the region. multiply the result by the distance transform to get just the distances from the edges to respective centroids.
  2 个评论
Ayesha ch
Ayesha ch 2016-5-10
编辑:Walter Roberson 2016-5-11
Thank you for the help, I've tried this:
stats=regionprops(Iout,'Centroid');
cents=vertcat(stats.Centroid);
mask=logical(size(output));
cents_ind=sub2ind(size(mask),round(cents(:,2)),round(cents(:,1)));
dists=bwdistgeodesic(output,mask);
r=bwmorph(im2double(Iout),'remove');
figure, imshow(r);
for i=1:count(dists)
d=r*dists;
end
d=d/count(dists);
but it gives me an out of range subscript error in sub2ind. kindly help
Walter Roberson
Walter Roberson 2016-5-11
stats=regionprops(Iout,'Centroid');
cents=vertcat(stats.Centroid);
mask = false(size(Iout));
cents_ind = sub2ind(size(mask), round(cents(:,2)), round(cents(:,1)));
mask(cents_ind) = true;
dists = bwdistgeodesic(Iout,mask);
However, I am finding that the centroids are not necessarily inside the regions. A lot depends on how you segmented into different regions: if you are able to get a clean break between regions then you probably will not do badly, but when I tried, the regions tended to run together.

请先登录,再进行评论。

更多回答(1 个)

Image Analyst
Image Analyst 2016-5-10
You can use bwboundaries() to get a list of x,y coordinates of your perimeters. You can use bwdist() or bwdistgeodesic() to get the distance of every pixel in each blob to the closest perimeter point. Or you can use the Pythagorean theorem and the coordinates from bwboundaries if you want an "as the crow flies" distance, which in general is different than you'll get from either bwdist function..

类别

Help CenterFile Exchange 中查找有关 Feature Detection and Extraction 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by