Isolating a face

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Isolating a face

Post by Bonzo »

I have been working with some javascript face detection software and it works quite well but not 100%. So I have been thinking about changing to a method where the user clicks the top left of a face and bottom right and Imagemagick creates a box between those two points.
That got me thinking about the user clicking on a face and Imagemagick draws a box; but the problem with that is how big to draw the box? So taking this a step further if the user clicks on part of the face could imagemagick find the limits of that area/colour and I could build a box around those dimensions. I suppose I could use that as a mask and fill everything outside the mask say red and then trim but I am sure there must be a better way?

A sample face:
Image

I should say I am looking to do two things:
1/ Highlight the face in the original image with a red border around it.
2/ Crop the face and double the size
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Isolating a face

Post by fmw42 »

Is the face image always grayscale? If not then you need to find typical face tones. Anyway, you could click on the face and do a fuzzy flood fill to create a mask. I do not know how well that would work. If you crop the face with your two point solution, then the fuzzy floodfill might work better. You can then expand the mask to full size with appropriate offset.

OpenCV, I believe, has some facial detection software.

You might also research the literature online.

Also, you could threshold the image, then use -connected components to removal all but the largest white area to create a mask. If the image is large, you can shrink it first. Some morphology smoothing might help and you can convert to vector and then expand using potrace.

Also see user snibgo's page at http://im.snibgo.com/canny.htm where he gets the canny edges and processes them to extract a hand in the original image.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Isolating a face

Post by Bonzo »

In the older photos it is always greyscale but the newer ones would be colour. I could change the photo to greyscale to create the mask and use that on the colour version?

I did try -connected components on another project and will look at it again along with snibgo's link.

I am using some face detection code from http://liuliu.me/ccv/js/nss/ that seems to work well and you do not need all the dependencies that OpenCV does.
Post Reply