how to convert RGB to YIQ color space ?

9 次查看(过去 30 天)
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.

采纳的回答

Thorsten
Thorsten 2014-12-2
编辑:Thorsten 2014-12-2
Hi Namita, there is a function on File Exchange that does a lot of color conversions that might be useful for you

更多回答(1 个)

DGM
DGM 2021-11-4
编辑:DGM 2023-5-12
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

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by