使用ISO V2 Coated等颜色配置文件将CMYK颜色转换为RGB?

我知道在几种不同的方式之前已经问过这个问题,但似乎与我的问题无关:我想使用ISO Coated V2等颜色配置文件将单个CMYK颜色精确地转换为RGB 。 我想这样做,因为直接的数学转换会导致CMYK色彩空间无法实现的明亮色彩。

区别:真正的青色和RGB青色

理想情况下,这可以在Ruby中实现,但我很乐意看到伪代码甚至JavaScript的解决方案。 我宁愿避免使用依赖于专有/不透明框架的解决方案 。

有任何想法吗?

以下方法通过ImageMagickRuby环境中执行CMYK/RGB颜色管理转换:

 def convert_cmyk_to_rgb_with_profiles(cmyk, profile_1, profile_2) c = MiniMagick::Tool::Convert.new c_255 = (cmyk[:c].to_f / 100.0 * 255.0).to_i m_255 = (cmyk[:m].to_f / 100.0 * 255.0).to_i y_255 = (cmyk[:y].to_f / 100.0 * 255.0).to_i k_255 = (cmyk[:k].to_f / 100.0 * 255.0).to_i c.xc("cmyk(#{c_255}, #{m_255}, #{y_255}, #{k_255})") c.profile(File.open("lib/assets/profiles/#{profile_1}.icc").path) c.profile(File.open("lib/assets/profiles/#{profile_2}.icc").path) c.format("%[pixel:up{0,0}]\n", "info:") result = c.call srgb_values = /srgb\(([0-9.]+)%,([0-9.]+)%,([0-9.]+)%\)/.match(result) r = (srgb_values[1].to_f / 100.0 * 255.0).round g = (srgb_values[2].to_f / 100.0 * 255.0).round b = (srgb_values[3].to_f / 100.0 * 255.0).round return { r: r, g: g, b: b } end 

致电:

 convert_cmyk_to_rgb_with_profiles({c:100, m:0, y:0, k:0}, "USWebCoatedSWOP", "sRGB_IEC61966-2-1_black_scaled") 

此解决方案的基础以及更多详细信息和上下文可在此处找到:

使用ImageMagick转换颜色(不是图像)

我假设您为CMYK显示的值是百分比(100/0/0/0)。 在Imagemagick命令行中,您可以执行以下操作来制作样本

 convert xc:"cmyk(100%,0%,0%,7%)" -profile /Users/fred/images/profiles/ISOcoated_v2_300_eci.icc -profile /Users/fred/images/profiles/sRGB.icc -scale 100x100! test.png 

在此处输入图像描述

或者您可以按如下方式获取值:

 convert xc:"cmyk(100%,0%,0%,7%)" -profile /Users/fred/images/profiles/ISOcoated_v2_300_eci.icc -profile /Users/fred/images/profiles/sRGB.icc -format "%[pixel:up{0,0}]\n" info: 

的sRGB(0%,61%,81%)

如果您想要的值范围为0到255而不是%,则添加-depth 8。

 convert xc:"cmyk(100%,0%,0%,7%)" -profile /Users/fred/images/profiles/ISOcoated_v2_300_eci.icc -profile /Users/fred/images/profiles/sRGB.icc -depth 8 -format "%[pixel:up{0,0}]\n" info: 

的sRGB(0156207)

您也可以从0到255之间的值开始。

 convert xc:"cmyk(255,0,0,17.85)" -profile /Users/fred/images/profiles/ISOcoated_v2_300_eci.icc -profile /Users/fred/images/profiles/sRGB.icc -depth 8 -format "%[pixel:up{0,0}]\n" info: 

的sRGB(0156207)

你可以通过RMagick做到这一点,但我不是RMagick的专家。 但请参阅sambecker的另sambecker