· KLDP.org · KLDP.net · KLDP Wiki · KLDP BBS ·
색상변환

색상변환

YCbCr 와 RGB간의 근사치 비율공식 (보정하지 않은 공식)

Y = krR + kgG + kbB
Cr = R - Y
Cg = G - Y
Cb = B - Y


YCbCr 와 RGB간의 비율상수공식

1 = kb + kr + kg
kr = 0.299
kg = 0.587
kb = 0.114

Y = krR + (1 - kb - kr)G + kbB
Cb = 0.5(B - Y)/(1 - kb)
Cr = 0.5(R - Y)/(1 - kr)

R = Y + (1 - kr)Cr/0.5
G = Y - 2kb(1 - kb)Cb/(1 - kb - kr) - 2kr(1 - kr)Cr/(1 - kb - kr)
B = Y + (1 - kb)Cb/0.5


YCbCr 와 RGB 간의 kb,kr,kg 비율상수 적용후 정리된 공식

Y = 0.299R + 0.587G + 0.114B
Cb = 0.564(B - Y)
Cr = 0.713(R - Y)

R = Y + 1.402Cr
G = Y - 0.344Cb - 0.714Cr
B = Y + 1.772Cb


YCbCr 와 RGB간의 변환 공식을 "8:8:8" 포맷에 대하여 최적화한 공식

Y = 0.299R + 0.587G + 0.114B = 77R/256 + 150G/256 + 29B/256
Cb = -0.16874R - 0.33126Green + 0.5B = -(44R/256) - 87G/256 + 131B/256 +128
Cr = 0.5R - 0.41869G - 0.08131B = 131R/256 - 110G/256 + 21B/256 +128

R = Y + 1.402Cr = s_Y + (359Cr - 128)/256
G = Y - 0.34414Cb - 0.71414Cr = Y - (88Cb - 128)/256 - (183Cr - 128)/256
B = Y + 1.772Cb = s_Y + (454Cb - 128)/256


RGB(8:8:8) to YUV(YCbCr, 8:8:8)

공식
Y  =  0.29900Red + 0.58700Green + 0.11400Blue =   ( 77Red/256) + (150Green/256) + ( 29Blue/256)
Cb = -0.16874Red - 0.33126Green + 0.50000Blue = - ( 44Red/256) - ( 87Green/256) + (131Blue/256) {+128}
Cr =  0.50000Red - 0.41869Green - 0.08131Blue =   (131Red/256) - (110Green/256) + ( 21Blue/256) {+128}

구현
void RGB_YCbCr(int s_Red, int s_Green, int s_Blue, int *s_Y, int *s_Cb, int *s_Cr)
{ /* 변환과정에서 색감 손실이 약 5% 까지 발생 */
 s_Red &= 0xff, s_Green &= 0xff, s_Blue  &= 0xff;
 *s_Y  = (int)(  ((19595 * s_Red) >> 16) + ((38470 * s_Green) >> 16) + ((7471  * s_Blue) >> 16)       );
 *s_Cb = (int)( -((11059 * s_Red) >> 16) - ((21709 * s_Green) >> 16) + ((32768 * s_Blue) >> 16) + 128 );
 *s_Cr = (int)(  ((32768 * s_Red) >> 16) - ((27439 * s_Green) >> 16) - ((5329  * s_Blue) >> 16) + 128 );
 *s_Y  = (int)(  (*s_Y  > 0) ? *s_Y  : 0);  *s_Y  = (int)((*s_Y  < 255) ? *s_Y  : 255        );
 *s_Cb = (int)(  (*s_Cb > 0) ? *s_Cb : 0);  *s_Cb = (int)((*s_Cb < 255) ? *s_Cb : 255        );
 *s_Cr = (int)(  (*s_Cr > 0) ? *s_Cr : 0);  *s_Cr = (int)((*s_Cr < 255) ? *s_Cr : 255        );
}


YUV(YCbCr, 8:8:8) to RGB(8:8:8)

공식
Red   = 1.00000Y + 1.40200Cr             = s_Y + (359s_Cr{-128}/256)   
Green = 1.00000Y - 0.34414Cb - 0.71414Cr = s_Y - ( 88s_Cb{-128}/256) - (183s_Cr{-128}/256)
Blue  = 1.00000Y + 1.77200Cb             = s_Y + (454s_Cb{-128}/256)

구현
void YCbCr_RGB(int s_Y, int s_Cb, int s_Cr, int *s_Red, int *s_Green, int *s_Blue)
{ /* 변환과정에서 색감 손실이 약 5% 까지 발생 */
 s_Y &= 0xff, s_Cb &= 0xff, s_Cr &= 0xff;
 s_Cb -= 128;
 s_Cr -= 128;
 *(s_Red)   = (int)( s_Y + ((91881 *s_Cr)/65536) );
 *(s_Green) = (int)( s_Y - ((22554 *s_Cb)/65536) - ((46802*s_Cr)/65536) );
 *(s_Blue)  = (int)( s_Y + ((116130*s_Cb)/65536) );
}


실제 구현 예제소스

필자의 Color 변환 library 공개프로젝트 : [http]http://bbs.minzkn.com/viewtopic.php?t=478[]

ID
Password
Join
You like to form new friendships and make new acquaintances.


sponsored by andamiro
sponsored by cdnetworks
sponsored by HP

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2008-06-25 16:01:01
Processing time 0.0049 sec