平滑颜色过渡算法 [英] Smooth color transition algorithm

查看:654
本文介绍了平滑颜色过渡算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个通用的算法来平滑地在两种颜色之间转换。

I am looking for a general algorithm to smoothly transition between two colors.

例如,此图像来自维基百科,并显示从橙色到蓝色的过渡。

For example, this image is taken from Wikipedia and shows a transition from orange to blue.

当我尝试使用我的代码(C ++)做同样的事情,第一个想法是使用HSV色彩空间,但是烦人的中间颜色显示。

When I try to do the same using my code (C++), first idea that came to mind is using the HSV color space, but the annoying in-between colors show-up.

img src =http://i.stack.imgur.com/0wmXK.pngalt =输入图片说明here>>

什么是好的办法实现这个?似乎与减少对比度有关,或者可能使用不同的颜色空间?

What is the good way to achieve this ? Seems to be related to diminution of contrast or maybe use a different color space ?

推荐答案

。平滑可以以许多不同的方式执行,但是他们可能在这里做的是一个简单的线性方法。这就是说,对于每个R,G和B分量,他们只是计算出连接两个点的y = m * x + b方程,并使用它来计算出两个分量之间的分量。

I have done tons of these in the past. The smoothing can be performed many different ways, but the way they are probably doing here is a simple linear approach. This is to say that for each R, G, and B component, they simply figure out the "y = m*x + b" equation that connects the two points, and use that to figure out the components in between.

m[RED]   = (ColorRight[RED]   - ColorLeft[RED])   / PixelsWidthAttemptingToFillIn
m[GREEN] = (ColorRight[GREEN] - ColorLeft[GREEN]) / PixelsWidthAttemptingToFillIn
m[BLUE]  = (ColorRight[BLUE]  - ColorLeft[BLUE])  / PixelsWidthAttemptingToFillIn

b[RED]   = ColorLeft[RED]
b[GREEN] = ColorLeft[GREEN]
b[BLUE]  = ColorLeft[BLUE]

之间的任何新颜色现在是:

Any new color in between is now:

NewCol[pixelXFromLeft][RED]   = m[RED]   * pixelXFromLeft + ColorLeft[RED]    
NewCol[pixelXFromLeft][GREEN] = m[GREEN] * pixelXFromLeft + ColorLeft[GREEN]
NewCol[pixelXFromLeft][BLUE]  = m[BLUE]  * pixelXFromLeft + ColorLeft[BLUE]

有许多数学方法来创建转换,我们真正想做的是了解你真正想要的转换看到。如果你想看到从上面的图像的确切转换,值得看看该图像的颜色值。我写了一个程序的方式回到时间来看这样的图像,并以图形输出值。这是我的程序的输出为上述pseudocolor标度。

There are many mathematical ways to create a transition, what we really want to do is understand what transition you really want to see. If you want to see the exact transition from the above image, it is worth looking at the color values of that image. I wrote a program way back in time to look at such images and output there values graphically. Here is the output of my program for the above pseudocolor scale.

基于查看图表,它比我上面所说的线性图更复杂。蓝色分量看起来大多是线性的,红色可以被模拟为线性,但是绿色看起来具有更圆的形状。我们可以执行绿色的数学分析,以更好地了解其数学函数,并使用它。你可能会发现,在像素70之后,在0和〜70像素之间具有线性递减斜率的线性插值是足够好的。

Based upon looking at the graph, it IS more complex than a linear as I stated above. The blue component looks mostly linear, the red could be emulated to linear, the green however looks to have a more rounded shape. We could perform mathematical analysis of the green to better understand its mathematical function, and use that instead. You may find that a linear interpolation with an increasing slope between 0 and ~70 pixels with a linear decreasing slope after pixel 70 is good enough.

如果你看底部这个程序给出了每个颜色分量的一些统计测量值,例如最小值,最大值和平均值,以及读取的图像宽度有多少像素。

If you look at the bottom of the screen, this program gives some statistical measures of each color component, such as min, max, and average, as well as how many pixels wide the image read was.

这篇关于平滑颜色过渡算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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