需要帮助了解 Alpha 通道
我有一个像素的 RGB 元组,我们将其称为 P。
(255, 0, 0) 是 P 的颜色,alpha 通道为 1.0。
当 Alpha 通道为 0.8 时,P 的颜色变为 (255, 51, 51)。
如何获取影响 P 颜色的像素颜色?
I have the RGB tuple of a pixel we'll call P.
(255, 0, 0) is the color of P with the alpha channel at 1.0.
With the alpha channel at 0.8, P's color becomes (255, 51, 51).
How can I get the color of the pixel that is influencing P's color?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
让我们从头开始吧。具有 Alpha 的像素只有在与其他内容混合时才有意义。如果您有一个带有 alpha 的上层 U 和一个完全不透明的下层 L,则方程为:
重新排列公式,您将得到:
显然,当 alpha 为 1.0 时,该方程没有意义,因为您需要除以为零。
代入数字后,像素 L 的 R=255、G=255 和 B=255。
按照惯例,图像中的最低层几乎都是白色的 (255,255,255),这几乎是普遍现象。
Let's start from the beginning. A pixel with alpha only makes sense when it is blended with something else. If you have an upper layer U with alpha and a lower layer L that is totally opaque, the equation is:
Rearranging the formula, you obtain:
Obviously the equation doesn't make sense when the alpha is 1.0, as you'd be dividing by zero.
Plugging your numbers in reveals that R=255, G=255, and B=255 for the pixel L.
It is almost universal that the lowest layer in an image will be all white (255,255,255) by convention.
只需查看您提供的数字即可:
其中:
这适合您的 B 和 G 通道例子。
因此,在一般情况下,它似乎是通道值(RGB)和背景颜色(在您的情况下为白色 - 255)之间的简单加权平均值。 Alpha 被用作权重。
下面是一些 Python 代码:
和一些输出:
尝试其他示例(特别是非白色背景)——可能就是这么简单。如果没有,请使用新示例编辑您的答案,我会再看一下。
Just looking at the numbers you provided:
Where:
This fits the B and G channels of your example.
So, in the general case, it seems to be a simple weighted average between the channel value (either of RGB) and the background color (in your case, white -- 255). Alpha is being used as the weight.
Here's some Python code:
And some output:
Try this for other examples (in particular, non-white backgrounds) -- it's probably that simple. If not, edit your answer with new examples, and I'll have another look.