Hi all,
I need to calculate the number of pixels of the long path (the blue one) obtained by a contour function, in order to calculate its length. I think a lot but got no solution

 채택된 답변

DGM
DGM 2023년 4월 17일
편집: DGM 2023년 4월 17일

1 개 추천

If you're trying to find the length of the curve defined by a set of xy coordinates, one way would be to do:
% a binary image
inpict = imread('cmantifmk.png');
inpict = inpict>128;
xy = bwtraceboundary(inpict,[41 50],'e'); % get xy coordinates
D = diff(xy,1,1); % point differences
D = sum(hypot(D(:,1),D(:,2))) % total euclidean distance
D = 871.8864
This is the sum of the distances between the centers of neighboring pixels in the boundary curve. This value will tend to be different than the results calculated by counting pixels or by using regionprops(...,'perimeter'). If you want to use regionprops(), you can look at the docs and decide which best suits your needs.

댓글 수: 3

yes, i am trying to find the length of the curve, but only the lower part (the blue curve), i used the way you proposed, but the distance sum up to zero.
Walter Roberson
Walter Roberson 2023년 4월 17일
threshold, trace boundary, disconnect boundary at the extreme left and extreme right, calculate length of each of the two resulting curves, take the longer ?
thanks alot, it worked, but insted of using xy in the diff funcition, i used the defined contour (intcont)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by