Thinking in Frequency

COS 351 - Computer Vision

recap

thinking in frequency

Gaussian

Why does the Gaussian give a nice smooth image, but the square filter give edgy artifacts?

Gaussian
Box filter

hybrid images




Hybrid Images. A. Oliva, A. Torralba, P.G. Schyns. SIGGRAPH 2006 ]

hybrid images

Why do we get different, distance-dependent interpretations of hybrid images?

[ slide: Holem ]

subsampling

Why does a lower resolution image still make sense to us? What do we lose?





Thinking in terms of frequency

Jean Baptiste Joseph Fourier (1768–1830)

Fourier had crazy idea in 1807:

Any univariate function can be rewritten as a weighted sum of sines and cosines of different frequencies

Fourier

Jean Baptiste Joseph Fourier (1768–1830)

Don't believe it?


Laplace
Lagrange
Legendre
Poisson

Jean Baptiste Joseph Fourier (1768–1830)

But it's (mostly) true!

... the manner in which the author arrives at these equations is not exempt of difficulties and ... his analysis to integrate them still leaves something to be desired on the score of generality and even rigour.

Jean Baptiste Joseph Fourier (1768–1830)

French mathematician who discovered that any periodic motion can be written as a superposition of sinusoidal and cosinusoidal vibrations. He developed a mathematical theory of heat in Theorie Analytique de la Chaleur (Analytic Theory of Heat) (1822), discussing it in terms of differential equations.

Fourier was a friend and advisor of Napolean. Fourier believed that his health would be improved by wrapping himself up in blankets, and in this state he tripped down the stairs in his house and killed himself. The paper of Galois which he had taken home to read shortly before his death was never recovered.

[ 1996–2007 Eric W. Weisstein ]

How would math have changed if the Slanket or Snuggie had been invented?

Jean Baptiste Joseph Fourier (1768–1830)

a sum of sines

Our building block:

\[ A \sin(\omega x + \phi) \]

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

frequency spectra

example: \(g(t) = sin(2 \pi f t) + (1/3) \sin(2 \pi(3f) t)\)

\(=\) \(+\)

[ slides: Efros ]

frequency spectra

How do we create this wave?


frequency spectra

How do we create this wave?


\(+\) \(=\)

frequency spectra

How do we create this wave?


\(+\) \(=\)

frequency spectra

How do we create this wave?


\(+\) \(=\)

frequency spectra

How do we create this wave?


\(+\) \(=\)

frequency spectra

How do we create this wave?


\(+\) \(=\)

frequency spectra

How do we create this wave?


\[= A \sum_{k=1}^\infty \frac{1}{k} \sin(2 \pi kt)\]

example: music

We think of music in terms of frequencies at different magnitudes



[ slide: Holem ]

other signals

We can also think of all kinds of other signals the same way

xkcd.com

fourier analysis in images

Intensity Image:

Fourier Image:

fourier transform

Fourier transform stores the magnitude and phase at each frequency


Amplitude: \(A = \pm \sqrt{R(\omega)^2 + I(\omega)^2}\)

Phase: \(\phi = \tan^{-1} \frac{I(\omega)}{R(\omega)}\)

Salvador Dali invented Hybrid images?

[ "Gala Contemplating the Mediterranean Sea, which at 30 meters becomes the portrait of Abraham Lincoln". Salvador Dali. 1976 ]

Salvador Dali invented Hybrid images?

[ "Gala Contemplating the Mediterranean Sea, which at 30 meters becomes the portrait of Abraham Lincoln". Salvador Dali. 1976 ]

Salvador Dali invented Hybrid images?

[ "Gala Contemplating the Mediterranean Sea, which at 30 meters becomes the portrait of Abraham Lincoln". Salvador Dali. 1976 ]

fourier bases

Teases away fast vs. slow changes in the image

This change of basis is the Fourier Transform
In MATLAB, check out: imagesc(log(abs(ffshift(fft2(im)))));

man-made scene

can change spectrum, then reconstruct

low and high pass filtering

the convolution theorem

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

\[F[g * h] = F[g] F[h]\]

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

\[g*h = F^{-1}[F[g] F[h]]\]

filtering in spatial domain

10-1
20-2
10-1

\(*\) \(=\)

filtering in frequency domain

FFT on image and kernel

\(\Rightarrow\)

\(\Rightarrow\)

[ slide: Holem ]

filtering in frequency domain

Multiply FFT of image and FFT of kernel

\(\times\) \(=\)

[ slide: Holem ]

filtering in frequency domain

Inverse FFT of result

\(\Rightarrow\)

[ slide: Holem ]

FFT in matlab

Filtering with FFT

im = double(imread('...'))/255;
im = rgb2gray(im); % im should be a gray-scale floating point image
[imh,imw] = size(im);

hs = 50; % filter half-size
fil = fspecial('gaussian', hs*2+1, 10);

fftsize = 1024; % should be order of 2 (for speed) and incl. padding
im_fft  = fft2(im, fftsize, fftsize);  % 1) fft im with padding
fil_fft = fft2(fil, fftsize, fftsize); % 2) fft fil, pad to same
                                       %    size as im
im_fil_fft = im_fft .* fil_fft;        % 3) multiply fft images
im_fil = ifft2(im_fil_fft);            % 4) inverse fft2
im_fil = im_fil(1+hs:imh+hs, 1+hs:imw+hs); % 5) remove padding

Displaying with fft

figure(1), imagesc(log(abs(fftshift(im_fft)))), axis image, colormap jet
[ slide: Holem ]

filtering

Why does the Gaussian give a nice smooth image, but the square filter give edgy artifacts?

Gaussian
Box filter

Gaussian

box filter

sampling

Why does a lower resolution image still make sense to us? What do we lose?

subsampling by a factor of 2

Throw away every other row and column to create a 1/2 size image

aliasing problem

1D example (sine wave)

[ source: S. Marschner ]

aliasing problem

1D example (sine wave)

[ source: S. Marschner ]

aliasing problem

[ source: D. Forsyth ]

aliasing in video

Imagine a spoked wheel moving to the right (rotating clockwise). Mark wheel with dot so we can see what's happening.

If camera shutter is only open for a fraction of a frame tme (frame time = 1/30 sec for video, 1/24 sec for film):

Without dot, wheel appears to be rotating slowly backwards! (counterclockwise)

[ slide: Steve Seitz ]

aliasing in graphics

[ source: A. Efros ]

sampling and aliasing

nyquist-shannon sampling theorem

anti-aliasing

Solutions:

algorithm for downsampling by factor of 2

  1. Start with image(h,w)
  2. Apply low-pass filter

    im_blur = imfilter(image, fspecial('gaussian', 7, 1))

  3. Sample every other pixel

    im_small = im_blur(1:2:end, 1:2:end);

anti-aliasing

[ Forsyth and Ponce 2002 ]

subsampling without pre-filtering

[ slide: Steve Seitz ]

subsampling with gaussian pre-filtering

[ slide: Steve Seitz ]

clues from human perception

early visual processing: multi-scale edge and blob filters

campbell-robson contrast sensitivity curve

sensitivity

hybrid image in FFT

Hybrid image in FFT is low-pass image plus high-pass image

\(=\) \(+\)

things to remember

  • Sometimes it makes sense to think of images and filtering in the frequency domain
    • Fourier analysis
  • Can be faster to filter using FFT for large images (\(N \log N\) vs. \(N^2\) for auto-correlation)
  • Images are mostly smooth
    • Basis for compression
  • Remember to low-pass before sampling
loading...