算法寻找颜色两个人之间 - 在涂色的色彩 [英] Algorithm for finding the color between two others - in the colorspace of painted colors

查看:246
本文介绍了算法寻找颜色两个人之间 - 在涂色的色彩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在混合蓝色和黄色的油漆,结果是某种类型的绿色的。

When mixing blue and yellow paint, the result is some sort of green.

我有两个RGB颜色:

蓝色=(0,0,255)

blue = (0, 0, 255)

和黄=(255,255,0)

and yellow = (255, 255, 0)

是什么算法查找RGB颜色是混合两种颜色的结果,因为它们将用油漆时出现?从算法所得的颜色不必是非常精确的。因为这上面的例子将只需要看起来像某种绿色的。

What is the algorithm for finding the rgb color that is the result of mixing the two colors, as they would appear when using paint? The resulting colors from the algorithm does not have to be terribly exact. For the example above it would only have to look like some sort of green.

在此先感谢。

编辑::此功能,写的围棋,为我工作的基础上,从LAC答案

This function, written in Go, worked for me, based on the answer from LaC.

func paintMix(c1, c2 image.RGBAColor) image.RGBAColor { 
    r := 255 - ((255 - c1.R) + (255 - c2.R))
    g := 255 - ((255 - c1.G) + (255 - c2.G))
    b := 255 - ((255 - c1.B) + (255 - c2.B))
    return image.RGBAColor{r, g, b, 255}
}

编辑#2 Allthought这个管理混合青色和黄色,蓝色和黄色的搭配变成了黑色,这似乎并不正确。我还在找工作的算法。

Edit #2 Allthought this manages to mix cyan and yellow, the mix between blue and yellow becomes black, which doesn't seem right. I'm still looking for a working algorithm.

编辑#3 下面是围棋中的一个完整的工作示例,使用HLS色彩: HTTP ://go.pastie.org/1976031 。感谢马克赎金。

Edit #3 Here's a complete working example in Go, using the HLS colorspace: http://go.pastie.org/1976031. Thanks Mark Ransom.

编辑#4 这似乎是前进的方向为更好的色彩混合将使用库贝尔卡-Munk公式

Edit #4 It seems like the way forward for even better color mixing would be to use the Kubelka-Munk equation

推荐答案

漆作品吸收。你开始用白色光(255,255,255)和吸收的因素相乘。

Paint works by absorption. You start with white light (255,255,255) and multiply it by the absorption factors.

蓝色油漆吸收所有红色和绿色的光,击中它。

Blue paint absorbs all red and green light that hits it.

黄颜料吸收所有蓝光击中它。

Yellow paint absorbs all blue light that hits it.

在一个完美的世界,这意味着相结合的黄色和蓝色的油漆会导致黑漆,或者充其量是一个泥泞的灰色。在实践中,蓝色漆具有对绿色的偏见,所以你得到一个泥泞的绿色。我从来没有见过混合黄色和产生令人满意的蓝绿色的一个例子。维基进入一些这种过程的复杂性:<一href="http://en.wikipedia.org/wiki/Primary_color#Subtractive_primaries">http://en.wikipedia.org/wiki/Primary_color#Subtractive_primaries

In a perfect world, that means that combining yellow and blue paint would result in black paint, or at best a muddy gray. In practice the "blue" paint has a bias towards green, so you get a muddy green. I've never seen an example of mixing yellow and blue that produces a satisfactory green. Wikipedia goes into some of the complexities of this process: http://en.wikipedia.org/wiki/Primary_color#Subtractive_primaries

我觉得你真正问的是如何插值颜色沿着色轮。这应该是独立的颜色是否吸收如在油漆,或发射如在RGB显示器

I think what you are really asking is how to interpolate colors along a color wheel. This should be independent of whether the colors are absorptive as in paint, or emissive as in RGB displays.

编辑:通过在HSL颜色空间中工作,你可以得到的那种你正在寻找的结果。下面是一些code在Python实现算法;平均色调是棘手的,而且是基于矿一个previous答案平均角度的。

By working in the HSL color space you can get the kind of results you're looking for. Here's some code in Python that implements the algorithm; averaging hues is tricky, and is based on a previous answer of mine for averaging angles.

from colorsys import rgb_to_hls,hls_to_rgb
from math import sin,cos,atan2,pi

def average_colors(rgb1, rgb2):
    h1, l1, s1 = rgb_to_hls(rgb1[0]/255., rgb1[1]/255., rgb1[2]/255.)
    h2, l2, s2 = rgb_to_hls(rgb2[0]/255., rgb2[1]/255., rgb2[2]/255.)
    s = 0.5 * (s1 + s2)
    l = 0.5 * (l1 + l2)
    x = cos(2*pi*h1) + cos(2*pi*h2)
    y = sin(2*pi*h1) + sin(2*pi*h2)
    if x != 0.0 or y != 0.0:
        h = atan2(y, x) / (2*pi)
    else:
        h = 0.0
        s = 0.0
    r, g, b = hls_to_rgb(h, l, s)
    return (int(r*255.), int(g*255.), int(b*255.))

>>> average_colors((255,255,0),(0,0,255))
(0, 255, 111)
>>> average_colors((255,255,0),(0,255,255))
(0, 255, 0)

请注意,这个答案确实的不可以模拟调漆,为上述原因。相反,它给出了一个未在任何物理世界的现实接地颜色的直观的混合

Note that this answer does not emulate paint mixing, for the reasons stated above. Rather it gives an intuitive mixing of colors that is not grounded in any physical world reality.

这篇关于算法寻找颜色两个人之间 - 在涂色的色彩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆