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

时间:2021-03-14 15:46:17

标签: python image opencv python-imaging-library

那里!如何在不改变图片颜色的情况下将 CMYK 图像转换为 RGB 图像? 当前结果:

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

我正在使用这张图片: enter image description here

转换后,我得到以下结果: enter image description here

1 个答案:

答案 0 :(得分:1)

尝试使用 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')
相关问题