使用像ISO V2 Coated这样的色彩配置文件将CMYK颜色转换为RGB?

3
我知道这个问题以多种不同的方式被问过,但似乎都与我的问题无关:我想使用颜色配置文件(如ISO Coated V2)将单个CMYK颜色精确地转换为RGB。我想以这种方式做是因为简单的数学转换结果会产生在CMYK颜色空间中无法实现的鲜艳颜色。

The difference between: Real Cyan and RGB Cyan

理想情况下,这可以通过Ruby实现,但是我很高兴看到伪代码或甚至JavaScript的解决方案。我更喜欢避免依赖于专有/不透明框架的solution 有什么建议吗?
2个回答

1
以下方法通过 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:u.p{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转换颜色(而不是图像)


0

我假设你展示的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

enter image description here

或者你可以按照以下方式获取返回值:

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:u.p{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:u.p{0,0}]\n" info:


srgb(0,156,207)

您也可以使用介于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:u.p{0,0}]\n" info:


srgb(0,156,207)

你可以通过RMagick来实现这个,但我不是RMagick的专家。不过可以看看sambecker的其他帖子。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接