Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
638 views
in Technique[技术] by (71.8m points)

python - Conversion from CMYK to RGB with Pillow is different from that of Photoshop

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:WindowsSystem32spooldriverscolorUSWebCoatedSWOP.icc
C:Program Files (x86)Common FilesAdobeColorProfilesRecommendedUSWebCoatedSWOP.icc
C:Program Files (x86)AdobeAcrobat DCResourceColorProfilesRecommendedUSWebCoatedSWOP.icc

C:WindowsSystem32spooldriverscolorsRGB Color Space Profile.icm
C:Program Files (x86)Common FilesAdobeColorProfilesRecommendedsRGB Color Space Profile.icm
C:Program Files (x86)AdobeAcrobat DCResourceColorProfilesRecommendedsRGB Color Space Profile.icm

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...