trouble using regionprops and imdistline

i 'm dealing with a binary image that has a curved line and i want to find the tortuosity of the line, where tortuosity = (length of line) / (distance between the two endpoints). I'm calling regionprops-area to find the length and then i'm using the imdistline and getdistance commands in order to find the distance between the two endpoints (the coordinates of the endpoints are given). As a matter of fact the length is 113 pixels and the distance 121, but that makes no sense since the length of a curve between two points is always greater than the distance between them. Does anyone know what is wrong? i'm using the following code:
F2=[111 301;222 349];
hline = imdistline(gca, F2(:,1), F2(:,2));
dist = getDistance(hline);
stats=regionprops(F1, 'area');
length = [stats.Area] ;
tortuosity= length / dist;

 Accepted Answer

Sean de Wolski
Sean de Wolski on 10 Mar 2014
Edited: Sean de Wolski on 10 Mar 2014
Use bwmorph with the 'endpoints' option to identify the end points and then use the distance formula (i.e. hypot()) to calculate distance between endpoints.
If this is a skeleton, use regionprops' 'perimeter' option and divide it by two. The problem with using area is that it calculates city-block distance rather than quasi-euclidean and will not give you a good approximation to length. See the description here.

6 Comments

I don't need the bwmoprh-endpoints command as i already know the coordinates of the endpoints. i also tried pdist-euclidean and i got exactly the same distance (121 pixels) with imdistiline-getdistance.
When i use the half of the perimeter, the length is estimated at 130 pixels but i don't know if this result is right or wrong.The width of the line is 1 pixel (i have called bwmorph-thin to get this line)so is it ok to use perimeter instead of area?
Area will be a very bad measurement, perimeter/2 will be a much better approximation to the length.
why is that? can you please explain that a littl bit further? cause i need to justify my options..
The area doesn't care, the perimeter does.
oh ok, now i get it.thank you very much for all your help! :)
Sometimes the area calculation depends on the pixel configuration, as you can see from the two different ways that bwarea() and regionprops() calculate area.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!