How to get the distance between Centroid to Top and Centroid to Bottom and respectively right and left in a binary image?

1 view (last 30 days)
I have marked the Centroid and Top ,Bottom,Left and Right in a binary image
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');

Answers (1)

Image Analyst
Image Analyst on 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.

Categories

Find more on Images in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!