How to find distance between boundary pixels and centroid?
4 ビュー (過去 30 日間)
古いコメントを表示
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/163891/image.png)
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
0 件のコメント
採用された回答
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 件のコメント
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
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..
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!