色彩空間的轉換

2021-04-12 16:27:14 字數 1043 閱讀 6396

彩圖與灰度圖的相互轉換 rgb <-> gray:

rgb[a]->gray: y=0.212671*r + 0.715160*g + 0.072169*b

gray->rgb[a]:r=y g=y b=y a=0

rgb<=>xyz :

|x|   |0.412411  0.357585  0.180454| |r|

|y| = |0.212649  0.715169  0.072182|*|g|

|z|   |0.019332  0.119195  0.950390| |b|

|r|   | 3.240479  -1.53715  -0.498535| |x|

|g| = |-0.969256   1.875991  0.041556|*|y|

|b|   | 0.055648  -0.204043  1.057311| |z|

rgb<=>ycrcb

y=0.299*r + 0.587*g + 0.114*b

cr=(r-y)*0.713 + 128

cb=(b-y)*0.564 + 128

r=y + 1.403*(cr - 128)

g=y - 0.344*(cr - 128) - 0.714*(cb - 128)

b=y + 1.773*(cb - 128)

rgb=>hsv

v=max(r,g,b)

s=(v-min(r,g,b))*255/v   if v!=0, 0 otherwise

(g - b)*60/s,  if v=r

h= 180+(b - r)*60/s,  if v=g

240+(r - g)*60/s,  if v=b

若 h<0,則 h=h+360

使用上面從 0° 到 360° 變化的公式計算色調( hue)值,確保它們被 2 除后能試用於8位。 

色彩空間轉換

rgb轉換為yuv void rgb2yuv double r,double g,double b,double y,double u,double v yuv轉換為rgb void yuv2rgb double y,double u,double v,double r,double g,doubl...

色彩空間轉換

rgb轉換為yuv void rgb2yuv double r,double g,double b,double y,double u,double v yuv轉換為rgb void yuv2rgb double y,double u,double v,double r,double g,doubl...

色彩空間轉換

rgb轉換為yuv void rgb2yuv double r,double g,double b,double y,double u,double v yuv轉換為rgb void yuv2rgb double y,double u,double v,double r,double g,doubl...