91
Image Processing Alexei Efros, CS280, Spring 2018

Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

Image Processing

Alexei Efros, CS280, Spring 2018

Page 2: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

Image Formation

Digital Camera

The Eye

Film

Page 3: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

What is an image? We can think of an image as a function, f, from R2 to R:

• f( x, y ) gives the intensity at position ( x, y ) • Realistically, we expect the image only to be defined over a rectangle,

with a finite range: – f: [a,b]x[c,d] [0,1]

A color image is just three functions pasted together.

We can write this as a “vector-valued” function:

( , )( , ) ( , )

( , )

r x yf x y g x y

b x y

=

Presenter
Presentation Notes
As opposed to [0..255]
Page 4: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

Images as functions

Presenter
Presentation Notes
Render with scanalyze????
Page 5: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

What’s in the “pixel intensity”?

f(x,y) = reflectance(x,y) * illumination(x,y) Reflectance in [0,1], illumination in [0,inf]

Page 6: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

Problem: Dynamic Range

1500

1

25,000

400,000

2,000,000,000

The real world is High dynamic range

Page 7: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

Long Exposure

10-6 106

10-6 106

Real world

Picture

0 to 255

High dynamic range

• What does pixel value 255 mean?

Page 8: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

Short Exposure

10-6 106

10-6 106

Real world

Picture

0 to 255

High dynamic range

• What does pixel value 0 mean?

Page 9: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

pixel (312, 284) = 42

Image

42 photos?

Is Camera a photometer?

Page 10: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

scene radiance

(W/sr/m )

∫ sensor irradiance

sensor exposure

Lens Shutter

2

∆t

analog voltages

digital values

pixel values

CCD ADC Remapping

Image Acquisition Pipeline

Camera is NOT a photometer!

Page 11: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

Simple Point Processing: Enhancement

Page 12: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

Point Processing The simplest kind of range transformations are

these independent of position x,y: g = T(f)

This is called point processing. e.g. Gain and Bias transform: g(x,y) = a*f(x,y) + b Important: every pixel for himself – spatial

information completely lost!

Page 13: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

Power-law transformations

Page 14: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

Basic Point Processing

Page 15: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

Negative

Page 16: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

Log

Page 17: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

Contrast Stretching

Page 18: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

Image Histograms

Cumulative Histograms

s = T(r)

Page 19: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

Histogram Equalization

Page 21: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

Limitations of Point Processing Q: What happens if I reshuffle all pixels within

the image? A: It’s histogram won’t change. No point

processing will be affected…

Page 22: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

Sampling and Reconstruction

Page 23: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

Sampling and Quantization

Page 24: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

© 2006 Steve Marschner • 24

Sampled representations

• How to store and compute with continuous functions?

• Common scheme for representation: samples – write down the function’s values at many points

[FvD

FH fi

g.14

.14b

/ W

olbe

rg]

Page 25: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

© 2006 Steve Marschner • 25

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

[FvD

FH fi

g.14

.14b

/ W

olbe

rg]

Page 26: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

1D Example: Audio

low high frequencies

Page 27: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

© 2006 Steve Marschner • 27

Sampling in digital audio

• Recording: sound to analog to samples to disc

• Playback: disc to samples to analog to sound again – how can we be sure we are filling in the gaps correctly?

Page 28: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

© 2006 Steve Marschner • 28

Sampling and Reconstruction

• Simple example: a sign wave

Page 29: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

© 2006 Steve Marschner • 29

Undersampling

• What if we “missed” things between the samples?

• Simple example: undersampling a sine wave – unsurprising result: information is lost

Page 30: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

© 2006 Steve Marschner • 30

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

Page 31: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

© 2006 Steve Marschner • 31

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

Page 32: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

Aliasing in video

Slide by Steve Seitz

Page 33: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

Aliasing in images

Page 34: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

Antialiasing What can we do about aliasing? Sample more often

• Join the Mega-Pixel craze of the photo industry • But this can’t go on forever

Make the signal less “wiggly”

• Get rid of some high frequencies • Will loose information • But it’s better than aliasing

Page 35: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

© 2006 Steve Marschner • 36

Preventing aliasing

• Introduce lowpass filters: – remove high frequencies leaving only safe, low frequencies – choose lowest frequency in reconstruction (disambiguate)

Page 36: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

© 2006 Steve Marschner • 37

Linear filtering: a key idea

• Transformations on signals; e.g.: – bass/treble controls on stereo – blurring/sharpening operations in image editing – smoothing/noise reduction in tracking

• 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

• Can be modeled mathematically by convolution

Page 37: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

© 2006 Steve Marschner • 38

Moving Average

• basic idea: define a new function by averaging over a sliding window

• a simple example to start off: smoothing

Page 38: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

© 2006 Steve Marschner • 39

Moving Average

• Can add weights to our moving average

• Weights […, 0, 1, 1, 1, 1, 1, 0, …] / 5

Page 39: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

1 1 1

1 1 1

1 1 1

Slide credit: David Lowe (UBC)

],[ ⋅⋅h

In 2D: box filter

Page 40: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 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 90 0 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 90 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

0 0 0 0 0 0 0 0 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 90 0 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 90 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0

Credit: S. Seitz

],[],[],[,

lnkmflkhnmglk

++= ∑

[.,.]g[.,.]f

Image filtering 1 1 1

1 1 1

1 1 1

],[ ⋅⋅h

Presenter
Presentation Notes
ones, divide by 9
Page 41: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 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 90 0 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 90 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0

0 10

0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 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 90 0 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 90 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0

[.,.]g[.,.]f

Image filtering 1 1 1

1 1 1

1 1 1

],[ ⋅⋅h

Credit: S. Seitz

],[],[],[,

lnkmflkhnmglk

++= ∑

Presenter
Presentation Notes
ones, divide by 9
Page 42: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 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 90 0 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 90 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0

0 10 20

0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 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 90 0 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 90 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0

[.,.]g[.,.]f

Image filtering 1 1 1

1 1 1

1 1 1

],[ ⋅⋅h

Credit: S. Seitz

Presenter
Presentation Notes
ones, divide by 9
Page 43: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 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 90 0 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 90 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0

0 10 20 30

0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 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 90 0 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 90 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0

[.,.]g[.,.]f

Image filtering 1 1 1

1 1 1

1 1 1

],[ ⋅⋅h

Credit: S. Seitz

Presenter
Presentation Notes
ones, divide by 9
Page 44: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

0 10 20 30 30

0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 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 90 0 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 90 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0

[.,.]g[.,.]f

Image filtering 1 1 1

1 1 1

1 1 1

],[ ⋅⋅h

Credit: S. Seitz

Presenter
Presentation Notes
ones, divide by 9
Page 45: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

0 10 20 30 30

0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 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 90 0 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 90 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0

[.,.]g[.,.]f

Image filtering 1 1 1

1 1 1

1 1 1

],[ ⋅⋅h

Credit: S. Seitz

?

Presenter
Presentation Notes
ones, divide by 9
Page 46: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

0 10 20 30 30

50

0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 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 90 0 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 90 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0

[.,.]g[.,.]f

Image filtering 1 1 1

1 1 1

1 1 1

],[ ⋅⋅h

Credit: S. Seitz

?

Presenter
Presentation Notes
ones, divide by 9
Page 47: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 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 90 0 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 90 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0

0 10 20 30 30 30 20 10

0 20 40 60 60 60 40 20

0 30 60 90 90 90 60 30

0 30 50 80 80 90 60 30

0 30 50 80 80 90 60 30

0 20 30 50 50 60 40 20

10 20 30 30 30 30 20 10

10 10 10 0 0 0 0 0

[.,.]g[.,.]f

Image filtering 1 1 1 1 1 1 1 1 1 ],[ ⋅⋅h

Credit: S. Seitz

],[],[],[,

lnkmflkhnmglk

++= ∑

Page 48: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

What does it do? • Replaces each pixel with

an average of its neighborhood

• Achieve smoothing effect (remove sharp features)

1 1 1

1 1 1

1 1 1

Slide credit: David Lowe (UBC)

],[ ⋅⋅h

Box Filter

Page 49: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

Linear filters: examples

Original

1 1 1 1 1 1 1 1 1

Blur (with a mean filter)

Source: D. Lowe

=

Page 50: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

Cross-correlation

This is called a cross-correlation operation:

Let be the image, be the kernel (of size 2k+1 x 2k+1), and be the output image

• Can think of as a “dot product” between local neighborhood and kernel for each pixel

Page 51: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

Practice with linear filters

0 0 0 0 1 0 0 0 0

Original

?

Source: D. Lowe

Page 52: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

Practice with linear filters

0 0 0 0 1 0 0 0 0

Original Filtered (no change)

Source: D. Lowe

Page 53: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

Practice with linear filters

Original

?

Source: D. Lowe

0 0 0 1 0 0 0 0 0

Page 54: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

Practice with linear filters

0 0 0 1 0 0 0 0 0

Original Shifted left By 1 pixel

Source: D. Lowe

Page 55: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

Other filters

-1 0 1

-2 0 2

-1 0 1

Vertical Edge (absolute value)

Sobel

Page 56: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

Other filters

-1 -2 -1

0 0 0

1 2 1

Horizontal Edge (absolute value)

Sobel

Q?

Presenter
Presentation Notes
Questions at this point?
Page 57: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

Back to the box filter

Page 58: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

© 2006 Steve Marschner • 59

Moving Average

• Can add weights to our moving average

• Weights […, 0, 1, 1, 1, 1, 1, 0, …] / 5

Page 59: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

© 2006 Steve Marschner • 60

Weighted Moving Average

• bell curve (gaussian-like) weights […, 1, 4, 6, 4, 1, …]

Page 60: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

© 2006 Steve Marschner • 61

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 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 90 0 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 90 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Slide by Steve Seitz

Presenter
Presentation Notes
ones, divide by 9
Page 61: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

62

Gaussian filtering A Gaussian kernel gives less weight to pixels further from the center of the window

This kernel is an approximation of a Gaussian function:

0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 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 90 0 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 90 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

Slide by Steve Seitz

Page 62: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

63

Mean vs. Gaussian filtering

Slide by Steve Seitz

Page 63: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

64

Weight contributions of neighboring pixels by nearness

0.003 0.013 0.022 0.013 0.003 0.013 0.059 0.097 0.059 0.013 0.022 0.097 0.159 0.097 0.022 0.013 0.059 0.097 0.059 0.013 0.003 0.013 0.022 0.013 0.003

5 x 5, σ = 1

Slide credit: Christopher Rasmussen

Important filter: Gaussian

Page 64: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

65

Gaussian Kernel

• Standard deviation σ: determines extent of smoothing

Source: K. Grauman

σ = 2 with 30 x 30 kernel

σ = 5 with 30 x 30 kernel

Page 65: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

Gaussian filters

= 30 pixels = 1 pixel = 5 pixels = 10 pixels

Page 66: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

67

Choosing kernel width • The Gaussian function has infinite support, but discrete filters

use finite kernels

Source: K. Grauman

Page 67: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

68

How big should the filter be?

Values at edges should be near zero

Rule of thumb for Gaussian: set filter half-width to about 3 σ

Practical matters

Side by Derek Hoiem

Page 68: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

Cross-correlation vs. 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: Convolution is commutative and associative

Slide by Steve Seitz

Page 69: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

Convolution

Adapted from F. Durand

Page 70: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

© 2006 Steve Marschner • 71

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, …]

• Conceptually no distinction between filter and signal

• Usefulness of associativity – often apply several filters one after another: (((a * b1) * b2) * b3) – this is equivalent to applying one filter: a * (b1 * b2 * b3)

Page 71: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

Gaussian and convolution • Removes “high-frequency” components from

the image (low-pass filter) • Convolution with self is another Gaussian

– Convolving twice with Gaussian kernel of width = convolving once with kernel of width

Source: K. Grauman

* =

Presenter
Presentation Notes
Linear vs. quadratic in mask size
Page 72: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

The Convolution Theorem The greatest thing since sliced (banana) bread!

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

• The inverse Fourier transform of the product of two Fourier transforms is the convolution of the two inverse Fourier transforms

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

]F[]F[]F[ hghg =∗

][F][F][F 111 hggh −−− ∗=

Page 73: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

2D convolution theorem example

*

f(x,y)

h(x,y)

g(x,y)

|F(sx,sy)|

|H(sx,sy)|

|G(sx,sy)|

Page 74: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

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

Gaussian Box filter

Filtering

Presenter
Presentation Notes
Things we can’t understand without thinking in frequency
Page 75: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

Fourier Transform pairs

Page 76: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

Practical matters What is the size of the output? MATLAB: filter2(g, f, shape) or conv2(g,f,shape)

• shape = ‘full’: output size is sum of sizes of f and g • shape = ‘same’: output size is same as f • shape = ‘valid’: output size is difference of sizes of f and g

f

g g

g g

f

g g

g g

f

g g

g g

full same valid

Source: S. Lazebnik

Page 77: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

Image half-sizing

This image is too big to fit on the screen. How can we reduce it? How to generate a half- sized version?

Page 78: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

Image sub-sampling

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

- called image sub-sampling

1/4

1/8

Slide by Steve Seitz

Page 79: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

Image sub-sampling

1/4 (2x zoom) 1/8 (4x zoom)

Aliasing! What do we do?

1/2

Slide by Steve Seitz

Page 80: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

Sampling an image

Examples of GOOD sampling

Page 81: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

Undersampling

Examples of BAD sampling -> Aliasing

Page 82: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

Gaussian (lowpass) pre-filtering

G 1/4

G 1/8

Gaussian 1/2

Solution: filter the image, then subsample • Filter size should double for each ½ size reduction. Why?

Slide by Steve Seitz

Page 83: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

Subsampling with Gaussian pre-filtering

G 1/4 G 1/8 Gaussian 1/2

Slide by Steve Seitz

Page 84: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

Compare with...

1/4 (2x zoom) 1/8 (4x zoom) 1/2

Slide by Steve Seitz

Page 85: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

Gaussian (lowpass) pre-filtering

G 1/4

G 1/8

Gaussian 1/2

Solution: filter the image, then subsample • Filter size should double for each ½ size reduction. Why? • How can we speed this up? Slide by Steve Seitz

Page 86: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

Image Pyramids

Known as a Gaussian Pyramid [Burt and Adelson, 1983] • In computer graphics, a mip map [Williams, 1983] • A precursor to wavelet transform

Slide by Steve Seitz

Page 87: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

A bar in the big images is a hair on the zebra’s nose; in smaller images, a stripe; in the smallest, the animal’s nose

Figure from David Forsyth

Page 88: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

Gaussian pyramid construction

filter mask

Repeat • Filter • Subsample

Until minimum resolution reached • can specify desired number of levels (e.g., 3-level pyramid)

The whole pyramid is only 4/3 the size of the original image! Slide by Steve Seitz

Page 89: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

What are they good for? Improve Search

• Search over translations – Classic coarse-to-fine strategy

• Search over scale – Template matching – E.g. find a face at different scales

Page 90: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

Sharpening What does blurring take away?

original smoothed (5x5)

detail

=

sharpened

=

Let’s add it back:

original detail

+ α

Page 91: Image Processing - University of California, Berkeleycs280/sp18/lectures/7.pdf · A color image is just three functions pasted together. ... High dynamic range . Long Exposure . 10-6

Unsharp mask filter

Gaussian unit impulse

Laplacian of Gaussian

))1(()1()( gefgffgfff ααααα −+∗=∗−+=∗−+

image blurred image

unit impulse (identity)

Presenter
Presentation Notes
f + a(f - f * g) = (1+a)f-af*g = f*((1+a)e-g)