12

I need to convert an image from CMYK to RGB in python. I used Pillow in this way:

img = Image.open('in.jpg')
img = img.convert('RGB')
img.save('out.jpg')

The code works, but if I convert the same image with Photoshop I have a different result as shown below:-

a

The only operation done in photoshop is to change method from CMYK to RGB. Why there is this difference between the two RGB images? It can be a color profile problem?

Sardar Usama
  • 19,536
  • 9
  • 36
  • 58
grausof
  • 532
  • 3
  • 15
  • Jgeg images always use [YCbCr](https://en.wikipedia.org/wiki/YCbCr) as [color format](https://en.wikipedia.org/wiki/JPEG#Encoding) so this conversion is superfluous - it looks like photoshop knows this and doesnt touch the image but pillow naively compresses the image normally on saving (adding compression artifacts) – janbrohl Aug 09 '16 at 15:58
  • 2
    Also pillow possibly does not take an embedded [ICC profile](https://en.wikipedia.org/wiki/ICC_profile) into account changing the colors of the image a bit. – janbrohl Aug 09 '16 at 16:07

1 Answers1

16

SOLVED

The problem is that Pillow does not know the input ICC profile, while photoshop had one set as default.

Photoshop use for

CMYK: U.S. Web Coated (SWOP) v2

RGB: sRGB IEC61966-2.1

So I've solved in this way:

img = Image.open('in.jpg')
img = ImageCms.profileToProfile(img, 'USWebCoatedSWOP.icc', 'sRGB Color Space Profile.icm', renderingIntent=0, outputMode='RGB')
img.save('out.jpg', quality=100)

On Windows the profiles can be found (if installed) in these folders:

C:\Windows\System32\spool\drivers\color\USWebCoatedSWOP.icc
C:\Program Files (x86)\Common Files\Adobe\Color\Profiles\Recommended\USWebCoatedSWOP.icc
C:\Program Files (x86)\Adobe\Acrobat DC\Resource\Color\Profiles\Recommended\USWebCoatedSWOP.icc

C:\Windows\System32\spool\drivers\color\sRGB Color Space Profile.icm
C:\Program Files (x86)\Common Files\Adobe\Color\Profiles\Recommended\sRGB Color Space Profile.icm
C:\Program Files (x86)\Adobe\Acrobat DC\Resource\Color\Profiles\Recommended\sRGB Color Space Profile.icm
grausof
  • 532
  • 3
  • 15
  • I'm getting "cannot open profile file" error. I guess, I need these profile `*.icc` files. Where do I find them? – akinuri May 21 '18 at 07:22
  • 2
    I'm going to take liberty and add the paths to these profile files. Hope that's okay. – akinuri May 21 '18 at 07:31
  • If you do not already have them, you can download the Adobe profiles here: https://www.adobe.com/support/downloads/iccprofiles/iccprofiles_win.html – kgriffs May 01 '20 at 19:45
  • Also, note that on macOS you can get pretty close with the generic CMYK profile (under `/System/Library/ColorSync/Profiles/Generic CMYK Profile.icc` on Catalina) – kgriffs May 01 '20 at 19:47