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

 Respuesta aceptada

DGM
DGM el 17 de Abr. de 2023
Editada: DGM el 17 de Abr. de 2023
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 comentarios

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 el 17 de Abr. de 2023
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)

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by