71
CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Embed Size (px)

Citation preview

Page 1: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

CSCE 643 Computer Vision:Template Matching, Image Pyramids and Denoising

Jinxiang Chai

Page 2: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Today’s class

• Template matching

• Gaussian Pyramids

• Laplacian Pyramids

• Image denoising

Page 3: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Template matching• Goal: find in image

Page 4: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Template matching• Goal: find in image

• Main challenge: What is a good similarity or distance measure between two patches?

Page 5: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Template matching• Goal: 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

Slide: Hoiem

Page 6: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Matching with filters• Goal: find in image• Method 0: filter the image with eye patch

Input Filtered Image

],[],[],[,

lnkmflkgnmhlk

What went wrong?

f = imageg = filter

Slide: Hoiem

Page 7: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Problem with Correlation

Page 8: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Problem with Correlation

Page 9: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Solution

Page 10: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Slide: Hoiem

Matching with filters• Goal: find in image• Method 1: filter the image with zero-mean eye

Input Filtered Image (scaled) Thresholded Image

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

lkgflnkmfnmhlk

True detections

False detections

mean of f

Page 11: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Slide: Hoiem

Matching with filters• Goal: find in image• Method 2: SSD

Input 1- sqrt(SSD) Thresholded Image

2

,

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

True detections

Page 12: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Relationship SSD and Correlation

Page 13: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Matching with filters• Goal: find in image• Method 2: SSD

Input 1- sqrt(SSD)

2

,

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

What’s the potential downside of SSD?

Slide: Hoiem

Page 14: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Matching with filters• Goal: find in image• Method 3: Normalized cross-correlation - subtracting the mean - dividing by the standard deviation

Page 15: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Matching with filters• Goal: find in image• Method 3: Normalized cross-correlation

5.0

,

2,

,

2

,,

)],[()],[(

)],[)(],[(

],[

lknm

lk

nmlk

flnkmfglkg

flnkmfglkg

nmh

Matlab: normxcorr2(template, im)

mean image patchmean template

Page 16: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Slide: Hoiem

Matching with filters• Goal: find in image• Method 3: Normalized cross-correlation

Input Normalized X-Correlation Thresholded Image

True detections

Page 17: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Matching with filters• Goal: find in image• Method 3: Normalized cross-correlation

Input Normalized X-Correlation Thresholded Image

True detections

Slide: Hoiem

Page 18: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Q: What is the best method to use?

A: Depends• SSD: faster, sensitive to overall intensity• Normalized cross-correlation: slower, invariant

to local average intensity and contrast

Page 19: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Q: What if we want to find larger or smaller eyes?

A: Image Pyramid

Page 20: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Gaussian Pyramid

Low-Pass Filtered ImageImage

GaussianFilter Sample

Low-Res Image

Page 21: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Gaussian Pyramid

filter mask

Repeat– Filter– Subsample

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

Page 22: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Gaussian pyramid

Page 23: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Template Matching with Image Pyramids

Input: Image, Template1. Match template at current scale

2. Downsample image

3. Repeat 1-2 until image is very small

4. Take responses above some threshold, perhaps with non-maxima suppression

Page 24: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Laplacian pyramid

Page 25: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Laplacian FilterThe filtering kernel for Laplacian is

Finite difference allows us to approximate the Laplacian using the following filtering kernel.

Page 26: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Laplacian Pyramid

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

Page 27: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

The Laplacian of Gaussian Kernel

),()()),(( 22 yxIGyxIG

2

22

24

222222 2

yx

eyx

x

G

x

GG

is the Laplacian operator:

Page 28: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

The Laplacian of Gaussian Filter Kernel

0.1

4.1

Page 29: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Laplacian Pyramid

What happens in frequency domain?

Page 30: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Laplacian Pyramid

What happens in frequency domain? Bandpass filters

Can we reconstruct the original from the laplacian pyramid?

Page 31: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Laplacian Pyramid

What happens in frequency domain? Bandpass filters

Can we reconstruct the original from the laplacian pyramid?- Yes, laplacian pyramid is a complete image representation which encodes fine to course structure in a different level

Page 32: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Image representation

• Pixels: great for spatial resolution, poor access to frequency

• Fourier transform: great for frequency, not for spatial info such as locations.

• Pyramids/filter banks: balance between spatial and frequency information

Page 33: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Major uses of image pyramids

• Compression

• Object detection– Scale search– Features

• Detecting stable interest points

• Image blending/mosaicing

• Registration– Course-to-fine

Page 34: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Multi-resolution SIFT Feature Detection

- Object recognition from local scale-invariant features [pdf link], ICCV 09

- David G. Lowe, "Distinctive image features from scale-invariant keypoints," International Journal of Computer Vision, 60, 2 (2004), pp. 91-110

Page 35: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Pyramid Blending

Page 36: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

laplacianlevel

4

laplacianlevel

2

laplacianlevel

0

left pyramid right pyramid blended pyramid

Page 37: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Hierarchical Image Registration1. Compute Gaussian pyramid2. Align with coarse pyramid3. Successively align with finer

pyramids– Search smaller range

Why is this faster?

- Hierarchical Model-Based Motion Estimation, ECCV 92

Page 38: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Denoising

Additive Gaussian Noise

Gaussian Filter

Page 39: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Gaussian

input Gaussian filter

Page 40: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Median Filter

• For each neighbor in image, sliding the window• Sort pixel values• Set the center pixel to the median

Page 41: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Median Filter

input Gaussian filter Median filter

Page 42: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Median Filter Examples

input Median 7X7

Page 43: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Median Filter Examples

Median 11X11Median 3X3

Page 44: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Median Filter Examples

Median 11X11Median 3X3

Straight edges kept

Sharp features lost

Page 45: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Median Filter Properties

Can remove outliers (peppers and salts)

Window size controls size of structure

Preserve some details but sharp corners and edges might get lost

Page 46: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Comparison of Mean, Gaussian, and Median

original Mean with 6 pixels

Page 47: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Comparison of Mean, Gaussian, and Median

original Gaussian with 6 pixels

Page 48: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Comparison of Mean, Gaussian, and Median

original Median with 6 pixels

Page 49: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Common Problems

Mean: blurs image, removes simple noise, no details are preserved

Page 50: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Common Problems

Mean: blurs image, removes simple noise, no details are preserved

Gaussian: blurs image, preserves details only for small σ.

Page 51: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Common Problems

Mean: blurs image, removes simple noise, no details are preserved

Gaussian: blurs image, preserves details only for small σ.

Median: preserves some details, good at removing strong noise

Page 52: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Common Problems

Mean: blurs image, removes simple noise, no details are preserved

Gaussian: blurs image, preserves details only for small σ.

Median: preserves some details, good at removing strong noise

Can we find a filter that not only smooths regions but preserves sharp features such as edges?

Page 53: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Common ProblemsMean: blurs image, removes simple noise, no details

are preservedGaussian: blurs image, preserves details only for small

σ.Median: preserves some details, good at removing

strong noise

Can we find a filter that not only smooths regions but preserves sharp features such as edges?

- yes, Tomasi's Bilateral Filter!

Page 54: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Bilateral Filter Example

Gaussian filter Bilateral filter

Page 55: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Bilateral Filter Example

Gaussian filter Bilateral filter

Page 56: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

1D Graphical ExampleCenter Sample u

It is clear that in weighting this neighborhood, we would like to preserve the step

Neighborhood

I(p)

p

)(uneighborp

Page 57: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

The Weights

)2

)(exp()( 2

2

c

c

pupW

p

I(p)

Page 58: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Filtered Values

)2

)(exp()( 2

2

c

c

pupW

p

I(p)

Filtered value

Page 59: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Edges Are Smoothed

)2

)(exp()( 2

2

c

c

pupW

p

I(p)

Filtered value

Page 60: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

What Causes the Problem?

)2

)(exp()( 2

2

c

c

pupW

p

I(p)

Filtered value

Page 61: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

What Causes the Problem?

)2

)(exp()( 2

2

c

c

pupW

p

I(p)

Filtered value

Same weights for these two pixels!!

Page 62: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

The Weights

)2

))()((exp()( 2

2

s

s

pIuIpW

)2

)(exp()( 2

2

c

c

pupW

p

I(p)

Page 63: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Bilateral filter

2

2 2

2

2 2

2 2

2 2

( )

'

c s

c s

I u I pu p

p N u

I u I pu p

p N u

e e I p

I u

e e

Denoise Feature preserving

Normalization

Bilateral FilteringBilateral Filtering

Page 64: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Filter Parameters

As proposed by Tomasi and Manduchi, the filter is controlled by 3 parameters:

The filter can be applied for several iterations in order to further strengthen its edge-preserving smoothing

N(u) – The neighbor size of the filter support,c – The variance of the spatial distances,s – The variance of the value distances,

)(

)(

)(*)(

)(*)(*)()(

uNp sc

uNp sc

pWpW

pIpWpWuI

Page 65: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Bilateral Filter Results

Original

Page 66: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Bilateral Filter Results

σc = 3, σs = 3

Page 67: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Bilateral Filter Results

σc = 6, σs = 3

Page 68: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Bilateral Filter Results

σc = 12, σs = 3

Page 69: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Bilateral Filter Results

σc = 12, σs = 6

Page 70: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Bilateral Filter Results

σc = 15, σs = 8

Page 71: CSCE 643 Computer Vision: Template Matching, Image Pyramids and Denoising Jinxiang Chai

Summary– Template matching (SSD or Normxcorr2)

• SSD can be done with linear filters, is sensitive to overall intensity

– Gaussian pyramid• Coarse-to-fine search, multi-scale detection

– Laplacian pyramid• More compact image representation• Can be used for compositing in graphics

– Image denoising