2D inverse stationary wavelet packet

  • Follow


Hello dear Friends,
I am inspired from the 1D swpt posted on the forum to build the 2D swpt (swpt2).
I think that the foward transform (swpt2) works well but reconstruction gives bad results. Can you help me on the inverse transformation and if possible suggest me an idea on the best basis selection in function of entropy criterion. 
Thx

Here are the highlights
1. swpt2.m
function coeffs=swpt2(x,n,type)

siz=size(x); [lo,hi]=wfilters(type,'d'); lo=lo(:)'; hi=hi(:)';
old_modeDWT=dwtmode('status','nodisp'); 
modeDWT='per'; dwtmode(modeDWT,'nodisp');
coeffs = cell(n,2^(2*n));
k=1;m=1;
lf=length(lo);first=[lf+1,lf+1];x=wextend('2D',modeDWT,x,[lf/2,lf/2]);
[coeffs{k,4*m-3},coeffs{k,4*m-2},coeffs{k,4*m-1},coeffs{k,4*m}] = decomposeLOC(x);
% upsample filters.
lo(2,length(lo))=0; lo=lo(:)'; hi(2,length(hi))=0; hi=hi(:)';        
for k = 2:n
    for m = 1:2^(2*(k-1))
        lf =length(lo); first=[lf+1,lf+1];
        x =wextend('2D',modeDWT,coeffs{k-1,m},[lf/2,lf/2]);
       [coeffs{k,4*m-3},coeffs{k,4*m-2},coeffs{k,4*m-1},coeffs{k,4*m}] =    decomposeLOC(x);
    end
% upsample filters.
     lo(2,length(lo))=0; lo=lo(:)';hi(2,length(hi))=0;hi=hi(:)';  
end
% Restore DWT_Mode.
dwtmode(old_modeDWT,'nodisp');
%---------------------------------------------------------------%
   function [ch,cv,cd,ca] = decomposeLOC(x)
    y=conv2(double(x),lo);z=(conv2(y',lo))';ca=keepLOC(z,size2D);
    z=(conv2(y',hi))'; ch=keepLOC(z,size2D); y=conv2(double(x),hi);
    z=(conv2(y',lo))'; cv=keepLOC(z,size2D);z=(conv2(y',hi))';cd=keepLOC(z,size2D);
    end
    function y = keepLOC(z,siz)
     sz=size(z); siz(siz>sz)=sz(siz>sz); last=first+siz-1;
     y=z(first(1):last(1),first(2):last(2),:);
    end
end

2. iswpt2.m (???)
function y=iswpt2(swpc2,n,type)

[lo,hi]=wfilters(type,'r'); lo=lo(:)'; hi=hi(:)';
 for k=n:-1:1
    step=4^(k-1);subband=4^k;last=step;
    y=swpc2{k,1};[rx,cx]=size(y);
    for r=1:4:subband;
        for first=1:last
            iRow=first:step:rx;lR=length(iRow);iCol=first:step:cx;lC=length(iCol);
            sR=iRow(1:2:lR);sC=iCol(1:2:lC);
            ca=swpc2{k,r+3};ch=swpc2{k,r+2};cv=swpc2{k,r+1};cd=swpc2{k,r};
            x1=idwt2LOC(ca(sR,sC),ch(sR,sC),cv(sR,sC),cd(sR,sC),lo,hi,[lR lC],[0,0]); 
            sR=iRow(2:2:lR);sC=iCol(2:2:lC);
            x2=idwt2LOC(ca(sR,sC),ch(sR,sC),cv(sR,sC),cd(sR,sC),lo,hi,[lR lC],[-1,-1]);
            y(iRow,iCol) = 0.5*(x1+x2); 
            if k>1
                swpc2{k-1,(r+3)/4}= y;
            end
        end
    end
end
%---------------------------------------------------------------%
    function y=idwt2LOC(a,h,v,d,lo_R,hi_R,sy,shift)
      y=upconvLOC(a,lo_R,lo_R,sy)+ upconvLOC(h,hi_R,lo_R,sy)+ ...  
          upconvLOC(v,lo_R,hi_R,sy)+ upconvLOC(d,hi_R,hi_R,sy); 
      if shift(1)==-1 , y=y([end,1:end-1],:); end
      if shift(2)==-1 , y=y(:,[end,1:end-1]); end
    end
    function y=upconvLOC(x,f1,f2,s)
      lf=length(f1);
      y=dyadup(x,'mat',0,1);y=wextend('2D','per',y,[lf/2,lf/2]);
      y=wconv2('col',y,f1);y=wconv2('row',y,f2);
      y=wkeep2(y,s,[lf lf]);
     end
end
0
Reply Julio 10/11/2010 3:08:03 AM


0 Replies
418 Views

(page loaded in 0.023 seconds)

Similiar Articles:













7/14/2012 1:45:56 AM


Reply: