# Algorithm for finding length and end points of a curly human hair

I'm trying to do some analysis of a curly human hair on an iPhone app. I've been using the openCV library.

Particularly I want to be able to estimate the length of the hair, and locate its end points (a measure of curliness is stretched end-to-end length vs. relaxed end-to-end length).

My approach so far has been to use a canny edge detector to find the hair. Then to dilate the result. Finally to skeletonise the image and consider the ends to be those pixels that only have one neighbour. Since the resulting image would hopefully be a one pixel thick line, I could just count the pixels to estimate the length (and maybe adjust for diagonal movements).

The trouble is when the hair is so curly it crosses itself. This makes the skeletonisation add in extra branches and rings that mess up the results.

Is there a better approach for very curly hairs?

Some examples:

Note that once you obtain the skeleton, it is very hard to reverse back to separate the connected components that should not be connected.

The problem is that your original image contrast is too low. I would operate an open morphological operation on your raw image to remove the background, hence increase the contrast of hair.

Your raw image (reverse each pixel by 255-I):

Background ( Open operation with the 20*20 all ones kernel, in order to remove the dark regions, along with the small, thin bright regions, only keep the large bright regions, which are viewed as the noisy background):

Subtract the background from the raw image, and binarize the output, you have:

Next I would do a dilation with the kernel:

[0 0 1;...
0 1 0;...
1 0 0]


Remove the small isolated object, you have:

Finally you extract the skeleton: