swt2
Discrete stationary 2D wavelet transform
Description
[
returns the approximation coefficients A
,H,V,D
] = swt2(X
,N
,wname
)A
and the horizontal,
vertical, and diagonal detail coefficients H
, V
,
and D
, respectively, of the stationary 2D wavelet decomposition of
the image X
at level N
using the wavelet
wname
.
Note
swt2
is uses periodic extension.swt2
uses doubleprecision arithmetic internally and returns doubleprecision coefficient matrices.swt2
warns if there is a loss of precision when converting to double.
returns the
approximation and detail coefficients in swc
= swt2(___)swc
.
Examples
Extract and Display 2D Stationary Wavelet Decomposition
Load and display an image.
load woman imagesc(X) colormap(map) title('Original')
Perform the stationary wavelet decomposition of the image at level 2 using db6
.
[ca,chd,cvd,cdd] = swt2(X,2,'db6');
Extract the level 1 and level 2 approximation and detail coefficients from the decomposition.
A1 = wcodemat(ca(:,:,1),255); H1 = wcodemat(chd(:,:,1),255); V1 = wcodemat(cvd(:,:,1),255); D1 = wcodemat(cdd(:,:,1),255); A2 = wcodemat(ca(:,:,2),255); H2 = wcodemat(chd(:,:,2),255); V2 = wcodemat(cvd(:,:,2),255); D2 = wcodemat(cdd(:,:,2),255);
Display the approximation and detail coefficients from the two levels.
subplot(2,2,1) imagesc(A1) title('Approximation Coef. of Level 1') subplot(2,2,2) imagesc(H1) title('Horizontal Detail Coef. of Level 1') subplot(2,2,3) imagesc(V1) title('Vertical Detail Coef. of Level 1') subplot(2,2,4) imagesc(D1) title('Diagonal Detail Coef. of Level 1')
subplot(2,2,1) imagesc(A2) title('Approximation Coef. of Level 2') subplot(2,2,2) imagesc(H2) title('Horizontal Detail Coef. of Level 2') subplot(2,2,3) imagesc(V2) title('Vertical Detail Coef. of Level 2') subplot(2,2,4) imagesc(D2) title('Diagonal Detail Coef. of Level 2')
Stationary Wavelet Transform of RGB Image
This example shows how to obtain singlelevel and multilevel stationary wavelet decompositions of an RGB image.
Load and view an RGB image. The image is a 3D array of type uint8
. Since swt2
requires that the first and second dimensions both be divisible by a power of 2, extract a portion of the image.
imdata = imread('ngc6543a.jpg'); x = imdata(1:512,1:512,:); image(x) title('RGB Image')
Obtain the level 4 stationary wavelet decomposition of the image using the db4
wavelet. Return the approximation coefficients. Note the dimensions of the coefficients array.
[a,~,~,~] = swt2(x,4,'db4');
size(a)
ans = 1×4
512 512 3 4
The coefficients are all of type double
. In an RGB array of type double
, each color component is a value between 0 and 1. Rescale the level 2 approximation coefficients to values between 0 and 1 and view the result.
a2 = a(:,:,:,2);
a2 = (a2min(a2(:)))/(max(a2(:))min(a2(:)));
image(a2)
title('Level 2 Approximation')
Obtain the singlelevel stationary wavelet decomposition of the image using the db4
wavelet. Return the approximation coefficients. In a singlelevel decomposition of an RGB image, the third dimension is singleton.
[a,~,~,~] = swt2(x,1,'db4');
size(a)
ans = 1×4
512 512 1 3
View the approximation coefficients. To prevent an error when using image
, squeeze the approximation coefficients array to remove the singleton dimension.
a2 = squeeze(a);
a2 = (a2min(a(:)))/(max(a(:))min(a(:)));
image(a2)
title('Approximation')
Input Arguments
X
— Input image
2D matrix  3D array
Input image, specified as a realvalued 2D matrix or realvalued 3D array. If
X
is 3D, X
is assumed to be an RGB image,
also referred to as a truecolor image, and the third dimension of
X
must equal 3. For more information on truecolor images, see
Image Types.
Data Types: double
N
— Level of decomposition
positive integer
Level of decomposition, specified as a positive integer.
2^{N} must divide size(X,1)
and
size(X,2)
. Use wmaxlev
to determine the maximum level of decomposition.
wname
— Analyzing wavelet
character vector  string scalar
Analyzing wavelet, specified as a character vector or string scalar.
swt2
supports only Type 1 (orthogonal) or Type 2 (biorthogonal)
wavelets. See wfilters
for a list of orthogonal and
biorthogonal wavelets.
LoD,HiD
— Wavelet decomposition filters
evenlength realvalued vectors
Wavelet decomposition filters, specified as a pair of evenlength realvalued
vectors. LoD
is the lowpass decomposition filter, and
HiD
is the highpass decomposition filter. The lengths of
LoD
and HiD
must be equal. See wfilters
for additional information.
Output Arguments
A
— Approximation coefficients
2D matrix  3D array  4D array
Approximation coefficients, returned as a multidimensional array. The dimensions of
A
depend on the dimensions of the input X
and the level of decomposition N
.
If
X
is mbyn:If
N
is greater than 1, thenA
is mbynbyN
. For 1 ≤ i ≤N
,A(:,:,i)
contains the approximation coefficients at level i.If
N
is equal to 1, thenA
is mbyn.
If
X
is mbynby3:If
N
is greater than 1, thenA
is mbynby3byN
. For 1 ≤ i ≤N
andj = 1, 2, 3
,A(:,:,j,i)
contains approximation coefficients at level i.If
N
is equal to 1, thenA
is mbynby1by3. Since MATLAB^{®} removes singleton last dimensions by default, the third dimension is singleton.
Data Types: double
H,V,D
— Detail coefficients
2D matrix  3D array  4D array
Detail coefficients, returned as multidimensional arrays of equal size.
H
, V
, and D
contain the
horizontal, vertical, and diagonal detail coefficients, respectively. The dimensions of
the arrays depend on the dimensions of the input X
and the level of
decomposition N
.
If
X
is mbyn:If
N
is greater than 1, the arrays are mbynbyN
. For 1 ≤ i ≤N
,H(:,:,i)
,V(:,:,i)
, andD(:,:,i)
contain the detail coefficients at level i.If
N
is equal to 1, the arrays are mbyn.
If
X
is mbynby3:If
N
is greater than 1, the arrays are mbynby3byN
. For 1 ≤ i ≤N
andj = 1, 2, 3
,H(:,:,j,i)
,V(:,:,j,i)
, andD(:,:,j,i)
contain the detail coefficients at level i.If
N
is equal to 1, the arrays are mbynby1by3. Forj = 1, 2, 3
,H(:,:,1,j)
,V(:,:,1,j)
andD(:,:,1,j)
contain the detail coefficients. Since MATLAB removes singleton last dimensions by default, the third dimension is singleton.
Data Types: double
swc
— Stationary wavelet decomposition
3D array  4D array
Stationary wavelet decomposition, returned as a multidimensional array.
swc
is the concatenation of the approximation coefficients
A
and detail coefficients H
,
V
, and D
.
Algorithms
2D Discrete Stationary Wavelet Transform
For images, a stationary wavelet transform (SWT) algorithm similar to the onedimensional case is possible for twodimensional wavelets and scaling functions obtained from onedimensional functions by tensor product. This kind of twodimensional SWT leads to a decomposition of approximation coefficients at level j into four components: the approximation at level j+1, and the details in three orientations (horizontal, vertical, and diagonal).
This chart describes the basic decomposition step for images.
where
— Convolve the rows of the entry with filter X.
— Convolve the columns of the entry with filter X.
Initialization
cA_{0} = s
F_{0} =
LoD
G_{0} =
HiD

where denotes upsample.
Note that size(cA_{j}) =
size(cD_{j}^{(h)}) =
size(cD_{j}^{(v)}) =
size(cD_{j}^{(d)}) =
s
, where s equals the size of the
analyzed image.
Truecolor Image Coefficient Arrays
To distinguish a singlelevel decomposition of a truecolor image from a multilevel decomposition of an indexed image, the approximation and detail coefficient arrays of truecolor images are 4D arrays.
If you perform a multilevel decomposition, the dimensions of
A
,H
,V
, andD
are mbynby3byk, where k is the level of decomposition.If you perform a singlelevel decomposition, the dimensions of
A
,H
,V
, andD
are mbynby1by3. Since MATLAB removes singleton last dimensions by default, the third dimension of the arrays is singleton.
References
[1] Nason, G. P., and B. W. Silverman. “The Stationary Wavelet Transform and Some Statistical Applications.” In Wavelets and Statistics, edited by Anestis Antoniadis and Georges Oppenheim, 103:281–99. New York, NY: Springer New York, 1995. https://doi.org/10.1007/9781461225447_17.
[2] Coifman, R. R., and D. L. Donoho. “TranslationInvariant DeNoising.” In Wavelets and Statistics, edited by Anestis Antoniadis and Georges Oppenheim, 103:125–50. New York, NY: Springer New York, 1995. https://doi.org/10.1007/9781461225447_9.
[3] Pesquet, J.C., H. Krim, and H. Carfantan. “TimeInvariant Orthonormal Wavelet Representations.” IEEE Transactions on Signal Processing 44, no. 8 (August 1996): 1964–70. https://doi.org/10.1109/78.533717.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
The input wavelet name must be constant.
The input level of decomposition must be defined as a scalar during compilation.
Version History
Introduced before R2006aR2017b: Distinguish SingleLevel Truecolor Image from Multilevel Indexed Image Decompositions
To distinguish a singlelevel decomposition of a truecolor image from a multilevel decomposition of an indexed image, the approximation and detail coefficient arrays of truecolor images are 4D arrays.
Migrate from Previous Releases to R2017b
Depending on the original input data type and level of wavelet decomposition, you might have to take different steps to make
swt2
coefficient arrays from previous releases compatible with R2017b coefficient arrays. The steps depend on whether you have a single coefficient array or separate approximation and detail coefficient arrays.Single Coefficient Array Multiple Coefficient Arrays Input: Index image
Singlelevel: No compatibility issues
Multilevel: No compatibility issues
Input: Index image
Singlelevel: No compatibility issues
Multilevel: No compatibility issues
Input: Truecolor image
Singlelevel: If
swc
is the output ofswt2
from a previous release, execute:swc1 = double(swc);
Multilevel: If
swc
is the output ofswt2
from a previous release, execute:swc1 = double(swc);
Input: Truecolor image
Singlelevel: If
ca
,chd
,cvd
, andcdd
are outputs ofswt2
from a previous release, execute:ca1 = double(ca); chd1 = double(chd); cvd1 = double(cvd); cdd1 = double(cdd); ca2 = reshape(ca1,[m,n,1,3]); chd2 = reshape(chd1,[m,n,1,3]); cvd2 = reshape(cvd1,[m,n,1,3]); cdd2 = reshape(cdd1,[m,n,1,3]);
Multilevel: If
ca
,chd
,cvd
, andcdd
are outputs ofswt2
from a previous release, execute:ca1 = double(ca); chd1 = double(chd); cvd1 = double(cvd); cdd1 = double(cdd);
Migrate from R2017b to Previous Releases
Depending on the original input data type and level of wavelet decomposition, you might have to take different steps to make R2017b
swt2
coefficient arrays compatible with the coefficient arrays from previous releases. The steps depend on whether you have a single coefficient array or separate approximation and detail coefficient arrays.Single Coefficient Array Multiple Coefficient Arrays Input: Index image
Singlelevel: No compatibility issues
Multilevel: No compatibility issues
Input: Index image
Singlelevel: No compatibility issues
Multilevel: No compatibility issues
Input: Truecolor image
Singlelevel: No compatibility issues
Multilevel: No compatibility issues
Input: Truecolor image
Singlelevel: If
ca
,chd
,cvd
, andcdd
are outputs ofswt2
from R2017b, execute:ca1 = single(squeeze(ca)); chd1 = single(squeeze(chd)); cvd1 = single(squeeze(cvd)); cdd1 = single(squeeze(cdd));
Multilevel: No compatibility issues
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
 América Latina (Español)
 Canada (English)
 United States (English)
Europe
 Belgium (English)
 Denmark (English)
 Deutschland (Deutsch)
 España (Español)
 Finland (English)
 France (Français)
 Ireland (English)
 Italia (Italiano)
 Luxembourg (English)
 Netherlands (English)
 Norway (English)
 Österreich (Deutsch)
 Portugal (English)
 Sweden (English)
 Switzerland
 United Kingdom (English)