首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >胶片负RGB转换为正RGB的算法

胶片负RGB转换为正RGB的算法
EN

Stack Overflow用户
提问于 2015-11-19 00:49:34
回答 1查看 1.3K关注 0票数 4

假设我的摄影底片扫描为RGB图像,我试图找到一个算法,将颜色值转换为RGB正片。

由于橙色的偏倚( http://photo.net/learn/orange-negative-mask ),如果我简单地说redPositive =255-redNegative,我得到最后的图像,它有强烈的青色,并且被洗掉了。这意味着这里给出的答案是:Convert negative image to positive是不正确的。

那么,我将如何制作以下例程:

代码语言:javascript
复制
struct RGB
{
    unsigned byte red;
    unsigned byte green;
    unsigned byte blue;
};

void FilmNegativeToPositive(RGB const &negative, RGB &positive)
{
    // What goes here?
}
EN

回答 1

Stack Overflow用户

发布于 2015-11-19 01:32:52

我没有数据可供测试,但根据你给出的链接,负片是青、品红和黄色染料的混合物,它们是不纯的:

黄色的染料层是最纯净的。洋红染色层中含有明显的黄色。青染层中含有明显的黄色和洋红色。

因此,您需要这样做(未经测试的伪代码):

代码语言:javascript
复制
Let I_MY be the ratio of yellow impurity to pure magenta dye
Let I_CY be the ratio of yellow impurity to pure cyan dye
Let I_CM be the ratio of magenta impurity to pure cyan dye

Given R, G, B in [0, 255]
Convert to CMY:
  C = 1.0 - R/255.0
  M1 = 1.0 - G/255.0
  Y1 = 1.0 - B/255.0

Calculate the impurities in the cyan dye and remove them, since we assume no other dye has cyan impurities:
  M = M1 - I_CM×C
  Y2 = Y1 - I_CY×C

Now the amount of magenta dye is correct, so subtract its yellow impurity:
  Y = Y2 - I_MY×M

Convert the corrected CMY values back to RGB:
  R' = 255×(1.0-C)
  G' = 255×(1.0-M)
  B' = 255×(1.0-Y)

如果发现有比这更复杂的污染,你就会得到一个线性代数问题:

代码语言:javascript
复制
[   1 I_MC I_YC]   [C']   [C]
[I_CM    1 I_YM] × [M'] = [M]
[I_CY I_MY    1]   [Y']   [Y]

其中您想要求解C',M‘和Y',然后转换回RGB颜色空间。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33793359

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档