clc;
clear all;
close all;
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;
x0=max(x);
y1=max(x0);
for i=0:12
if 2^i<y1 & 2^i>0.5*y1
threshold=2^i;
break;
end
end
sublist=[];
[xx,yy]=size(x);
global N;
A=maping(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~=60;
%dominant pass
[D,x,sublist]=dominatepass(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
global N;
%EZW decoder
[m,n]=size(N);
xx=zeros(8);
threshold=initialthreshold;
%initial threshold
sublist=[];
for k=1:6
rr=zeros(8);
[a,b]=size(DD{k});
%dominant pass
i=1;j=1;
while i<=m
if j>b
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;
sublist=[sublist;N(i,1),N(i,2)];
end
if DD{k}(j)=='z'
rr(N(i,1),N(i,2))=1;
end
if DD{k}(j)=='t'
rr(N(i,1),N(i,2))=1;
end
rr=checkchildren(i,rr);
i=i+1; j=j+1;
end
end
%subordinate pass
[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
initial image = x0
reconstructed image = xx
difference=xx-x0
评论0