how to convert RGB to YIQ color space ?
이전 댓글 표시
hello sir, I am trying to convert an RGB image to YIQ color space, and convert it back to RGB. what is the correct way of converting into YUV color space to get Y I and Q component separately.
채택된 답변
추가 답변 (1개)
Image Processing Toolbox has rgb2ntsc() and ntsc2rgb() which do YIQ conversion without the need for anything external.
EDIT: rereading this, I noticed something I glossed over before.
what is the correct way of converting into YUV color space to get Y I and Q component separately.
Everyone seems to refer to all luma-chroma transformations using a random assortment of names as if they're all identical. That said, the question could be taken literally and it would be answerable despite YUV and YIQ not being completely interchangeable synonyms.
The two are simply related by a 33 degree rotation. You could convert into YUV and then calculate I and Q from UV:
rgbpict = imread('peppers.png');
% forward xform from RGB to BT601 YUV
A = [0.299 0.587 0.114; -0.14713 -0.28886 0.436; 0.615 -0.51499 -0.10001];
yuvpict = imapplymatrix(A,im2double(rgbpict));
% rotate chroma components from YUV to YIQ
[Y U V] = imsplit(yuvpict);
I = -sind(33)*U + cosd(33)*V;
Q = cosd(33)*U + sind(33)*V;
yiqpict = cat(3,Y,I,Q); % reassemble into a single array if desired
... or you could simply apply the rotation to A prior to conversion instead of to the entire image after conversion.
rgbpict = imread('peppers.png');
% rotate A instead of the entire YUV image
A = [0.299 0.587 0.114; -0.14713 -0.28886 0.436; 0.615 -0.51499 -0.10001]; % for RGB->YUV
R = [1 0 0; 0 -sind(33) cosd(33); 0 cosd(33) sind(33)]; % rotation
A = R*A % for RGB->YIQ
yiqpict = imapplymatrix(A,im2double(rgbpict)); % convert straight to YIQ
... but if you looked up the transformation matrix for YUV, you could have just looked up the one for YIQ instead.
rgbpict = imread('peppers.png');
% why not?
A = [0.299 0.587 0.114; 0.5959 -0.2746 -0.3213; 0.2115 -0.5227 0.3112];
yiqpict = imapplymatrix(A,im2double(rgbpict)); % convert straight to YIQ
... but remembering those matrices is a pain, so maybe just
rgbpict = imread('peppers.png');
yiqpict = rgb2ntsc(rgbpict); % convert straight to YIQ
카테고리
도움말 센터 및 File Exchange에서 Convert Image Type에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!