You are on page 1of 47

Wavelets,

for the Layman


Mike Acton
25 Jan 08
Introduction
• This won’t be math-heavy.
• De-mystify the jargon.
• Enough understanding to use it yourself.
• Just an introduction – From here you’ll
know what to look for.
• It’s really easy.
What’s are these wavelets?
• It does something with a sequence
(vector) of sample values, but is it…
• Some kind of fancy pants compression?
• Some kind of tricky math?
• Some kind of scam to give people to write
something a thesis about?
It’s a transform
• When you hear “wavelets”, you should
really think “wavelet transform”
• Take data from one format, change it to
another format that is better organized.
• There is no compression!
It’s a transform
• Take data from one format, change it to another
format that is better organized.
• In a raw signal, everything has the same weight
(equally important).
• We want to reduce the energy needed to
produce the exact same signal. (What this
means depends on context. But, for example:
number of bits needed for compression)
– i.e. Lower the entropy.
– NOTE: Implies that there is order to be found in the
system. (Not random!)
• We also want to sort information by importance.
It’s a transform
• Think something like the Burrows-Wheeler
transform.
– http://en.wikipedia.org/wiki/Burrows-Wheeler_transform
• Find the “order” in the system. BWT (as most text
transforms) organizes by entry in the palette.
• ^BANANA@  BNN^AA@A
– Now there’s some exploitable order.
– e.g. Now usually takes less energy to describe with just RLE
It’s a transform
• The transform from 20,000 ft:
• Given signal vector [x] of length n,
– F(x) transforms [X] into vector [F] of length n/2
– G(x) transforms [X] info vector [G] of length n/2
– H(F(x),G(x)) transforms [F],[G] back into [X]
It’s a transform
• F(x) can be considered…
– Low-pass filter, or…
– Prediction
• G(x) can be considered…
– High-pass filter, or…
– Update
• H(f,g) can be considered…
– Band-pass combine, or…
– Inverse
It’s a transform
• “Wavelet” refers to the shape of
F(x) and G(x)
It’s a transform
• Why “Wavelet” and not “Wave”?
– A wave cycles, a wavelet doesn’t.
– Only acts on local area of the input vector.
– Then with all the local “wavelet” results, we
can recombine to the larger, full signal.
It’s a transform
• In practice, any functions
for F(x), G(x) and H(x) that
satisfy the conditions you want
can be considered.
• Choosing the right functions is
a bit of a challenge. But there
are lots of good ones.
Discrete Wavelet Transform
• Recursively transform LOW, F(x)

• That’s it.
Wavelet Packet Transform
• Recursively transform both, F(x) and G(x)
Best Basis
• Sometimes, less processed vectors end up
“cheaper” (use less energy)
e.g. [F0] might be cheaper than [f1], [gf1]

So we keep F[0] instead. (Requires an extra list of what was kept)


Start with an example.
• The classic favorite: “Average and
difference”

• F(x) = 0.5 * (x[n] + x[n+1])


• G(x) = x[n] – F(x)
• (H) Reconstruct with simple line segment.
Average and Difference, con’t
• (H) Reconstruct with simple line segment.
• X[n] = G[n/2] + F[n/2]
• X[n+1] = G[n/2] – F[n/2]
Example 1
• Notice:
– [F] and [G] are each half length of [X]
– i.e {[F],[G]} is same length as [X]
– The range of [G] is much smaller than [X]
– “Less energy” in this case = less bits needed.
– [G] has order: Larger values are more
“important” than smaller values. Particularly
for images.
It’s a transform
• Why else a “Wavelet” and not “Wave”?
– i.e. Given [X] of length n,
• Ax = b
• Matrix [A] is n by n and contains F(x) and G(x)
• Vector [B] is length n and contains the vectors [F]
and [G]
• Matrix [A] contains F(x) and G(x)
• Matrix [A] is sparse and only non-zero in the
diagonal (more-or-less).
2D Example
• Let’s look at a 2D DWT image example
using “average and difference”…
• (Difference might be hard to see. Look
closely!)
2D Example
• How do you do DWT in 2D?
– Easiest answer: You don’t. Combine two 1D
signals.
– Row-transform (or column) first, then treat the
full result as the input for column-transform (or
row). Note: G(x) is filtered twice.
2D Example
• What are the tricky bits with images?
• Filter outside range of signal. (i.e. before or after
the row/column)
– For most images, best result is to treat it as a cyclic
signal around each row/column.
• What if it doesn’t fit in memory (i.e. on SPU)
– Use a sliding window of source data with borders
equal to ½ length of the filter. Then stitch them back
together.
2D Example
• What are the tricky bits with images?
• Filter outside range of signal. (i.e. before or after
the row/column)
– For most images, best result is to treat it as a cyclic
signal around each row/column.
• What if it doesn’t fit in memory (i.e. on SPU)
– Use a sliding window of source data with borders
equal to ½ length of the filter. Then stitch them back
together.
Final Example
• Use Daubuchies-4 Filter
Final Example
• Use Daubuchies-4 Filter
const float d4_low[4] =
{ +0.482962910f,
+0.836516300f,
+0.224143860f,
-0.129409522f };

const float d4_high[4] =


{ +0.129409522f,
+0.224143860f,
-0.836516300f,
+0.482962910f };
Final Example
• Recurse until 1 pixel
• Organize into Zero-Tree
– Zeros in parent mean likely zeros in child
• Encode with arithmetic coder
– Q-Coder, in this case.
• Decide how big you want the data in bpp.
– Throw out any bits after (bpp*width*height)
Then Decompress…
• Stop at 0.75 bpp
– Source data = 24bpp
• 1024x768x24bpp = 2,359,296 bytes + header
– Compressed version,
• 1024x768x0.75bpp = 73,728 bytes + header
– e.g. 32:1 compression

• Still room to improve quality AND


compression!
Then Decompress…
• Let’s flip between them.
– Next image: original
– The one after that: compressed then
decompressed.
Conclusion
• It’s simple.
• Of course, there’s a lot of devil in the
details, but you should now know what to
look for.

• Recommended reading:
– Ripples in Mathematics: The Discrete Wavelet
Transform by A.Jensen, A.la Cour-Harbo
• This is the best book on wavelets that I’ve found.

You might also like