使用颜色配置文件(例如ISO V2 Coated)将CMYK颜色转换为RGB? [英] Convert a CMYK color to RGB using a color profile like ISO V2 Coated?

查看:899
本文介绍了使用颜色配置文件(例如ISO V2 Coated)将CMYK颜色转换为RGB?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这个问题已经通过几种不同的方式问过,但似乎与我的问题无关:我想将一种 CMYK 颜色准确地转换为 RGB 使用颜色配置文件,例如 ISO Coated V2 。我想这样做是因为直接进行数学转换会导致在 CMYK 颜色空间中无法实现亮色。

I know this question has been asked before several different ways but none seem relevant to my problem: I would like to convert a single CMYK color accurately to RGB using a color profile such as ISO Coated V2. I want to do it this way because straightforward mathematical conversions result in bright colors unachievable in the CMYK color space.

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

Ideally this can be achieved in Ruby but I would be happy to see a solution in pseudo code or even JavaScript. I would prefer to avoid a solution that relies on a proprietary/opaque framework.

有什么想法吗?

推荐答案

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

The following method performs CMYK/RGB color-managed conversion in the Ruby environment via ImageMagick:

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")

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

The foundation for this solution, along with more detail and context, can be found here:

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

这篇关于使用颜色配置文件(例如ISO V2 Coated)将CMYK颜色转换为RGB?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆