% This is a test program that tests the EZW
% matrix X is an example matrix same as Shapiro's paper given
X=[63 -34 49 10 7 13 -12 7;
-31 23 14 -13 3 4 6 -1;
15 14 3 -12 5 -7 3 9;
-9 -7 -14 8 4 -2 3 2;
-5 9 -1 47 4 6 -2 2;
3 0 -3 2 3 -2 0 4;
2 -3 6 -4 3 6 3 6;
5 11 5 6 0 3 -4 4];
X0=X;
Y0=max(X);
Y1=max(Y0);
for i=0:12;
if 2^i<Y1 & 2^i>0.5*Y1;
threshold=2^i; % get initial threshold T0;
break;
end;
end;
sublist=[];
[xx,yy]=size(X);
global N
A=mapping(xx);
[m,n]=size(A);
k=1; N=[];
for k=1:m*n;
flag=0;
for i=1:m;
if flag==1;
break;
end
for j=1:n;
if A(i,j)==k;
N=[N;i,j];
flag=1;
break;
end
end
end
end
order=1;
while threshold ~= 0.5, % if threshold~=1, do dominantpass and subordinatepass.
threshold
%Dominant Pass
[D,X,sublist] = dominantpass(X,threshold,sublist);
DD{order}=D
%Subordinate pass
threshold=threshold/2;
if threshold ==0.5,
break;
end
S = subordinatepass(sublist,threshold);
SS{order}=S
order=order+1;
end
% EZW decoder
global N;
[m,n]=size(N);% the size of initial image
% m is the pixels of initial image
XX=zeros(8); % initialize the reconstructured image to zero;
initialthreshold=32;
threshold=initialthreshold; % initial theshold ;
sublist=[]; % sublist is the new position matrix
% for all significant coefficients 'p' and 'n';
for k=1:6; % laststeplevel=6;
RR=zeros(8); % reference matrix RR;
[a,b]=size(DD{k}); % ?
% dominant pass
i=1; j=1;
while i<=m;
if j>b; % b is the length of dominant pass vector
break;
end
if RR(N(i,1),N(i,2))==1;
i=i+1;
else
if DD{k}(j)=='p';
XX(N(i,1),N(i,2))=threshold;
RR(N(i,1),N(i,2))=1; %reference matrix =1;
sublist=[sublist;N(i,1),N(i,2)];
end
if DD{k}(j)=='n';
XX(N(i,1),N(i,2))=-threshold;
RR(N(i,1),N(i,2))=1; %reference matrix =1;
sublist=[sublist;N(i,1),N(i,2)];
end
if DD{k}(j)=='z';
RR(N(i,1),N(i,2))=1; %reference matrix =1;
end
if DD{k}(j)=='t';
RR(N(i,1),N(i,2))=1; %reference matrix =1;
RR=checkchildren(i,RR);% all zerotree's descendants are set to 1.
end
i=i+1;j=j+1;
end
end
% subordinate pass
%[xx,yy]=size(s{k});
[xx,yy]=size(sublist);
threshold=threshold/2;
for i=1:xx;
if k==6 |threshold==0.5;
break;
end
if SS{k}(i)==1;
if XX(sublist(i,1),sublist(i,2))>0;
XX(sublist(i,1),sublist(i,2))= XX(sublist(i,1),sublist(i,2))+ threshold;
else
XX(sublist(i,1),sublist(i,2))= XX(sublist(i,1),sublist(i,2))-threshold;
end
end
end
threshold
k
XX
end
initialiamge=X0
reconstructuredimage=XX
difference=XX-X0