1

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

amv_23
  • 29
  • 5
  • Does this answer your question? [PIL/Pillow decode icc profile information](https://stackoverflow.com/questions/31865743/pil-pillow-decode-icc-profile-information) – HansHirse Mar 30 '21 at 07:31
  • Hello @HansHirse, I tried that as well. However, for some reason when I run `Image.open(path).info.get('icc_profile')` on my image I get `None` – amv_23 Mar 30 '21 at 08:20

1 Answers1

1

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.

amv_23
  • 29
  • 5