Alpha 混合红色、蓝色和绿色图像以生成着色为任何 RGB 值的图像?

发布于 2024-08-17 09:47:23 字数 178 浏览 13 评论 0原文

基本上,我有一个上下文,我无法以编程方式对图像进行着色,尽管我可以更改它的 alpha 值。通过一些实验,我发现我可以使用特定的 alpha 值对图像的红色、蓝色和绿色版本进行分层,以产生各种颜色。但是我想知道是否可以通过这种方法实现真正​​的RGB表示?如果是这样,将 RGB 值转换为红色、蓝色和绿色层的不同 alpha 值的公式是什么?

Basically, I have a context where I can't programatically tint an image, though I can change it's alpha value. With some experimentation, I've found that I can layer a red, blue, and green version of the image, with specific alpha values, to produce a wide range of colors. However, I am wondering if it's possible to achieve a true RGB representation through this method? If so, what is the formula for converting an RGB value into different alpha values for the red, blue, and green layers.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

つ可否回来 2024-08-24 09:47:23

Alpha 组合的基本“方程”是:

alpha * (R1,G1,B1) + (1-alpha) * (R2,G2,B2)

当您有 3 个带有 Alpha 的图层时,您实际上组合了 4 个图层(第 4 个是黑色),因此最终颜色是:

alpha1 * (R1,G1,B1) + (1-alpha1) * ( 
   alpha2 * (R2,G2,B2) + (1-alpha2) * (
      alpha3 * (R3,G3,B3) + (1-alpha2) * (0,0,0) ) )

假设每个图层上都有相同的图像,并且第 1 层是红色通道 (G1=B1=0) 且第 2 层为绿色,第 3 层为蓝色,您将得到:

(alpha1 * R, (1-alpha1)*alpha2 * G, (1-alpha1)*(1-alpha2)*alpha3 * B)

对于白色像素,您可以采用任何可能的颜色。对于黑色像素,除了黑色之外你什么也做不了。对于任何其他像素,您都受到 R、G 和 B 值的限制。

假设您想在当前颜色为 (R, G, B) 的像素处实现 (Rd, Gd, Bd),那么您必须选择:

alpha1 = Rd/R
alpha2 = Gd/(G*(1-alpha1))
alpha3 = Bd/(B*(1-alpha1)*(1-alpha2))

问题是 alpha 通常只能在 0 和 1 之间。因此,例如,如果 Rd > R 你无能为力。

如果您可以控制混合功能(例如在 Photoshop 中),您可以做得更好。

The basic "equation" of alpha combination is:

alpha * (R1,G1,B1) + (1-alpha) * (R2,G2,B2)

When you have three layers with alpha you are actually combining 4 layers (the 4th one is black) so the final color is:

alpha1 * (R1,G1,B1) + (1-alpha1) * ( 
   alpha2 * (R2,G2,B2) + (1-alpha2) * (
      alpha3 * (R3,G3,B3) + (1-alpha2) * (0,0,0) ) )

Provided you have the same image on each layer and layer1 is the red channel (G1=B1=0) and layer2 is green and layer3 is blue you get:

(alpha1 * R, (1-alpha1)*alpha2 * G, (1-alpha1)*(1-alpha2)*alpha3 * B)

For a white pixel you can do any possible color. For a black pixel you cannot do anything but black. For any other pixel, you are restricted by the values of R, G and B.

Say you wanted to achieve (Rd, Gd, Bd) at a pixel where the current color is (R, G, B) then you would have to choose:

alpha1 = Rd/R
alpha2 = Gd/(G*(1-alpha1))
alpha3 = Bd/(B*(1-alpha1)*(1-alpha2))

The problem is that alpha can typically only be between 0 and 1. So, for example, if Rd > R there is nothing you can do.

You can do better if you can control the blending function (for example, in Photoshop).

征﹌骨岁月お 2024-08-24 09:47:23

如果我理解正确的话,我认为这是不可能的。

如果对于某个像素,图像的红色值为 0.5,则可以将其与(典型)范围 [0,1] 中的 alpha 结合起来,形成 0.5 以内的任何值(包括 0.5),但不能继续上面,得到例如 0.6 左右的输出值。

I don't think that's possible, if I understand you correctly.

If, for a certain pixel, your image's red value is, say, 0.5, you can combine that with an alpha in the (typical) range [0,1] to form any value up to and including 0.5, but you can't go above, to get e.g. 0.6 or so as the output value.

漫漫岁月 2024-08-24 09:47:23

如果您想要创建 3 个图层,将它们混合在一起形成原始图像,这是完全有可能的。下面是一个 Python 脚本的链接,该脚本调用 Paint Shop Pro 中的函数来完成困难的部分。

http://pixelnook.home.comcast.net/~pixelnook/SplitToRGB.htm< /a>

如果您需要更多详细信息,请发表评论,我稍后会尝试填写。

If you're looking to create 3 layers that blended together add up to the original image, it's quite possible. Here's a link to a Python script that calls functions in Paint Shop Pro to do the hard parts.

http://pixelnook.home.comcast.net/~pixelnook/SplitToRGB.htm

If you need more detail than that, leave a comment and I'll try to fill it in later.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文