RGB和HSV顏色空間的快速近似轉換演算法

2021-04-22 09:30:19 字數 755 閱讀 6625

rgb轉化到hsv的演算法:

max = max(r, g, b)

min = min(r, g, b)

if r = max, h = (g - b)/(max - min)

if g = max, h = 2 + (b - r)/(max - min)

if b = max, h = 4 + (r - g)/(max - min)

h = h * 60

if h < 0, h = h + 360

v = max(r, g, b)

s = (max - min)/max

hsv轉化到rgb的演算法

if s = 0

r = g = b = v

else

h /= 60

i = integer(h)

f = h - i

a = v * ( 1 - s )

b = v * ( 1 - s * f )

c = v * ( 1 - s * (1 - f ) )

switch(i)

case 0: r = v; g = c; b = a;

case 1: r = b; g = v; b = a;

case 2: r = a; g = v; b = c;

case 3: r = a; g = b; b = v;

case 4: r = c; g = a; b = v;

case 5: r = v; g = a; b = b;

RGB和HSV顏色空間

rgb顏色空間 rgb red,green,blue 顏色空間最常用的用途就是顯示器系統,彩色陰極射線管,彩色光柵圖形的顯示器都使用r g b數值來驅動r g b電子槍發射電子,並分別激發螢光屏上的r g b三種顏色的螢光粉發出不同亮度的光線,並通過相加混合產生各種顏色 掃瞄器也是通過吸收原稿經反射...

RGB顏色空間轉換為HSV空間顏色值

void rgb2hsv float r,float g,float b,float h,float s,float v if r max h g b delta between yellow magenta else if g max h 2 b r delta between cyan yell...

RGB到HSV顏色空間的轉換

opencv預設讀取影象是rgb通道,現需要轉化到hsv hue,saturation,value 顏色空間,opencv提供cvtcolor c void cvtcolor inputarray src,outputarray dst,int code,int dstcn 0 函式對顏色空間進行轉...