gpt4 book ai didi

c++ - 将胶片负 RGB 转换为正 RGB 的算法

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:16:20 26 4
gpt4 key购买 nike

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

由于橙色偏差 (http://photo.net/learn/orange-negative-mask),如果我简单地说 redPositive = 255 - redNegative,我得到的最终图像具有强烈的青色色调,并且非常褪色。这意味着这里给出的答案:Convert negative image to positive 是正确的。

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

struct RGB
{
unsigned byte red;
unsigned byte green;
unsigned byte blue;
};

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

最佳答案

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

The yellow dye layer is the most pure. The magenta dye layer has a noticeable amount of yellow in it. The cyan dye layer has noticeable amounts of both yellow and magenta in it.

因此,您想做这样的事情(未经测试的伪代码):

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)

如果事实证明存在比这更复杂的污染,你就会遇到线性代数问题:

[   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 颜色空间。

关于c++ - 将胶片负 RGB 转换为正 RGB 的算法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33793359/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com