本文介绍了最快的公式来从RGB色调得到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您将得到红,绿,以及从0-255的范围蓝色的值,这将是最快的计算得到公正的色调值?这个公式将在640×480图像的每个像素30fps的(920万次),所以速度优化的每一点帮助可以使用。我见过其他公式,但我不是很满意,他们多少步骤涉及。我在寻找一个实际的公式,而不是一个内置的库函数。


解决方案

    <$ P $号码: -
  1. 转换的RGB值的范围0-1,这可以通过除以255的数值为8位颜色深度(被给定的值的R,G,B)进行>
    R = R / 255 = 0.09
    G =克/ 255 = 0.38
    B = B / 255 = 0.46


  2. 查找R,G和B的最大值和最小值。


  3. 根据什么RGB颜色通道的最大值。三种不同的公式为:
    如果红色是最大值,则色相=(G-B)/(最大 - 最小)
    如果绿色是最大,那么色调= 2.0 +(B-R)/(最大值 - 最小值)
    如果蓝色是最大,那么色调= 4.0 +(R-G)/(最大值 - 最小值)

你需要的色调值60相乘将其转换成度上的颜色圈。如果色相为负则需要加360,因为一个圆有360度左右。

下面是。

If you are given red, green, and blue values that range from 0-255, what would be the fastest computation to get just the hue value? This formula will be used on every pixel of a 640x480 image at 30fps (9.2 million times a second) so every little bit of speed optimization helps. I've seen other formulas but I'm not happy with how many steps they involve. I'm looking for an actual formula, not a built in library function.

解决方案
  1. Convert the RGB values to the range 0-1, this can be done by dividing the value by 255 for 8-bit color depth (r,g,b - are given values):

    R = r / 255 = 0.09
    G = g / 255 = 0.38
    B = b / 255 = 0.46
  2. Find the minimum and maximum values of R, G and B.

  3. Depending on what RGB color channel is the max value. The three different formulas are:If Red is max, then Hue = (G-B)/(max-min)If Green is max, then Hue = 2.0 + (B-R)/(max-min)If Blue is max, then Hue = 4.0 + (R-G)/(max-min)

The Hue value you get needs to be multiplied by 60 to convert it to degrees on the color circle. If Hue becomes negative you need to add 360 to, because a circle has 360 degrees.

Here is full article.

这篇关于最快的公式来从RGB色调得到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 00:26