i=imread('cameraman.tif');
[r c]=size(i);
ID=double(i);
if(r==c)
N=c;
else
error('Error');
end
for u=0:N-1
for v=0:N-1
if(u==0)
c(u+1,v+1)=sqrt(1/N);
else
c(u+1,v+1)=sqrt(2/N)*cos(((2*v+1)*pi*u)/(2*N));
end
end
end
dct2=c*ID*(c');
subplot(1,3,1);
imshow(i);
title('Original image');
subplot(1,3,2);
imshow(uint8(dct2));
title('DCT of image');
dct2_inv=(c')*dct2*c;
subplot(1,3,3);
imshow(uint8(dct2_inv));
title('IDCT of image');
No comments:
Post a Comment