35
Image as a linear combination of basis images 16 235 245 231 28 20 17 1 0 0 11 243 70 253 99 16 12 0 0 0 14 170 60 253 169 16 6 1 0 0 19 87 69 248 188 18 4 0 0 0 21 171 187 226 82 21 13 11 0 0 22 224 250 188 74 29 7 1 0 0 21 235 247 71 97 92 20 3 0 0 29 251 246 76 45 34 14 0 0 0 65 252 246 183 17 4 0 0 0 1 38 71 162 174 8 0 0 0 0 0

Image as a linear combination of basis images 16 235 245 231 28 20 17 1 0 0 11 243 70 253 99 16 12 0 0 0 14 170 60 253 169 16 6 1 0 0 19 87 69 248 188

Embed Size (px)

Citation preview

Page 1: Image as a linear combination of basis images 16 235 245 231 28 20 17 1 0 0 11 243 70 253 99 16 12 0 0 0 14 170 60 253 169 16 6 1 0 0 19 87 69 248 188

Image as a linear combination of basis images

16 235 245 231 28 20 17 1 0 0 11 243 70 253 99 16 12 0 0 0 14 170 60 253 169 16 6 1 0 0 19 87 69 248 188 18 4 0 0 0

21 171 187 226 82 21 13 11 0 0 22 224 250 188 74 29 7 1 0 0 21 235 247 71 97 92 20 3 0 0 29 251 246 76 45 34 14 0 0 0 65 252 246 183 17 4 0 0 0 1 38 71 162 174 8 0 0 0 0 0

Page 2: Image as a linear combination of basis images 16 235 245 231 28 20 17 1 0 0 11 243 70 253 99 16 12 0 0 0 14 170 60 253 169 16 6 1 0 0 19 87 69 248 188

= 243 * + 70 * +…

16 235 245 231 28 20 17 1 0 0 11 243 70 253 99 16 12 0 0 0 14 170 60 253 169 16 6 1 0 0 19 87 69 248 188 18 4 0 0 0

21 171 187 226 82 21 13 11 0 0 22 224 250 188 74 29 7 1 0 0 21 235 247 71 97 92 20 3 0 0 29 251 246 76 45 34 14 0 0 0 65 252 246 183 17 4 0 0 0 1 38 71 162 174 8 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Image as a linear combination of basis images

Page 3: Image as a linear combination of basis images 16 235 245 231 28 20 17 1 0 0 11 243 70 253 99 16 12 0 0 0 14 170 60 253 169 16 6 1 0 0 19 87 69 248 188

= 243 * + 70 * +…

16 235 245 231 28 20 17 1 0 0 11 243 70 253 99 16 12 0 0 0 14 170 60 253 169 16 6 1 0 0 19 87 69 248 188 18 4 0 0 0

21 171 187 226 82 21 13 11 0 0 22 224 250 188 74 29 7 1 0 0 21 235 247 71 97 92 20 3 0 0 29 251 246 76 45 34 14 0 0 0 65 252 246 183 17 4 0 0 0 1 38 71 162 174 8 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Image as a linear combination of basis images

If we agree on basis, then we only need the coefficients (243,70,…) to describe image

What about other basis images beyond impulse images?

Page 4: Image as a linear combination of basis images 16 235 245 231 28 20 17 1 0 0 11 243 70 253 99 16 12 0 0 0 14 170 60 253 169 16 6 1 0 0 19 87 69 248 188

A nice set of basis

This change of basis has a special name…

Teases away fast vs. slow changes in the image.

Page 5: Image as a linear combination of basis images 16 235 245 231 28 20 17 1 0 0 11 243 70 253 99 16 12 0 0 0 14 170 60 253 169 16 6 1 0 0 19 87 69 248 188

Jean Baptiste Joseph Fourier (1768-1830)

had crazy idea (1807):Any periodic function can be rewritten as a weighted sum of sines and cosines of different frequencies.

Don’t believe it? • Neither did Lagrange,

Laplace, Poisson and other big wigs

• Not translated into English until 1878!

But it’s true!• called Fourier Series

Page 6: Image as a linear combination of basis images 16 235 245 231 28 20 17 1 0 0 11 243 70 253 99 16 12 0 0 0 14 170 60 253 169 16 6 1 0 0 19 87 69 248 188

A sum of sinesOur building block:

Add enough of them to get any signal f(x) you want!

How many degrees of freedom?

What does each control?

Which one encodes the coarse vs. fine structure of the signal?

xAsin(

Page 7: Image as a linear combination of basis images 16 235 245 231 28 20 17 1 0 0 11 243 70 253 99 16 12 0 0 0 14 170 60 253 169 16 6 1 0 0 19 87 69 248 188

Fourier TransformWe want to understand the frequency of our signal. So, let’s reparametrize the signal by instead of x:

xAsin(

f(x) F()Fourier Transform

F() f(x)Inverse Fourier Transform

For every from 0 to inf, F() holds the amplitude A and phase of the corresponding sine

• How can F hold both? Complex number trick!

)()()( iIRF 22 )()( IRA

)(

)(tan 1

R

I

We can always go back:

Page 8: Image as a linear combination of basis images 16 235 245 231 28 20 17 1 0 0 11 243 70 253 99 16 12 0 0 0 14 170 60 253 169 16 6 1 0 0 19 87 69 248 188

Time and Frequency

example : g(t) = sin(2pf t) + (1/3)sin(2p(3f) t)

Page 9: Image as a linear combination of basis images 16 235 245 231 28 20 17 1 0 0 11 243 70 253 99 16 12 0 0 0 14 170 60 253 169 16 6 1 0 0 19 87 69 248 188

Time and Frequency

example : g(t) = sin(2pf t) + (1/3)sin(2p(3f) t)

= +

Page 10: Image as a linear combination of basis images 16 235 245 231 28 20 17 1 0 0 11 243 70 253 99 16 12 0 0 0 14 170 60 253 169 16 6 1 0 0 19 87 69 248 188

Frequency Spectra

example : g(t) = sin(2pf t) + (1/3)sin(2p(3f) t)

= +

Page 11: Image as a linear combination of basis images 16 235 245 231 28 20 17 1 0 0 11 243 70 253 99 16 12 0 0 0 14 170 60 253 169 16 6 1 0 0 19 87 69 248 188

Frequency SpectraLet’s reconstruct a box using a basis of wiggly functions

Page 12: Image as a linear combination of basis images 16 235 245 231 28 20 17 1 0 0 11 243 70 253 99 16 12 0 0 0 14 170 60 253 169 16 6 1 0 0 19 87 69 248 188

= +

=

Frequency Spectra

Page 13: Image as a linear combination of basis images 16 235 245 231 28 20 17 1 0 0 11 243 70 253 99 16 12 0 0 0 14 170 60 253 169 16 6 1 0 0 19 87 69 248 188

= +

=

Frequency Spectra

Page 14: Image as a linear combination of basis images 16 235 245 231 28 20 17 1 0 0 11 243 70 253 99 16 12 0 0 0 14 170 60 253 169 16 6 1 0 0 19 87 69 248 188

= +

=

Frequency Spectra

Page 15: Image as a linear combination of basis images 16 235 245 231 28 20 17 1 0 0 11 243 70 253 99 16 12 0 0 0 14 170 60 253 169 16 6 1 0 0 19 87 69 248 188

= +

=

Frequency Spectra

Page 16: Image as a linear combination of basis images 16 235 245 231 28 20 17 1 0 0 11 243 70 253 99 16 12 0 0 0 14 170 60 253 169 16 6 1 0 0 19 87 69 248 188

= +

=

Frequency Spectra

Page 17: Image as a linear combination of basis images 16 235 245 231 28 20 17 1 0 0 11 243 70 253 99 16 12 0 0 0 14 170 60 253 169 16 6 1 0 0 19 87 69 248 188

= 1

1sin(2 )

k

A ktk

Frequency Spectra

Page 18: Image as a linear combination of basis images 16 235 245 231 28 20 17 1 0 0 11 243 70 253 99 16 12 0 0 0 14 170 60 253 169 16 6 1 0 0 19 87 69 248 188

Frequency Spectra

Page 19: Image as a linear combination of basis images 16 235 245 231 28 20 17 1 0 0 11 243 70 253 99 16 12 0 0 0 14 170 60 253 169 16 6 1 0 0 19 87 69 248 188

Extension to 2D

in Matlab, check out: imagesc(log(abs(fftshift(fft2(im)))));

Page 20: Image as a linear combination of basis images 16 235 245 231 28 20 17 1 0 0 11 243 70 253 99 16 12 0 0 0 14 170 60 253 169 16 6 1 0 0 19 87 69 248 188

Man-made Scene

Page 21: Image as a linear combination of basis images 16 235 245 231 28 20 17 1 0 0 11 243 70 253 99 16 12 0 0 0 14 170 60 253 169 16 6 1 0 0 19 87 69 248 188

Can change spectrum, then reconstruct

Page 22: Image as a linear combination of basis images 16 235 245 231 28 20 17 1 0 0 11 243 70 253 99 16 12 0 0 0 14 170 60 253 169 16 6 1 0 0 19 87 69 248 188

Low and High Pass filtering

Page 23: Image as a linear combination of basis images 16 235 245 231 28 20 17 1 0 0 11 243 70 253 99 16 12 0 0 0 14 170 60 253 169 16 6 1 0 0 19 87 69 248 188

The Convolution TheoremThe greatest thing since sliced (banana) bread!

• The Fourier transform of the convolution of two functions is the product of their Fourier transforms

• The inverse Fourier transform of the product of two Fourier transforms is the convolution of the two inverse Fourier transforms

• Convolution in spatial domain is equivalent to multiplication in frequency domain!

]F[]F[]F[ hghg

][F][F][F 111 hggh

Page 24: Image as a linear combination of basis images 16 235 245 231 28 20 17 1 0 0 11 243 70 253 99 16 12 0 0 0 14 170 60 253 169 16 6 1 0 0 19 87 69 248 188

Fourier Transform pairs

Reason why gaussian smoothing is better than averaging

Page 25: Image as a linear combination of basis images 16 235 245 231 28 20 17 1 0 0 11 243 70 253 99 16 12 0 0 0 14 170 60 253 169 16 6 1 0 0 19 87 69 248 188

2D convolution theorem example

*

f(x,y)

h(x,y)

g(x,y)

|F(sx,sy)|

|H(sx,sy)|

|G(sx,sy)|

Page 26: Image as a linear combination of basis images 16 235 245 231 28 20 17 1 0 0 11 243 70 253 99 16 12 0 0 0 14 170 60 253 169 16 6 1 0 0 19 87 69 248 188

Low-pass, Band-pass, High-pass filters

low-pass:

High-pass / band-pass:

Page 27: Image as a linear combination of basis images 16 235 245 231 28 20 17 1 0 0 11 243 70 253 99 16 12 0 0 0 14 170 60 253 169 16 6 1 0 0 19 87 69 248 188

Edges in images

Page 28: Image as a linear combination of basis images 16 235 245 231 28 20 17 1 0 0 11 243 70 253 99 16 12 0 0 0 14 170 60 253 169 16 6 1 0 0 19 87 69 248 188

Where is the edge?

Solution: smooth first

Look for peaks in

Page 29: Image as a linear combination of basis images 16 235 245 231 28 20 17 1 0 0 11 243 70 253 99 16 12 0 0 0 14 170 60 253 169 16 6 1 0 0 19 87 69 248 188

Derivative theorem of convolution

This saves us one operation:

Page 30: Image as a linear combination of basis images 16 235 245 231 28 20 17 1 0 0 11 243 70 253 99 16 12 0 0 0 14 170 60 253 169 16 6 1 0 0 19 87 69 248 188

Laplacian of Gaussian

Consider

Laplacian of Gaussianoperator

Where is the edge? Zero-crossings of bottom graph

Page 31: Image as a linear combination of basis images 16 235 245 231 28 20 17 1 0 0 11 243 70 253 99 16 12 0 0 0 14 170 60 253 169 16 6 1 0 0 19 87 69 248 188

2D edge detection filters

is the Laplacian operator:

Laplacian of Gaussian

Gaussian derivative of Gaussian

Page 32: Image as a linear combination of basis images 16 235 245 231 28 20 17 1 0 0 11 243 70 253 99 16 12 0 0 0 14 170 60 253 169 16 6 1 0 0 19 87 69 248 188

MATLAB demo

g = fspecial('gaussian',15,2);imagesc(g)colorbarsurfl(g)im = im2single(rgb2gray(‘image.jpg’));gim = conv2(im,g,'same');imagesc(conv2(im,[-1 1],'same'));imagesc(conv2(im,[-1 1],'same'));dx = conv2(im,[-1 1],'same');imagesc(conv2(im,dx,'same'));lg = fspecial('log',15,2);lim = conv2(im,lg,'same');Imagesc(lim)Imagesc(im + .2*lim)

Page 33: Image as a linear combination of basis images 16 235 245 231 28 20 17 1 0 0 11 243 70 253 99 16 12 0 0 0 14 170 60 253 169 16 6 1 0 0 19 87 69 248 188

Lossy Image Compression (JPEG)

Block-based Discrete Cosine Transform (DCT)

Page 34: Image as a linear combination of basis images 16 235 245 231 28 20 17 1 0 0 11 243 70 253 99 16 12 0 0 0 14 170 60 253 169 16 6 1 0 0 19 87 69 248 188

Using DCT in JPEG

A variant of discrete Fourier transform• Real numbers• Fast implementation

Block size• small block

– faster – correlation exists between neighboring pixels

• large block– better compression in smooth regions

Page 35: Image as a linear combination of basis images 16 235 245 231 28 20 17 1 0 0 11 243 70 253 99 16 12 0 0 0 14 170 60 253 169 16 6 1 0 0 19 87 69 248 188

JPEG compression comparison

89k 12k