How to find distance between boundary pixels and centroid?
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Ayesha ch
am 10 Mai 2016
Kommentiert: Walter Roberson
am 11 Mai 2016
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 Kommentare
Akzeptierte Antwort
Walter Roberson
am 10 Mai 2016
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 Kommentare
Walter Roberson
am 11 Mai 2016
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.
Weitere Antworten (1)
Image Analyst
am 10 Mai 2016
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 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!