How to get the distance between Centroid to Top and Centroid to Bottom and respectively right and left in a binary image?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I have marked the Centroid and Top ,Bottom,Left and Right in a binary image
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/154951/image.jpeg)
what i have to do is mesure the distance between the centroid to top point and centroid to bottom point and centroid to left and finally centroid to right point
the left right and top and bottom is marked by
centroidColumn = int32(measurements.Centroid(1)); % "X" value
centroidRow = int32(measurements.Centroid(2)); %"Y" value.
%Then extract a row or column and use find to find the first and last element that's set:
middleColumn = binaryImage(:, centroidColumn);
topRowY = find(middleColumn, 1, 'first'); % Find top.
bottomRowY = find(middleColumn, 1, 'last'); % Find bottom.
middleRow = binaryImage(centroidRow, :);
leftColumnX = find(middleRow, 1, 'first'); % Find left.
rightColumnX= find(middleRow, 1, 'last'); % Find right.
and it is plotted as
imshow(binaryImage);hold(imgca,'on');plot(centroidColumn, centroidRow,'r*','MarkerSize', 6, 'LineWidth', 3);
plot(centroidColumn, topRowY,'r*','MarkerSize', 6, 'LineWidth', 3);
plot(centroidColumn, bottomRowY, 'r*','MarkerSize', 6, 'LineWidth', 3);
plot(leftColumnX, centroidRow, 'r*','MarkerSize', 6, 'LineWidth', 3);
plot(rightColumnX, centroidRow,'r*','MarkerSize', 6, 'LineWidth', 3); hold(imgca,'off');
0 Kommentare
Antworten (1)
Image Analyst
am 11 Jan. 2014
I think the Pythagorean theorem would work nicely here. You have all the coordinates, after all, you plotted them, so just put them into the formula. Or you can use hypot() if you want.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Feature Detection and Extraction finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!