C OMPUTATIONAL A SPECTS OF C OMPUTATIONAL D IGITAL P HOTOGRAPHY P - - PowerPoint PPT Presentation

c omputational a spects of
SMART_READER_LITE
LIVE PREVIEW

C OMPUTATIONAL A SPECTS OF C OMPUTATIONAL D IGITAL P HOTOGRAPHY P - - PowerPoint PPT Presentation

CS 89.15/189.5, Fall 2015 C OMPUTATIONAL A SPECTS OF C OMPUTATIONAL D IGITAL P HOTOGRAPHY P HOTOGRAPHY Filtering & convolution Wojciech Jarosz wojciech.k.jarosz@dartmouth.edu Your Spanish castle illusions CS 89/189: Computational


slide-1
SLIDE 1

Filtering & convolution

COMPUTATIONAL ASPECTS OF DIGITAL PHOTOGRAPHY

Wojciech Jarosz wojciech.k.jarosz@dartmouth.edu

COMPUTATIONAL PHOTOGRAPHY

CS 89.15/189.5, Fall 2015

slide-2
SLIDE 2

Your Spanish castle illusions

CS 89/189: Computational Photography, Fall 2015 2

slide-3
SLIDE 3 Yuan Tian
slide-4
SLIDE 4 Yuan Tian
slide-5
SLIDE 5 Tianyuan Zhang
slide-6
SLIDE 6 Tianyuan Zhang
slide-7
SLIDE 7 Weichen
slide-8
SLIDE 8 Weichen
slide-9
SLIDE 9 Maxim
slide-10
SLIDE 10 Maxim
slide-11
SLIDE 11

Timelapse photography in the news

CS 89/189: Computational Photography, Fall 2015 11

slide-12
SLIDE 12 https://youtu.be/MPql1VHbYl4
slide-13
SLIDE 13

Today’s agenda

Linear filtering & convolution

  • blurring
  • sharpening

Complexity analysis

  • Optimizations

Denoising from a single image

  • Bilateral filtering

CS 89/189: Computational Photography, Fall 2015 13

slide-14
SLIDE 14

Blur, sharpen

slide-15
SLIDE 15

Image processing motivation

Sharpen images Downsample images Fake depth of field Smooth out noise, skin blemishes ... We must understand convolution!

CS 89/189: Computational Photography, Fall 2015

15

After a slide by Frédo Durand

slide-16
SLIDE 16

CS 89/189: Computational Photography, Fall 2015

Sharpening

16

After a slide by Frédo Durand

slide-17
SLIDE 17

Yikes! Herringbone patterns

Downsampling

17

After a slide by Frédo Durand

Downsample by a scale of 0.2

slide-18
SLIDE 18

We “randomly” pick a color in the high
 frequency pattern

Downsampling

Downsample by a scale of 0.2

18

After a slide by Frédo Durand

slide-19
SLIDE 19

Solution: blur the pattern to get
 average color over new pixels

Downsampling

Blur Down
 sample

19

After a slide by Frédo Durand

slide-20
SLIDE 20

Fake tilt shift

http://www.tiltshiftphotography.net/photoshop-tutorial.php

CS 89/189: Computational Photography, Fall 2015

20

After a slide by Frédo Durand

slide-21
SLIDE 21

Blur in optics

Diffraction Lens aberrations Object movement Camera shake Can we remove blur computationally?

  • invert the blur equation
  • deconvolution

CS 89/189: Computational Photography, Fall 2015

21

After a slide by Frédo Durand

slide-22
SLIDE 22

Lens diffraction

After a slide by Frédo Durand

http://luminous-landscape.com/ tutorials/understanding-series/u- diffraction.shtml

(heavily cropped) See also


http://www.cambridgeincolour.com/ tutorials/diffraction-photography.htm

slide-23
SLIDE 23

Blur example: spherical aberration

Pixel value: weighted average of local color

CS 89/189: Computational Photography, Fall 2015

23 Sensor lens

  • bject with 


color variation

After a slide by Frédo Durand

slide-24
SLIDE 24

Remove optical artifacts

Calibrate lenses and remove blur e.g. DXO

CS 89/189: Computational Photography, Fall 2015

24

After a slide by Frédo Durand

slide-25
SLIDE 25

CS 89/189: Computational Photography, Fall 2015

Removing camera shake

25

Original Naïve Sharpening

After a slide by Frédo Durand

Fergus et al’s algorithm

slide-26
SLIDE 26

Convolution 101

slide-27
SLIDE 27

Blur as convolution

Replace each pixel by a linear combination of its neighbors.

  • only depends on relative position of neighbors

The prescription for the linear combination is called the “convolution kernel”.

CS 89/189: Computational Photography, Fall 2015

27

local image data kernel modified image 10 5 3 4 5 1 1 1 7 0.5 1 0.5 7

After a slide by Frédo Durand

slide-28
SLIDE 28

Linear shift-invariant filtering

Replace each pixel by a linear combination of its neighbors.

  • only depends on relative position of neighbors

The prescription for the linear combination is called the “convolution kernel”.

  • same kernel for all pixels

CS 89/189: Computational Photography, Fall 2015

28

local image data kernel modified image 10 5 3 4 5 1 1 1 7 0.5 1 0.5 7

After a slide by Frédo Durand

slide-29
SLIDE 29

Example of linear NON-shift invariant transformation?

e.g. neutral-density graduated filter (darken high y):

  • J(x,y) = I(x,y)*(1-y/ymax)

Formally, what does linear mean?

  • For two scalars a & b and two inputs x & y: F(ax+by) = aF(x)+bF(y)

What does shift invariant mean?

  • For a translation T: F(T(x)) = T(F(x))
  • If I blur a translated image, I get a translated blurred image

CS 89/189: Computational Photography, Fall 2015

29

After a slide by Frédo Durand

slide-30
SLIDE 30

CS 89/189: Computational Photography, Fall 2015

Questions?

30

slide-31
SLIDE 31

Convolution algorithm

set output image to zero for all pixels (x,y) in output image for all (x’,y’) in kernel

  • ut(x,y) += input(x+x’,y+y’)*kernel(x’,y’)

(this assumes the kernel coordinates are centered)

CS 89/189: Computational Photography, Fall 2015

31

local image data kernel modified image 10 5 3 4 5 1 1 1 7 0.5 1 0.5 7

After a slide by Frédo Durand

slide-32
SLIDE 32

Questions?

s for all pixels (x,y) in for all (x’,y’)

  • ut(x,y) += input(x+x’,y+y’)*kernel(x’,y’)

(this assumes the kernel coordinates are centered)

CS 89/189: Computational Photography, Fall 2015

32

local image data kernel modified image 10 5 3 4 5 1 1 1 7 0.5 1 0.5 7

After a slide by Frédo Durand

slide-33
SLIDE 33

CS 89/189: Computational Photography, Fall 2015

Convolution (warm-up slide)

33

  • riginal

?

After a slide by Frédo Durand

1 pixel offset coefficient

⨂ =

slide-34
SLIDE 34

CS 89/189: Computational Photography, Fall 2015

Convolution (warm-up slide)

34

  • riginal

After a slide by Frédo Durand

1 pixel offset coefficient filtered
 (no change)

= ⨂

slide-35
SLIDE 35

CS 89/189: Computational Photography, Fall 2015

Convolution (warm-up slide)

35

  • riginal

After a slide by Frédo Durand

1 pixel offset coefficient filtered
 (no change)

= ⨂

δ f = f ⊗ δ f

slide-36
SLIDE 36

CS 89/189: Computational Photography, Fall 2015

Convolution

36

  • riginal

?

After a slide by Frédo Durand

1 pixel offset coefficient

⨂ =

slide-37
SLIDE 37

CS 89/189: Computational Photography, Fall 2015

Convolution

37

  • riginal

?

After a slide by Frédo Durand

1 pixel offset coefficient

⨂ =

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

slide-38
SLIDE 38

CS 89/189: Computational Photography, Fall 2015

Convolution

38

  • riginal

?

After a slide by Frédo Durand

1/3 pixel offset coefficient

⨂ =

slide-39
SLIDE 39

CS 89/189: Computational Photography, Fall 2015

Blurring

39

  • riginal

After a slide by Frédo Durand

1/3 pixel offset coefficient

⨂ =

blurred
 (applied in both dimensions)

slide-40
SLIDE 40

CS 89/189: Computational Photography, Fall 2015

Blur examples

40

  • riginal

After a slide by Frédo Durand

1/3 pixel offset coefficient

⨂ =

8 8/3 filtered

impulse

slide-41
SLIDE 41

CS 89/189: Computational Photography, Fall 2015

Blur examples

41

  • riginal

After a slide by Frédo Durand

1/3 pixel offset coefficient

⨂ =

8 8/3 filtered

impulse

  • riginal

1/3 pixel offset coefficient

⨂ =

8

edge

4 filtered 8 4

slide-42
SLIDE 42

CS 89/189: Computational Photography, Fall 2015

Questions?

42

slide-43
SLIDE 43

Formally

slide-44
SLIDE 44

(I ⌦ g)(x) =

Z

x0 I(x0) g(x x0) dx0

I

More formally: Convolution

CS 89/189: Computational Photography, Fall 2015

44

g

After a slide by Frédo Durand

slide-45
SLIDE 45

I

Questions?

CS 89/189: Computational Photography, Fall 2015

45

g

(I ⌦ g)(x) =

Z

x0 I(x0) g(x x0) dx0

After a slide by Frédo Durand

slide-46
SLIDE 46

What’s up with the flipping?

slide-47
SLIDE 47

Convolution & probability

Convolution was first used by Laplace to study the probability of the sum of two random variables

CS 89/189: Computational Photography, Fall 2015

47

After a slide by Frédo Durand

slide-48
SLIDE 48

Random variables

CS 89/189: Computational Photography, Fall 2015

48

X

30% 50% 20%

Y

1 50% 40% 10%

  • 1

1

  • 1

Probability?

  • P(X=-1)*P(Y=1)
  • P(X=0)*P(Y=0)
  • P(X=1)*P(Y=-1)

How can X+Y=0?

  • X=-1, Y=1
  • X=0, Y=0
  • X=1, Y=-1

After a slide by Frédo Durand

slide-49
SLIDE 49

Sum of random variables

CS 89/189: Computational Photography, Fall 2015

49

X

30% 50% 20%

Y

1 50% 40% 10%

  • 1

1

  • 1

Probability?

  • P(X=-1)*P(Y=1)
  • P(X=0)*P(Y=0)
  • P(X=1)*P(Y=-1)

How can X+Y=0?

  • X=-1, Y=1
  • X=0, Y=0
  • X=1, Y=-1

P(X + Y = k) = ∑

k0

P(X = k0)P(Y = k k0)

After a slide by Frédo Durand

slide-50
SLIDE 50

Questions?

CS 89/189: Computational Photography, Fall 2015

50

X

30% 50% 20%

Y

1 50% 40% 10%

  • 1

1

  • 1

Probability?

  • P(X=-1)*P(Y=1)
  • P(X=0)*P(Y=0)
  • P(X=1)*P(Y=-1)

How can X+Y=0?

  • X=-1, Y=1
  • X=0, Y=0
  • X=1, Y=-1

P(X + Y = k) = ∑

k0

P(X = k0)P(Y = k k0)

After a slide by Frédo Durand

slide-51
SLIDE 51

Compare

CS 89/189: Computational Photography, Fall 2015

51

(I ⌦ g)(x) =

Z

x0 I(x0) g(x x0) dx0

Forward model: light goes from x to x+x’ Backward model: light at x comes from x-x’ P(X + Y = k) = ∑

k0

P(X = k0)P(Y = k k0)

After a slide by Frédo Durand

slide-52
SLIDE 52

Image processing

I will often use the term “convolution” improperly and fail to flip the kernel

  • Called correlation
  • Won’t matter most of the time because our kernels are

symmetric

CS 89/189: Computational Photography, Fall 2015

52

After a slide by Frédo Durand

slide-53
SLIDE 53

CS 89/189: Computational Photography, Fall 2015

Questions?

53

slide-54
SLIDE 54

Movie break

slide-55
SLIDE 55 https://youtu.be/HyZfIlxwsfI
slide-56
SLIDE 56

Blur zoo

slide-57
SLIDE 57

http://graphics.stanford.edu/courses/cs178/applets/ convolution.html

CS 89/189: Computational Photography, Fall 2015 57 After a slide by Frédo Durand

slide-58
SLIDE 58

Box filter

CS 89/189: Computational Photography, Fall 2015 58

After a slide by Frédo Durand

slide-59
SLIDE 59

Nice and smooth: Gaussian

CS 89/189: Computational Photography, Fall 2015 59

After a slide by Frédo Durand

slide-60
SLIDE 60

Gaussian formula

r is the distance to the center a is a normalization constant

  • I usually just normalize my kernels


after the fact

σ is the standard deviation and controls the width of the Gaussian

CS 89/189: Computational Photography, Fall 2015 60 http://en.wikipedia.org/wiki/Gaussian_function After a slide by Frédo Durand

ae− r2

2σ2

slide-61
SLIDE 61

Gaussian formula

Gaussians have infinite support

  • >0 everywhere

but are often truncated

  • consider Gaussian to be zero beyond e.g. 3σ
  • for computational tractability/efficiency

CS 89/189: Computational Photography, Fall 2015 61

ae− r2

2σ2

http://en.wikipedia.org/wiki/Gaussian_function After a slide by Frédo Durand

slide-62
SLIDE 62

Sharpening

slide-63
SLIDE 63

How can we sharpen?

Blurring was easy Sharpening is not as obvious

CS 89/189: Computational Photography, Fall 2015 63 After a slide by Frédo Durand

slide-64
SLIDE 64

How can we sharpen?

Blurring was easy Sharpening is not as obvious Idea: amplify the stuff not in the blurry image

  • utput = input + k*(input-blur(input))

CS 89/189: Computational Photography, Fall 2015 64 After a slide by Frédo Durand

slide-65
SLIDE 65

CS 89/189: Computational Photography, Fall 2015

Sharpening

65

  • =

= +k* high pass sharpened image input blurred high pass input

After a slide by Frédo Durand

slide-66
SLIDE 66

Sharpening: kernel view

Recall f is the input f’ is a sharpened image g is a blurring kernel k is a scalar controlling the strength of sharpening

CS 89/189: Computational Photography, Fall 2015 66

f 0 = f + k ⇤ ( f f ⌦ g)

After a slide by Frédo Durand

slide-67
SLIDE 67

Sharpening: kernel view

Recall Denote δ the Dirac kernel (pure impulse)

CS 89/189: Computational Photography, Fall 2015 67

f 0 = f + k ⇤ ( f f ⌦ g)

After a slide by Frédo Durand

f = f ⊗ δ

slide-68
SLIDE 68

Sharpening: kernel view

Recall Sharpening is also a convolution

CS 89/189: Computational Photography, Fall 2015 68

f 0 = f + k ⇤ ( f f ⌦ g) f 0 = f ⌦ δ + k ⇤ ( f ⌦ δ f ⌦ g) f 0 = f ⌦ ((k + 1)δ g)

After a slide by Frédo Durand

slide-69
SLIDE 69

Sharpening kernel

Note: many other sharpening kernels exist 
 (just like we saw multiple blurring kernels) Amplify the difference between a pixel and its neighbors

CS 89/189: Computational Photography, Fall 2015 69

blue: positive
 red: negative

f 0 = f ⌦ ((k + 1)δ g)

After a slide by Frédo Durand

slide-70
SLIDE 70

Alternate interpretation

  • ut = input + k*(input-blur(input))
  • ut = (1 + k)*input - k*blur(input)
  • ut = lerp(blur(input), input, 1+k)
  • linearly extrapolate from the blurred image “past” the
  • riginal input image

CS 89/189: Computational Photography, Fall 2015 70

slide-71
SLIDE 71

CS 89/189: Computational Photography, Fall 2015

Questions?

71

  • =

= +k*

slide-72
SLIDE 72

Unsharp mask

slide-73
SLIDE 73

Unsharp mask

Sharpening is often called “unsharp mask” because photographers used to sandwich a negative with a blurry positive film in order to sharpen

CS 89/189: Computational Photography, Fall 2015 73

http://www.tech-diy.com/UnsharpMasks.htm

After a slide by Frédo Durand

slide-74
SLIDE 74

CS 89/189: Computational Photography, Fall 2015 74

http://www.tech-diy.com/images/unsharp2.jpg

After a slide by Frédo Durand

slide-75
SLIDE 75

Unsharp mask

http://en.wikipedia.org/wiki/Unsharp_masking http://www.largeformatphotography.info/unsharp/ http://www.tech-diy.com/UnsharpMasks.htm http://www.cambridgeincolour.com/tutorials/unsharp-mask.htm

CS 89/189: Computational Photography, Fall 2015 75 After a slide by Frédo Durand

slide-76
SLIDE 76

Sharpening++

slide-77
SLIDE 77

Problem with excess

Haloes around strong edges

CS 89/189: Computational Photography, Fall 2015 77 After a slide by Frédo Durand

slide-78
SLIDE 78

CS 89/189: Computational Photography, Fall 2015

Oversharpening

78

coefficient

  • 0.3
  • riginal

8 Sharpened (differences are accentuated; constant areas are left untouched). 11.2 1.7

  • 0.25

8

After a slide by Frédo Durand

slide-79
SLIDE 79

Bells and whistles

Apply mostly on luminance Old Clarity in Lightroom/Adobe Camera Raw

  • As far as I understand, apply only for mid-tones
  • Avoids haloes around black and white points

Only apply at edges

  • To avoid the amplification of noise

Sharpening chrominance as well

  • But with very large blur

CS 89/189: Computational Photography, Fall 2015 79 After a slide by Frédo Durand

slide-80
SLIDE 80

Lightroom demo

CS 89/189: Computational Photography, Fall 2015 80

slide-81
SLIDE 81

Oriented filters

slide-82
SLIDE 82

Gradient: finite difference

horizontal gradient [[-1, 1]] vertical gradient: [[-1], [1]]

CS 89/189: Computational Photography, Fall 2015 82 After a slide by Frédo Durand

slide-83
SLIDE 83

Gradient: finite difference

horizontal gradient [[-1, 1]] vertical gradient: [[-1], [1]]

CS 89/189: Computational Photography, Fall 2015 83

Gradient magnitude Vertical gradient (absolute value) Horizontal gradient (absolute value)

After a slide by Frédo Durand

slide-84
SLIDE 84

e.g. Sobel [http://en.wikipedia.org/wiki/Sobel_operator]

Gradient

CS 89/189: Computational Photography, Fall 2015 84

Horizontal gradient Vertical gradient Magnitude

Gx =  

−1 +1 −2 +2 −1 +1

  ⊗ A and Gy =  

−1 −2 −1 +1 +2 +1

  ⊗ A

After a slide by Frédo Durand

slide-85
SLIDE 85

Cost

slide-86
SLIDE 86

Convolution cost?

set output image to zero for all pixels (x,y) in output image for all (x’,y’) in kernel

  • ut(x,y) += input(x+x’,y+y’)*kernel(x’,y’)

Cost?

  • O(input.width * input.height * kernel.width * kernel.height)

CS 89/189: Computational Photography, Fall 2015

86

After a slide by Frédo Durand

slide-87
SLIDE 87

Separable filters

slide-88
SLIDE 88

Separability

Sometimes the 2D kernel can be decomposed into the convolution of a horizontal and a vertical filter. Example: box

  • g(x) = const if (-k ≤ x ≤ k) , 0 otherwise
  • g(x,y) = g(x) ⨂ g(y)
  • (separability doesn’t require the two 1D kernels to be the

same, but it’s the case here)

CS 89/189: Computational Photography, Fall 2015 88

=

After a slide by Frédo Durand

slide-89
SLIDE 89

Separable box blur

CS 89/189: Computational Photography, Fall 2015

First blur horizontally using g(x) Then blur vertically using g(y)

89 After a slide by Frédo Durand

⊗ ⊗

slide-90
SLIDE 90

Separable convolution cost?

for all pixels (x,y) in output image for all x’ in kernel

  • utX(x,y) += input(x+x’,y)*kernel(x’)

for all pixels (x,y) in output image for all y’ in kernel

  • ut(x,y) += outX(x,y+y’)*kernel(y’)

Horizontal cost? Vertical cost? Total: Instead of:

CS 89/189: Computational Photography, Fall 2015 90

O(input.width * input.height * kernel.width) O(input.width * input.height * (kernel.height+kernel.width)) O(input.width * input.height * kernel.height) O(input.width * input.height * (kernel.height*kernel.width))

After a slide by Frédo Durand

slide-91
SLIDE 91

Good news

Gaussians are separable too See Assignment 4!

CS 89/189: Computational Photography, Fall 2015 91

slide-92
SLIDE 92

Box blur: Can we do even better?

Can we get even better asymptotic complexity? Very large kernel sizes?

CS 89/189: Computational Photography, Fall 2015 92

slide-93
SLIDE 93

Box blur: Can we do even better?

Since 2D box is separable, let’s focus


  • n the 1D case

The neighborhoods of pixel i and
 pixel i+1 are very similar In fact, they only differ by 2 pixels, so:

  • ut(i+1) = out(i) + (in(i+k+1) – in(i-k+1))/(2k+1)

Asymptotically independent of kernel size, depends only on image size!

CS 89/189: Computational Photography, Fall 2015 93

pixel i neighborhood(i) neighborhood(i+1)

slide-94
SLIDE 94

Box blur cost?

Naïve: Separable: Incremental:

CS 89/189: Computational Photography, Fall 2015 94

O(input.width * input.height * (kernel.height+kernel.width)) O(input.width * input.height * (kernel.height*kernel.width))

After a slide by Frédo Durand

O(input.width * input.height + (kernel.height+kernel.width)) O(input.width * input.height)

slide-95
SLIDE 95

Repeated convolution

CS 89/189: Computational Photography, Fall 2015 95

slide-96
SLIDE 96

Repeated convolution

CS 89/189: Computational Photography, Fall 2015 96

slide-97
SLIDE 97

Repeated convolution

CS 89/189: Computational Photography, Fall 2015 97

slide-98
SLIDE 98

Repeated convolution

CS 89/189: Computational Photography, Fall 2015 98

slide-99
SLIDE 99

Repeated convolution

Convolution of two box kernels yields a tent kernel

CS 89/189: Computational Photography, Fall 2015 99

slide-100
SLIDE 100

Repeated convolution

Yet another convolution with a box yields piecewise quadratic

CS 89/189: Computational Photography, Fall 2015 100

slide-101
SLIDE 101

Repeated convolution

The pattern continues

  • Box filtering the piecewise quadratic will yield a piecewise

cubic, and so on.

Each time we make the kernel smoother Taking this to the limit will yield a Gaussian

CS 89/189: Computational Photography, Fall 2015 101

slide-102
SLIDE 102

delta 1D box box box ⨂ box box ⨂ box ⨂ box box ⨂ box ⨂ box ⨂ box box ⨂ box ⨂ box ⨂ box ⨂ box

Photoshops’ Gaussian not a true Gaussian

slide-103
SLIDE 103

Gaussian blur as multi-box blur

Can approximate Gaussian blur with several box blurs Asymptotically independent of kernel size! Assignment 4 extra credit

  • what is Gaussian’s σ for 5 box blurs?

CS 89/189: Computational Photography, Fall 2015 103

slide-104
SLIDE 104

Nitty-gritty stuff

slide-105
SLIDE 105

Best input to debug convolution

Impulse

CS 89/189: Computational Photography, Fall 2015 105 After a slide by Frédo Durand

slide-106
SLIDE 106

Centering the kernel

Our images are defined with 0,0 in the upper left corner Kernels are usually assumed to have origin at the center

CS 89/189: Computational Photography, Fall 2015 106 After a slide by Frédo Durand

slide-107
SLIDE 107

Normalization

As a rule of thumb, you want kernels to be normalized when you want the output to preserve the overall brightness of the image.

CS 89/189: Computational Photography, Fall 2015 107 After a slide by Frédo Durand

slide-108
SLIDE 108

Denoising from a single image

slide-109
SLIDE 109

Denoising from 1 image

We can’t take average over multiple images

CS 89/189: Computational Photography, Fall 2015 109

Noisy input

After a slide by Frédo Durand

slide-110
SLIDE 110

Denoising from 1 image

We can’t take average over multiple images Idea 1: take a spatial average

  • Most pixels have roughly the same color

as their neighbor

  • Noise looks high frequency => do a low

pass

Here: Gaussian blur

CS 89/189: Computational Photography, Fall 2015 110

Noisy input

After a slide by Frédo Durand

slide-111
SLIDE 111

Gaussian blur

CS 89/189: Computational Photography, Fall 2015 111

After Gaussian blur

After a slide by Frédo Durand

slide-112
SLIDE 112

Gaussian blur

Noise is mostly gone But image is blurry

  • duh!

CS 89/189: Computational Photography, Fall 2015 112

After Gaussian blur

After a slide by Frédo Durand

slide-113
SLIDE 113

Bilateral filtering

slide-114
SLIDE 114

Gaussian blur

Noise is mostly gone But image is blurry

  • duh!

Problem: not all neighbors have the same color Bilateral filter idea: only consider neighbors that have similar values

CS 89/189: Computational Photography, Fall 2015 114

After Gaussian blur

After a slide by Frédo Durand

slide-115
SLIDE 115

Bilateral filter

Tomasi and Manduci 1998 http://www.cse.ucsc.edu/~manduchi/Papers/ ICCV98.pdf Developed for denoising Related to

  • SUSAN filter [Smith and Brady 95] http://citeseer.ist.psu.edu/smith95susan.html
  • Digital-TV [Chan, Osher and Chen 2001] http://citeseer.ist.psu.edu/

chan01digital.html

  • sigma filter http://www.geogr.ku.dk/CHIPS/Manual/f187.htm

Full survey: http://people.csail.mit.edu/sparis/publi/2009/fntcgv/ Paris_09_Bilateral_filtering.pdf

CS 89/189: Computational Photography, Fall 2015 115 After a slide by Frédo Durand

slide-116
SLIDE 116

Bilateral filtering

Images are often piecewise constant with noise added

  • Then nearby pixels are a different noisy

measurement of the same value

Simply blurring doesn’t work

  • also blurs edges

We should blur only within each constant- colored region

  • not across edges between regions

CS 89/189: Computational Photography, Fall 2015 116 [Tomasi and Manduchi 1998]

⨂ =

😖

After a slide by Marc Levoy

slide-117
SLIDE 117

Bilateral filtering

If pixels are similar in intensity, they are probably from the same region of the scene Perform a “convolution” where the weight applied to nearby pixels falls off with:

  • increasing (x,y) distance from the pixel being

blurred

  • increasing intensity difference from the pixel


being blurred

i.e. blur in domain and range dimensions!

CS 89/189: Computational Photography, Fall 2015 117 [Tomasi and Manduchi 1998]

⨂ =

😄

After a slide by Marc Levoy

slide-118
SLIDE 118

Here, input is a step function + noise

Start with Gaussian filtering

  • utput

input

J

=

f

I

118 After a slide by Frédo Durand

slide-119
SLIDE 119

Weight of ξ depends on distance to x

Gaussian filter as weighted average

  • utput

input

ξ

f (x,ξ)

I(ξ)

ξ x x ξ

J(x) =

119 After a slide by Frédo Durand

slide-120
SLIDE 120

The problem of edges

  • utput

input

x ξ Ι(ξ) I(x)

ξ

f (x,ξ)

I(ξ)

J(x) =

Here, Ι(ξ) “pollutes” our estimate J(x) ¡ It is too different

120 After a slide by Frédo Durand

slide-121
SLIDE 121

Penalty g on the intensity difference

Principle of Bilateral filtering

  • utput

input

J(x) =

1 k(x)

ξ

∑ f (x,ξ)

g(I(ξ) − I(x)) I(ξ)

x Ι(ξ) I(x)

121 After a slide by Frédo Durand

slide-122
SLIDE 122

Bilateral filtering

  • utput

input

J(x) =

1 k(x)

ξ

∑ f (x,ξ)g(I(ξ) − I(x)) I(ξ)

x ξ x

Spatial Gaussian f

122

[Tomasi and Manduchi 1998]

After a slide by Frédo Durand

slide-123
SLIDE 123

Spatial Gaussian f Gaussian g on the intensity difference

Bilateral filtering

  • utput

input

J(x) =

1 k(x)

ξ

∑ f (x,ξ) g(I(ξ) − I(x))I(ξ)

x Ι(ξ) I(x)

123

[Tomasi and Manduchi 1998]

After a slide by Frédo Durand

slide-124
SLIDE 124

k(x)=

Normalization factor

  • utput

input

J(x) =

1 k(x)

ξ

∑ f (x,ξ)

g(I(ξ) − I(x)) I(ξ)

ξ

∑ f (x,ξ) g(I(ξ) − I(x))

124

[Tomasi and Manduchi 1998]

After a slide by Frédo Durand

slide-125
SLIDE 125

Bilateral filtering is non-linear

  • utput

input

The weights are different for each output pixel

125

[Tomasi and Manduchi 1998]

After a slide by Frédo Durand

slide-126
SLIDE 126

Bilateral filter

Noisy input After bilateral filter

After a slide by Frédo Durand

slide-127
SLIDE 127

Can we do better?

Noisy input After bilateral filter

chroma noise

After a slide by Frédo Durand

slide-128
SLIDE 128

Chroma noise

Our visual system has different spatial frequency response to chrominance vs. luminance Perform Bilateral filtering in YUV Bigger spatial filter in U & V

CS 89/189: Computational Photography, Fall 2015 128 After a slide by Frédo Durand

slide-129
SLIDE 129

Normal RGB Bilateral filter

Noisy input After bilateral filter

After a slide by Frédo Durand

slide-130
SLIDE 130

YUV Bilateral filter

Noisy input After YUV bilateral filter

After a slide by Frédo Durand

slide-131
SLIDE 131

Comparison

Noisy input Bilateral filter YUV bilateral filter

After a slide by Frédo Durand 131

slide-132
SLIDE 132

Bilateral filtering

Also used to remove skin blemishes in portraits

  • Surface blur in photoshop


(although box spatial kernel instead of Gaussian)

Useful for lots of other things

  • More in future lectures
  • In particular, tone mapping for contrast reduction and high-

dynamic-range imaging

CS 89/189: Computational Photography, Fall 2015 132 After a slide by Frédo Durand

slide-133
SLIDE 133

Photoshop surface blur

Note the radius and threshold controls

  • same as σdomain and σrange

CS 89/189: Computational Photography, Fall 2015 133 After a slide by Frédo Durand

slide-134
SLIDE 134

Assignment 4

slide-135
SLIDE 135

Assignment 4

Convolution Separable Unsharp mask Gradient Denoising YUV denoising

CS 89/189: Computational Photography, Fall 2015 135

slide-136
SLIDE 136

Other approaches to denoising

slide-137
SLIDE 137

Denoising

Bayesian coring in the wavelet domain

  • Simoncelli & Adelson

Big heuristics

  • BM3D

NL means

  • Buades et al.
  • Bilateral in the space of patches

Statistics of natural images

CS 89/189: Computational Photography, Fall 2015 137

slide-138
SLIDE 138

References

http://www.cambridgeincolour.com/tutorials/image-noise.htm http://www.cambridgeincolour.com/tutorials/image-noise-2.htm http://www.clarkvision.com/imagedetail/does.pixel.size.matter2/ http://www.clarkvision.com/articles/digital.sensor.performance.summary/ http://books.google.com/books?id=OYFYt5C4N94C&pg=PA405&dq=binomial+film+grain+noise#v=onepage&q=binomial %20film%20grain%20noise&f=false http://en.wikipedia.org/wiki/Image_noise http://www.picturecode.com/noise.htm http://www.instructables.com/id/Avoiding-Camera-Noise-Signatures/ http://www.photoxels.com/tutorial_noise.html http://people.csail.mit.edu/hasinoff/hdrnoise/hasinoff-sensornoise-tutorial-iccp10.pptx http://theory.uchicago.edu/~ejm/pix/20d/tests/noise/ http://www.imatest.com/docs/noise/ http://www.cambridgeincolour.com/tutorials/image-averaging-noise.htm http://www.petapixel.com/2012/02/21/a-simple-explanation-of-how-iso-works-in-digital-photography/

CS 89/189: Computational Photography, Fall 2015 138

slide-139
SLIDE 139

Slide credits

Frédo Durand

CS 89/189: Computational Photography, Fall 2015 139