给定 R、G、B 三元组和因子 F,我如何计算“水印”?版本颜色?
我有一个 (R, G, B) 三元组,其中每种颜色都在 0.0 和 1.0 之间。给定因子 F(0.0 表示原始颜色,1.0 表示白色),我想计算一个新的三元组,即颜色的“水印”版本。
我使用以下表达式(伪代码):
for each c in R, G, B:
new_c ← c + F × (1 - c)
这会产生看起来不错的东西,但我知道这会引入颜色色调的偏差(检查转换前后的 HSV 等效项),我不知道这是否是可以预料的。
是否有“标准”(带或不带引号)算法来计算颜色的“水印”版本?如果有,是哪一个?如果没有,您能告诉我还有什么其他算法可以达到相同的效果吗?
I have an (R, G, B) triplet, where each color is between 0.0 and 1.0 . Given a factor F (0.0 means the original color and 1.0 means white), I want to calculate a new triplet that is the “watermarked” version of the color.
I use the following expression (pseudo-code):
for each c in R, G, B:
new_c ← c + F × (1 - c)
This produces something that looks okayish, but I understand this introduces deviations to the hue of the color (checking the HSV equivalent before and after the transformation), and I don't know if this is to be expected.
Is there a “standard” (with or without quotes) algorithm to calculate the “watermarked” version of the color? If yes, which is it? If not, what other algorithms to the same effect can you tell me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
实际上,这看起来应该给出正确的色调,减去算术舍入误差的小变化。
这当然是合理的,简单就是实现水印效果了。我不知道还有其他“标准”的,有几种方法可以做到。
替代方案是:
与白色混合,但在 F 上进行非线性混合,例如 new_c = c + sqrt(F)*(1-c),或者您可以使用其他非线性函数 - 它可能有助于水印看起来或多或少“平坦”。
您可以通过执行以下操作更有效地完成此操作(其中 F 取范围 0..INF):
对于实际像素值 (0..255),这将转换为:
不仅在整数算术中相当快,而且您可以能够以 32b 整数并行进行。
Actually this looks like it should give the correct hue, minus small variations for arithmetic rounding errors.
This is certainly a reasonable, simple was to achieve a watermark effect. I don't know of any other "standard" ones, there are a few ways you could do it.
Alternatives are:
Blend with white but do it non-linearly on F, e.g.
new_c = c + sqrt(F)*(1-c)
, or you could use other non-linear functions - it might help the watermark look more or less "flat".You could do it more efficiently by doing the following (where F takes the range 0..INF):
for real pixel values (0..255) this would convert into:
Not only is that reasonably fast in integer arithmetic, but you may be able to do it in a 32b integer in parallel.
为什么不只是?
我认为你应该首先检查水印像素并弄清楚它应该更暗还是更亮。
对于打火机,公式可能是
新_c=1-F*(c-1)
Why not just?
I think you should go first over watermarking pixels and figure out if it should be darker or lighter.
For lighter the formula might be
new_c=1-F*(c-1)