Continuing on my experimentations with face transformation algorithms, I was wondering if it was possible to detect and extract, with a certain accuracy, the hair of a person in a facial picture. I found two useful publications on the topic, Detection and Analysis of Hair (Yacoob and Davis, 2006), and Frequential and color analysis for hair mask segmentation (Rousset and Coulon, 2008). Their approaches are quite similar, and make use of color models, frequency filters and Gaussian kernels.
Based on these publications, I improved a bit the methods that they proposed by adding the use of the GrabCut algorithm. GrabCut does something similar to what the magic wand does in Photoshop: you feed it with some pixels, and it finds similar contiguous pixels. I am basically using the publications cited above to find some areas of the image that I am sure are hair. Then I feed these areas to GrabCut, and by iterating I can detect the hair with with more precision.
I implemented the whole thing in C++ with OpenCV. For GrabCut, I am using the implementation given in OpenCV, which is giving me good results. I have to admit however that I wouldn’t mind if it could be a bit faster.
I am planning to release the code under an open source license at some point, but I would need to clean it up a little before I do so. [EDIT: 2014-06-25: The code was licensed in a commercial application and thus will not be released] Below are some examples of results, using pictures from the IMM Face Database (click on the pictures to enlarge). The last example is particularly interesting, as it shows that the detection is also successful in case of absence of hair 🙂