Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to achieve the alpha matting algorithm using python

Tags:

python

alpha

I want to extract the foreground in image. I know that the grabcut can achieve it. But I want to use the alpha matting method. I'm searching the code that alpha matting algorithm by python and I can't find it. Can you help me? Thank you

like image 604
user3960019 Avatar asked Nov 09 '22 01:11

user3960019


1 Answers

I'm not aware of a tool you can use out of the box that does what you want, but here is a method you can use to implement alpha matting:

  1. I'd explore Pillow (Python Image Library fork).
  2. Specifically, I'd look into the .split() method found here, which splits the image into R, G,B, and A bands.
  3. From there you should be able to .filter() on the appropriate band to find edges and outline them.
  4. After recomposing/merging and saving the image, the result should be alpha matted.
like image 139
pygeek Avatar answered Nov 14 '22 22:11

pygeek