【问题标题】:Convert a CMYK color to RGB using a color profile like ISO V2 Coated?使用 ISO V2 Coated 等颜色配置文件将 CMYK 颜色转换为 RGB?
【发布时间】:2017-06-23 22:52:45
【问题描述】:

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

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

有什么想法吗?

【问题讨论】:

    标签: javascript ruby-on-rails ruby web-services colors


    【解决方案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")
    

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

    Converting colors (not images) with ImageMagick

    【讨论】:

      【解决方案2】:

      我假设您为 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: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 的另一篇文章。

      【讨论】:

        猜你喜欢
        • 2011-01-26
        • 2014-04-13
        • 2013-01-22
        • 2019-02-08
        • 1970-01-01
        • 1970-01-01
        • 2013-01-28
        • 2011-11-04
        • 1970-01-01
        相关资源
        最近更新 更多