61
Pyramid Blending, Templates, NL Filters CS194: Intro to Comp. Vision and Comp. Photo Alexei Efros, UC Berkeley, Fall 2020

Pyramid Blending, Templates, NL Filters

  • Upload
    others

  • View
    6

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Pyramid Blending, Templates, NL Filters

Pyramid Blending, Templates, NL Filters

CS194: Intro to Comp. Vision and Comp. PhotoAlexei Efros, UC Berkeley, Fall 2020

Page 2: Pyramid Blending, Templates, NL Filters

Application: Hybrid ImagesGaussian Filter

Laplacian Filter

A. Oliva, A. Torralba, P.G. Schyns, “Hybrid Images,” SIGGRAPH 2006

Gaussianunit impulse Laplacian of Gaussian

Page 3: Pyramid Blending, Templates, NL Filters

Band-pass filtering

Laplacian Pyramid (subband images)Created from Gaussian pyramid by subtraction

Gaussian Pyramid (low-pass images)

Page 4: Pyramid Blending, Templates, NL Filters

Laplacian Pyramid

How can we reconstruct (collapse) this pyramid into the original image?

Need this!

Originalimage

Page 5: Pyramid Blending, Templates, NL Filters

Blending

Page 6: Pyramid Blending, Templates, NL Filters

Alpha Blending / Feathering

01

01

+

=Iblend = αIleft + (1-α)Iright

Page 7: Pyramid Blending, Templates, NL Filters

Affect of Window Size

0

1 left

right0

1

Page 8: Pyramid Blending, Templates, NL Filters

Affect of Window Size

0

1

0

1

Page 9: Pyramid Blending, Templates, NL Filters

Good Window Size

0

1

“Optimal” Window: smooth but not ghosted

Page 10: Pyramid Blending, Templates, NL Filters

What is the Optimal Window?To avoid seams

• window = size of largest prominent feature

To avoid ghosting• window <= 2*size of smallest prominent feature

Natural to cast this in the Fourier domain• largest frequency <= 2*size of smallest frequency• image frequency content should occupy one “octave” (power of two)

FFT

Page 11: Pyramid Blending, Templates, NL Filters

What if the Frequency Spread is Wide

Idea (Burt and Adelson)• Compute Fleft = FFT(Ileft), Fright = FFT(Iright)• Decompose Fourier image into octaves (bands)

– Fleft = Fleft1 + Fleft

2 + …• Feather corresponding octaves Fleft

i with Frighti

– Can compute inverse FFT and feather in spatial domain• Sum feathered octave images in frequency domain

Better implemented in spatial domain

FFT

Page 12: Pyramid Blending, Templates, NL Filters

Octaves in the Spatial Domain

Bandpass Images

Lowpass Images

Page 13: Pyramid Blending, Templates, NL Filters

Pyramid Blending

0

1

0

1

0

1

Left pyramid Right pyramidblend

Page 14: Pyramid Blending, Templates, NL Filters

Pyramid Blending

Page 15: Pyramid Blending, Templates, NL Filters

laplacianlevel

4

laplacianlevel

2

laplacianlevel

0

left pyramid right pyramid blended pyramid

Page 16: Pyramid Blending, Templates, NL Filters

Blending Regions

Page 17: Pyramid Blending, Templates, NL Filters

Laplacian Pyramid: BlendingGeneral Approach:

1. Build Laplacian pyramids LA and LB from images A and B2. Build a Gaussian pyramid GR from selected region R3. Form a combined pyramid LS from LA and LB using nodes

of GR as weights:• LS(i,j) = GR(I,j,)*LA(I,j) + (1-GR(I,j))*LB(I,j)

4. Collapse the LS pyramid to get the final blended image

Page 18: Pyramid Blending, Templates, NL Filters

Horror Photo

© david dmartin (Boston College)

Page 19: Pyramid Blending, Templates, NL Filters

Results from this class (fall 2005)

© Chris Cameron

Page 20: Pyramid Blending, Templates, NL Filters

Simplification: Two-band BlendingBrown & Lowe, 2003

• Only use two bands: high freq. and low freq.• Blends low freq. smoothly• Blend high freq. with no smoothing: use binary alpha

Page 21: Pyramid Blending, Templates, NL Filters

Low frequency (λ > 2 pixels)

High frequency (λ < 2 pixels)

2-band “Laplacian Stack” Blending

Page 22: Pyramid Blending, Templates, NL Filters

Linear Blending

Page 23: Pyramid Blending, Templates, NL Filters

2-band Blending

Page 24: Pyramid Blending, Templates, NL Filters

Review: Smoothing vs. derivative filtersSmoothing filters

• Gaussian: remove “high-frequency” components; “low-pass” filter

• Can the values of a smoothing filter be negative?• What should the values sum to?

– One: constant regions are not affected by the filter

Derivative filters• Derivatives of Gaussian• Can the values of a derivative filter be negative?• What should the values sum to?

– Zero: no response in constant regions• High absolute value at points of high contrast

Page 25: Pyramid Blending, Templates, NL Filters

Template matchingGoal: find in image

Main challenge: What is a good similarity or distance measure between two patches?• Correlation• Zero-mean correlation• Sum Square Difference• Normalized Cross Correlation

Side by Derek Hoiem

Page 26: Pyramid Blending, Templates, NL Filters

Matching with filtersGoal: find in imageMethod 0: filter the image with eye patch

Input Filtered Image

],[],[],[,

lnkmflkgnmhlk

++=∑

What went wrong?

f = imageg = filter

Side by Derek Hoiem

Page 27: Pyramid Blending, Templates, NL Filters

Matching with filtersGoal: find in imageMethod 1: filter the image with zero-mean eye

Input Filtered Image (scaled) Thresholded Image

)],[()],[(],[,

lnkmgflkfnmhlk

++−=∑

True detections

False detections

mean of f

Page 28: Pyramid Blending, Templates, NL Filters

Matching with filtersGoal: find in imageMethod 2: SSD

Input 1- sqrt(SSD) Thresholded Image

2

,)],[],[(],[ lnkmflkgnmh

lk++−=∑

True detections

Page 29: Pyramid Blending, Templates, NL Filters

Matching with filters

Can SSD be implemented with linear filters?2

,)],[],[(],[ lnkmflkgnmh

lk++−=∑

Side by Derek Hoiem

Page 30: Pyramid Blending, Templates, NL Filters

Matching with filtersGoal: find in imageMethod 2: SSD

Input 1- sqrt(SSD)

2

,)],[],[(],[ lnkmflkgnmh

lk++−=∑

What’s the potential downside of SSD?

Side by Derek Hoiem

Page 31: Pyramid Blending, Templates, NL Filters

Matching with filtersGoal: find in imageMethod 3: Normalized cross-correlation

5.0

,

2,

,

2

,,

)],[()],[(

)],[)(],[(],[

−++−

−++−=

∑ ∑

lknm

lk

nmlk

flnkmfglkg

flnkmfglkgnmh

mean image patchmean template

Side by Derek Hoiem

Page 32: Pyramid Blending, Templates, NL Filters

Matching with filtersGoal: find in imageMethod 3: Normalized cross-correlation

Input Normalized X-Correlation Thresholded Image

True detections

Page 33: Pyramid Blending, Templates, NL Filters

Matching with filtersGoal: find in imageMethod 3: Normalized cross-correlation

Input Normalized X-Correlation Thresholded Image

True detections

Page 34: Pyramid Blending, Templates, NL Filters

Q: What is the best method to use?

A: DependsZero-mean filter: fastest but not a great

matcherSSD: next fastest, sensitive to overall

intensityNormalized cross-correlation: slowest,

invariant to local average intensity and contrast

Side by Derek Hoiem

Page 35: Pyramid Blending, Templates, NL Filters

Denoising

Additive Gaussian Noise

Gaussian Filter

Page 36: Pyramid Blending, Templates, NL Filters

Smoothing with larger standard deviations suppresses noise, but also blurs the image

Reducing Gaussian noise

Source: S. Lazebnik

Page 37: Pyramid Blending, Templates, NL Filters

Reducing salt-and-pepper noise by Gaussian smoothing

3x3 5x5 7x7

Page 38: Pyramid Blending, Templates, NL Filters

Alternative idea: Median filteringA median filter operates over a window by

selecting the median intensity in the window

• Is median filtering linear?Source: K. Grauman

Page 39: Pyramid Blending, Templates, NL Filters

Median filterWhat advantage does median filtering

have over Gaussian filtering?• Robustness to outliers

Source: K. Grauman

Page 40: Pyramid Blending, Templates, NL Filters

Median filterSalt-and-pepper

noiseMedian filtered

Source: M. Hebert

MATLAB: medfilt2(image, [h w])

Page 41: Pyramid Blending, Templates, NL Filters

Median vs. Gaussian filtering3x3 5x5 7x7

Gaussian

Median

Page 42: Pyramid Blending, Templates, NL Filters

A Gentle Introductionto Bilateral Filteringand its Applications

“Fixing the Gaussian Blur”: the Bilateral Filter

Sylvain Paris – MIT CSAIL

Page 43: Pyramid Blending, Templates, NL Filters

Blur Comes from Averaging across Edges

*

*

*

input output

Same Gaussian kernel everywhere.

Page 44: Pyramid Blending, Templates, NL Filters

Bilateral FilterNo Averaging across Edges

*

*

*

input output

The kernel shape depends on the image content.

[Aurich 95, Smith 97, Tomasi 98]

Page 45: Pyramid Blending, Templates, NL Filters

space weight

not new

range weight

I

new

normalizationfactor

new

Bilateral Filter Definition:an Additional Edge Term

( ) ( )∑∈

−−=S

IIIGGW

IBFq

qqpp

p qp ||||||1][rs σσ

Same idea: weighted average of pixels.

Page 46: Pyramid Blending, Templates, NL Filters

Illustration a 1D Image

• 1D image = line of pixels

• Better visualized as a plot

pixelintensity

pixel position

Page 47: Pyramid Blending, Templates, NL Filters

space

Gaussian Blur and Bilateral Filter

space rangenormalization

Gaussian blur

( ) ( )∑∈

−−=S

IIIGGW

IBFq

qqpp

p qp ||||||1][rs σσ

Bilateral filter[Aurich 95, Smith 97, Tomasi 98]

space

spacerange

p

p

q

q

( )∑∈

−=S

IGIGBq

qp qp ||||][ σ

Page 48: Pyramid Blending, Templates, NL Filters

q

The picture can't be displayed.

Bilateral Filter on a Height Field

output input

( ) ( )∑∈

−−=S

IIIGGW

IBFq

qqpp

p qp ||||||1][rs σσ

p

reproducedfrom [Durand 02]

Page 49: Pyramid Blending, Templates, NL Filters

Space and Range Parameters

• space σs : spatial extent of the kernel, size of the considered neighborhood.

• range σr : “minimum” amplitude of an edge

( ) ( )∑∈

−−=S

IIIGGW

IBFq

qqpp

p qp ||||||1][rs σσ

Page 50: Pyramid Blending, Templates, NL Filters

Influence of Pixels

p

Only pixels close in space and in range are considered.

space

range

Page 51: Pyramid Blending, Templates, NL Filters

σs = 2

σs = 6

σs = 18

σr = 0.1 σr = 0.25σr = ∞

(Gaussian blur)

input

Exploring the Parameter Space

Page 52: Pyramid Blending, Templates, NL Filters

σs = 2

σs = 6

σs = 18

σr = 0.1 σr = 0.25σr = ∞

(Gaussian blur)

input

Varying the Range Parameter

Page 53: Pyramid Blending, Templates, NL Filters

input

Page 54: Pyramid Blending, Templates, NL Filters

σr = 0.1

Page 55: Pyramid Blending, Templates, NL Filters

σr = 0.25

Page 56: Pyramid Blending, Templates, NL Filters

σr = ∞(Gaussian blur)

Page 57: Pyramid Blending, Templates, NL Filters

σs = 2

σs = 6

σs = 18

σr = 0.1 σr = 0.25σr = ∞

(Gaussian blur)

input

Varying the Space Parameter

Page 58: Pyramid Blending, Templates, NL Filters

input

Page 59: Pyramid Blending, Templates, NL Filters

σs = 2

Page 60: Pyramid Blending, Templates, NL Filters

σs = 6

Page 61: Pyramid Blending, Templates, NL Filters

σs = 18