最后,我们以一幅64*64的Lena局部图像来演示EZW算法的编解码效果。
首先给出相关的编解码主程序。
function y=ezw(Im,imDim,codeDim,DecodeDim)
global row col
[row,col]=size(Im);
% ----- Wavedec -----%
DecIm=mywavedec2(Im,imDim);
% ----- Select threshold -----%
MaxDecIm=max(max(abs(DecIm)));
T=zeros(1,codeDim);
T(1)=2^flor(log2(MaxDecIm));
for i=2:codeDim
T(i)=T(i-1)/2;
end
% ----- EZW coding -----%
[CodeList,LenSubCL,QuantiFlagList,LenSubQFL]=ezwcode(DecIm,T,codeDim);
% ----- EZW decoding -----%
DecodeMat=ezwdecode(DecIm,T(1),DecodeDim,CodeList,LenSubCL,QuantiFlagList,LenSubQFL);
% ----- Waverec -----%
DecIm(1:row/8,1:col/8)
DecodeMat(1:row/8,1:col/8)
RecIm=mywaverec2(DecodeMat,imDim);
function [CodeList,LenSubCL,QuantiFlagList,LenSubQFL]=ezwcode(Mat,threshold,codedim)
global row col
scanlist=morton(Mat);
flaglist(1:row,1:col)='Z';
imptvalue=[];
imptflag=[];
% ----- Intializing EZW coding output variables -----%
CodeList=[];
LenSubCL=[];
QuantiFlagList=[];
LenSubQFL=[];
% ----- Coding loop -----%
for d=1:codedim
[imptvalue,imptflag,scancode,scanflag,flaglist]=mainscan(Mat,scanlist,flaglist,imptvalue,imptflag,threshold(d));
[quantilist,quantiflag,recvalue,quantifierMat]=assistscan(imptvalue,d,threshold(1));
% Produce code dataflow
CodeList=[CodeList,scancode];
LenSubCL=[LenSubCL,length(scancode)];
QuantiFlagList=[QuantiFlagList,quantiflag'];