嵌入式小波零树(EZW)算法的过程详解和Matlab代码(4)运行示例

来源:互联网 发布:dbc2000数据库对应 编辑:程序博客网 时间:2024/06/07 13:48

最后,我们以一幅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'];
    LenSubQFL=[LenSubQFL,length(quantiflag)];
end


function DecodeMat=ezwdecode(Mat,T1,decodeDim,CodeList,LenSubCL,QuantiFlagList,LenSubQFL)
global row col
recvalue=[];
rIlist=[];
quantiflagOld=[];
scanorder=listorder(row,col,1,1);
flagMat(1:row,1:col)='Z';
 
for level=1:decodeDim
    scancode=CodeList(1:LenSubCL(level));
    CodeList=CodeList(LenSubCL(level)+1:end);
    quantiflag=QuantiFlagList(1:LenSubQFL(level));
    QuantiFlagList=QuantiFlagList(LenSubQFL(level)+1:end);
       
    DecodeMat=Mat;
    qrNum=1;
    scNum=1;
   
    [antiQuantiMat,rIlist,quantiflagOld]=antiquantifier(T1,level,rIlist,quantiflag,quantiflagOld);
    [DecodeMat,recvalue,qrNum]=updateRecvalue(DecodeMat,recvalue,qrNum,quantiflag,antiQuantiMat,rIlist);
    [DecodeMat,flagMat,recvalue]=decoding(DecodeMat,flagMat,recvalue,antiQuantiMat,quantiflag,rIlist,scanorder,scancode,scNum,qrNum);
%     if level<decodeDim
%         button = questdlg('Need the nest decode processing ?','Decode Level','Yes','No','Yes');
%         if button(1)=='N'
%             break;
%         end
%     end
end



(1)图像3级分解、5级编码、5级解码下的效果图。

ezw(Im64,3,5,5);

分解矩阵DecIm的部分数据

   40.9531   87.2344   94.2188  161.2031   64.3125   40.4063   37.5781   65.6875
  110.8281  129.3125   91.5625  164.3750  107.1719   50.5469   34.9688   75.2188
  150.7813  134.5156   98.0625  164.9688  121.7344   67.5469   28.0938   77.1250
  132.9219  117.7656   91.0938  155.3125  117.0781   53.0781   28.1563   83.3750
  119.3281  118.5156   95.1875  137.1719  105.8750   30.3906   33.6094   79.6406
  100.8906  102.9375  119.2031  132.8438   71.5000   28.6875   38.5313   75.3281
  103.2813   85.3750  102.6250  107.4531   31.3594   28.2656   45.3438   79.7813
   98.4844  120.0938  134.8438   73.3281   29.1719   33.6094   50.3906   86.0781

解码矩阵DecodeMat的对应数据

    42    86    94   162    66    42    38    66
   110   130    90   166   106    50    34    74
   150   134    98   166   122    66    30    78
   134   118    90   154   118    54    30    82
   118   118    94   138   106    30    34    78
   102   102   118   134    70    30    38    74
   102    86   102   106    30    30    46    78
    98   122   134    74    30    34    50    86

运行效果:




(2)图像3级分解、10级编码、8级解码下的效果图。

ezw(Im64,3,10,8);

分解矩阵DecIm的部分数据

   40.9531   87.2344   94.2188  161.2031   64.3125   40.4063   37.5781   65.6875
  110.8281  129.3125   91.5625  164.3750  107.1719   50.5469   34.9688   75.2188
  150.7813  134.5156   98.0625  164.9688  121.7344   67.5469   28.0938   77.1250
  132.9219  117.7656   91.0938  155.3125  117.0781   53.0781   28.1563   83.3750
  119.3281  118.5156   95.1875  137.1719  105.8750   30.3906   33.6094   79.6406
  100.8906  102.9375  119.2031  132.8438   71.5000   28.6875   38.5313   75.3281
  103.2813   85.3750  102.6250  107.4531   31.3594   28.2656   45.3438   79.7813
   98.4844  120.0938  134.8438   73.3281   29.1719   33.6094   50.3906   86.0781


解码矩阵DecodeMat的对应数据

   40.7500   87.2500   94.2500  161.2500   64.2500   40.2500   37.7500   65.7500
  110.7500  129.2500   91.7500  164.2500  107.2500   50.7500   34.7500   75.2500
  150.7500  134.7500   98.2500  164.7500  121.7500   67.7500   28.2500   77.2500
  132.7500  117.7500   91.2500  155.2500  117.2500   53.2500   28.2500   83.2500
  119.2500  118.7500   95.2500  137.2500  105.7500   30.2500   33.7500   79.7500
  100.7500  102.7500  119.2500  132.7500   71.7500   28.7500   38.7500   75.2500
  103.2500   85.2500  102.7500  107.2500   31.2500   28.2500   45.2500   79.7500
   98.2500  120.2500  134.7500   73.2500   29.2500   33.7500   50.2500   86.2500

运行效果:



原创粉丝点击