且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在HSV色彩空间中插值色调值?

更新时间:2023-01-27 11:17:03

out是从开始色调到结束色调的最短路径。这可以很容易地完成,因为色相值范围从0到255.

You should just need to find out which is the shortest path from starting hue to ending hue. This can be done easily since hue values range from 0 to 255.

您可以先从较高的色调中减去较低的色调,然后添加256到较低的色调,再次与交换操作数的差异。

You can first subtract the lower hue from the higher one, then add 256 to the lower one to check again the difference with swapped operands.

int maxCCW = higherHue - lowerHue;
int maxCW = (lowerHue+256) - higherHue;

所以你会得到两个值,大的一个决定你是顺时针还是逆时针。那么你必须找到一种方法使插值对色调的模256运算,所以如果你从 246 插入到 20 如果系数> = 0.5f ,您应该将hue重置为0(因为它达到256和 hue = hue%

So you'll obtain two values, the greater one decides if you should go clockwise or counterclockwise. Then you'll have to find a way to make the interpolation operate on modulo 256 of the hue, so if you are interpolating from 246 to 20 if the coefficient is >= 0.5f you should reset hue to 0 (since it reaches 256 and hue = hue%256 in any case).

实际上如果你不关心色调,而内插在0,但只是应用模运算符计算新的色调它应该工作。

Actually if you don't care about hue while interpolating over the 0 but just apply modulo operator after calculating the new hue it should work anyway.