Produce a 4:2:2 sub sampled Y matrix, Cr matrix, Cb matrix for an image

552 Views Asked by At

I have write the matlab code below for to extract Y, Cb, Cr information from the picture:

img=imread('flowers.tif');
figure(1), imshow(img);title('original image');
Y=0.299*img(:,:,1)+0.587*img(:,:,2)+0.114*img(:,:,3);
Cb=-0.1687*img(:,:,1)-0.3313*img(:,:,2)+0.5*img(:,:,3)+128;
Cr=0.5*img(:,:,1)-0.4187*img(:,:,2)-0.0813*img(:,:,3)+128;

%print Y, Cb, Cr components

figure(2), subplot (1,3,1), imshow(Y), title('Y,Cb,Cr components'),
subplot(1,3,2), imshow(Cb),subplot(1,3,3), imshow(Cr);

But i dont know how i can change the code in order to produce a 4:2:2 sub-sampled Y,Cb,Cr. If i have 4:2:0 formay where i need to put the change?