Convert JPG from AdobeRGB to sRGB using PIL?

后端 未结 3 1505
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-13 19:15

How can I detect if the JPG is AdobeRGB and if it is convert it in python to sRGB JPG.

If that is possible in PIL, that would be great. Thank you.

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-13 20:20

    To program this yourself, you could convert pixels in the AdobeRGB colorspace to CIE XYZ, and then convert that to sRGB. PIL image objects have a method named convert() with the ability to apply a general matrix transformation to all the pixels in an image (see the section on Image.convert() in the the online documentation of the PIL Image module -- note the example showing the matrix values needed for going from RGB to XYZ).

    Section 4.3.4 in the AdobeRGB1998 .pdf spec shows a matrix for transforming XYZ into RGB.

    I'm not sure how to detect the colorspace of JPG images. I recall reading something about ICC xml profiles being attached to the end of the file (and a problem arising when there was more than one), but I can't vouch for its validity. The Wikipedia article on the JPEG file format says profiles are embedded.

提交回复
热议问题