I would like to analyze close-up images of human hair. My goal is to detect and count the number of hair strands and determine their width, but I am having a hard time binarizing the image. Seems like there is too much noise. Any suggestions ?

Image is below: enter image description here

I used the following code and got a result that does not detect all the hairs:

arm2 = ColorNegate[DeleteSmallComponents[Binarize[arm, 0.42]]]

enter image description here

  • $\begingroup$ You should try to take the image. Run ReplacePixelValue and change all of the values that have Pixel Values you know are not hair to plain white so Binarize would have an easier time to distinguish. Make sure that you also account the fact that the edges of the hair ends will be lighter than the center. Let me know how it goes. Good Luck. I will try it on my own later on if you don't get it. $\endgroup$
    – mildused
    Commented Jul 12, 2014 at 23:58
  • 1
    $\begingroup$ This or this may be related. Searching for related questions is recommended. $\endgroup$ Commented Jul 13, 2014 at 0:53
  • $\begingroup$ I already saw the first link and didn't have luck using their code. Thanks for the second link. I'll look into it. $\endgroup$ Commented Jul 14, 2014 at 15:57

1 Answer 1


This appears to work nicely:

DeleteSmallComponents @ LocalAdaptiveBinarize[ColorNegate[img], 10, {1, 1, 0.02}]

enter image description here

  • 4
    $\begingroup$ might be worth mentioning that LocalAdaptiveBinarize is new for version 10... $\endgroup$
    – cormullion
    Commented Jul 13, 2014 at 9:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.