简体   繁体   English

在不改变颜色的情况下将 CMYK 转换为 RGB

[英]Convert CMYK to RGB without changing the color

there?那里? How can you convert an CMYK image in RGB image without changing the color of the picture: Current result:如何在不改变图片颜色的情况下将 CMYK 图像转换为 RGB 图像: 当前结果:

from PIL import Image
image = Image.open('img.jpg').convert('RGB')
image.save('out.jpg')

I am using this picture:我正在使用这张图片: 在此处输入图像描述

After conversion, I get the following result:转换后,我得到以下结果: 在此处输入图像描述

Try using ImageCms from PIL to do the profile conversion:尝试使用 PIL 中的 ImageCms 进行配置文件转换:

from PIL import Image
from PIL import ImageCms
import numpy

img_path = 'input.png'

def cmyk_to_rgb(cmyk_img):
    img = Image.open(cmyk_img)
    if img.mode == "CMYK":
        img = ImageCms.profileToProfile(img, "Color Profiles\\USWebCoatedSWOP.icc", "Color Profiles\\sRGB_Color_Space_Profile.icm", outputMode="RGB")
    return numpy.array(img)

orig_img = cmyk_to_rgb(str(img_path))
pilImage = Image.fromarray(orig_img)
pilImage.save('output.png')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM