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

问题描述

如果给定范围为 0-255 的红色、绿色和蓝色值,那么获得色调值的最快计算是什么?此公式将以 30fps(每秒 920 万次)的速度用于 640x480 图像的每个像素,因此每一点速度优化都会有所帮助.

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. 将 RGB 值转换为 0-1 范围,这可以通过将 8 位颜色深度的值除以 255 来完成(r、g、b - 是给定值):

  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

  • 求 R、G 和 B 的最小值和最大值.

  • Find the minimum and maximum values of R, G and B.

    最大值取决于 RGB 颜色通道.这三个不同的公式是:

    Depending on what RGB color channel is the max value. The three different formulas are:

    • 如果红色是最大值,则 Hue = (G-B)/(max-min)
    • 如果绿色是最大值,则 Hue = 2.0 + (B-R)/(max-min)
    • 如果蓝色为最大值,则 Hue = 4.0 + (R-G)/(max-min)

    你得到的 Hue 值需要乘以 60 才能转换成色环上的度数.如果 Hue 变成负数,你需要加上 360,因为一个圆有 360 度.

    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.

    这是全文.

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

  • 06-21 04:16