clear all
clc
I=imread('cameraman.tif');
imshow(I);
%I=rgb2gray(I);
I=im2double(I);
J=dct2(I);
J(abs(J)<0.1)=0;
Z=transpose(J);
[wi br]=size(Z);
i=wi;
j=br;
y=reshape(Z,1,(i*j));
[c b]=size(y);
j=1;
k=1;
m=1;
i=1;
while(i<=b)
a(m)=y(i);
if y(i)==0
count=1;
for k=i:1:b
y(b+1)=1;
if y(k)==y(k+1)
count=count+1;
else
break;
end
end
m=m+1;
a(m)=count;
i=i+count-1;
end
m=m+1;
i=i+1;
end
[c b]=size(a);
i=1;
m=1;
while(i<=b)
a1(m)=a(i);
if a(i)==0
for j=1:1:a(i+1)-1
m=m+1;
a1(m)=0;
end
i=i+1;
end
m=m+1;
i=i+1;
end
Z11=reshape(a1,wi,br);
Z11=transpose(Z11);
I2=idct2(Z11);
figure,imshow(I2);
[s1 s2]=size(I);
[x1 x2]=size(a);
CR=(s1*s2)/x2;
I3=imabsdiff(I,I2);
figure,imshow(I3);
MSE=mse(I3);