我想用RGB轉換成HLS或者HSV的格式 但是一開始怎么把RGB565的像素點轉換成值域為0-255的三原色值 求一個算法程序 最好有注釋
在線等 著急啊
下面是我把RGB轉成HLS的程序 可參考
int r, g, b;
int h, l, s;
int max, min, dif;
r = color_rgb->Red; //紅色
g = color_rgb->Green;//綠色
b = color_rgb->Blue; //藍色
max = maxOf3Values( r, g, b );
min = minOf3Values( r, g, b );
dif = max - min;
//計算l,亮度
l = ( max + min ) * 240 / 255 / 2;
//計算h,色度
if( max == min )//無定義
{
s = 0;
h = 0;
}
else
{
//計算色度
if( max == r )
{
if( min == b )//h介于0到40
{
h = 40 * ( g - b ) / dif;
}
else if( min == g )//h介于200到240
{
h = 40 * ( g - b ) / dif + 240;
}
}
else if( max == g )
{
h = 40 * ( b - r ) / dif + 80;
}
else if( max == b )
{
h = 40 * ( r - g ) / dif + 160;
}
//計算飽和度
if( l == 0 )
{
s = 0;
}
else if( l <= 120 )
{
s = dif * 240 / ( max + min );
}
else
{
s = dif * 240 / ( 480 - ( max + min ) );
}
}
color_hls->Hue = h; //色度
color_hls->Lightness = l; //亮度
color_hls->Saturation = s; //飽和度
注:程序來自網上資料
|