Você está na página 1de 10

dwt2

Single-level discrete 2-D wavelet transform.

Examples See Also

Syntax
[cA,cH,cV,cD] = dwt2(X,'wname') [cA,cH,cV,cD] = dwt2(X,Lo_D,Hi_D)

Description
The dwt2 command performs a single-level two-dimensional wavelet decomposition with respect to either a particular wavelet (' wname', see wfilters) or particular wavelet decomposition filters ( Lo_D and Hi_D) you specify. [cA,cH,cV,cD] = dwt2(X,'wname') computes the approximation coefficients matrix cA and the details coefficients matrices cH, cV, and cD (horizontal, vertical, and diagonal), obtained by wavelet decomposition of the input matrix X. [cA,cH,cV,cD] = dwt2(X,Lo_D,Hi_D) computes the two-dimensional wavelet decomposition as above, based on wavelet decomposition filters you specify: Lo_D is the decomposition low-pass filter and Hi_D is the decomposition high-pass filter. and Hi_D must be the same length. If sx = size(X) and lf is the length of filters, then size(cA) = size(cH) = size(cV) = size(cD) = floor((sx+lf1)/2). For information about the different discrete wavelet transform extension modes, see dwtmode.
Lo_D

Examples
% Load original image. load woman; % X contains the loaded image. % map contains the loaded colormap. nbcol = size(map,1); % Perform single-level decomposition % of X using db1. [cA1,cH1,cV1,cD1] = dwt2(X,'db1'); % Images coding. cod_X = wcodemat(X,nbcol);

cod_cA1 cod_cH1 cod_cV1 cod_cD1 dec2d =

= wcodemat(cA1,nbcol); = wcodemat(cH1,nbcol); = wcodemat(cV1,nbcol); = wcodemat(cD1,nbcol); [... cod_cA1, cod_cH1; cod_cV1, cod_cD1 ];

... ...

Algorithm
For images, an algorithm similar to the one-dimensional case is possible for two-dimensional wavelets and scaling functions obtained from onedimensional ones by tensorial product. This kind of two-dimensional DWT leads to a decomposition of approximation coefficients at level j in four components: the approximation at level j + 1 and the details in three orientations (horizontal, vertical, and diagonal). The following chart describes the basic decomposition steps for images:

Note: In order to deal with signal-end effects involved by convolution based algorithm, a global variable managed by dwtmode is used. The possible options are: zero-padding (used in the previous example, this mode is the default), symmetric extension, and smooth extension. It should be noted that dwt2 has the same single inverse function idwt2 for the three extension modes.

Limitations
Periodized wavelet transform is handled separately (see dwtper2 and idwtper2).

wcodemat
Extended pseudocolor matrix scaling.

Syntax
Y Y Y Y = = = = wcodemat(X,NB,OPT,ABSOL) wcodemat(X,NB,OPT) wcodemat(X,NB) wcodemat(X)

Description
wcodemat

is a general utility.

returns a coded version of input matrix X if ABSOL = 0, or ABS(X) if ABSOL is nonzero, using the first NB integers. Coding can be done rowwise (OPT = 'row'), columnwise (OPT = 'col') or globally (OPT = 'mat'). Coding uses a regular grid between the minimum and the maximum values of each row (column or matrix, respectively). Y = wcodemat(X,NB,OPT) is equivalent to Y = wcodemat(X,NB,OPT,1). Y = wcodemat(X,NB) is equivalent to Y = wcodemat(X,NB, 'mat',1). Y = wcodemat(X) is equivalent to Y = wcodemat(X,16,'mat',1).
Y = wcodemat(X,NB,OPT,ABSOL)

wcodemat
Extended pseudocolor matrix scaling

Syntax
Y = wcodemat(X)
Y = wcodemat(X,NBCODES) Y = wcodemat(X,NBCODES,OPT) Y = wcodemat(X,NBCODES,OPT,ABSOL)

Description wcodemat rescales an input matrix to a specified range for display. If the specified range is the full range of the current colormap, wcodemat is similar in behavior to imagesc. Y = wcodemat(X) rescales the matrix X to integers in the range [1,16]. Y = wcodemat(X,NBCODES) rescales the input X as integers in the range [1,NBCODES] . The default value of NBCODES is 16. Y = wcodemat(X,NBCODES,OPT) rescales the matrix along the dimension specified by OPT. Valid strings for OPT are: 'column' (or 'c'), 'row' (or 'r'), and 'mat' (or 'm'). 'rows' scales X row-wise,'column' scales X column-wise, and 'mat' scales X globally. The default value of OPT is 'mat'. Y = wcodemat(X,NBCODES,OPT,ABSOL) rescales the input matrix X based on the absolute values of the entries in X if ABSOL is nonzero, or based on the signed values of X if ABSOL is equal to zero. The default value of ABSOL is 1. Examples

Scale level-one approximation coefficients globally to the full range of the colormap.

load woman; % Get the range of the colormap NBCOL = size(map,1); % Obtain the 2D dwt using the Haar wavelet [cA1,cH1,cV1,cD1] = dwt2(X,'db1'); % Display without scaling image(cA1); colormap(map); title('Unscaled Image'); figure; % Display with scaling image(wcodemat(cA1,NBCOL)); colormap(map); title('Scaled Image');

function y = dyaddown(x,IN2,IN3) %DYADDOWN Dyadic downsampling. % Y = DYADDOWN(X,EVENODD) where X is a vector, and returns % a version of X that has been downsampled 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 Y Y Y Y Y

= = = = = =

DYADDOWN(X) is equivalent to DYADDOWN(X,0,'c'). DYADDOWN(X,'type') is equivalent to DYADDOWN(X,0,'type'). DYADDOWN(X,EVENODD) is equivalent to DYADDOWN(X,EVENODD,'c'). |1 2 3 4| X = |2 4 6 8| |3 6 9 0| we obtain: |2 4| DYADDOWN(X,'c') = |4 8| |6 0| |1 3| , DYADDOWN(X,'m',1) = |3 9|

When

|1 2 3 4| DYADDOWN(X,'r',1) = |3 6 9 0|

dyaddown
Dyadic downsampling

Syntax
Y = dyaddown(X,EVENODD)
Y Y Y Y Y Y Y Y = = = = = = = = dyaddown(X) dyaddown(X,EVENODD,'type') dyaddown(X,'type',EVENODD) dyaddown(X) dyaddown(X,'type') dyaddown(X,0,'type') dyaddown(X,EVENODD) dyaddown(X,EVENODD,'c')

Description Y = dyaddown(X,EVENODD) where X is a vector, returns a version of X that has been downsampled 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) (even-indexed samples). Y = dyaddown(X,EVENODD,'type') or Y = dyaddown(X,'type',EVENODD), where X is a matrix, returns a version of X obtained by suppressing one out of two: Columns of X If 'type'= 'c'
Rows of X Rows and columns of X If 'type'= 'r' If 'type'= 'm'

according to the parameter EVENODD, which is as above. If you omit the EVENODD or 'type' arguments, dyaddown defaults to EVENODD indexed samples) and 'type'= 'c' (columns).

= 0 (even-

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 % For a vector. s = 1:10 s = 1 2 3 4 5 6 7 8 9 10

dse = dyaddown(s) dse = 2 4 6 8

% Downsample elements with even indices.

10

% or equivalently dse = dyaddown(s,0) dse = 2 4 6 8 10

dso = dyaddown(s,1) % Downsample elements with odd indices. dso = 1 3 5 7 9

% For a matrix. s = (1:3)'*(1:4) s =

1 2 3

2 4 6

3 6 9

4 8 12

dec = dyaddown(s,0,'c') % Downsample columns with even indices. dec = 2 4 6 4 8 12

der = dyaddown(s,1,'r') % Downsample rows with odd indices. der = 1 3 2 6 3 9 4 12

dem = dyaddown(s,1,'m') % Downsample rows and columns % with odd indices. dem = 1 3 3 9

idwt2

Single-level inverse discrete 2-D wavelet transform

Syntax
X = idwt2(cA,cH,cV,cD,'wname')
X = idwt2(cA,cH,cV,cD,Lo_R,Hi_R) X = idwt2(cA,cH,cV,cD,'wname',S) X = idwt2(cA,cH,cV,cD,Lo_R,Hi_R,S) idwt2(cA,cH,cV,cD,'wname') X = idwt2(...,'mode',MODE) X = idwt2(cA,[],[],[],...) X = idwt2([],cH,[],[],...)

Description
The idwt2 command performs a single-level two-dimensional wavelet reconstruction with respect to either a particular wavelet ('wname', see wfilters for more information) or particular wavelet reconstruction filters (Lo_R and Hi_R) that you specify.

X = idwt2(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 details matrices cH,cV, and cD (horizontal, vertical, and diagonal, respectively). X = idwt2(cA,cH,cV,cD,Lo_R,Hi_R) reconstructs as above, using filters that you specify. Lo_R is the reconstruction low-pass filter. Hi_R is the reconstruction high-pass filter. Lo_R and Hi_R must be the same length. Let sa = size(cA) = size(cH) = size(cV) = size(cD) and lf the length of the filters; thensize(X) = SX, where SX = 2* SA, if the DWT extension mode is set to periodization. For the other extension modes, SX = 2*size(cA)-lf+2. For more information about the different Discrete Wavelet Transform extension modes, see dwtmode. 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 the syntax idwt2(cA,cH,cV,cD,'wname'). S must be less than SX. X = idwt2(...,'mode',MODE) computes the wavelet reconstruction using the extension modeMODE that you specify. X = idwt2(cA,[],[],[],...) returns the single-level reconstructed approximation coefficients matrix X based on approximation coefficients matrix cA. X = idwt2([],cH,[],[],...) returns the single-level reconstructed detail coefficients matrix Xbased on horizontal detail coefficients matrix cH. The same result holds for X = idwt2([],[],cV,[],...) and X = idwt2([],[],[],cD,...), based on vertical and diagonal details. More generally, X = idwt2(AA,HH,VV,DD,...) returns the single-level reconstructed matrix X, whereAA can be cA or [], and so on. idwt2 is the inverse function of dwt2 in the sense that the abstract statement idwt2(dwt2(X,'wname'),'wname') would give back X. Examples % The current extension mode is zero-padding (see dwtmode).

% Load original image. load woman; % X contains the loaded image. sX = size(X); % Perform single-level decomposition % of X using db4. [cA1,cH1,cV1,cD1] = dwt2(X,'db4'); % Invert directly decomposition of X % using coefficients at level 1. A0 = idwt2(cA1,cH1,cV1,cD1,'db4',sX); % Check for perfect reconstruction. max(max(abs(X-A0))) ans = 3.4176e-10

Você também pode gostar