I'm trying to make a jpeg compressor and found a bit of code which supposedly donwsamples the chrominance of an image but I don't understand how it achieves this.
x = 2
pic = imread("picture.jpg");
pic_ycbcr = rgb2ycbcr(pic); %convert rgb image to equivalent Y, Cb, Cr values
pic_downSampled = pic_ycbcr;
pic_downSampled(:,:,2) = x*round(pic_downSampled(:,:,2)/x);
pic_downSampled(:,:,3) = x*round(pic_downSampled(:,:,3)/x);
It is the final two lines which I don't understand.
It is difficult to notice the downsampling when x = 2 but when using higher values of x and converting pic_downSampled back to rgb and comparing it against the original image you can clearly see differences in the image.
I even took a small section of the picture to compare the chroma values in the matrix before and after the downsampling but there's only minor changes to the values which are just being caused by the round function which is why I really don't understand how this is downsampling anything or how it would make the size of an image smaller.