1

Foreground-extraction

I am extracting a person from its background and I am using cv2.grabcut for that. But sometimes the background pixels are misclassified as foreground hence the extraction is not perfect. I have attached the resultant image. How to improve this extraction?

Joel Jacob
  • 11
  • 3
  • 1
    You should provide the original image and minimal reproducing code. Otherwise we can only provide a few tips. – JoOkuma Aug 27 '20 at 11:46

1 Answers1

1

To improve the extraction you need to play with iterCount and mode parameters.

  • For instance:

I have the following image:


enter image description here

enter image description here

  • Can I improve by changing the iterCount?

    • iterCount=10, 20 (respectively)

    enter image description hereenter image description here

    • iterCount = 30, 40 (respectively)

    enter image description hereenter image description here

  • Can I improve by changing the modes?


    mode = GC_INIT_WITH_RECT, GC_INIT_WITH_MASK (respectively)

    enter image description here enter image description here

In my case GC_INIT_WITH_MASK works good, but I said you need to change parameters until the satisfactory result comes out.

Ahmet
  • 7,527
  • 3
  • 23
  • 47
  • Based on the code you provided, the mask was manually created using paint. I am looking for something that doesnt require manual intervention – Joel Jacob Aug 27 '20 at 10:08
  • You don't have to use GC_INIT_WITH_MASK, maybe GC_INIT_WITH_RECT works better – Ahmet Aug 27 '20 at 11:16
  • I am using GC_INIT_WITH_RECT only, as I am detecting the person through object detection and passing its coordinates to the grabcut for extraction – Joel Jacob Aug 27 '20 at 11:28