Sampling and Reconstruction: 15-463: Computational Photography Alexei Efros, CMU, Fall 2007
Sampling and Reconstruction: 15-463: Computational Photography Alexei Efros, CMU, Fall 2007
1D Example: Audio
low frequencies
high
Sampled representations
How to store and compute with continuous functions? Common scheme for representation: samples
write down the functions values at many points
Reconstruction
Making samples back into a continuous function
for output (need realizable method) for analysis or processing (need mathematical method) amounts to guessing what the function did in between
Undersampling
What if we missed things between the samples? Simple example: undersampling a sine wave
unsurprising result: information is lost
Undersampling
What if we missed things between the samples? Simple example: undersampling a sine wave
unsurprising result: information is lost surprising result: indistinguishable from lower frequency
Undersampling
What if we missed things between the samples? Simple example: undersampling a sine wave
unsurprising result: information is lost surprising result: indistinguishable from lower frequency also was always indistinguishable from higher frequencies aliasing: signals traveling in disguise as other frequencies
Aliasing in video
Aliasing in images
Whats happening?
Input signal:
Plot as image:
Antialiasing
What can we do about aliasing? Sample more often
Join the Mega-Pixel crazy of the photo industry But this cant go on forever
Preventing aliasing
Introduce lowpass filters:
remove high frequencies leaving only safe, low frequencies choose lowest frequency in reconstruction (disambiguate)
Key properties
linearity: filter(f + g) = filter(f) + filter(g) shift invariance: behavior invariant to shifting the input
delaying an audio signal sliding an image around
Moving Average
basic idea: define a new function by averaging over a sliding window a simple example to start off: smoothing
Moving Average In 2D
What are the weights H?
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 90 0 0 0 90 90 90 90 90 0 0 0 0 0 90 90 90 0 90 0 0 0 0 0 90 90 90 90 90 0 0 0 0 0 90 90 90 90 90 0 0 0 0 0 90 90 90 90 90 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Cross-correlation filtering
Lets write this down as an equation. Assume the averaging window is (2k+1)x(2k+1):
We can generalize this idea by allowing different weights for different neighboring pixels:
This is called a cross-correlation operation and written: H is called the filter, kernel, or mask.
Slide by Steve Steve Seitz 2006 Marschner 21
Gaussian filtering
A Gaussian kernel gives less weight to pixels further from the center of the window
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 90 0 0 0 90 90 90 90 90 0 0 0 0 0 90 90 90 0 90 0 0 0 0 0 90 90 90 90 90 0 0 0 0 0 90 90 90 90 90 0 0 0 0 0 90 90 90 90 90 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 1 2 4 2 1 2 1
22
Thi k
li
ti
ti
23
Convolution
cross-correlation:
A convolution operation is a cross-correlation where the filter is flipped both horizontally and vertically before being applied to the image:
It is written:
Suppose H is a Gaussian or mean kernel. How does convolution differ from cross-correlation?
Slide by Steve Seitz
Convolution is nice!
Notation: Convolution is a multiplication-like operation
commutative associative distributes over addition scalars factor out identity: unit impulse e = [, 0, 0, 1, 0, 0, ]
Image half-sizing
This image is too big to fit on the screen. How can we reduce it? How to generate a halfsized version?
Image sub-sampling
1/8 1/4
Throw away every other row and column to create a 1/2 size image - called image sub-sampling
Slide by Steve Seitz
Image sub-sampling
1/2
1/4
(2x zoom)
1/8
(4x zoom)
G 1/8 G 1/4
Gaussian 1/2
Gaussian 1/2
G 1/4
G 1/8
Compare with...
1/2
1/4
(2x zoom)
1/8
(4x zoom)
G 1/8 G 1/4
Gaussian 1/2
Image Pyramids
A bar in the big images is a hair on the zebras nose; in smaller images, a stripe; in the smallest, the animals nose
Pre-computation
Need to access image at different blur levels Useful for texture mapping at different resolutions (called mip-mapping)
filter mask
Repeat
Filter Subsample
The whole pyramid is only 4/3 the size of the original image!
Slide by Steve Seitz
Continuous convolution
Sliding average expressed mathematically:
weighting is now by a function weighted integral is like weighted average again bounds are set by support of f(x)
Reconstruction
Resampling
Changing the sample rate
in images, this is enlarging and reducing
Resampling
Reconstruction creates a continuous function
forget its origins, go ahead and sample it
Cont.disc. convolution in 2D
same convolutionjust two variables now
loop over nearby pixels, average using filter weight looks like discrete filter, but offsets are not integers and filter is continuous remember placement of filter relative to grid is variable
A gallery of filters
Box filter
Simple and cheap
Tent filter
Linear interpolation
Gaussian filter
Very smooth antialiasing filter
B-spline cubic
Very smooth
Box filter
Properties of filters
Degree of continuity Impulse response Interpolating or no Ringing, or overshoot
Ripples
constant in, non-const. out ripple free when:
Yucky details
What about near the edge?
the filter window falls off the edge of the image need to extrapolate methods:
clip filter (black) wrap around copy edge reflect across edge vary filter near edge
Median filters
A Median Filter operates over a window by selecting the median intensity in the window. What advantage does a median filter have over a mean filter? Is a median filter a kind of convolution?
3x3
5x5
7x7