Reputation: 29
I am trying to get an image with an alpha channel and a color profile of sRGB IEC61966-2.1.
The image I am starting with does not have an alpha channel but it does have the color profile I want. see starting image
If I run the following,
from PIL import Image
img = Image.open('84.png')
print(img.mode)
img.convert('RGBA').save('84a.png')
I get an alpha channel, but the color profile seems to be gone. see ending image. Note that img.mode is 'P'. I saw this solution, but I would like to do it without cv2 if possible. Also I think that solution is starting with an image that already has an alpha channel. Maybe it applies and I am missing something.
Thank you
Upvotes: 1
Views: 730
Reputation: 29
This solution helped to figure it out. All I did was find my desired *.icc file at /System/Library/ColorSync/Profiles/
. I copied it to my run directory and called it sRGB.icc
. Then I ran
from PIL import Image, ImageCms
img = Image.open('84.png').convert('RGBA')
img = ImageCms.profileToProfile(img, 'sRGB.icc', 'sRGB.icc', renderingIntent=0, outputMode='RGBA')
img.save('84a.png')
This gave me the alpha channel and color profile I wanted. However, it is a little 'hacky' since profileToProfile()
should convert from one profile to another. Python returns None
when I run Image.open('84.png').info.get('icc_profile')
so there seems to be no initial color profile recognized.
Upvotes: 1