我试图像PhotoShop一样调整HSV色彩空间。
我尝试了什么:
RGB到HSV,它似乎是一个正确的步骤。但我发现HSV调整是一个谎言。无论我尝试调整hue \ saturation \ Bright,结果都不等于PS。
最后,我改变主意去改造HSL,得到了相同的结果。但是在S小于V(RGB到HSV)的情况下结果是正确的。
当S大于V时,PS中还有另一种情况,饱和度会随着光的变化而变化(RGB到HSL),它是我无法进行模拟的非线性关系。 / p>
步骤:
RGB到HSL;
RGB到HSV;
代码逻辑......
if(HSV.S less than HSV.V);
Adjust HSL; //H range = -180 to180, Sat = -1 to 1, Light = -1 to 1;
功能
if(S or L less than 0)
_S=S+S*Op;
_L=L+L*Op;
else
_S=S+(1-S)*Op
_L=L+(1-L)*Op
HSL TO RGB
如果(HSV.S超过HSV.V)
Nonlinear relation //If add L value,the S will be reduce.
HLSL代码:
//RGB to HSL
Color.xyz=RGB_TO_HSL(Color.xyz);
//Adjustment of increment
//x ~hue [-180,180]
//y ~saturation [-1,1]or[-100%,100%]
//z ~bright [-1,1]or[-100%,100%]
float3 Op = HSVOperate[basehsv].xyz;
//H
float Flag = Color.x;
Color.x += Op.x;
if (Color.x > 360)
Color.x -= 360;
else if(Color.x<0)
Color.x += 360;
//S
float Gap = Max - Min;
float S, V;
if (Max == 0)
S = 0;
else
S = Gap / Max;
V = Max;
if (S <=V){
if (Op.z<0)
Color.z = Color.z + Color.z*Op.z;
else
Color.z = Color.z + (1 - Color.z)*Op.z;
if (Op.y < 0)
Color.y = Color.y + Color.y*Op.y;
else
Color.y = Color.y + (1 - Color.y)*Op.y;
}
else if(S >V){
// process Blue as same as S<V; I don't know why result was
// correct.
if (Flag <= 270 && Flag > 210)
{
if (Op.z<0)
Color.z = Color.z + Color.z*Op.z;
else
Color.z = Color.z + (1 - Color.z)*Op.z;
if (Op.y < 0)
Color.y = Color.y + Color.y*Op.y;
else
Color.y = Color.y + (1 - Color.y)*Op.y;
}
else
{
// Add directly for Saturation
Color.z = Color.z +Op.z;
if (Color.y > 1)
Color.y = 1;
if(Color.y<0)
Color.y = 0;
//But bright will has a influence to Saturation
// ?
// ? I can't simulate the relation using matlab,
// Because different S and V,different relation.
}
}
//L
Color.xyz=HSL_TO_RGB(Color.xyz);