Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python PIL How do I convert 1 bit deep images to RGBA?

Exactly like the title. I take a single-band image of mode "1" and open it using

image = Image.open("picture.tif")

I then try to convert it to RGBA with

image.convert("RGBA")

And then whenever I check the mode of it using

print(image.mode)

I get that it's still "1". I've even tried this using "L" (which is another single-band image mode) and still no luck. No matter what I do, it won't convert. Searching the web only seems to reveal converting from "RGBA" to "1" but I haven't been able to find anything about the other way around. Is there ANY way (even outside Python) to convert 1 bit deep images to RGBA?

Help?

like image 797
TrentFaris242 Avatar asked Feb 20 '23 06:02

TrentFaris242


1 Answers

image.convert doesn't change the mode of the image, it returns a new image with the new mode.

image = image.convert("RGBA")

From the documentation:

Unless otherwise stated, all methods return a new instance of the Image class, holding the resulting image.

like image 94
Mark Ransom Avatar answered Feb 22 '23 05:02

Mark Ransom