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

조회 수: 1 (최근 30일)
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');

답변 (1개)

Image Analyst
Image Analyst 2014년 1월 11일
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.

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by