Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two...

93
Image Sampling Michael Kazhdan (601.457/657) HB Ch. 4.8, 16.5 FvDFH Ch. 14.10, 17.6

Transcript of Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two...

Page 1: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Image Sampling

Michael Kazhdan

(601.457/657)

HB Ch. 4.8, 16.5

FvDFH Ch. 14.10, 17.6

Page 2: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Sampling Questions

• How should we sample an image: Nearest Point Sampling?

Bilinear Sampling?

Gaussian Sampling?

Something Else?

Page 3: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Image Representation

What is an image?

An image is a discrete collection of pixels, each

representing a sample of a continuous function.

Continuous image Digital image

Page 4: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Sampling

Let’s look at a 1D example:

Continuous Function Discrete Samples

Page 5: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Sampling

At in-between positions, values are undefined.

How do we determine the value of a sample?

Discrete Samples

?

We need to reconstruct a

continuous function, turning a

collection of discrete samples

into a 1D function that we can

sample at arbitrary locations.

Page 6: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Nearest Point Sampling

The value at a point is the value of the closest

discrete sample.

Discrete SamplesReconstructed Function

?

Page 7: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Nearest Point Sampling

The value at a point is the value of the closest

discrete sample.

Discrete Samples

?

Reconstructed Function

The reconstruction:

✓ Interpolates the samples

Is not continuous

Page 8: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Bilinear Sampling

The value at a point is the (bi)linear interpolation of

the two surrounding samples.

Discrete SamplesReconstructed Function

?

Page 9: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Bilinear Sampling

The value at a point is the (bi)linear interpolation of

the two surrounding samples.

Discrete Samples

?

Reconstructed Function

The reconstruction:

✓ Interpolates the samples

Is not smooth

Page 10: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Gaussian Sampling

The value at a point is the Gaussian average of the

surrounding samples.

Discrete SamplesReconstructed Function

?

Page 11: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Gaussian Sampling

The value at a point is the Gaussian average of the

surrounding samples.

Discrete Samples

?

Reconstructed Function

The reconstruction:

Does not interpolate

✓ Is smooth

Page 12: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Image Sampling

Typically this is done in two steps:1. Reconstruct a continuous function from input samples.

2. Sample a continuous function at a fixed resolution.

Challenge:

Reconstruction is an under-constrained problem.

⇒ Need to define what makes a good reconstruction.

(1) (2)

Page 13: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Image Sampling

Typically this is done in two steps:1. Reconstruct a continuous function from input samples.

2. Sample a continuous function at a fixed resolution.

Challenge:

Reconstruction is an under-constrained problem.

⇒ Need to define what makes a good

reconstruction.

(1) (2)

Key Ideas:

(1) Of all possible reconstructions, we want the one that

is smoothest (has lowest frequencies).

(2) How we reconstruct should also depend on how we

will sample.

Signal processing helps us formulate this precisely.

Page 14: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Fourier Analysis

• Fourier analysis provides a way for expressing (or

approximating) any signal as a sum of scaled and

shifted cosine functions.

The Building Blocks for the Fourier Decomposition

- - - -

- - -

cos 0𝜃 cos 1𝜃 cos 2𝜃 cos 3𝜃

cos 4𝜃 cos 5𝜃 cos 6𝜃

Page 15: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Fourier Analysis

• Fourier analysis provides a way for expressing (or

approximating) any signal as a sum of scaled and

shifted cosine functions.

The Building Blocks for the Fourier Decomposition

cos 0𝜃 cos 1𝜃 cos 2𝜃 cos 3𝜃

cos 4𝜃 cos 5𝜃 cos 6𝜃

- - - -

- - -

Recall:

In the expression cos 𝑘𝜃 , the value 𝑘 is the

frequency of the function.

Page 16: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Fourier Analysis

• As higher frequency components are added to the

approximation, finer details are captured.

Initial Function 0th Order Approximation

0th Order Component

𝑓(𝜃)

𝑓0 𝜃 = 𝑎0 ⋅ cos 0 ⋅ 𝜃 + 𝜙0

Page 17: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Fourier Analysis

• As higher frequency components are added to the

approximation, finer details are captured.

Initial Function 1st Order Approximation

+

1st Order Component

0th Order Approximation

𝑓(𝜃)

𝑓1 𝜃 = 𝑎1 ⋅ cos 1 ⋅ 𝜃 + 𝜙1

Page 18: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Fourier Analysis

• As higher frequency components are added to the

approximation, finer details are captured.

Initial Function 2nd Order Approximation

+

2nd Order Component

1st Order Approximation

𝑓(𝜃)

𝑓2 𝜃 = 𝑎2 ⋅ cos 2 ⋅ 𝜃 + 𝜙2

Page 19: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Fourier Analysis

• As higher frequency components are added to the

approximation, finer details are captured.

Initial Function 3rd Order Approximation

+

3rd Order Component

2nd Order Approximation

𝑓(𝜃)

𝑓3 𝜃 = 𝑎3 ⋅ cos 3 ⋅ 𝜃 + 𝜙3

Page 20: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Fourier Analysis

• As higher frequency components are added to the

approximation, finer details are captured.

Initial Function 4th Order Approximation

+

4th Order Component

3rd Order Approximation

𝑓(𝜃)

𝑓4 𝜃 = 𝑎4 ⋅ cos 4 ⋅ 𝜃 + 𝜙4

Page 21: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Fourier Analysis

• As higher frequency components are added to the

approximation, finer details are captured.

Initial Function 5th Order Approximation

+

5th Order Component

4th Order Approximation

𝑓(𝜃)

𝑓5 𝜃 = 𝑎5 ⋅ cos 5 ⋅ 𝜃 + 𝜙5

Page 22: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Fourier Analysis

• As higher frequency components are added to the

approximation, finer details are captured.

Initial Function 6th Order Approximation

+

6th Order Component

5th Order Approximation

𝑓(𝜃)

𝑓6 𝜃 = 𝑎6 ⋅ cos 6 ⋅ 𝜃 + 𝜙6

Page 23: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Fourier Analysis

• As higher frequency components are added to the

approximation, finer details are captured.

Initial Function 7th Order Approximation

+

7th Order Component

6th Order Approximation

𝑓(𝜃)

𝑓7 𝜃 = 𝑎7 ⋅ cos 7 ⋅ 𝜃 + 𝜙8

Page 24: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Fourier Analysis

• As higher frequency components are added to the

approximation, finer details are captured.

Initial Function 8th Order Approximation

+

8th Order Component

7th Order Approximation

𝑓(𝜃)

𝑓8 𝜃 = 𝑎8 ⋅ cos 8 ⋅ 𝜃 + 𝜙8

Page 25: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Fourier Analysis

• As higher frequency components are added to the

approximation, finer details are captured.

Initial Function 9th Order Approximation

+

9th Order Component

8th Order Approximation

𝑓(𝜃)

𝑓9 𝜃 = 𝑎9 ⋅ cos 9 ⋅ 𝜃 + 𝜙9

Page 26: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Fourier Analysis

• As higher frequency components are added to the

approximation, finer details are captured.

Initial Function 10th Order Approximation

+

10th Order Component

9th Order Approximation

𝑓(𝜃)

𝑓10 𝜃 = 𝑎10 ⋅ cos 10 ⋅ 𝜃 + 𝜙10

Page 27: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Fourier Analysis

• As higher frequency components are added to the

approximation, finer details are captured.

Initial Function 11th Order Approximation

+

11th Order Component

10th Order Approximation

𝑓(𝜃)

𝑓11 𝜃 = 𝑎11 ⋅ cos 11 ⋅ 𝜃 + 𝜙11

Page 28: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Fourier Analysis

• As higher frequency components are added to the

approximation, finer details are captured.

Initial Function 12th Order Approximation

+

12th Order Component

11th Order Approximation

𝑓(𝜃)

𝑓12 𝜃 = 𝑎12 ⋅ cos 12 ⋅ 𝜃 + 𝜙12

Page 29: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Fourier Analysis

• As higher frequency components are added to the

approximation, finer details are captured.

Initial Function 13th Order Approximation

+

13th Order Component

12th Order Approximation

𝑓13 𝜃 = 𝑎13 ⋅ cos 13 ⋅ 𝜃 + 𝜙13

𝑓(𝜃)

Page 30: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Fourier Analysis

• As higher frequency components are added to the

approximation, finer details are captured.

Initial Function 14th Order Approximation

+

14th Order Component

13th Order Approximation

𝑓14 𝜃 = 𝑎14 ⋅ cos 14 ⋅ 𝜃 + 𝜙14

𝑓(𝜃)

Page 31: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Fourier Analysis

• As higher frequency components are added to the

approximation, finer details are captured.

Initial Function 15th Order Approximation

+

15th Order Component

14th Order Approximation

𝑓15 𝜃 = 𝑎15 ⋅ cos 15 ⋅ 𝜃 + 𝜙15

𝑓(𝜃)

Page 32: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Fourier Analysis

• As higher frequency components are added to the

approximation, finer details are captured.

Initial Function 16th Order Approximation

+

16th Order Component

15th Order Approximation

𝑓(𝜃)

𝑓16 𝜃 = 𝑎16 ⋅ cos 16 ⋅ 𝜃 + 𝜙16

Page 33: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Fourier Analysis

• Combining all of the frequency components

together, we get the initial function:

𝑓 𝜃 =

𝑘=0

𝑓𝑘 𝜃 =

𝑘=0

𝑎𝑘 ⋅ cos 𝑘 𝜃 + 𝜙𝑘

Initial Function

+ + + +

+ + + +

=

𝑓(𝜃)

𝑓0() 𝑓1() 𝑓2() 𝑓3() 𝑓4()

𝑓5() 𝑓6() 𝑓7() 𝑓8()

𝑎𝑘: amplitude of the 𝑘th frequency component

𝜙𝑘: shift of the 𝑘th frequency component

Page 34: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Question

Goal:

• Fit a continuous signals to the samples using only

the lowest frequencies.

• Using the 𝑛 lowest frequencies, how many

samples can we fit?

Initial Function

+ + + +

+ + + +

=

𝑓(𝜃)

𝑓0() 𝑓1() 𝑓2() 𝑓3() 𝑓4()

𝑓5() 𝑓6() 𝑓7() 𝑓8()

Page 35: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Question

Goal:

• Fit a continuous signals to the samples using only

the lowest frequencies.

• Using the 𝑛 lowest frequencies, how many

samples can we fit?

Initial Function

+ + + +

+ + + +

=

𝑓( )

𝑓0() 𝑓1() 𝑓2() 𝑓3() 𝑓4()

𝑓5() 𝑓6() 𝑓7() 𝑓8()

Each frequency component has two degrees of freedom:

• Amplitude

• Shift

With 𝑛 frequencies we can fit 2𝑛 samples.

Page 36: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Sampling Theorem

Shannon’s Theorem:

A signal can be reconstructed from its samples, if

the original signal has no frequencies above 1/2 the

sampling rate -- a.k.a. the Nyquist Frequency.

Terminology: A signal is band-limited if its highest non-zero

frequency is bounded.

The frequency is called the bandwidth.

The minimum sampling rate for band-limited function is

called the Nyquist rate (twice the bandwidth).

Page 37: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Image Sampling

To reconstruct the continuous function from 𝑚samples, we can find the unique function of

frequency 𝑚/2 that interpolates the values.

Q: Why don’t we just evaluate this function at the 𝑛sample positions?

A: If 𝑛 < 𝑚 we sample below the Nyquist rate!

(1) (2)

𝑚 samples 𝑛 samples

Page 38: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Aliasing

• When a high-frequency signal is sampled with

insufficiently many samples, it can be perceived as a

lower-frequency signal. This masking of higher

frequencies as lower ones is referred to as aliasing.

-

Page 39: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Aliasing

• When a high-frequency signal is sampled with

insufficiently many samples, it can be perceived as a

lower-frequency signal. This masking of higher

frequencies as lower ones is referred to as aliasing.

-

Page 40: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Aliasing

• When a high-frequency signal is sampled with

insufficiently many samples, it can be perceived as a

lower-frequency signal. This masking of higher

frequencies as lower ones is referred to as aliasing.

-

Page 41: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Aliasing

• When a high-frequency signal is sampled with

insufficiently many samples, it can be perceived as a

lower-frequency signal. This masking of higher

frequencies as lower ones is referred to as aliasing.

-

Page 42: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Temporal Aliasing

• Artifacts due to limited temporal resolution

10 fps

Page 43: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Temporal Aliasing

• Artifacts due to limited temporal resolution

10 fps 25 fps

Page 44: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Temporal Aliasing

• Artifacts due to limited temporal resolution

Page 45: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Temporal Aliasing

• Artifacts due to limited temporal resolution

Page 46: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Temporal Aliasing

• Artifacts due to limited temporal resolution

Page 47: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Temporal Aliasing

• Artifacts due to limited temporal resolution

Page 48: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Sampling

• There are two problems: You don’t have enough samples to correctly

reconstruct your high-frequency information

You corrupt the low-frequency information because

the high-frequencies mask themselves as lower ones.

Page 49: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Anti-Aliasing

Two possible ways to address aliasing:

• Sample at higher rate

• Pre-filter to form band-limited signal

Page 50: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Anti-Aliasing

Two possible ways to address aliasing:

• Sample at higher rate Not always possible

Still rendering to fixed resolution

• Pre-filter to form band-limited signal

Page 51: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Anti-Aliasing

Two possible ways to address aliasing:

• Sample at higher rate

• Pre-filter to form a band-limited signal You still don’t get your high frequencies, but at least the

low frequencies are uncorrupted.

Page 52: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Fourier Analysis

• If we look at the amplitude at each frequency, we

obtain the power spectrum of the signal:

Initial Function

+ + + +

+ + + +

= 𝑓 𝜃 =

𝑘=0

𝑎𝑘 cos 𝑘 𝜃 + 𝜙𝑘

Page 53: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Fourier Analysis

• If we look at the amplitude at each frequency, we

obtain the power spectrum of the signal:

Initial Function

+ + + +

+ + + +

=

Power Spectrum

𝑓 𝜃 =

𝑘=0

𝑎𝑘 cos 𝑘 𝜃 + 𝜙𝑘

Page 54: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Pre-Filtering

• Band-limit by discarding the high-frequency

components that can’t be represented by the

output sampling resolution.

Initial Power Spectrum Band-Limited Power Spectrum

Page 55: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Pre-Filtering

• Band-limit by discarding the high-frequency

components that can’t be represented by the

output sampling resolution.

• We could do this if we could multiply the

frequency components by a 0/1 function:

1

X =

Initial Power Spectrum Band-Limited SpectrumFrequency Filter

Page 56: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Pre-Filtering

• Band-limit by discarding the high-frequency

components that can’t be represented by the

output sampling resolution.

• We could do this if we could multiply the

frequency components by a 0/1 function:

1

X =

Initial Power Spectrum Band-Limited SpectrumFrequency Filter

𝑓 𝜃 =

𝑘=0

𝑎𝑘 cos 𝑘 𝜃 + 𝜙𝑘

𝑓 𝜃 =

𝑘=0

𝑚/2

𝑎𝑘 cos 𝑘 𝜃 + 𝜙𝑘

Page 57: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Fourier Theory

• A fundamental fact from Fourier theory is that

multiplication in the frequency domain is

equivalent to convolution in the spatial domain.

Page 58: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Convolution

• To convolve two functions 𝑓 and 𝑔, we resample

the function 𝑓 using the weights given by 𝑔.

𝑓(𝜃)

𝑔(𝜃)1

Page 59: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Convolution

• To convolve two functions 𝑓 and 𝑔, we resample

the function 𝑓 using the weights given by 𝑔.

𝑓(𝜃)

𝑔(𝜃)

(𝑓𝑔)()

1

1 0

Page 60: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Convolution

• To convolve two functions 𝑓 and 𝑔, we resample

the function 𝑓 using the weights given by 𝑔.

𝑓(𝜃)

𝑔(𝜃).6

(𝑓𝑔)()

.4

.6 .4 0

Page 61: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Convolution

• To convolve two functions 𝑓 and 𝑔, we resample

the function 𝑓 using the weights given by 𝑔.

𝑓(𝜃)

(𝑓𝑔)()

𝑔(𝜃).6.4

.4 .6 0

Page 62: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Convolution

• To convolve two functions 𝑓 and 𝑔, we resample

the function 𝑓 using the weights given by 𝑔.

𝑓(𝜃)

𝑔(𝜃)

(𝑓𝑔)()

1

1 00

Page 63: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Convolution

• To convolve two functions 𝑓 and 𝑔, we resample

the function 𝑓 using the weights given by 𝑔.

.6

.4

.6 .40

𝑓(𝜃)

𝑔(𝜃)

(𝑓𝑔)()

Page 64: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Convolution

• To convolve two functions 𝑓 and 𝑔, we resample

the function 𝑓 using the weights given by 𝑔.

.6

.4

.4 .60

𝑓(𝜃)

𝑔(𝜃)

(𝑓𝑔)()

Page 65: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Convolution

• To convolve two functions 𝑓 and 𝑔, we resample

the function 𝑓 using the weights given by 𝑔.

1

10 0

𝑓(𝜃)

𝑔(𝜃)

(𝑓𝑔)()

Page 66: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Convolution

• To convolve two functions 𝑓 and 𝑔, we resample

the function 𝑓 using the weights given by 𝑔.

0.5

.5 .50

𝑓(𝜃)

𝑔(𝜃)

(𝑓𝑔)()

Page 67: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Convolution

• To convolve two functions 𝑓 and 𝑔, we resample

the function 𝑓 using the weights given by 𝑔.

1

10 0

𝑓(𝜃)

𝑔(𝜃)

(𝑓𝑔)()

Page 68: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Convolution

• To convolve two functions 𝑓 and 𝑔, we resample

the function 𝑓 using the weights given by 𝑔.

1

10

𝑓(𝜃)

𝑔(𝜃)

(𝑓𝑔)()

Page 69: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Convolution

• To convolve two functions 𝑓 and 𝑔, we resample

the function 𝑓 using the weights given by 𝑔.

• Nearest point, bilinear, and Gaussian interpolation

are just convolutions with different filters.

*

*

*

=

=

=

Page 70: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Convolution

• Recall that convolution in the spatial domain is

equal to multiplication in the frequency domain.

• In order to avoid aliasing, we need to convolve

with a filter whose power spectrum has value: 1 at low frequencies

0 at high frequencies

1

X =

Initial Power

SpectrumBand-Limited SpectrumFrequency Filter

Page 71: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Nearest Point Convolution

* =

Filter Spectrum

Discrete Samples Reconstruction Filter Reconstructed

Function

Page 72: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

(Bi)Linear Convolution

* =Discrete Samples Reconstruction Filter Reconstructed

Function

Filter Spectrum

Page 73: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Gaussian Convolution

* =Discrete Samples Reconstruction Filter Reconstructed

Function

Filter Spectrum

Page 74: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Convolution

• The ideal filter for avoiding aliasing should have a

power spectrum with values: 1 at low frequencies

0 at high frequencies

• The sinc function has such a power spectrum and

is referred to as the ideal reconstruction filter:

sinc 𝜃 = ቐsin 𝜃

𝜃if 𝜃 ≠ 0

1 if 𝜃 = 0

Page 75: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

The Sinc Filter

• The ideal filter for avoiding aliasing should have a

power spectrum with values: 1 at low frequencies

0 at high frequencies

• The sinc function has such a power spectrum and

is referred to as the ideal reconstruction filter:

Reconstruction Filter Filter Spectrum

Page 76: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

The Sinc Filter

• Limitations: Has negative values, giving rise to negative weights in

the interpolation.

Reconstruction Filter

* =

Initial Function Reconstructed Function

Page 77: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

The Sinc Filter

• Limitations: Has negative values, giving rise to negative weights in

the interpolation.

Discontinuity in the frequency domain causes ringing

near spatial discontinuities (Gibbs Phenomenon).

Reconstruction Filter

* =

Initial Function Reconstructed Function

Page 78: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

The Sinc Filter

• Limitations: Has negative values, giving rise to negative weights in

the interpolation.

Discontinuity in the frequency domain causes ringing

near spatial discontinuities (Gibbs Phenomenon).

The filter has large support so evaluation is slow.

Reconstruction Filter

* =

Initial Function Reconstructed Function

Page 79: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Summary

There are different ways to sample an image: Nearest Point Sampling

Linear Sampling

Gaussian Sampling

Sinc Sampling

Page 80: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Summary – Nearest

✓Can be implemented efficiently because the filter

is non-zero in a very small region.

? Interpolates the samples.

Is discontinuous.

Does not address aliasing, giving bad results

when a high-frequency signal is under-sampled.

* =

Discrete Samples Reconstruction Filter Reconstructed Function

Page 81: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Summary – Linear

✓Can be implemented efficiently because the filter

is non-zero in a very small region.

? Interpolates the samples.

Is not smooth.

Partially addresses aliasing, but stills give bad

results when a high-frequency signal is under-

sampled.

* =

Discrete Samples Reconstruction Filter Reconstructed Function

Page 82: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Summary – Gaussian

Is slow to implement because the filter is non-zero

in a large region.

? Does not interpolate the samples.

✓ Is smooth.

✓Addresses aliasing by killing off high frequencies.

* =

Discrete Samples Reconstruction Filter Reconstructed Function

Page 83: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Summary – Sinc

Is really slow to implement because the filter is

non-zero, and large, in a large region.

? Interpolates the samples.

Assigns negative weights.

Ringing at discontinuities.

✓Addresses aliasing by killing off high frequencies.

* =

Discrete Samples Reconstruction Filter Reconstructed Function

Page 84: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Image Sampling (Theory)

Given a source signal sampled at 𝑚 positions, to get

a destination image sampled at 𝑛 positions we:1. Reconstruct:

Generate a source function with maximum non-zero

frequency equal to 𝑚/2.

2. Band-limit:

Filter the source function to have frequency no larger

than 𝑛/2.

3. Sample:

Evaluate the filtered function at the 𝑛 positions.

Page 85: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Example (25 → 25/10):

Image Sampling

Sampled 𝑚 = 25 Sampled 𝑚 = 25

Page 86: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Image Sampling

Example (25 → 25/10):Sampled 𝑚 = 25 Sampled 𝑚 = 25

Reconstruction Reconstruction

Page 87: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Image Sampling

Example (25 → 25/10):Sampled 𝑚 = 25

Sampled 𝑛 = 25 Sampled 𝑛 = 10

Reconstruction Reconstruction

Sampled 𝑚 = 25

Page 88: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Image Sampling (Practice)

Given a source signal sampled at 𝑚 positions, to get

a destination image sampled at 𝑛 positions we: Resample the source image using a (Gaussian) filter

whose width is determined by the number of

input/output samples.

Page 89: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Gaussian Sampling

Recall:

To avoid aliasing, we kill off the high-frequency

components by convolving with a Gaussian

because its power spectrum is: (approximately) one at low frequencies

(approximately) zero at high frequencies

Page 90: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Gaussian Sampling (Rule of Thumb)

Q: What standard deviation should we use?

A: The standard deviation should be between 0.5

and 1.0 times the maximum distance between

samples in the input and output.

Gaussians used for reconstructing and sampling a function with 20 samples

Page 91: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Gaussian Sampling (Rule of Thumb)

Q: What standard deviation should we use?

A: The standard deviation should be between 0.5

and 1.0 times the maximum distance between

samples in the input and output.

Power spectra of the Gaussians used for reconstructing and

sampling a function with 20 samples

Page 92: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Gaussian Sampling

Scaling Example:

Q: If we have data represented by 20 samples that

we would like to down-sample to 5 samples.

What standard deviation should we use?

A: Distance between adjacent input samples: 1

Distance between adjacent output samples: 4⇒ The standard deviation of the Gaussian should be

between 2.0 and 4.0.

Page 93: Image Sampling - cs.jhu.edumisha/Fall19/05.pdf · Image Sampling Typically this is done in two steps: 1. Reconstruct a continuous function from input samples. 2. Sample a continuous

Gaussian Sampling

Scaling Example:

Q: If we have data represented by 5 samples that

we would like to up-sample to 20 samples. What

standard deviation should we use?

A: Distance between adjacent input samples: 1

Distance between adjacent output samples: 0.25⇒ The standard deviation of the Gaussian should be

between 0.5 and 1.0.