Created
December 8, 2016 12:07
-
-
Save AxelStrem/6a44d46d8b794240fbad3fde4d1a16f4 to your computer and use it in GitHub Desktop.
Separates color-keyed alpha channel from RGB source
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import PIL | |
import numpy as np | |
img = PIL.Image.open('in.bmp') | |
palette = img.getpalette() | |
alpha = palette[0:3] | |
palette[0:3] = (0,0,0) | |
img.putpalette(palette) | |
img.save('out.bmp') | |
palette[3:(256*3)] = (255,255,255)*255 | |
img.putpalette(palette) | |
img.save('alpha.bmp') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment