Reputation: 2413
I have several images that claim to have a transparent background but are actually white. I'd like to use Python Image Library/PIL to set that white background color to actually be transparent.
Since PNG uses an alpha channel, I'd love to create the alpha channel by finding contiguous areas of white from the edges of the image (so I don't get "holes" of transparency when the image contains white data).
Any tips on how to create the alpha channel this way?
Upvotes: 0
Views: 1068
Reputation: 38749
I'd guess you'd want to run across the image in a spiral from the outside, setting a pixel to transparent if it is white, and a pixel further towards the edge is also white transparent. Stop once you've done a whole circle without changing any pixels.
Shouldn't be too difficult to write such a loop.
Do some kind of flood fill, seeded from the white edge pixels.
Upvotes: 2