filtering robert lin april 29, 2004. outline why filter? filtering for graphics sampling and...

38
Filtering Robert Lin April 29, 2004

Upload: ada-bond

Post on 02-Jan-2016

233 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Filtering Robert Lin April 29, 2004. Outline Why filter? Filtering for Graphics Sampling and Reconstruction Convolution The Fourier Transform Overview

Filtering

Robert LinApril 29, 2004

Page 2: Filtering Robert Lin April 29, 2004. Outline Why filter? Filtering for Graphics Sampling and Reconstruction Convolution The Fourier Transform Overview

Outline

Why filter? Filtering for Graphics Sampling and Reconstruction Convolution The Fourier Transform Overview of common filters

Page 3: Filtering Robert Lin April 29, 2004. Outline Why filter? Filtering for Graphics Sampling and Reconstruction Convolution The Fourier Transform Overview

Why Filter?

Anti-aliasing Signal reconstruction Remove frequencies

Remove which frequencies? Low-pass filter: removes high frequencies (blurring) High-pass filter: removes low frequencies (sharpens,

enhance edges) Graphics: usually want low pass filtering to remove

aliasing

Page 4: Filtering Robert Lin April 29, 2004. Outline Why filter? Filtering for Graphics Sampling and Reconstruction Convolution The Fourier Transform Overview

Image Filtering

Modify pixels of an image based on a function of local nearby pixels

Filter determines weight of a pixel

Page 5: Filtering Robert Lin April 29, 2004. Outline Why filter? Filtering for Graphics Sampling and Reconstruction Convolution The Fourier Transform Overview

Filtering for Sampling

Filtering can be used to determine which rays to cast for a particular pixel (e.g., cast more rays near the center)

Filtering can also be used to assign weights to the rays that determine how much they contribute to the pixel color

Page 6: Filtering Robert Lin April 29, 2004. Outline Why filter? Filtering for Graphics Sampling and Reconstruction Convolution The Fourier Transform Overview

Photon Filtering

We can filter the radiance estimate

Weight closer photons more when calculating radiance estimate

Can reduce blur at sharp edges when photon count is low – good for stuff like caustics

Page 7: Filtering Robert Lin April 29, 2004. Outline Why filter? Filtering for Graphics Sampling and Reconstruction Convolution The Fourier Transform Overview

Sampling and Reconstruction

Given a signal such as a sine wave with frequency 1 Hz:

Page 8: Filtering Robert Lin April 29, 2004. Outline Why filter? Filtering for Graphics Sampling and Reconstruction Convolution The Fourier Transform Overview

Sampling and Reconstruction

We can sample the points at a uniform rate of 3 Hz and reconstruct the signal:

Page 9: Filtering Robert Lin April 29, 2004. Outline Why filter? Filtering for Graphics Sampling and Reconstruction Convolution The Fourier Transform Overview

Sampling and Reconstruction

We can also sample the signal at a slower rate of 2 Hz and still accurately reconstruct the signal:

Page 10: Filtering Robert Lin April 29, 2004. Outline Why filter? Filtering for Graphics Sampling and Reconstruction Convolution The Fourier Transform Overview

Sampling and Reconstruction

However, if we sample below 2 Hz, we don’t have enough information to reconstruct the signal, and in fact we may construct a different signal:

Page 11: Filtering Robert Lin April 29, 2004. Outline Why filter? Filtering for Graphics Sampling and Reconstruction Convolution The Fourier Transform Overview

Nyquist Frequency

To reconstruct a signal with frequency f, we need to sample the signal at a rate of at least 2*f, which is the Nyquist Frequency

Example CD : SR = 44,100 Hz Nyquist Frequency = SR/2 = 22,050

Page 12: Filtering Robert Lin April 29, 2004. Outline Why filter? Filtering for Graphics Sampling and Reconstruction Convolution The Fourier Transform Overview

Nyquist Frequency

Sampling below the Nyquist frequency can cause aliasing – the reconstructed signal is a false representation of the original signal.

We can reduce aliasing by sampling more, or sampling intelligently (last lecture).

We can also use filtering to reduce aliasing.

Page 13: Filtering Robert Lin April 29, 2004. Outline Why filter? Filtering for Graphics Sampling and Reconstruction Convolution The Fourier Transform Overview

How do you filter?

To filter a function f(x), we use a filter function g(x) and convolute f(x) with g(x).

This is the same for filtering 2D images, and the functions become functions of x and y.

Page 14: Filtering Robert Lin April 29, 2004. Outline Why filter? Filtering for Graphics Sampling and Reconstruction Convolution The Fourier Transform Overview

Convolution

The convolution of a function f(x) and a function g(x) (usually a filter function), is defined to be:

The value of h(x) at each point is the integral of the product of f(x) with the filter function g(x) flipped about the y axis and shifted so that its origin is at that point

This is taking a weighted average of points near f(x), where g(x) defines what the weights are.

h žx Ÿ= f ⊗g =+ f žu Ÿg žx u Ÿdu

Page 15: Filtering Robert Lin April 29, 2004. Outline Why filter? Filtering for Graphics Sampling and Reconstruction Convolution The Fourier Transform Overview

Convolution

Green curve is the convolution of the Red curve, f(x), and the Blue curve, g(x).

The grey region indicates the product g(u) f(t – u) The convolution Is thus the area of the grey region

Page 16: Filtering Robert Lin April 29, 2004. Outline Why filter? Filtering for Graphics Sampling and Reconstruction Convolution The Fourier Transform Overview

The Fourier Transform

A signal can be expressed as a sum of different sine curves

The Fourier Transform determines which sine waves represent the original signal

Page 17: Filtering Robert Lin April 29, 2004. Outline Why filter? Filtering for Graphics Sampling and Reconstruction Convolution The Fourier Transform Overview

The Fourier Transform

The Fourier Transform F(k) of a function f(x) in spatial domain is defined to be:

F(k) is now in frequency domain, usually plotted with the x-axis as frequency, and the y-axis as magnitude.

Page 18: Filtering Robert Lin April 29, 2004. Outline Why filter? Filtering for Graphics Sampling and Reconstruction Convolution The Fourier Transform Overview

The Fourier Transform

A signal composed of two sine waves with frequency 2 Hz and 50 Hz

The Fourier Transform of the signal shows these two frequencies

The domain of the graph of the Fourier transform is frequency; the range is magnitude

Page 19: Filtering Robert Lin April 29, 2004. Outline Why filter? Filtering for Graphics Sampling and Reconstruction Convolution The Fourier Transform Overview

The Fourier Transform

Page 20: Filtering Robert Lin April 29, 2004. Outline Why filter? Filtering for Graphics Sampling and Reconstruction Convolution The Fourier Transform Overview

The Fourier Transform

-0.02

0.03

0.08

0.13

0.18

-0.02

0.03

0.08

0.13

0.18

Space Frequency

Page 21: Filtering Robert Lin April 29, 2004. Outline Why filter? Filtering for Graphics Sampling and Reconstruction Convolution The Fourier Transform Overview

The Fourier Transform

The convolution of f and g is the same as multiplying the Fourier transforms of f and g:

This lets us look at the frequency domain of a filter function to figure out what the filter does.

Page 22: Filtering Robert Lin April 29, 2004. Outline Why filter? Filtering for Graphics Sampling and Reconstruction Convolution The Fourier Transform Overview

Frequency Domain

=

=

Low-pass

High-pass

In the frequency domain, multiplying by a filter function removes particular frequencies

Page 23: Filtering Robert Lin April 29, 2004. Outline Why filter? Filtering for Graphics Sampling and Reconstruction Convolution The Fourier Transform Overview

Low Pass Filter in Frequency Domain

Page 24: Filtering Robert Lin April 29, 2004. Outline Why filter? Filtering for Graphics Sampling and Reconstruction Convolution The Fourier Transform Overview

Low Pass Filter

Page 25: Filtering Robert Lin April 29, 2004. Outline Why filter? Filtering for Graphics Sampling and Reconstruction Convolution The Fourier Transform Overview

High Pass Filter

Page 26: Filtering Robert Lin April 29, 2004. Outline Why filter? Filtering for Graphics Sampling and Reconstruction Convolution The Fourier Transform Overview

The Sinc Filter

Spatial: sinc Frequency: box

Page 27: Filtering Robert Lin April 29, 2004. Outline Why filter? Filtering for Graphics Sampling and Reconstruction Convolution The Fourier Transform Overview

The Sinc Filter

Perfect low-pass filter Cuts off all frequencies above a threshold Oscillates to infinity: need too many samples We use other functions similar to a sinc to filter

Page 28: Filtering Robert Lin April 29, 2004. Outline Why filter? Filtering for Graphics Sampling and Reconstruction Convolution The Fourier Transform Overview

The Box Filter

Spatial: Box Frequency: sinc

Page 29: Filtering Robert Lin April 29, 2004. Outline Why filter? Filtering for Graphics Sampling and Reconstruction Convolution The Fourier Transform Overview

The Box Filter

Smooths out function by averaging neighbors

Keeps low frequencies and reduces high frequencies (low-pass filter)

Equally weights all samples

In frequency domain, contains sidelobes to infinity, which can cause rings on sharp edges

Page 30: Filtering Robert Lin April 29, 2004. Outline Why filter? Filtering for Graphics Sampling and Reconstruction Convolution The Fourier Transform Overview

The Tent Filter

Spatial: Tent Frequency: sinc squared

Page 31: Filtering Robert Lin April 29, 2004. Outline Why filter? Filtering for Graphics Sampling and Reconstruction Convolution The Fourier Transform Overview

The Tent Filter

Reduces high frequencies more

Weights center sample more

Other samples weighted linearly

Page 32: Filtering Robert Lin April 29, 2004. Outline Why filter? Filtering for Graphics Sampling and Reconstruction Convolution The Fourier Transform Overview

The Gaussian Filter

-0.02

0.03

0.08

0.13

0.18

-0.02

0.03

0.08

0.13

0.18

Spatial: Gaussian Frequency: Gaussian

Page 33: Filtering Robert Lin April 29, 2004. Outline Why filter? Filtering for Graphics Sampling and Reconstruction Convolution The Fourier Transform Overview

The Gaussian Filter

Reduces high frequences even more

No sharp edges like in box, tent

Generally

Page 34: Filtering Robert Lin April 29, 2004. Outline Why filter? Filtering for Graphics Sampling and Reconstruction Convolution The Fourier Transform Overview

The B-Spline Filter

Each row and column of the image is represented by a B-Spline curve

Each pixel is a control point

Page 35: Filtering Robert Lin April 29, 2004. Outline Why filter? Filtering for Graphics Sampling and Reconstruction Convolution The Fourier Transform Overview

The B-Spline Filter

original

L(x,y) = 0.5 + (1 + sin( 0.01*(x*x + y*y)))

order 3

order 1

order 2

order 0

Page 36: Filtering Robert Lin April 29, 2004. Outline Why filter? Filtering for Graphics Sampling and Reconstruction Convolution The Fourier Transform Overview

The B-Spline Filter

Bilinear Bspline

Page 37: Filtering Robert Lin April 29, 2004. Outline Why filter? Filtering for Graphics Sampling and Reconstruction Convolution The Fourier Transform Overview

Conclusion

Filtering is good Reduces aliasing Makes the picture pretty Very similar to sampling We filter an image by convoluting it with the filter The FT gives information about the filter Try different filters, use the one that looks good

Page 38: Filtering Robert Lin April 29, 2004. Outline Why filter? Filtering for Graphics Sampling and Reconstruction Convolution The Fourier Transform Overview

References

Books: Andrew Glassner. Principles of Digital Image Synthesis. James D. Foley, Andries van Dam, Steven K. Feiner, John F.

Hughes. Computer Graphics: Principles and Practice. Peter Shirley, R. Keith Morley. Realistic Ray Tracing. Henrik Wann Jensen. Realistic Image Synthesis Using Photon

Mapping. Websites:

http://rise.sourceforge.net/cgi-bin/makepage.cgi?Filtering http://www.hinjang.com/gfx/gfx01.html http://www.relisoft.com/Science/Graphics/filter.html http://www.cg.tuwien.ac.at/courses/CG2/SS2002/

SamplingAndReconstruction-new.pdf http://w3.impa.br/~ipcg/c06/slides/main.pdf http://redwood.ucdavis.edu/bruno/npb261/aliasing.pdf