Filtering Robert Lin April 29, 2004. Outline Why filter? Filtering for Graphics Sampling and...

Post on 02-Jan-2016

225 views 0 download

Tags:

Transcript of Filtering Robert Lin April 29, 2004. Outline Why filter? Filtering for Graphics Sampling and...

Filtering

Robert LinApril 29, 2004

Outline

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

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

Image Filtering

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

Filter determines weight of a pixel

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

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

Sampling and Reconstruction

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

Sampling and Reconstruction

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

Sampling and Reconstruction

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

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:

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

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.

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.

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

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

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

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.

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

The Fourier Transform

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

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.

Frequency Domain

=

=

Low-pass

High-pass

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

Low Pass Filter in Frequency Domain

Low Pass Filter

High Pass Filter

The Sinc Filter

Spatial: sinc Frequency: box

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

The Box Filter

Spatial: Box Frequency: sinc

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

The Tent Filter

Spatial: Tent Frequency: sinc squared

The Tent Filter

Reduces high frequencies more

Weights center sample more

Other samples weighted linearly

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

The Gaussian Filter

Reduces high frequences even more

No sharp edges like in box, tent

Generally

The B-Spline Filter

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

Each pixel is a control point

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

The B-Spline Filter

Bilinear Bspline

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

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