Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Downsample chrominance components of images using matlab

I want to decompose an image to Y,Cb,Cr components and then to perform downsampling in YCbCr domain to form the 4:2:2 format.

Code for decomposition of the image to YCbCr:

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);

Now what i need to do to perform the down-sampling?

like image 267
20317 Avatar asked Jan 23 '26 06:01

20317


1 Answers

If by downsampling you specifically mean Chroma subsampling from 4:4:4 to 4:2:2, then one way to do it (and keep the original size of the channel) is to manually overwrite every other pixel with the previous value:

Cb(:, 2:2:end) = Cb(:, 1:2:end-1);
Cr(:, 2:2:end) = Cr(:, 1:2:end-1);

If you simply want to remove half of the columns, use:

Cb(:, 2:2:end) = [];
Cr(:, 2:2:end) = [];

Also in Matlab you don't need to write your own function for YCbCr conversion. Instead you can use rgb2ycbcr().

like image 146
Bee Avatar answered Jan 25 '26 03:01

Bee