MarcoForte / closed-form-matting

Python implementation of A. Levin D. Lischinski and Y. Weiss. A Closed Form Solution to Natural Image Matting. IEEE Conf. on Computer Vision and Pattern Recognition (CVPR), June 2006, New York
MIT License
435 stars 107 forks source link

“scribles input" mode does not get a good alpha map #14

Closed kkkmax closed 5 years ago

kkkmax commented 5 years ago

I use the same command:

Python closed_form_matting.py testdata/input_1.jpg testdata/scribles_1.jpg -o testdata/out_1.jp

hello g

The background area is marked with black, and the foreground area is marked with white, but the resulting picture looks like a grayscale image. Do I ignore any details?

wyshmily commented 5 years ago

I got the same problem as @kkkmax test1
test1_scribble image

image

shyyhs commented 5 years ago

I got almost the same problem as this image image image

Also, use the flower in the testdata but with slightly different scribbles will also cause this problem.

merofeev commented 5 years ago

This issue involves at least two problems:

  1. Small changes to pixel values during scribbles image creation. For example here is the actual difference between input image and scribbles image used by @shyyhs:
    cv2.imwrite('vis.png', cv2.imread('scribbles.png') - cv2.imread('image.png'))

    vis As you can see a lot of pixels have changed values. This might happen due to using of lossy compression for scribbles image (e.g. jpeg was used by @kkkmax and @wyshmily). Another possible source of these issue is color profile conversion in image editor.

I have tried adding scribbles with Gimp to image provided by @shyyhs and saving image with scribbles to png and haven't experienced these issue.

  1. Another issue is not perfectly white and black pixels. If you use brush tool with smooth edge to add scribbles, pixels around stroke edges will not be perfectly white/black. I believe that scribbles image from @wyshmily has such pixels. The current version of code can't play well with such pixels. I have submitted PR #15 to fix this.

To summarize:

  1. Use lossless compression (e.g. png) for scribbles image
  2. Use tool with hard edge (e.g. pencil) to draw scribbles
  3. Consider using trimap input instead of scribbles. The trimap is much more robust way to supply user-input to matting.