开发者

adding/mixing colors in HSV Space

开发者 https://www.devze.com 2023-04-04 08:00 出处:网络
I\'ve been trying to get a visualisation going for a few days. I\'m generating a diffraction image and want to color it depending on the wavelength of light.

I've been trying to get a visualisation going for a few days. I'm generating a diffraction image and want to color it depending on the wavelength of light.

The easiest way to get the right color was by using the HSV space with H varying with the wavelength and S,V set to 1.0

Alas, I can't find a formula/algorithm/way to mix different colors in the HSV space.

Is there a formula for mixin开发者_开发百科g in HSV or maybe another comprehensible way?


Honestly, I'd convert the RGB, average the components and convert back to HSV.

It's not the most efficient way, but you'll presumably have or need RGB<->HSV code and the RGB calculation is likely to be much simpler.


One of the standard references Computer Graphics: Principles and Practice by Foley et al. has this to say in section 13.3.7 "Interpolating in Color Space":

"When two images are blended [...] the colors may be quite distant, and an additive model, such as RGB, is appropriate. If, on the other hand, the objective is to interpolate between two colors of fixed hue (or saturation) and to maintain the fixed hue (or saturation) for all interpolated colors, then HSV or HLS is preferable. But note that fixed-saturation interpolation in HSV or HSL is not seen as having fixed saturation by the viewer [...]"

So they agree with the suggestion of @andrewmu, which seems like the best suggestion in general.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号