Wavelet Fractal compression

by

 

21 Apr 2007 (Updated )

it is proposed an efficient approach for compression microarray images. It is utilized a hybrid wave

wavelet_fractal_compressor.m
clc
clear
close all
ty = clock;

%%%%%%%%%%%%%%% You Must insert a picture in the "c:\cdna.tif" root which
%%%%%%%%%%%%%%% has more than 512 to 512 size
%%%%% you migh download such these picture from California University site
        
X=double((imread('c:\cdna.tif')));
X=imcrop(X,[80 80 511 511]);
%%%%%%%%%%%%%% Compressed Process  %%%%%%%%%%%%%%%%
[cA1,cH1,cV1,cD1] = dwt2( X,'Haar' );
[cA2,cH2,cV2,cD2] = dwt2(cA1,'Haar');
[cA3,cH3,cV3,cD3] = dwt2(cA2,'Haar');
[cA4,cH4,cV4,cD4] = dwt2(cA3,'Haar');
[cA5,cH5,cV5,cD5] = dwt2(cA4,'Haar');
[cA6,cH6,cV6,cD6] = dwt2(cA5,'Haar');
[M N]=size(cA1);

%%%%%%%%%%%%%%%%%%%%%%%%%%%  Search  %%%%%%%%%%%%%%%%%%%%%%%%%%%%
sizL1=8;
sizL2=4;
sizL3=2;
sizL4=1;

ss=-2;
iii=1
for k=0:31,    
jjj=1;
for h=0:31,  


for kk=0:15,    
for hh=0:15,

%%%%%%%%%%%%%%%%%%%%%%% S Calculation %%%%%%%%%%%%%%%%%%%%% sssV
sssV1(kk+1,hh+1)=sum(sum((cV2(sizL1*kk+1:sizL1*kk+sizL1,sizL1*hh+1:sizL1*hh+sizL1)...
    .*cV1(sizL1*k+1:sizL1*k+sizL1,sizL1*h+1:sizL1*h+sizL1) )))/sum(sum(...
    cV2(sizL1*kk+1:sizL1*kk+sizL1,sizL1*hh+1:sizL1*hh+sizL1).*cV2(sizL1*kk+1:sizL1*kk+sizL1,sizL1*hh+1:sizL1*hh+sizL1)));

sssV2(kk+1,hh+1)=sum(sum((cV3(sizL2*kk+1:sizL2*kk+sizL2,sizL2*hh+1:sizL2*hh+sizL2)...
    .*cV2(sizL2*k+1:sizL2*k+sizL2,sizL2*h+1:sizL2*h+sizL2) )))/sum(sum(...
    cV3(sizL2*kk+1:sizL2*kk+sizL2,sizL2*hh+1:sizL2*hh+sizL2).*cV3(sizL2*kk+1:sizL2*kk+sizL2,sizL2*hh+1:sizL2*hh+sizL2)));

sssV3(kk+1,hh+1)=sum(sum((cV4(sizL3*kk+1:sizL3*kk+sizL3,sizL3*hh+1:sizL3*hh+sizL3)...
    .*cV3(sizL3*k+1:sizL3*k+sizL3,sizL3*h+1:sizL3*h+sizL3) )))/sum(sum(...
    cV4(sizL3*kk+1:sizL3*kk+sizL3,sizL3*hh+1:sizL3*hh+sizL3).*cV4(sizL3*kk+1:sizL3*kk+sizL3,sizL3*hh+1:sizL3*hh+sizL3)));

sssV4(kk+1,hh+1)=sum(sum((cV5(sizL4*kk+1:sizL4*kk+sizL4,sizL4*hh+1:sizL4*hh+sizL4)...
    .*cV4(sizL4*k+1:sizL4*k+sizL4,sizL4*h+1:sizL4*h+sizL4) )))/sum(sum(...
    cV5(sizL4*kk+1:sizL4*kk+sizL4,sizL4*hh+1:sizL4*hh+sizL4).*cV5(sizL4*kk+1:sizL4*kk+sizL4,sizL4*hh+1:sizL4*hh+sizL4)));
  


%%%%%%%%%%%%%%%%%%%%%%% S Calculation %%%%%%%%%%%%%%%%%%%%% sssH
sssH1(kk+1,hh+1)=sum(sum((cH2(sizL1*kk+1:sizL1*kk+sizL1,sizL1*hh+1:sizL1*hh+sizL1)...
    .*cH1(sizL1*k+1:sizL1*k+sizL1,sizL1*h+1:sizL1*h+sizL1) )))/sum(sum(...
    cH2(sizL1*kk+1:sizL1*kk+sizL1,sizL1*hh+1:sizL1*hh+sizL1).*cH2(sizL1*kk+1:sizL1*kk+sizL1,sizL1*hh+1:sizL1*hh+sizL1)));

sssH2(kk+1,hh+1)=sum(sum((cH3(sizL2*kk+1:sizL2*kk+sizL2,sizL2*hh+1:sizL2*hh+sizL2)...
    .*cH2(sizL2*k+1:sizL2*k+sizL2,sizL2*h+1:sizL2*h+sizL2) )))/sum(sum(...
    cH3(sizL2*kk+1:sizL2*kk+sizL2,sizL2*hh+1:sizL2*hh+sizL2).*cH3(sizL2*kk+1:sizL2*kk+sizL2,sizL2*hh+1:sizL2*hh+sizL2)));

sssH3(kk+1,hh+1)=sum(sum((cH4(sizL3*kk+1:sizL3*kk+sizL3,sizL3*hh+1:sizL3*hh+sizL3)...
    .*cH3(sizL3*k+1:sizL3*k+sizL3,sizL3*h+1:sizL3*h+sizL3) )))/sum(sum(...
    cH4(sizL3*kk+1:sizL3*kk+sizL3,sizL3*hh+1:sizL3*hh+sizL3).*cH4(sizL3*kk+1:sizL3*kk+sizL3,sizL3*hh+1:sizL3*hh+sizL3)));

sssH4(kk+1,hh+1)=sum(sum((cH5(sizL4*kk+1:sizL4*kk+sizL4,sizL4*hh+1:sizL4*hh+sizL4)...
    .*cH4(sizL4*k+1:sizL4*k+sizL4,sizL4*h+1:sizL4*h+sizL4) )))/sum(sum(...
    cH5(sizL4*kk+1:sizL4*kk+sizL4,sizL4*hh+1:sizL4*hh+sizL4).*cH5(sizL4*kk+1:sizL4*kk+sizL4,sizL4*hh+1:sizL4*hh+sizL4)));


%%%%%%%%%%%%%%%%%%%%%%% S Calculation %%%%%%%%%%%%%%%%%%%%% sssD
sssD1(kk+1,hh+1)=sum(sum((cD2(sizL1*kk+1:sizL1*kk+sizL1,sizL1*hh+1:sizL1*hh+sizL1)...
    .*cD1(sizL1*k+1:sizL1*k+sizL1,sizL1*h+1:sizL1*h+sizL1) )))/sum(sum(...
    cD2(sizL1*kk+1:sizL1*kk+sizL1,sizL1*hh+1:sizL1*hh+sizL1).*cD2(sizL1*kk+1:sizL1*kk+sizL1,sizL1*hh+1:sizL1*hh+sizL1)));

sssD2(kk+1,hh+1)=sum(sum((cD3(sizL2*kk+1:sizL2*kk+sizL2,sizL2*hh+1:sizL2*hh+sizL2)...
    .*cD2(sizL2*k+1:sizL2*k+sizL2,sizL2*h+1:sizL2*h+sizL2) )))/sum(sum(...
    cD3(sizL2*kk+1:sizL2*kk+sizL2,sizL2*hh+1:sizL2*hh+sizL2).*cD3(sizL2*kk+1:sizL2*kk+sizL2,sizL2*hh+1:sizL2*hh+sizL2)));

sssD3(kk+1,hh+1)=sum(sum((cD4(sizL3*kk+1:sizL3*kk+sizL3,sizL3*hh+1:sizL3*hh+sizL3)...
    .*cD3(sizL3*k+1:sizL3*k+sizL3,sizL3*h+1:sizL3*h+sizL3) )))/sum(sum(...
    cD4(sizL3*kk+1:sizL3*kk+sizL3,sizL3*hh+1:sizL3*hh+sizL3).*cD4(sizL3*kk+1:sizL3*kk+sizL3,sizL3*hh+1:sizL3*hh+sizL3)));

sssD4(kk+1,hh+1)=sum(sum((cD5(sizL4*kk+1:sizL4*kk+sizL4,sizL4*hh+1:sizL4*hh+sizL4)...
    .*cD4(sizL4*k+1:sizL4*k+sizL4,sizL4*h+1:sizL4*h+sizL4) )))/sum(sum(...
    cD5(sizL4*kk+1:sizL4*kk+sizL4,sizL4*hh+1:sizL4*hh+sizL4).*cD5(sizL4*kk+1:sizL4*kk+sizL4,sizL4*hh+1:sizL4*hh+sizL4)));


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    
diffV1(kk+1,hh+1,((4*ss+8)+1))=...             %%%%%%%% DOMAIN POOL                           RANGE BLOCKS   %%%%%%%%%%
sum(sum(abs( -sssV1(kk+1,hh+1)*cV2(sizL1*kk+1:sizL1*kk+sizL1,sizL1*hh+1:sizL1*hh+sizL1)+cV1(sizL1*k+1:sizL1*k+sizL1,sizL1*h+1:sizL1*h+sizL1) )));
diffV2(kk+1,hh+1,((4*ss+8)+1))=... 
sum(sum(abs( -sssV2(kk+1,hh+1)*cV3(sizL2*kk+1:sizL2*kk+sizL2,sizL2*hh+1:sizL2*hh+sizL2)+cV2(sizL2*k+1:sizL2*k+sizL2,sizL2*h+1:sizL2*h+sizL2) )));
diffV3(kk+1,hh+1,((4*ss+8)+1))=... 
sum(sum(abs( -sssV3(kk+1,hh+1)*cV4(sizL3*kk+1:sizL3*kk+sizL3,sizL3*hh+1:sizL3*hh+sizL3)+cV3(sizL3*k+1:sizL3*k+sizL3,sizL3*h+1:sizL3*h+sizL3) )));
diffV4(kk+1,hh+1,((4*ss+8)+1))=... 
sum(sum(abs( -sssV4(kk+1,hh+1)*cV5(sizL4*kk+1:sizL4*kk+sizL4,sizL4*hh+1:sizL4*hh+sizL4)+cV4(sizL4*k+1:sizL4*k+sizL4,sizL4*h+1:sizL4*h+sizL4) )));

diffH1(kk+1,hh+1,((4*ss+8)+1))=...
sum(sum(abs( -sssH1(kk+1,hh+1)*cH2(sizL1*kk+1:sizL1*kk+sizL1,sizL1*hh+1:sizL1*hh+sizL1)+cH1(sizL1*k+1:sizL1*k+sizL1,sizL1*h+1:sizL1*h+sizL1) )));
diffH2(kk+1,hh+1,((4*ss+8)+1))=...
sum(sum(abs( -sssH2(kk+1,hh+1)*cH3(sizL2*kk+1:sizL2*kk+sizL2,sizL2*hh+1:sizL2*hh+sizL2)+cH2(sizL2*k+1:sizL2*k+sizL2,sizL2*h+1:sizL2*h+sizL2) )));
diffH3(kk+1,hh+1,((4*ss+8)+1))=...
sum(sum(abs( -sssH3(kk+1,hh+1)*cH4(sizL3*kk+1:sizL3*kk+sizL3,sizL3*hh+1:sizL3*hh+sizL3)+cH3(sizL3*k+1:sizL3*k+sizL3,sizL3*h+1:sizL3*h+sizL3) )));
diffH4(kk+1,hh+1,((4*ss+8)+1))=...
sum(sum(abs( -sssH4(kk+1,hh+1)*cH5(sizL4*kk+1:sizL4*kk+sizL4,sizL4*hh+1:sizL4*hh+sizL4)+cH4(sizL4*k+1:sizL4*k+sizL4,sizL4*h+1:sizL4*h+sizL4) )));

diffD1(kk+1,hh+1,((4*ss+8)+1))=...
sum(sum(abs( -sssD1(kk+1,hh+1)*cD2(sizL1*kk+1:sizL1*kk+sizL1,sizL1*hh+1:sizL1*hh+sizL1)+cD1(sizL1*k+1:sizL1*k+sizL1,sizL1*h+1:sizL1*h+sizL1) )));
diffD2(kk+1,hh+1,((4*ss+8)+1))=...
sum(sum(abs( -sssD2(kk+1,hh+1)*cD3(sizL2*kk+1:sizL2*kk+sizL2,sizL2*hh+1:sizL2*hh+sizL2)+cD2(sizL2*k+1:sizL2*k+sizL2,sizL2*h+1:sizL2*h+sizL2) )));
diffD3(kk+1,hh+1,((4*ss+8)+1))=...
sum(sum(abs( -sssD3(kk+1,hh+1)*cD4(sizL3*kk+1:sizL3*kk+sizL3,sizL3*hh+1:sizL3*hh+sizL3)+cD3(sizL3*k+1:sizL3*k+sizL3,sizL3*h+1:sizL3*h+sizL3) )));
diffD4(kk+1,hh+1,((4*ss+8)+1))=...
sum(sum(abs( -sssD4(kk+1,hh+1)*cD5(sizL4*kk+1:sizL4*kk+sizL4,sizL4*hh+1:sizL4*hh+sizL4)+cD4(sizL4*k+1:sizL4*k+sizL4,sizL4*h+1:sizL4*h+sizL4) )));

end
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  V1
[nnV1 ekkV1]=min(min(min(diffV1)));
[rtV1 yuV1]=min((diffV1(:,:,ekkV1)));
[eeV1 rrV1]=min(rtV1);
epV1=yuV1(rrV1);

xV1(iii,jjj)=epV1;
yV1(iii,jjj)=rrV1;
ssV1(iii,jjj)=sssV1(xV1(iii,jjj),yV1(iii,jjj));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  V2
[nnV2 ekkV2]=min(min(min(diffV2)));
[rtV2 yuV2]=min((diffV2(:,:,ekkV2)));
[eeV2 rrV2]=min(rtV2);
epV2=yuV2(rrV2);

xV2(iii,jjj)=epV2;
yV2(iii,jjj)=rrV2;
ssV2(iii,jjj)=sssV2(xV2(iii,jjj),yV2(iii,jjj));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  V3
[nnV3 ekkV3]=min(min(min(diffV3)));
[rtV3 yuV3]=min((diffV3(:,:,ekkV3)));
[eeV3 rrV3]=min(rtV3);
epV3=yuV3(rrV3);

xV3(iii,jjj)=epV3;
yV3(iii,jjj)=rrV3;
ssV3(iii,jjj)=sssV3(xV3(iii,jjj),yV3(iii,jjj));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  V4
[nnV4 ekkV4]=min(min(min(diffV4)));
[rtV4 yuV4]=min((diffV4(:,:,ekkV4)));
[eeV4 rrV4]=min(rtV4);
epV4=yuV4(rrV4);

xV4(iii,jjj)=epV4;
yV4(iii,jjj)=rrV4;
ssV4(iii,jjj)=sssV4(xV4(iii,jjj),yV4(iii,jjj));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% D1
[nnD1 ekkD1]=min(min(min(diffD1)));
[rtD1 yuD1]=min((diffD1(:,:,ekkD1)));
[eeD1 rrD1]=min(rtD1);
epD1=yuD1(rrD1);

xD1(iii,jjj)=epD1;
yD1(iii,jjj)=rrD1;
ssD1(iii,jjj)=sssD1(xD1(iii,jjj),yD1(iii,jjj));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  D2
[nnD2 ekkD2]=min(min(min(diffD2)));
[rtD2 yuD2]=min((diffD2(:,:,ekkD2)));
[eeD2 rrD2]=min(rtD2);
epD2=yuD2(rrD2);

xD2(iii,jjj)=epD2;
yD2(iii,jjj)=rrD2;
ssD2(iii,jjj)=sssD2(xD2(iii,jjj),yD2(iii,jjj));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  D3
[nnD3 ekkD3]=min(min(min(diffD3)));
[rtD3 yuD3]=min((diffD3(:,:,ekkD3)));
[eeD3 rrD3]=min(rtD3);
epD3=yuD3(rrD3);

xD3(iii,jjj)=epD3;
yD3(iii,jjj)=rrD3;
ssD3(iii,jjj)=sssD3(xD3(iii,jjj),yD3(iii,jjj));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  D4
[nnD4 ekkD4]=min(min(min(diffD4)));
[rtD4 yuD4]=min((diffD4(:,:,ekkD4)));
[eeD4 rrD4]=min(rtD4);
epD4=yuD4(rrD4);

xD4(iii,jjj)=epD4;
yD4(iii,jjj)=rrD4;
ssD4(iii,jjj)=sssD4(xD4(iii,jjj),yD4(iii,jjj));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  H1
[nnH1 ekkH1]=min(min(min(diffH1)));
[rtH1 yuH1]=min((diffH1(:,:,ekkH1)));
[eeH1 rrH1]=min(rtH1);
epH1=yuH1(rrH1);

xH1(iii,jjj)=epH1;
yH1(iii,jjj)=rrH1;
ssH1(iii,jjj)=sssH1(xH1(iii,jjj),yH1(iii,jjj));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  H2
[nnH2 ekkH2]=min(min(min(diffH2)));
[rtH2 yuH2]=min((diffH2(:,:,ekkH2)));
[eeH2 rrH2]=min(rtH2);
epH2=yuH2(rrH2);

xH2(iii,jjj)=epH2;
yH2(iii,jjj)=rrH2;
ssH2(iii,jjj)=sssH2(xH2(iii,jjj),yH2(iii,jjj));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  H3
[nnH3 ekkH3]=min(min(min(diffH3)));
[rtH3 yuH3]=min((diffH3(:,:,ekkH3)));
[eeH3 rrH3]=min(rtH3);
epH3=yuH3(rrH3);

xH3(iii,jjj)=epH3;
yH3(iii,jjj)=rrH3;
ssH3(iii,jjj)=sssH3(xH3(iii,jjj),yH3(iii,jjj));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  H4
[nnH4 ekkH4]=min(min(min(diffH4)));
[rtH4 yuH4]=min((diffH4(:,:,ekkH4)));
[eeH4 rrH4]=min(rtH4);
epH4=yuH4(rrH4);

xH4(iii,jjj)=epH4;
yH4(iii,jjj)=rrH4;
ssH4(iii,jjj)=sssH4(xH4(iii,jjj),yH4(iii,jjj));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



jjj=jjj+1;
end
iii=iii+1
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  LOGARITHM PROCESS  %%%%%%%%%%%%%%%%%%%%%
ssH1=ssH1*10000;
ssH2=ssH2*10000;
ssH3=ssH3*10000;
ssH4=ssH4*10000;

ssD1=ssD1*10000;
ssD2=ssD2*10000;
ssD3=ssD3*10000;
ssD4=ssD4*10000;

ssV1=ssV1*10000;
ssV2=ssV2*10000;
ssV3=ssV3*10000;
ssV4=ssV4*10000;





M=32;
N=32;
for i=1:32,
    for j=1:32,
       if ssH1(i,j)>0, ssH1(i,j)=2^(round(log2(ssH1(i,j)))); SH1(i,j)=1;end
       if ssH1(i,j)<0, ssH1(i,j)=-2^(round(log2(-ssH1(i,j))));SH1(i,j)=0; end
       
       if ssD1(i,j)>0, ssD1(i,j)=2^(round(log2(ssD1(i,j))));SD1(i,j)=1; end
       if ssD1(i,j)<0, ssD1(i,j)=-2^(round(log2(-ssD1(i,j))));SD1(i,j)=0; end
       
       
       
       if ssV1(i,j)>0, ssV1(i,j)=2^(round(log2(ssV1(i,j))));SV1(i,j)=1; end
       if ssV1(i,j)<0, ssV1(i,j)=-2^(round(log2(-ssV1(i,j)))); SV1(i,j)=0;end
    end
end


for i=1:32,
    for j=1:32,
          if ssH2(i,j)>0, ssH2(i,j)=2^(round(log2(ssH2(i,j)))); SH2(i,j)=1;end
          if ssH2(i,j)<0, ssH2(i,j)=-2^(round(log2(-ssH2(i,j)))); SH2(i,j)=0;end
         
          if ssD2(i,j)>0, ssD2(i,j)=2^(round(log2(ssD2(i,j)))); SD2(i,j)=1;end
          if ssD2(i,j)<0, ssD2(i,j)=-2^(round(log2(-ssD2(i,j)))); SD2(i,j)=0;end
       
          if ssV2(i,j)>0, ssV2(i,j)=2^(round(log2(ssV2(i,j)))); SV2(i,j)=1;end
          if ssV2(i,j)<0, ssV2(i,j)=-2^(round(log2(-ssV2(i,j)))); SV2(i,j)=0;end
    end
end

for i=1:32,
    for j=1:32,        
        if ssH3(i,j)>0, ssH3(i,j)=2^(round(log2(ssH3(i,j))));SH3(i,j)=1; end
        if ssH3(i,j)<0, ssH3(i,j)=-2^(round(log2(-ssH3(i,j))));SH3(i,j)=0; end
       
        if ssD3(i,j)>0, ssD3(i,j)=2^(round(log2(ssD3(i,j)))); SD3(i,j)=1;end
        if ssD3(i,j)<0, ssD3(i,j)=-2^(round(log2(-ssD3(i,j))));SD3(i,j)=0; end
        
        if ssV3(i,j)>0, ssV3(i,j)=2^(round(log2(ssV3(i,j)))); SV3(i,j)=1;end
        if ssV3(i,j)<0, ssV3(i,j)=-2^(round(log2(-ssV3(i,j)))); SV3(i,j)=0;end
       
    end
end

 

for i=1:32,
    for j=1:32, 
       if ssH4(i,j)>0, ssH4(i,j)=2^(round(log2(ssH4(i,j))));SH4(i,j)=1; end
       if ssH4(i,j)<0, ssH4(i,j)=-2^(round(log2(-ssH4(i,j))));SH4(i,j)=0; end
       
       if ssD4(i,j)>0, ssD4(i,j)=2^(round(log2(ssD4(i,j)))); SD4(i,j)=1;end
       if ssD4(i,j)<0, ssD4(i,j)=-2^(round(log2(-ssD4(i,j))));SD4(i,j)=0; end
       
       if ssV4(i,j)>0, ssV4(i,j)=2^(round(log2(ssV4(i,j)))); SV4(i,j)=1;end
       if ssV4(i,j)<0, ssV4(i,j)=-2^(round(log2(-ssV4(i,j))));SV4(i,j)=0; end
    end
end

   
ssH1=ssH1/10000;
ssH2=ssH2/10000;
ssH3=ssH3/10000;
ssH4=ssH4/10000;

ssD1=ssD1/10000;
ssD2=ssD2/10000;
ssD3=ssD3/10000;
ssD4=ssD4/10000;

ssV1=ssV1/10000;
ssV2=ssV2/10000;
ssV3=ssV3/10000;
ssV4=ssV4/10000;

Encode_Process_Time_as_Second=etime(clock, ty)
%%%%%%%%%%%%%%%%%%%%%%%%%%% Reconstrunction Process %%%%%%%%%%%%%%%%%%%%%%%%%%%% 
%%%%%%%%%%%%%%% SENT PARAM:ssH,ssV,ssD--xH,yH,xD,yD,xV,yV
ty = clock;
erw=1;
XI=zeros(512*erw);
for i=1:512*erw,
    for j=1:128*erw,
        XI(i,j)=255;
    end
end
Rreconstructed_Image=XI;

sizL1=8;
sizL2=4;
sizL3=2;
sizL4=1;


for iteration=1:10,   
   
XI=Rreconstructed_Image;
%%%%%%%%%%%%%% DeCompressed Process  %%%%%%%%%%%%%%%%
[cA1I,cH1I,cV1I,cD1I] = dwt2( XI,'Haar' );
[cA2I,cH2I,cV2I,cD2I] = dwt2(cA1I,'Haar');
[cA3I,cH3I,cV3I,cD3I] = dwt2(cA2I,'Haar');
[cA4I,cH4I,cV4I,cD4I] = dwt2(cA3I,'Haar');
[cA5I,cH5I,cV5I,cD5I] = dwt2(cA4I,'Haar');
[cA6I,cH6I,cV6I,cD6I] = dwt2(cA5I,'Haar');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  Reconstructing Process   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for k=0:31,    %%% 0 ~ 7  %%%
for h=0:31,    %%% 0 ~ 7  %%%
    
kH1=xH1(k+1,h+1)-1;
hH1=yH1(k+1,h+1)-1;

kH2=xH2(k+1,h+1)-1;
hH2=yH2(k+1,h+1)-1;

kH3=xH3(k+1,h+1)-1;
hH3=yH3(k+1,h+1)-1;

kH4=xH4(k+1,h+1)-1;
hH4=yH4(k+1,h+1)-1;
cH1R(sizL1*k+1:sizL1*k+sizL1,sizL1*h+1:sizL1*h+sizL1)=ssH1(k+1,h+1)*cH2I(sizL1*kH1+1:sizL1*kH1+sizL1,sizL1*hH1+1:sizL1*hH1+sizL1);
cH2R(sizL2*k+1:sizL2*k+sizL2,sizL2*h+1:sizL2*h+sizL2)=ssH2(k+1,h+1)*cH3I(sizL2*kH2+1:sizL2*kH2+sizL2,sizL2*hH2+1:sizL2*hH2+sizL2);
cH3R(sizL3*k+1:sizL3*k+sizL3,sizL3*h+1:sizL3*h+sizL3)=ssH3(k+1,h+1)*cH4I(sizL3*kH3+1:sizL3*kH3+sizL3,sizL3*hH3+1:sizL3*hH3+sizL3);
cH4R(sizL4*k+1:sizL4*k+sizL4,sizL4*h+1:sizL4*h+sizL4)=ssH4(k+1,h+1)*cH5I(sizL4*kH4+1:sizL4*kH4+sizL4,sizL4*hH4+1:sizL4*hH4+sizL4);
% cH5R(sizL5*k+1:sizL5*k+sizL5,sizL5*h+1:sizL5*h+sizL5)=ssH(k+1,h+1)*cH6I(sizL5*kH+1:sizL5*kH+sizL5,sizL5*hH+1:sizL5*hH+sizL5);



kD1=xD1(k+1,h+1)-1;
hD1=yD1(k+1,h+1)-1;

kD2=xD2(k+1,h+1)-1;
hD2=yD2(k+1,h+1)-1;

kD3=xD3(k+1,h+1)-1;
hD3=yD3(k+1,h+1)-1;

kD4=xD4(k+1,h+1)-1;
hD4=yD4(k+1,h+1)-1;
 cD1R(sizL1*k+1:sizL1*k+sizL1,sizL1*h+1:sizL1*h+sizL1)=ssD1(k+1,h+1)*cD2I(sizL1*kD1+1:sizL1*kD1+sizL1,sizL1*hD1+1:sizL1*hD1+sizL1);
cD2R(sizL2*k+1:sizL2*k+sizL2,sizL2*h+1:sizL2*h+sizL2)=ssD2(k+1,h+1)*cD3I(sizL2*kD2+1:sizL2*kD2+sizL2,sizL2*hD2+1:sizL2*hD2+sizL2);
cD3R(sizL3*k+1:sizL3*k+sizL3,sizL3*h+1:sizL3*h+sizL3)=ssD3(k+1,h+1)*cD4I(sizL3*kD3+1:sizL3*kD3+sizL3,sizL3*hD3+1:sizL3*hD3+sizL3);
cD4R(sizL4*k+1:sizL4*k+sizL4,sizL4*h+1:sizL4*h+sizL4)=ssD4(k+1,h+1)*cD5I(sizL4*kD4+1:sizL4*kD4+sizL4,sizL4*hD4+1:sizL4*hD4+sizL4);
% cD5R(sizL5*k+1:sizL5*k+sizL5,sizL5*h+1:sizL5*h+sizL5)=ssD(k+1,h+1)*cD6I(sizL5*kD5+1:sizL5*kD5+sizL5,sizL5*hD5+1:sizL5*hD5+sizL5);





kV1=xV1(k+1,h+1)-1;
hV1=yV1(k+1,h+1)-1;

kV2=xV2(k+1,h+1)-1;
hV2=yV2(k+1,h+1)-1;

kV3=xV3(k+1,h+1)-1;
hV3=yV3(k+1,h+1)-1;

kV4=xV4(k+1,h+1)-1;
hV4=yV4(k+1,h+1)-1;
cV1R(sizL1*k+1:sizL1*k+sizL1,sizL1*h+1:sizL1*h+sizL1)=ssV1(k+1,h+1)*cV2I(sizL1*kV1+1:sizL1*kV1+sizL1,sizL1*hV1+1:sizL1*hV1+sizL1);
cV2R(sizL2*k+1:sizL2*k+sizL2,sizL2*h+1:sizL2*h+sizL2)=ssV2(k+1,h+1)*cV3I(sizL2*kV2+1:sizL2*kV2+sizL2,sizL2*hV2+1:sizL2*hV2+sizL2);
cV3R(sizL3*k+1:sizL3*k+sizL3,sizL3*h+1:sizL3*h+sizL3)=ssV3(k+1,h+1)*cV4I(sizL3*kV3+1:sizL3*kV3+sizL3,sizL3*hV3+1:sizL3*hV3+sizL3);
cV4R(sizL4*k+1:sizL4*k+sizL4,sizL4*h+1:sizL4*h+sizL4)=ssV4(k+1,h+1)*cV5I(sizL4*kV4+1:sizL4*kV4+sizL4,sizL4*hV4+1:sizL4*hV4+sizL4);
% cV5R(sizL5*k+1:sizL5*k+sizL5,sizL5*h+1:sizL5*h+sizL5)=ssV(k+1,h+1)*cV6I(sizL5*kV+1:sizL5*kV+sizL5,sizL5*hV+1:sizL5*hV+sizL5);
end
end

Z=zeros(256,256);
% X4R=idwt2(cA5,cH5R,cV5R,cD5R,'Haar');
X3R=idwt2(cA4,cH4R,cV4R,cD4R,'Haar');
X2R=idwt2(X3R,cH3R,cV3R,cD3R,'Haar');
X1R=idwt2(X2R,cH2R,cV2R,cD2R,'Haar');
X0R=idwt2(X1R,cH1R,cV1R,cD1R,'Haar');
Rreconstructed_Image=X0R;
pause(1)
% Rreconstructed_Image(1:2,1:2)
subplot(121);
imshow(Rreconstructed_Image,[]);title('The ReConstructed Image By %d Level Itteration ');
subplot(122);
imshow(X,[]);title('The Original Image');

end
Decode_Process_Time_as_Second=etime(clock, ty)

%%%%%%%%%%%%%%%%%%%% PSNR Calculation %%%%%%%%%%%%% 
% 
clc
X=double((imread('c:\cdna.tif')));
X=imcrop(X,[80 80 511 511]);
% X=imresize(X,0.5,'bicubic');
Rreconstructed_Image=round(abs(Rreconstructed_Image));


a16=bitand(X,2^(16-1));
a15=bitand(X,2^(15-1));
a14=bitand(X,2^(14-1));
a13=bitand(X,2^(13-1));
a12=bitand(X,2^(12-1));
a11=bitand(X,2^(11-1));
a10=bitand(X,2^(10-1));
a9=bitand(X,2^(9-1));
a8=bitand(X,2^(8-1));
a7=bitand(X,2^(7-1));
a6=bitand(X,2^(6-1));
a5=bitand(X,2^(5-1));
a4=bitand(X,2^(4-1));
a3=bitand(X,2^(3-1));
a2=bitand(X,2^(2-1));
a1=bitand(X,2^(1-1));







ad16=bitand(Rreconstructed_Image,2^(16-1));
ad15=bitand(Rreconstructed_Image,2^(15-1));
ad14=bitand(Rreconstructed_Image,2^(14-1));
ad13=bitand(Rreconstructed_Image,2^(13-1));
ad12=bitand(Rreconstructed_Image,2^(12-1));
ad11=bitand(Rreconstructed_Image,2^(11-1));
ad10=bitand(Rreconstructed_Image,2^(10-1));
ad9=bitand(Rreconstructed_Image,2^(9-1));
ad8=bitand(Rreconstructed_Image,2^(8-1));
ad7=bitand(Rreconstructed_Image,2^(7-1));
ad6=bitand(Rreconstructed_Image,2^(6-1));
ad5=bitand(Rreconstructed_Image,2^(5-1));
ad4=bitand(Rreconstructed_Image,2^(4-1));
ad3=bitand(Rreconstructed_Image,2^(3-1));
ad2=bitand(Rreconstructed_Image,2^(2-1));
ad1=bitand(Rreconstructed_Image,2^(1-1));


% rr1=bitor(ad1,a16);
rr2=bitor(ad2,ad1);
rr3=bitor(ad3,rr2);
rr4=bitor(ad4,rr3);
rr5=bitor(ad5,rr4);
rr6=bitor(ad6,rr5);
rr7=bitor(ad7,rr6);
rr8=bitor(ad8,rr7);
rr9=bitor(ad9,rr8);
rr10=bitor(ad10,rr9);
rr11=bitor(ad11,rr10);
rr12=bitor(ad12,rr11);
rr13=bitor(ad13,rr12);
rr14=bitor(ad14,rr13);
rr15=bitor(ad15,rr14);
rr16=bitor(ad16,rr15);




Rreconstructed_Image=(rr16);
[M,N]=size(X);
diff1=0;
for i=1:M,
for j=1:N,
diff1=diff1+(Rreconstructed_Image(i,j)-X(i,j))^2;
end
end
MSE=sum(sum(diff1))/(M*N);
PSNR=10*log10(((65535)^2) /MSE ) 
display('            FINISH            ');



Contact us