47
Wavelets, for the Layman Mike Acton 25 Jan 08

Wavelets,...Introduction • This won’t be math-heavy. • De-mystify the jargon. • Enough understanding to use it yourself. • Just an introduction –From here you’llWhat’s

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Wavelets,...Introduction • This won’t be math-heavy. • De-mystify the jargon. • Enough understanding to use it yourself. • Just an introduction –From here you’llWhat’s

Wavelets,for the Layman

Mike Acton

25 Jan 08

Page 2: Wavelets,...Introduction • This won’t be math-heavy. • De-mystify the jargon. • Enough understanding to use it yourself. • Just an introduction –From here you’llWhat’s

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.

Page 3: Wavelets,...Introduction • This won’t be math-heavy. • De-mystify the jargon. • Enough understanding to use it yourself. • Just an introduction –From here you’llWhat’s

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?

Page 4: Wavelets,...Introduction • This won’t be math-heavy. • De-mystify the jargon. • Enough understanding to use it yourself. • Just an introduction –From here you’llWhat’s

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!

Page 5: Wavelets,...Introduction • This won’t be math-heavy. • De-mystify the jargon. • Enough understanding to use it yourself. • Just an introduction –From here you’llWhat’s

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.

Page 6: Wavelets,...Introduction • This won’t be math-heavy. • De-mystify the jargon. • Enough understanding to use it yourself. • Just an introduction –From here you’llWhat’s

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

Page 7: Wavelets,...Introduction • This won’t be math-heavy. • De-mystify the jargon. • Enough understanding to use it yourself. • Just an introduction –From here you’llWhat’s

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]

Page 8: Wavelets,...Introduction • This won’t be math-heavy. • De-mystify the jargon. • Enough understanding to use it yourself. • Just an introduction –From here you’llWhat’s

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

Page 9: Wavelets,...Introduction • This won’t be math-heavy. • De-mystify the jargon. • Enough understanding to use it yourself. • Just an introduction –From here you’llWhat’s

It’s a transform

• “Wavelet” refers to the shape of

F(x) and G(x)

Page 10: Wavelets,...Introduction • This won’t be math-heavy. • De-mystify the jargon. • Enough understanding to use it yourself. • Just an introduction –From here you’llWhat’s

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.

Page 11: Wavelets,...Introduction • This won’t be math-heavy. • De-mystify the jargon. • Enough understanding to use it yourself. • Just an introduction –From here you’llWhat’s

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.

Page 12: Wavelets,...Introduction • This won’t be math-heavy. • De-mystify the jargon. • Enough understanding to use it yourself. • Just an introduction –From here you’llWhat’s

Discrete Wavelet Transform

• Recursively transform LOW, F(x)

• That’s it.

Page 13: Wavelets,...Introduction • This won’t be math-heavy. • De-mystify the jargon. • Enough understanding to use it yourself. • Just an introduction –From here you’llWhat’s

Wavelet Packet Transform

• Recursively transform both, F(x) and G(x)

Page 14: Wavelets,...Introduction • This won’t be math-heavy. • De-mystify the jargon. • Enough understanding to use it yourself. • Just an introduction –From here you’llWhat’s

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)

Page 15: Wavelets,...Introduction • This won’t be math-heavy. • De-mystify the jargon. • Enough understanding to use it yourself. • Just an introduction –From here you’llWhat’s

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.

Page 16: Wavelets,...Introduction • This won’t be math-heavy. • De-mystify the jargon. • Enough understanding to use it yourself. • Just an introduction –From here you’llWhat’s

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]

Page 17: Wavelets,...Introduction • This won’t be math-heavy. • De-mystify the jargon. • Enough understanding to use it yourself. • Just an introduction –From here you’llWhat’s
Page 18: Wavelets,...Introduction • This won’t be math-heavy. • De-mystify the jargon. • Enough understanding to use it yourself. • Just an introduction –From here you’llWhat’s
Page 19: Wavelets,...Introduction • This won’t be math-heavy. • De-mystify the jargon. • Enough understanding to use it yourself. • Just an introduction –From here you’llWhat’s

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.

Page 20: Wavelets,...Introduction • This won’t be math-heavy. • De-mystify the jargon. • Enough understanding to use it yourself. • Just an introduction –From here you’llWhat’s

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).

Page 21: Wavelets,...Introduction • This won’t be math-heavy. • De-mystify the jargon. • Enough understanding to use it yourself. • Just an introduction –From here you’llWhat’s

2D Example

• Let’s look at a 2D DWT image example

using “average and difference”…

• (Difference might be hard to see. Look

closely!)

Page 22: Wavelets,...Introduction • This won’t be math-heavy. • De-mystify the jargon. • Enough understanding to use it yourself. • Just an introduction –From here you’llWhat’s
Page 23: Wavelets,...Introduction • This won’t be math-heavy. • De-mystify the jargon. • Enough understanding to use it yourself. • Just an introduction –From here you’llWhat’s
Page 24: Wavelets,...Introduction • This won’t be math-heavy. • De-mystify the jargon. • Enough understanding to use it yourself. • Just an introduction –From here you’llWhat’s
Page 25: Wavelets,...Introduction • This won’t be math-heavy. • De-mystify the jargon. • Enough understanding to use it yourself. • Just an introduction –From here you’llWhat’s
Page 26: Wavelets,...Introduction • This won’t be math-heavy. • De-mystify the jargon. • Enough understanding to use it yourself. • Just an introduction –From here you’llWhat’s
Page 27: Wavelets,...Introduction • This won’t be math-heavy. • De-mystify the jargon. • Enough understanding to use it yourself. • Just an introduction –From here you’llWhat’s
Page 28: Wavelets,...Introduction • This won’t be math-heavy. • De-mystify the jargon. • Enough understanding to use it yourself. • Just an introduction –From here you’llWhat’s

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.

Page 29: Wavelets,...Introduction • This won’t be math-heavy. • De-mystify the jargon. • Enough understanding to use it yourself. • Just an introduction –From here you’llWhat’s
Page 30: Wavelets,...Introduction • This won’t be math-heavy. • De-mystify the jargon. • Enough understanding to use it yourself. • Just an introduction –From here you’llWhat’s

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.

Page 31: Wavelets,...Introduction • This won’t be math-heavy. • De-mystify the jargon. • Enough understanding to use it yourself. • Just an introduction –From here you’llWhat’s

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.

Page 32: Wavelets,...Introduction • This won’t be math-heavy. • De-mystify the jargon. • Enough understanding to use it yourself. • Just an introduction –From here you’llWhat’s

Final Example

• Use Daubuchies-4 Filter

Page 33: Wavelets,...Introduction • This won’t be math-heavy. • De-mystify the jargon. • Enough understanding to use it yourself. • Just an introduction –From here you’llWhat’s

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 };

Page 34: Wavelets,...Introduction • This won’t be math-heavy. • De-mystify the jargon. • Enough understanding to use it yourself. • Just an introduction –From here you’llWhat’s

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)

Page 35: Wavelets,...Introduction • This won’t be math-heavy. • De-mystify the jargon. • Enough understanding to use it yourself. • Just an introduction –From here you’llWhat’s
Page 36: Wavelets,...Introduction • This won’t be math-heavy. • De-mystify the jargon. • Enough understanding to use it yourself. • Just an introduction –From here you’llWhat’s
Page 37: Wavelets,...Introduction • This won’t be math-heavy. • De-mystify the jargon. • Enough understanding to use it yourself. • Just an introduction –From here you’llWhat’s
Page 38: Wavelets,...Introduction • This won’t be math-heavy. • De-mystify the jargon. • Enough understanding to use it yourself. • Just an introduction –From here you’llWhat’s
Page 39: Wavelets,...Introduction • This won’t be math-heavy. • De-mystify the jargon. • Enough understanding to use it yourself. • Just an introduction –From here you’llWhat’s
Page 40: Wavelets,...Introduction • This won’t be math-heavy. • De-mystify the jargon. • Enough understanding to use it yourself. • Just an introduction –From here you’llWhat’s
Page 41: Wavelets,...Introduction • This won’t be math-heavy. • De-mystify the jargon. • Enough understanding to use it yourself. • Just an introduction –From here you’llWhat’s
Page 42: Wavelets,...Introduction • This won’t be math-heavy. • De-mystify the jargon. • Enough understanding to use it yourself. • Just an introduction –From here you’llWhat’s

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!

Page 43: Wavelets,...Introduction • This won’t be math-heavy. • De-mystify the jargon. • Enough understanding to use it yourself. • Just an introduction –From here you’llWhat’s
Page 44: Wavelets,...Introduction • This won’t be math-heavy. • De-mystify the jargon. • Enough understanding to use it yourself. • Just an introduction –From here you’llWhat’s

Then Decompress…

• Let’s flip between them.

– Next image: original

– The one after that: compressed then

decompressed.

Page 45: Wavelets,...Introduction • This won’t be math-heavy. • De-mystify the jargon. • Enough understanding to use it yourself. • Just an introduction –From here you’llWhat’s
Page 46: Wavelets,...Introduction • This won’t be math-heavy. • De-mystify the jargon. • Enough understanding to use it yourself. • Just an introduction –From here you’llWhat’s
Page 47: Wavelets,...Introduction • This won’t be math-heavy. • De-mystify the jargon. • Enough understanding to use it yourself. • Just an introduction –From here you’llWhat’s

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.