Search code examples
pythonopencvimage-processingobject-detection

Obtaining binary mask of skin from bounding box


I have trained an object detection model to detect fingertips of hand. I have extracted the fingertips from the bounding box coordinates. Here is what I got:

enter image description here enter image description hereenter image description here

Now I want to get the binary mask from these images, which include only the region of fingertip. I have tried these approaches and did not get satisfactory results.

  • Used canny edge detector approach.
  • Used Grabcut approach.
  • Normalized image, then extracted h channel from HSV to find the largest contour.

I want to extract the fingertip region from these bounding boxes, I am currently lost, will appreciate any leads in the right direction.

EDIT Images with red background:

enter image description here enter image description here


Solution

  • You can opt for the LAB color space.

    One extreme of the A-channel identifies red color. Hence applying Otsu threshold on this extreme can isolate it pretty well.

    Code:

    img = cv2.imread('finger_1.png')
    
    # convert to LAB color space
    lab = cv2.cvtColor(img, cv2.COLOR_BGR2LAB)
    
    # apply Otsu threshold on A-channel
    th = cv2.threshold(lab[:,:,1], 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]
    

    Results:

    enter image description here enter image description here enter image description here

    As a further option, you can try normalizing the same A-channel and proceed further.

    Also have a look at this post on how to segment green color.