%采用矩阵变换型计算YUV
img = imread('Airplane.jpg');
[m n dim]=size(img);
R = img(:,:,1);
G = img(:,:,2);
B = img(:,:,3);
Y = zeros(m,n);
U = zeros(m,n);
V = zeros(m,n);
trans_mat = [0.1826 0.6142 0.0620;
-0.1006 -0.3386 0.4392;
0.4392 -0.3989 -0.0403];
RU = double(R);
GU = double(G);
BU = double(B);
for i = 1:m
for j = 1:n
img_temp = trans_mat*[RU(i,j);
GU(i,j);
BU(i,j)];
Y(i,j) = img_temp(1)+16;
U(i,j) = img_temp(2)+128;
V(i,j) = img_temp(3)+128;
end
end
Y = uint8(Y);
U = uint8(U);
V = uint8(V);
subplot(221),imshow(Y);title('Y')
subplot(222),imshow(U);title('U')
subplot(223),imshow(V);title('V')