I have a JPEG image (which unfortunately I cannot share here) which I'm trying to re-save as PNG, while maintaining its color profile:
from PIL import Image
import numpy as np
pil_img = Image.open(path_to_jpeg)
# Some processing on the image...
np_img = np.array(pil_img)
Image.fromarray(np_img).save('/path/to/img.png', icc_profile=pil_img.info.get("icc_profile"))
Unfortunately, the colors change, so I assume the ICC profile is not saved correctly.
When switching to save a 'jpeg' then the colors are maintained correctly. But I do not wish to save as a jpeg.
Apparently the saving works OK, and PyCharm image viewer doesn't read the ICC profile correctly from the PNG files.
So just try to open the saved images with a different viewer (i.e. mac's viewer) and it would work just fine.