Wavelet Transform
Ruye Wang 2008-12-16 Why Wavelet?A time signal To address this dilemma, we can truncate the signal
![]() where the time window has width
![]() The spectrum of this windowed signal is for the specific time period
![]() The Fourier transform of this Gassian filtered time signal is called the
Gabor transform. Although the spectral property of a windowed signal can be
better localized in time, its resolution in frequency is reduced as its spectrum
is blurred by the convolution with
![]() Alternatively, we can assume the truncated signal We see that it is simply impossible to have the complete information of a given signal in both time and frequency domains at the same time, as increasing the resolution in one domain will necessarily reduce that in the other. This effect is referred to as Heisenberg uncertainty, as it is anologous to the fact in quantum physics that the position and momentum of a particle cannot be measured simultaneously, higher precision in one quantity implies lower in the other. If the characteristics of the signal in question do not change much over time, i.e, the signal is stationary, then Fourier transform is sufficient for the analysis of the signal. However, in many applications it is the transitory or nonstationary aspects of the signal (e.g., drift, trends, abrupt changes) that are of most interest. In such cases, Fourier analysis is unable to detect when/where such events take place and is therefore not suitable to describe or represent them. In order to overcome this limitation of Fourier analysis to gain information in both time and frequency domain, a different kind of transform, called wavelet transform can be used. Wavelewt transform can be viewed as a trade-off between time and frequency domains. Unlike Fourier transform which transforms a signal between time (or space) and frequency domains, wavelet transform emphasizes locations and scales (instead of frequency). From the lowest time scale to the highest, the scale is always halved to reveal more details (time resolution doubled), while the gap between consecutive scales is doubled, i.e., the scale resolution is reduced as illustrated by the Heisenberg Box (Cell) below: Haar WaveletsA continuous signal can be approximated by a sequence of unit impulse
functions, also called scaling functions, weighted by the sampling values of the
intensity or amplitude of the signal:
![]() where
![]() Consider two adjacent impulse functions:
![]() The sum of two adjacent impulse functions is a wider impulse:
![]() and the difference of two adjacent impulse functions is the basic
wavelet, denoted by
![]() By solving (adding and subtracting) the two equations above, the two
impulse functions can be obtained:
![]() Then any two-sample function can be written as
![]() where Scaling FunctionsConsider a set of functions
![]() where the specific function
![]() ![]()
![]() indicating how a function Corresponding to a specific index If a family of functions
![]()
Functions satisfying these requirements are called scaling
functions. As the basis functions, a subset of scaling functions
Note: The nested relations between the sequence of subspaces shown
above is closely related to the Gaussian-Laplacian pyramid discussed earlier.
Essentially they both state that a signal can be decomposed into a set of
components each representing details of different levels contained in the
signal. The images in the Laplacian pyramid correspond to the subspaces The basis functions
![]() And they can be expanded in the space
![]() where
![]() This is called refinement, dilation or MRA (multiresolution analysis) equation.
The first 4 panels show the scaling functions: Example: The Haar scaling function at level
![]() Scaling function
![]() For example, when
![]() A given function
![]() This is shown in panel 5 of the figure above. Moreover, the Haar scaling functions in space
![]() This is shown in panel 6 of the figure above. In particular,
![]() But as
![]() the above can be written as
![]() where the two coefficients Wavelet FunctionsWe denote by
![]() (where
![]() and finally:
![]()
Similar to a function space
![]() We see that the scaling sequence and the wavelet sequence correspond to low-pass filter and band-pass filter, respectively. Also, as the wavelet functions
![]() they can be expanded in the space
![]() where
![]() This is in the same form for the scaling functions:
![]() It can be shown that the coefficients of the two expressions are related
![]()
Examples: The Haar scaling function
![]() and the wavelet function is:
![]() where the two coefficients
The first two panels show the wavelet functions of scale
![]() The 3rd panel shows the wavelet functions of scale Wavelet ExpansionFor a specific value
![]() which indicates that any square-integrable function
![]() where
![]() and
![]()
The first term contained in the wavelet expansion of the function An Example A continuous function
![]() We use Haar wavelets, and a starting scale
![]()
![]()
![]()
![]() Therefore the wavelet series expansion of the function
![]() Here the first term is
This process can be carried out further. By contineously reducing the scale
by half (spaces Discrete Wavelet TransformThe discrete signal
![]() for some initial time
![]() This is the inverse wavelet transform where the summation over
![]()
![]() where An Example: Assume
![]() The coefficient for
![]() The coefficient for
![]() The two coefficients for
![]()
![]() In matrix form, we have
![]() Now the function
![]() or in matrix form:
![]() Fast Wavelet Transform (FWT) and Filter BankAs shown before, the discrete wavelet transform of a discrete signal
![]()
![]() where the basis scaling and wavelet functions are respectively
![]() Recall that both the scaling and wavelet functions can be expanded in
terms of the basis scaling functions of the next higher resolution:
![]() We now consider a fast algorithm to obtain the coefficients
![]() We then let
![]() Similarly, the wavelet function can also be expanded:
![]() This wavelet function is identical to the one used in the discrete
wavelet transform above, which can be replaced by the right-hand side of the
equation:
Note that the expression inside the brackets happens to be the wavelet
transform for the coefficient of scale
![]() therefore we have a recursive relation between the wavelet transform
coefficients of two consecutive scale levels
![]() and the same is true to the scaling function:
![]() Comparing these equations with a discrete convolution:
![]() we see that the wavelet transform coefficients
![]() Based on these two equations, all wavelet and scaling coefficients
![]() If we let the kth basis function be a unit pulse at the kth sampling
time, i.e., Inverse Wavelet Transform As the forward wavelet transform - finding the transform coefficients Complexity of FWT The computation cost of the fast wavelet transform (FWT) is the convolutions
carried out in each of the filters. The number of data samples in the
convolution is halved after each sub-sampling, therefore the total complexity
is:
![]() i.e., the FWT has linear complexity.
The system shown in the figure above is called a filter bank and is further discussed here A detailed discussion about Matlab implementaton can be found on this MathWorks webpage. 2D DWT
Matlab code for 2DWT (forward) Matlab code for 2DWT (inverse) function [c, s] = wavefast(x, n, varargin) %WAVEFAST Perform multi-level 2-dimensional fast wavelet transform. % [C, L] = WAVEFAST(X, N, LP, HP) performs a 2D N-level FWT of % image (or matrix) X with respect to decomposition filters LP and % HP. % % [C, L] = WAVEFAST(X, N, WNAME) performs the same operation but % fetches filters LP and HP for wavelet WNAME using WAVEFILTER. % % Scale parameter N must be less than or equal to log2 of the % maximum image dimension. Filters LP and HP must be even. To % reduce border distortion, X is symmetrically extended. That is, % if X = [c1 c2 c3 ... cn] (in 1D), then its symmetric extension % would be [... c3 c2 c1 c1 c2 c3 ... cn cn cn-1 cn-2 ...]. % % OUTPUTS: % Matrix C is a coefficient decomposition vector: % % C = [ a(n) h(n) v(n) d(n) h(n-1) ... v(1) d(1) ] % % where a, h, v, and d are columnwise vectors containing % approximation, horizontal, vertical, and diagonal coefficient % matrices, respectively. C has 3n + 1 sections where n is the % number of wavelet decompositions. % % Matrix S is an (n+2) x 2 bookkeeping matrix: % % S = [ sa(n, :); sd(n, :); sd(n-1, :); ... ; sd(1, :); sx ] % % where sa and sd are approximation and detail size entries. % % See also WAVEBACK and WAVEFILTER. % Copyright 2002-2004 R. C. Gonzalez, R. E. Woods, & S. L. Eddins % Digital Image Processing Using MATLAB, Prentice-Hall, 2004 % $Revision: 1.5 $ $Date: 2003/10/13 01:14:17 $ % Check the input arguments for reasonableness. error(nargchk(3, 4, nargin)); if nargin == 3 if ischar(varargin{1}) [lp, hp] = wavefilter(varargin{1}, 'd'); else error('Missing wavelet name.'); end else lp = varargin{1}; hp = varargin{2}; end fl = length(lp); sx = size(x); if (ndims(x) ~= 2) | (min(sx) < 2) | ~isreal(x) | ~isnumeric(x) error('X must be a real, numeric matrix.'); end if (ndims(lp) ~= 2) | ~isreal(lp) | ~isnumeric(lp) ... | (ndims(hp) ~= 2) | ~isreal(hp) | ~isnumeric(hp) ... | (fl ~= length(hp)) | rem(fl, 2) ~= 0 error(['LP and HP must be even and equal length real, ' ... 'numeric filter vectors.']); end if ~isreal(n) | ~isnumeric(n) | (n < 1) | (n > log2(max(sx))) error(['N must be a real scalar between 1 and ' ... 'log2(max(size((X))).']); end % Init the starting output data structures and initial approximation. c = []; s = sx; app = double(x); % For each decomposition ... for i = 1:n % Extend the approximation symmetrically. [app, keep] = symextend(app, fl); % Convolve rows with HP and downsample. Then convolve columns % with HP and LP to get the diagonal and vertical coefficients. rows = symconv(app, hp, 'row', fl, keep); coefs = symconv(rows, hp, 'col', fl, keep); c = [coefs(:)' c]; s = [size(coefs); s]; coefs = symconv(rows, lp, 'col', fl, keep); c = [coefs(:)' c]; % Convolve rows with LP and downsample. Then convolve columns % with HP and LP to get the horizontal and next approximation % coeffcients. rows = symconv(app, lp, 'row', fl, keep); coefs = symconv(rows, hp, 'col', fl, keep); c = [coefs(:)' c]; app = symconv(rows, lp, 'col', fl, keep); end % Append final approximation structures. c = [app(:)' c]; s = [size(app); s]; %-------------------------------------------------------------------% function [y, keep] = symextend(x, fl) % Compute the number of coefficients to keep after convolution % and downsampling. Then extend x in both dimensions. keep = floor((fl + size(x) - 1) / 2); y = padarray(x, [(fl - 1) (fl - 1)], 'symmetric', 'both'); %-------------------------------------------------------------------% function y = symconv(x, h, type, fl, keep) % Convolve the rows or columns of x with h, downsample, % and extract the center section since symmetrically extended. if strcmp(type, 'row') y = conv2(x, h); y = y(:, 1:2:end); y = y(:, fl / 2 + 1:fl / 2 + keep(2)); else y = conv2(x, h'); y = y(1:2:end, :); y = y(fl / 2 + 1:fl / 2 + keep(1), :); end ****************************************************************** function [varargout] = waveback(c, s, varargin) %WAVEBACK Performs a multi-level two-dimensional inverse FWT. % [VARARGOUT] = WAVEBACK(C, S, VARARGIN) computes a 2D N-level % partial or complete wavelet reconstruction of decomposition % structure [C, S]. % % SYNTAX: % Y = WAVEBACK(C, S, 'WNAME'); Output inverse FWT matrix Y % Y = WAVEBACK(C, S, LR, HR); using lowpass and highpass % reconstruction filters (LR and % HR) or filters obtained by % calling WAVEFILTER with 'WNAME'. % % [NC, NS] = WAVEBACK(C, S, 'WNAME', N); Output new wavelet % [NC, NS] = WAVEBACK(C, S, LR, HR, N); decomposition structure % [NC, NS] after N step % reconstruction. % % See also WAVEFAST and WAVEFILTER. % Copyright 2002-2004 R. C. Gonzalez, R. E. Woods, & S. L. Eddins % Digital Image Processing Using MATLAB, Prentice-Hall, 2004 % $Revision: 1.5 $ $Date: 2003/10/13 01:29:36 $ % Check the input and output arguments for reasonableness. error(nargchk(3, 5, nargin)); error(nargchk(1, 2, nargout)); if (ndims(c) ~= 2) | (size(c, 1) ~= 1) error('C must be a row vector.'); end if (ndims(s) ~= 2) | ~isreal(s) | ~isnumeric(s) | (size(s,2) ~= 2) error('S must be a real, numeric two-column array.'); end elements = prod(s, 2); if (length(c) < elements(end)) | ... ~(elements(1) + 3 * sum(elements(2:end - 1)) >= elements(end)) error(['[C S] must be a standard wavelet ' ... 'decomposition structure.']); end % Maximum levels in [C, S]. nmax = size(s, 1) - 2; % Get third input parameter and init check flags. wname = varargin{1}; filterchk = 0; nchk = 0; switch nargin case 3 if ischar(wname) [lp, hp] = wavefilter(wname, 'r'); n = nmax; else error('Undefined filter.'); end if nargout ~= 1 error('Wrong number of output arguments.'); end case 4 if ischar(wname) [lp, hp] = wavefilter(wname, 'r'); n = varargin{2}; nchk = 1; else lp = varargin{1}; hp = varargin{2}; filterchk = 1; n = nmax; if nargout ~= 1 error('Wrong number of output arguments.'); end end case 5 lp = varargin{1}; hp = varargin{2}; filterchk = 1; n = varargin{3}; nchk = 1; otherwise error('Improper number of input arguments.'); end fl = length(lp); if filterchk % Check filters. if (ndims(lp) ~= 2) | ~isreal(lp) | ~isnumeric(lp) ... | (ndims(hp) ~= 2) | ~isreal(hp) | ~isnumeric(hp) ... | (fl ~= length(hp)) | rem(fl, 2) ~= 0 error(['LP and HP must be even and equal length real, ' ... 'numeric filter vectors.']); end end if nchk & (~isnumeric(n) | ~isreal(n)) % Check scale N. error('N must be a real numeric.'); end if (n > nmax) | (n < 1) error('Invalid number (N) of reconstructions requested.'); end if (n ~= nmax) & (nargout ~= 2) error('Not enough output arguments.'); end nc = c; ns = s; nnmax = nmax; % Init decomposition. for i = 1:n % Compute a new approximation. a = symconvup(wavecopy('a', nc, ns), lp, lp, fl, ns(3, :)) + ... symconvup(wavecopy('h', nc, ns, nnmax), ... hp, lp, fl, ns(3, :)) + ... symconvup(wavecopy('v', nc, ns, nnmax), ... lp, hp, fl, ns(3, :)) + ... symconvup(wavecopy('d', nc, ns, nnmax), ... hp, hp, fl, ns(3, :)); % Update decomposition. nc = nc(4 * prod(ns(1, :)) + 1:end); nc = [a(:)' nc]; ns = ns(3:end, :); ns = [ns(1, :); ns]; nnmax = size(ns, 1) - 2; end % For complete reconstructions, reformat output as 2-D. if nargout == 1 a = nc; nc = repmat(0, ns(1, :)); nc(:) = a; end varargout{1} = nc; if nargout == 2 varargout{2} = ns; end %-------------------------------------------------------------------% function z = symconvup(x, f1, f2, fln, keep) % Upsample rows and convolve columns with f1; upsample columns and % convolve rows with f2; then extract center assuming symmetrical % extension. y = zeros([2 1] .* size(x)); y(1:2:end, :) = x; y = conv2(y, f1'); z = zeros([1 2] .* size(y)); z(:, 1:2:end) = y; z = conv2(z, f2); z = z(fln - 1:fln + keep(1) - 2, fln - 1:fln + keep(2) - 2);
|
|