Advance Digital Signal Processing
HW3
B97901181 陳亭妤
1. Write the Matlab program for the 4:2:0 image compression technique.
function de_im_rgb=C420(a)
b=rgb2ycbcr(a);
c=b(1:2:end,1:2:end,:);
compressedY=b(:,:,1);
compressedCb=c(:,:,2);
compressedCr=c(:,:,3);
de_Cb=zeros(size(a,1),size(a,2),1);
de_Cr=zeros(size(a,1),size(a,2),1);
%decompression
pic=c;
[r c d] = size(c);
de_im_rgb=uint8(zeros(floor(r*2),floor(c*2),d));
[nr nc nd]=size(de_im_rgb);
de_im_rgb(:,:,1)=compressedY;
for i = 1:nr;
for j = 1:nc;
x1 = floor(i/2);
x2 = ceil(i/2);
y1 = floor(j/2);
y2 = ceil(j/2);
x1(x1==0)=1;
y1(y1==0)=1;
x = rem(i/2,1);
y = rem(j/2,1);
de_im_rgb(i,j,2:3) =
(((pic(x2,y2,2:3)*y)+(pic(x2,y1,2:3)*(1-y)))*x)+(((pic(x1,y2,2:3)*
y)+(pic(x1,y1,2:3)*(1-y)))*(1-x));
end
end
de_im_rgb=ycbcr2rgb(de_im_rgb);
imwrite(de_im_rgb,'com_image.jpg');