3

My goal is to draw a rectangle border around the face by removing the neck area connected to the whole face area. All positive values here represent skin color pixels. Here I have so far filtered out the binary image using OpenCV and python. Code so far skinid.py

Below is the test image.

enter image description here

Noise removals have also been applied to this binary image

enter image description here

Up to this point, I followed this paper Face segmentation using skin-color map in videophone applications. And for the most of it, I used custom functions rather than using built-in OpenCV functions because I kind of wanted to do it from scratch. (although some erosion, opening, closing were used to tune it up)

I want to know a way to split the neck from the whole face area and remove it like this,

enter image description here

as I am quite new to the whole image processing area.

nayab
  • 2,332
  • 1
  • 20
  • 34
melkorCba
  • 458
  • 5
  • 9
  • Are you looking for OpenCV functions to do the same thing you have achieved or you want to draw rectangles around the face as shown in most face detection tutorials? Please add some images to show what point you are starting from and what you expect as desired result. – Deepak Garud Jun 15 '20 at 07:22
  • no @DeepakGarud . I need to way to split the neck area I have already filtered out here. – melkorCba Jun 15 '20 at 07:39
  • 1
    You can find the width of the BoundingBox of the topmost element, multiply by about 1.5 and get the height of the face to the neck, starting from the top point. I think that in most cases this will work. – Alex Alex Jun 15 '20 at 14:54
  • Do you only care about this image or every image in a yearbook? – Sneaky Polar Bear Jun 15 '20 at 17:14
  • 1
    @SneakyPolarBear actually, this is just a single frame of a video I am working on. But the face is almost still throughout the whole video. (stays at same position). – melkorCba Jun 16 '20 at 16:06
  • Sounds good, feel free to post any frames giving you grief and your current code, if you get some but not all of the frames – Sneaky Polar Bear Jun 16 '20 at 19:03
  • @SneakyPolarBear I'm kind of stuck separating head part and hand into 2 images because the hand part is interfering with head detection. And I want to use that hand part later to detect palm along with the face detection. – melkorCba Jun 21 '20 at 12:56
  • The hand and arm shouldn't have much effect on a distance transform as they are narrow objects. Could you post an image/ result where the distance transform failed because of the hand? – Sneaky Polar Bear Jun 22 '20 at 13:40
  • 1
    Actually I did manage to do this in a bit different way. I used HSV color space and tweaks the threshold values and manage to get a clear separation head from the neck. [see this](https://imagehost.com.au//btnXq). Sorry for the delayed response, it was a busy week with a ton of assignments. And thanks for your help @SneakyPolarBear – melkorCba Jun 26 '20 at 17:49

1 Answers1

1

Perform a distance transform (built into opencv or you could write by hand its a pretty fun and easy one to write using the erode function iteratively, and adding the result into another matrix each round, lol slow but conceptually easy). On the binary image you presented above, the highest value in a distance transform (and tbh I think pretty generalized across any mug shots) will be the center of the face. So that pixel is the center of your box, but also that value (value of that pixel after the distance transform) will give you a pretty solid approx face size (since it is going to be the pixel distance from the center of the face to the horizontal edges of the face). Depending on what you are after, you may just be able to multiply that distance by say 1.5 or so (figure out standard face width to height ratio and such to choose your best multiplier), set that as your circle radius (or half side width for a box) and call it a day. Comment if you need anything clarified as I am pretty confident in this answer and would be happy to write up some quick code (in c++ opencv) if you need/ it would help.

(alt idea). You could tweak your color filter a bit to reject darker areas (this will at least in the image presented) create a nice separation between your face and neck due to the shadowing of the chin. (you may have to dial back your dilate/ closing op tho)

Sneaky Polar Bear
  • 1,611
  • 2
  • 17
  • 29