You are on page 1of 5

12/30/2015

WaveletSoftwareatBrooklynPoly

MatlabImplementationofWaveletTransforms
ShihuaCai&KeyongLi
Advisor:Prof.IvanSelesnick

2DDiscreteWaveletTransform
1.2DFilterBanks
To use the wavelet transform for image processing we must
implement a 2D version of the analysis and synthesis filter
banks.Inthe2Dcase,the1Danalysisfilterbankisfirstapplied
tothecolumnsoftheimageandthenappliedtotherows.Ifthe
imagehasN1rowsandN2columns,thenafterapplyingthe1D
analysis filter bank to each column we have two subband
images, each having N1/2 rows and N2 columns afterapplying
the 1D analysis filter bank to each row of both of the two
subband images, we have four subband images, each having
N1/2 rows and N2/2 columns. This is illustrated in the diagram
below. The 2D synthesis filter bank combines the four subband
imagestoobtaintheoriginalimageofsizeN1byN2.

http://eeweb.poly.edu/iselesni/WaveletSoftware/standard2D.html

1/5

12/30/2015

WaveletSoftwareatBrooklynPoly

Fig. 2.1 One stage in multiresolution wavelet decomposition of


animage[3]

The 2D analysis filter bank is implemented with the Matlab


functionafb2D.m.Thisfunctioncallsasubfunction,afb2D_A.m,
which applies the 1D analysis filter bank along one dimension
only (either along the columns or along the rows). The function
afb2D.mreturnstwovariables:loisthelowpasssubbandimage
hiisacellarraycontainingthe3othersubbandimages.

Table2.1Matlabfunctionafb2D.m
function[lo,hi]=afb2D(x,af1,af2)
%2DAnalysisFilterBank
%
%[lo,hi]=afb2D(x,af1,af2);
%INPUT:
%xNxMmatrix,wheremin(N,M)>2*length(filter)
%(N,Mareeven)
%af1analysisfilterforthecolumns
%af2analysisfilterfortherows
%afi(:,1)lowpassfilter
%afi(:,2)highpassfilter
%OUTPUT:
%lo,hilowpass,highpasssubbands
%hi{1}='lohi'subband
%hi{2}='hilo'subband
%hi{3}='hihi'subband
ifnargin<3
af2=af1;
end
%filteralongcolumns
[L,H]=afb2D_A(x,af1,1);
%filteralongrows
[lohi{1}]=afb2D_A(L,af2,2);
[hi{2}hi{3}]=afb2D_A(H,af2,2);

The 2D synthesis filter bank is similarly implemented with the


commandssfb2D.mandsfb2D_A.m.
Introduction
http://eeweb.poly.edu/iselesni/WaveletSoftware/standard2D.html

2/5

12/30/2015

WaveletSoftwareatBrooklynPoly

SeparableDWT
1DDWT
2DDWT
3DDWT

2.2DDiscreteWaveletTransform
Asinthe1Dcase,the2Ddiscretewavelettransformofasignal

DualtreeDWT

x is implemented by iterating the 2D analysis filter bank on the

1DDWT
2DDWT
3DDWT

lowpass subband image. In this case, at each scale there are


threesubbandsinsteadofone.Thefunction,dwt2D.m,computes

Denoising
Thresholding
BiShrink

the Jscale 2D DWT w of an image x by repeatedly calling


afb2D.m.

References
People
Download(zip)

Table2.2Matlabfunctiondwt2D.m
functionw=dwt2D(x,J,af)

%discrete2Dwavelettransform
%
%w=dwt2D(x,stages,af)
%INPUT:
%x:NxMmatrix(N,Meven)
%J:numberofstages
%af:analysisfilters
%OUPUT:
%w:cellarrayofwaveletcoefficients
fork=1:J
[xw{k}]=afb2D(x,af,af);
end
w{J+1}=x;

Again,wisaMatlabcellarrayforj=1..J,d=1..3,w{j}{d}is
oneofthethreesubbandimagesproducedatstagej.w{J+1}is
the lowpass subband image produced at the last stage. The
functionidwt2D.mcomputestheinverse2DDWT.

The perfect reconstruction of the 2D DWT is verified in the


followingexample.Wecreatearandominputsignalxofsize128
by64,applytheDWTanditsinverse,andshowitreconstructsx
fromthewaveletcoefficientsinw.
EXAMPLE(VERIFYPERFECTRECONSTRUNCTION)
http://eeweb.poly.edu/iselesni/WaveletSoftware/standard2D.html

3/5

12/30/2015

WaveletSoftwareatBrooklynPoly

>>[af,sf]=farras;
>>x=rand(128,64);
>>w=dwt2D(x,3,af);
>>y=idwt2D(w,3,sf);
>>err=xy;
>>max(max(abs(err)))
ans=
8.9817e014

There are three wavelets associated with the 2D wavelet


transform.Thefollowingfigureillustratesthreewaveletsasgray
scaleimages.

Note that the first two wavelets are oriented in the vertical and
horizontaldirections,however,thethirdwaveletdoesnothavea
dominant orientation. The third wavelet mixes two diagonal
orientations, which gives rise to the checkerboard artifact. (The
2D DWT is poor at isolating the two diagonal orientations.) This
figure was produced with the following Matlab code fragment
(dwt2D_plots.m).
Table2.3Matlabfunctiondwt2D_plots.m
%dwt2D_plots
%DISPLAY2DWAVELETSOFDWT2D.M
[af,sf]=farras;
J=5;
L=3*2^(J+1);
N=L/2^J;
http://eeweb.poly.edu/iselesni/WaveletSoftware/standard2D.html

4/5

12/30/2015

WaveletSoftwareatBrooklynPoly

x=zeros(L,3*L);
w=dwt2D(x,J,af);
w{J}{1}(N/2,N/2+0*N)=1;
w{J}{2}(N/2,N/2+1*N)=1;
w{J}{3}(N/2,N/2+2*N)=1;
y=idwt2D(w,J,sf);
figure(1)
clf
imagesc(y);
axisequal
axisoff
colormap(gray(128))

Asinthe1Dcase,wesetallofthewaveletcoefficientstozero,
for the exception of one wavelet coefficient in each of the three
subbands.Wethentaketheinversewavelettransform.
Summaryofprograms:
1. farras.mAsetofperfectreconstructionfilters
2. afb2D.mAnalysisfilterbank(singlestage)
3. sfb2D.mSynthesisfilterbank(singlestage)
4. dwt2D.mForwardwavelettransform
5. idwt2D.mInversewavelettransform
6. cshift2D.mCircularshift
7. dwt2D_plots.mDisplay2dwaveletsofdwt2d.m

SupportedbygrantsfromtheNationalScienceFoundation andtheOthmerInstitutefor
InterdisciplinaryStudies
ElectricalEngineering,PolytechnicUniversity
6MetrotechCenter,Brooklyn,NY11201

http://eeweb.poly.edu/iselesni/WaveletSoftware/standard2D.html

5/5

You might also like