Escolar Documentos
Profissional Documentos
Cultura Documentos
A fractal along with a two level Haar (standard) decomposition. Image source: Carlson's Fractal Gallery.
1 Goal
The goals with this lab are: 1. Understand the properties of the Haar basis. 2. Understand the averaging and differencing technique and how it relates to a wavelet decomposition. 3. Use the Haar transform to compress and de-noise one dimensional signals and images.
2 Introduction
This lab will illustrate some fundamental concepts about wavelets and multiresolution theory. Most examples and definitions will be made with respect to the Haar scaling function and the Haar wavelet. However, the concepts covered in this lab are true for more ``advanced'' wavelets such as the Daubechies wavelets.
(1)
Define
as
(2)
(3)
where
The index j refers to dilation and i refers to translation. Warning! This definition may be different in different texts! Sometimes one defines the scaling function for negative integers as well and uses a different sign convention. Whenever you use a text on wavelets, make sure you know what sign convention is being used.
The constant
when j is fixed.
(4)
Based on your plots in a) above, convince yourself (and the reader of your lab report) that this property holds for the Haar scaling function. (If you see this relation written in ``the opposite direction'' in some text, they used a different sign convention. The relation given above is consistent with Definition 1.) Definition 2 (The Haar wavelet function) Let be defined by
(5)
Define
as
(6)
(7)
where
Warning! This definition may be different in different texts! Sometimes one defines the wavelet function for negative integers as well and uses a different sign convention. Whenever you use a text on wavelets, make sure you know what sign convention is being used.
when j is fixed.
(8)
Based on your plots in a) above, convince yourself (and the reader of your lab report) that this property holds for the Haar wavelet function. (If you see this relation written in ``the opposite direction'' in some text, they used a different sign convention. The relation given above is consistent with Definition 2.) c) A standard argument for using wavelets rather than the Fourier basis for signal processing is that the Haar wavelet is localized. By looking at your plots from a) above, can you see why the Haar wavelet is called a ``localized'' function? Is the Fourier basis localized?
(9)
Using, e.g., the Matlab functions haargrid.m and haarwavelet.m, produce a few plots that illustrate the following relation:
(10)
(The formulation of this exercise is very vague. However, the purpose is to visualize the important relation Use your imagination to do this.)
(11)
Let
be an ON-basis in
.Then
(12)
Let us first review how this was used for Fourier analyzing a signal and then see how this can be used for wavelet expansion of a
http://amath.colorado.edu/courses/5720/2000Spr/Labs/Haar/haar.html (4 of 15)5/19/2010 12:08:54 PM
signal.
(13)
Denote the (n+1):th element of the v vector as v [n]. Then f can be expanded as in (12) with
k k
(14)
where * denotes complex conjugation. Numerically, we compute <f,v > by using the Fast Fourier Transform.
k
(15)
The correspondence to Fourier expanding a signal is now to compute the inner products
and
. In
principle, we could do this by evaluating an integral (or a sum in the discrete case). In practice, computation of the inner products for a wavelet basis is done as illustrated by the following example.
Step 1:
Step 2:
Step 3:
The numbers in the final vector are the coefficients in the expansion (15). You probably notice the pattern, we add/subtract a pair of numbers, divide by the normalization factor and between every step we don't touch the last elements of the vector. This
procedure is called ``averaging and differencing''. In the next section, we will study this example in more depth and see what we really did mathematically.
Haar mother scaling function which has been dilated so that each basis function has a support equal to 1/8 (=1 pixel) of the support of f which is 8 pixels. Our goal is to expand f into . We will do this in three steps.
The first step in the example above can be described as the matrix-vector multiplication f1=W1f where
http://amath.colorado.edu/courses/5720/2000Spr/Labs/Haar/haar.html (6 of 15)5/19/2010 12:08:54 PM
(16)
Notice that the first four rows correspond to the basis vectors
and
and
Hence, the final vector in Step 1 in the example above is nothing more than the coefficients of f in the expansion
(17)
In this step we notice that we already have the coefficients for the basis vectors of W2. Hence we don't have to worry about these coefficients in this step, we simply just keep these coefficients (the last four entries of our vector in the previous step) and only work with the first four entries. The second step can be described as the matrix-vector multiplication f2=W2f1 where
(18)
We can combine the first and the second step as f2=W2W1f where
(19)
Notice that the first two rows correspond to the basis vectors
and
The third and fourth rows correspond to the basis vectors vectors of W2.
and
which span W1. The last four rows correspond to the basis
Hence, the final vector in Step 2 in the example above is nothing else than the coefficients of f in the expansion
(20)
In this step we notice that we already have the coefficients for the basis vectors of
about these coefficients in this step, we simply just keep these coefficients (the last six entries of our vector in the previous step) and only work with the first two entries. The third step can be described as the matrix-vector multiplication f3=W3f2 where
(21)
We can combine the first, second and third step as f3=W3W2W1f where
(22)
Notice that the first row corresponds to the basis vector which spans W0 and so on.
which spans V0, the second row corresponds to the basis vector
Hence, the final vector in Step 3 in the example above is nothing else than the coefficients of f in the expansion
(23)
(24)
input data. The low pass and high pass filters make up what in signal processing language is referred to as a filter bank. The method of averaging and differencing is referred to as analysis. The reverse procedure (going the opposite way in the example above) is called synthesis. Hence, the wavelet transform separates low and high frequencies, just as the Fourier transform. Since different features of a signal (background, details, noise, edges, etc.) correspond to different frequencies, this is a key to use wavelets in signal processing. The nice thing is that wavelets are localized since they only live on part of the interval of the data, as opposed to the trigonometric functions used in Fourier analysis which live on the entire interval of the data.
6 Exercises
In the previous lab on Fourier techniques in image processing, we learned that when we want to manipulate an image (compress, denoise, etc.), we first transformed the image into the Fourier basis, performed our manipulations in this basis, and then transformed back. The same principle holds when using wavelets techniques for image processing! Now we will transform our image into a wavelet basis, perform our manipulations in this basis, and then transform back. The foundation of signal processing can be described as to find a basis which is suitable for the manipulations we need. This means that image processing relies on concepts from linear algebra such as orthogonality, norms, inner products, etc.
When doing the exercises below, there are a few things you should keep in mind. Just as you probably has developed a feeling for what a Fourier spectrum looks like and how it can be interpreted, try to get a feeling for how a signal looks like in the Haar wavelet basis. Where can you find the high/low frequencies? Where is the magnitude of the coefficients large/small? When you wavelet decompose images, there is a trick to make it easier to study the decomposition. Usually a major part of the decomposition (see the image in the beginning of this instruction) is very dark. If you use Matlab, use the command brighten() to find a suitable brightness of the picture. When you run your wavelet transform in Matlab, you may notice that the transform is quite slow. Even though you may have implemented your wavelet transform as a ``fast algorithm'', the architecture of the Matlab language may slow down your algorithm considerably. This has to do with the fact that loops and recursive functions calls (which you may need) are time consuming in Matlab. Don't worry about that, but keep in mind that your algorithm probably is much faster in C or Fortran which can handle loops and subroutine calls much more efficient than Matlab.
A vector of length 2 where k is a positive integer. The ``level'' of decomposition. (E.g., the first step in the example in section 5.2.1 corresponds to a first level decomposition, the second step corresponds to a second level decomposition and the third step corresponds to a third level decomposition.)
Output:
q
A vector which is the Haar transformation of the vector you gave as input corresponding to the level you gave as an input.
The purpose of this exercise is to build a Haar transform to use for the following exercises. If you want to use slightly different input/ outputs, feel free to do so as long as you can use your Haar transform efficiently. a) Verify that your transform can reproduce the example in section 5.2.1. b) Verify that the l2-norm is preserved in each of the three steps in the example. c) Build an inverse Haar transform, i.e., a code that takes a Haar transformed vector and returns a non-transformed vector. (A ``reverse'' of the code in a).)
(25)
at at least 1024 points. Plot the wavelet decomposition of the signal at a few different levels. By using thresholding (like in the previous lab) on the Haar transformed signal, investigate the compression performance of the Haar transform. Compare the compression performance to a compression using the FFT of the same signal. Bonus question: If this signal represents a sound signal, what does the signal sound like?
Fractal from Carlson's Fractal Gallery with random noise added. (Do not expect your de-noising to do miracles. There are many approaches to de-noise. The simplest is probably to do thresholding on your wavelet decomposed image but you may come up with other methods that work better.)
Do a Haar wavelet decomposition of this image at a few different levels. What are your observations? (You may have to adjust the brightness of the wavelet decomposition using brighten() in Matlab.)
An MRI (Magnetic Resonance Imaging) image from First Radiology Clinic with "a scratch" added. Medical imaging is a very important application of digital image processing.
8 Questions?
In case you have questions regarding the material in this lab, do not hesitate to contact me at kristian.sandberg@colorado.
http://amath.colorado.edu/courses/5720/2000Spr/Labs/Haar/haar.html (14 of 15)5/19/2010 12:08:54 PM
edu or visit me during my lab hours Mondays 4:30-6 pm and Thursdays 4-5:30 pm in ECCR 143. Lycka till!