0

I have some pictures that I want to extract numerical value in RGB tuples using:

from PIL import Image
raw_data = np.array(Image.open("./image.jpg"))

However, I just realized that these images do not have build in icc profiles. In other words, when I use

Image.open("./image.jpg").info.get('icc_profile','')

I get None.

According to https://github.com/python-pillow/Pillow/issues/3270 , some cameras does not store color space into icc profile, instead it is stored into EXif file. I tried to print its exif.get(0xA001) and it is indeed in sRGB space.

However, I just wonder that when I use np.array(Image.open("./image.jpg")) to get the numerical value of this image, will PIL realize that this image is in sRGB space and do the conversion into RGB value automatically? (it seems that np.array(Image.open("./image.jpg")) and np.array(Image.open("./image.jpg").convert("RGB")) give me the same results) or I have to take the numerical values I get and do gamma correction formula to convert from sRGB to RGB values myself?

Thanks!

  • For first part, you may want to check https://stackoverflow.com/questions/50622180/does-pil-image-convertrgb-convert-images-to-srgb-or-adobergb . PS: instead of linking an image of gamma correction formula, why just not linking the section of Wikipedia article (were the formula was taken, so there are extra information, and link should be more stable) – Giacomo Catenazzi Oct 25 '21 at 07:04
  • Thanks Giacomo! I have updated the link. I do have noticed this question you listed here, however I do not really understand what it means by "When you use Image.convert('RGB') it just converts each pixel to the triple 8-bit value. So it fundamentally changes the mode of how image is represented and stored." Also, the next part basically talks about saving sRGB file, but I am still confused about how sRGB file is opened. – Patchouli_goo Oct 25 '21 at 14:07
  • The related question is only about profile. I have no idea on the linearization (and pillow documentation didn't help). Note: to store linear value, you need larger data (and preferably a half-float or large), or you risk to have artefacts when you convert back. – Giacomo Catenazzi Oct 25 '21 at 14:11
  • According to [Wikipedia](https://en.wikipedia.org/wiki/SRGB): *"If the color space of an image is unknown and it is an 8-bit image format, sRGB is usually the assumed default, and is a safe choice"*. There is no automatic conversion (in your case). PIL just assumes the color standard is sRGB. – Rotem Oct 25 '21 at 14:35

0 Answers0