2-D Discrete Wavelet Function in Matlab 71

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

3.

2-D DISCRETE WAVELET FUNCTION IN MATLAB 71

3. 2-D Discrete Wavelet Function In MATLAB


2-D Discrete Wavelet Transform in MATLAB
The following functions are already in the MATLAB Wavelet Tool-
box. They are often used for performing 2-D wavelet transform.
dwt2, wavedec2, idwt2, waverec2, upcoef2, detcoef2, app-
coef2, upwlev2.
function a = appcoef2(c,s,arg3,arg4,arg5)
APPCOEF2 Extract 2-D approximation coefficients.
APPCOEF2
computes the approximation coefficients of a two-dimensional sig-
nal.
A = APPCOEF2(C,S, ‘wname’,N)
computes the approximation coefficients at level N using the wavelet
decomposition structure [C,S]
(see WAVEDEC2). ‘wname’ is a string containing the wavelet
name. Level N must be an integer such that 0 ¡= N ¡= size(S,1)-2.
A = APPCOEF2(C,S, ‘wname’)
extracts the approximation coefficients at the last level size(S,1)-2.
Instead of giving the wavelet name, you can give the filters. For
A = APPCOEF2(C,S,Lo R,Hi R) or
A = APPCOEF2(C,S,Lo R,Hi R,N),
Lo R is the reconstruction low-pass filter and Hi R is the recon-
struction high-pass filter.
function d = detcoef2(o,c,s,n)
DETCOEF2 Extract 2-D detail coefficients.
D=DETCOEF2(O,C,S,N)
extracts from the wavelet decomposition structure [C,S]
(see WAVEDEC2), the horizontal, vertical or diagonal detail coef-
ficients for O =‘h’ (or ‘v’ or ‘d’, respectively), at level N. Level N must
be an integer such that 1 ¡=N ¡= size(S,1)-2.
function [a,h,v,d] = dwtper2(x,arg2,arg3)
DWTPER2 Single-level discrete 2-D wavelet transform (periodized).
[CA,CH,CV,CD] = DWTPER2(X, ‘wname’)
computes the approximation coefficients matrix CA and details co-
efficients matrices CH, CV, CD, obtained by periodized wavelet de-
composition of the input matrix X. ‘wname’ is a string containing the
wavelet name (see WFILTERS). Instead of giving the wavelet name,
you can give the filters. When used with three arguments:
[CA,CH,CV,CD] = DWTPER2(X,Lo D,Hi D)
Lo D is the decomposition low-pass filter and Hi D is the decom-
position high-pass filter.
If sx = size(X) then size(CA) = size(CH) = size(CV) = size(CD)
= CEIL(sx/2).
72 JIANZHONG WANG

function [a,h,v,d] = dwt2(x,arg2,arg3)


DWT2 Single-level discrete 2-D wavelet transform.
DWT2
performs a single-level 2-D wavelet decomposition with respect to
either a particular wavelet ( ‘wname’, see WFILTERS) or particular
wavelet filters (Lo D and Hi D) you specify.
[CA,CH,CV,CD] = DWT2(X, ‘wname’)
computes the approximation coefficients matrix CA and details co-
efficients matrices CH, CV, CD, obtained by wavelet decomposition of
the input matrix X. ‘wname’ is a string containing the wavelet name.
[CA,CH,CV,CD] = DWT2(X,Lo D,Hi D)
computes the 2-D wavelet decomposition as above given these fil-
ters as input: Lo D is the decomposition low-pass filter and Hi D is
the decomposition high-pass filter. Lo D and Hi D must be the same
length. size(X) and lf is the length of filters then
size(CA) = size(CH) = size(CV) = size(CD) = FLOOR((sx+lf-
1)/2).
function y = dyaddown(x,arg2,arg3)
DYADDOWN Dyadic downsampling.
Y = DYADDOWN(X,EVENODD),
where X is a vector, returns a version of X that has been downsam-
pled by 2. Whether Y contains the even- or odd-indexed samples of X
depends on the value of positive integer EVENODD: If EVENODD is
even, then Y(k) = X(2k). If EVENODD is odd, then Y(k) = X(2k+1).
Y = DYADDOWN(X) is equivalent to
Y = DYADDOWN(X,0).
Y = DYADDOWN(X,EVENODD, ‘type’) or
Y = DYADDOWN(X, ‘type’,EVENODD)
where X is a matrix return a version of X obtained by suppressing
columns (or rows or both) if ‘type’ = ‘c’ (or ‘r’ or ‘m’ respectively),
according to the parameter EVENODD which is as above.
Y = DYADDOWN(X) is equivalent to
Y = DYADDOWN(X,0, ‘c’).
Y = DYADDOWN(X, ‘type’) is equivalent to
Y = DYADDOWN(X,0, ‘type’).
Y = DYADDOWN(X,EVENODD) is equivalent to
Y = DYADDOWN(X,EVENODD, ‘c’).
Examples :
 
1 2 3 4
X =  2 4 6 8 ,
3 6 9 0
 
2 4
DYADDOWN(X, ‘c’)=  4 8  .
6 0
3. 2-D DISCRETE WAVELET FUNCTION IN MATLAB 73
· ¸
1 2 3 4
DYADDOWN(X, ‘r’,1)= .
3 6 9 0
· ¸
1 3
DYADDOWN(X, ‘m’,1) = .
3 9

function y=dyadup(x,arg2,arg3)
DYADUP Dyadic upsampling.
DYADUP
implements a simple zero-padding scheme very useful in the wavelet
reconstruction algorithm.
Y = DYADUP(X,EVENODD),
where X is a vector, returns an extended copy of vector X obtained
by inserting zeros. Whether the zeros are inserted as even- or odd-
indexed elements of Y depends on the value of positive integer
EVENODD:
If EVENODD is even, then Y(2k+1) = X(k), Y(2k) = 0.
If EVENODD is odd, then Y(2k+1) = 0 , Y(2k) = X(k).
Y = DYADUP(X) is equivalent to
Y = DYADUP(X,1).
Y = DYADUP(X,EVENODD, ‘type’) or
Y = DYADUP(X, ‘type’, EVENODD)
where X is a matrix, return extended copies of X obtained by in-
serting columns of zeros (or rows or both) if ‘type’ = ‘c’ (or ‘r’ or
‘m’ respectively), according to the parameter EVENODD which is as
above.
Y = DYADUP(X) is equivalent to
Y = DYADUP(X,1, ‘c’).
Y = DYADUP(X, ‘type’) is equivalent to
Y = DYADUP(X,1, ‘type’).
Y = DYADUP(X,EVENODD) is equivalent to
Y = DYADUP(X,EVENODD, ‘c’)

function x = idwt2(a,h,v,d,arg5,arg6,arg7)
IDWT2 Single-level inverse discrete 2-D wavelet transform.
IDWT2
performs a single-level 2-D wavelet reconstruction with respect to
either a particular wavelet (‘wname’, see WFILTERS) or particular
wavelet reconstruction filters you specify.
DWT2(CA,CH,CV,CD, ‘wname’)
uses the wavelet ‘wname” to compute the single-level reconstructed
approximation coefficients matrix X based on approximation matrix
CA and (horizontal, vertical, and diagonal) details matrices CH, CV
and CD.
X = IDWT2(CA,CH,CV,CD,Lo R,Hi R)
74 JIANZHONG WANG

reconstructs as above, using filters you specify: Lo R is the recon-


struction low-pass filter and Hi R is the reconstruction high-pass filter.
Lo R and Hi R must be the same length.
If sa = size(CA) = size(CH) = size(CV) = size(CD) and lf is the
length of the filters, then size(X) = 2*size(CA)-lf+2.
X = IDWT2(CA,CH,CV,CD, ‘wname’,S) and
X = IDWT2(CA,CH,CV,CD,Lo R,Hi R,S)
return the size-S central portion of the result obtained using
IDWT2(CA,CH,CV,CD, ‘wname’).
S must be less than 2*size(CA)-lf+2.

function x = idwtper2(a,h,v,d,arg5,arg6,arg7)
IDWTPER2 Single-level inverse discrete 2-D wavelet transform (pe-
riodized).
X = IDWTPER2(CA,CH,CV,CD, ‘wname’)
returns the single-level reconstructed approximation coefficients ma-
trix X based on approximation and details matrices CA, CH, CV and
CD at a given level, using the periodized inverse wavelet transform.
‘wname’ is a string containing the wavelet name (see WFILTERS).
Instead of giving the wavelet name, you can give the filters. For
X = IDWTPER2(CA,CH,CV,CD,Lo R,Hi R),
Lo R is the reconstruction low-pass filter and Hi R is the recon-
struction high-pass filter.
If sa = size(CA) = size(CH) = size(CV) = size(CD) then size(X)
= 2*sa. For
X = IDWTPER2(CA,CH,CV,CD, ‘wname’,S) or
X = IDWTPER2(CA,CH,CV,CD,Lo R,Hi R,S),
S is the size of the result.

function y = upcoef2(o,x,arg3,arg4,arg5,arg6)
UPCOEF2 Direct reconstruction from 2-D wavelet coefficients.
Y = UPCOEF2(O,X, ‘wname’,N,S)
computes the N steps reconstructed coefficients of matrix X and
takes the size-S central portion of the result. ‘wname’ is a string con-
taining the name of the wavelet.
If O = ‘a’, approximation coefficients are reconstructed, otherwise
if O = ‘h’ (or ‘v’ or ‘d’), horizontal (vertical or diagonal respectively),
detail coefficients are reconstructed. N must be a strictly positive in-
teger. Instead of giving the wavelet name, you can give the filters.
For
Y = UPCOEF2(O,X,Lo R,Hi R,N,S)
Lo R is the reconstruction low-pass filter and Hi R is the recon-
struction high-pass filter.
Y = UPCOEF2(O,X, ‘wname’,N) or
Y = UPCOEF2(O,X,Lo R,Hi R,N),
return the computed result without any truncation.
3. 2-D DISCRETE WAVELET FUNCTION IN MATLAB 75

Y = UPCOEF2(O,X, ‘wname’) is equivalent to


Y = UPCOEF2(O,X, ‘wname’,1).
Y = UPCOEF2(O,X,Lo R,Hi R) is equivalent to
Y = UPCOEF2(O,X,Lo R,Hi R,1).

function [Nc,Ns,a] = upwlev2(c,s,arg3,arg4)


UPWLEV2 Single-level reconstruction of 2-D wavelet decomposi-
tion.
[NC,NS,CA] = UPWLEV2(C,S, ‘wname’)
performs the single-level reconstruction of wavelet decomposition
structure [C,S] giving the new one [NC,NS], and extract the last ap-
proximation coefficients matrix CA. [C,S] is a decomposition at level n
= size(S,1)-2, so [NC,NS] is the same decomposition at level n-1 and
CA is the approximation matrix at level n. ‘wname’ is a string contain-
ing the wavelet name, C is the original wavelet decomposition vector
and S the corresponding bookkeeping matrix (for detailed storage in-
formation, see WAVEDEC2). Instead of giving the wavelet name, you
can give the filters. For
[NC,NS,CA] = UPWLEV2(C,S,Lo R,Hi R),
Lo R is the reconstruction low-pass filter and Hi R is the recon-
struction high-pass filter.

function [c,s] = wavedec2(x,n,arg3,arg4)


WAVEDEC2 Multi-level 2-D wavelet decomposition.
[C,S] = WAVEDEC2(X,N,‘wname’)
returns the wavelet decomposition of the matrix X at level N, using
the wavelet named in string ‘wname’ (see WFILTERS). Outputs are
the decomposition vector C and the corresponding bookkeeping matrix
S. N must be a strictly positive integer (see WMAXLEV). Instead of
giving the wavelet name, you can give the filters. For
[C,S] = WAVEDEC2(X,N,Lo D,Hi D),
Lo D is the decomposition low-pass filter and Hi D is the decompo-
sition high-pass filter. The output wavelet 2-D decomposition structure
[C,S] contains the wavelet decomposition vector C and the correspond-
ing bookkeeping matrix S. Vector C is organized as: C = [A(N), H(N),
V(N), D(N), ... H(N-1), V(N-1), D(N-1), ..., H(1), V(1), D(1)],
where A, H, V, D, are row vectors such that:
A = approximation coefficients,
H = hori. detail coefficients,
V = vert. detail coefficients,
D = diag. detail coefficients, each vector is the vector column-wise
storage of a matrix. Matrix S is such that:
S(1,:) = size of app. coef.(N)
S(i,:) = size of det. coef.(N-i+2) for i = 2,...,N+1,
and
S(N+2,:) = size(X).
76 JIANZHONG WANG

function x = waverec2(c,s,arg3,arg4)
WAVEREC2 Multi-level 2-D wavelet reconstruction.
WAVEREC2
performs a multi-level 2-D wavelet reconstruction using either a
specific wavelet ( ‘wname’, see WFILTERS) or specific reconstruction
filters (Lo R and Hi R).
X = WAVEREC2(C,S, ‘wname’)
reconstructs the matrix X based on the multi-level wavelet decom-
position structure [C,S] (see WAVEDEC2). For
X = WAVEREC2(C,S,Lo R,Hi R),
Lo R is the reconstruction low-pass filter and Hi R is the recon-
struction high-pass filter.
function x = wrcoef2(o,c,s,arg4,arg5,arg6)
WRCOEF2 Reconstruct single branch from 2-D wavelet coefficients.
WRCOEF2 reconstructs the coefficients of an image.
X = WRCOEF2( ‘type’,C,S, ‘wname’,N)
computes the matrix of reconstructed coefficients of level N, based
on the wavelet decomposition structure [C,S] (see WAVEDEC2). ‘wname’
is a string containing the name of the wavelet. If ‘type’ = ‘a’, approxi-
mation coefficients are reconstructed otherwise if ‘type’ = ‘h’ ( ‘v’ or ‘d’
respectively), horizontal (vert. or diag. respectively) detail coefficients
are reconstructed.
Level N must be an integer such that:
0 ¡= N ¡= size(S,1)-2 if ‘type’ = ‘a’ and such that
1 ¡= N ¡= size(S,1)-2 if ‘type’ = ‘h’, ‘v’ or ‘d’.
Instead of giving the wavelet name, you can give the filters. For
X = WRCOEF2( ‘type’,C,S,Lo R,Hi R,N),
Lo R is the reconstruction low-pass filter and Hi R is the recon-
struction high-pass filter.
X = WRCOEF2( ‘type’,C,S, ‘wname’) or
X = WRCOEF2( ‘type’,C,S,Lo R,Hi R)
reconstructs coefficients of maximum level N = size(S,1)-2.

You might also like