introduction and course overvie16385/lectures/lecture2.pdf · course announcements • make sure...

116
Image filtering 16-385 Computer Vision Spring 2020, Lecture 2 http://www.cs.cmu.edu/~16385/

Upload: others

Post on 21-May-2020

8 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Image filtering

16-385 Computer VisionSpring 2020, Lecture 2http://www.cs.cmu.edu/~16385/

Page 2: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Course announcements

• Make sure you are on Piazza (sign up on your own using the link on the course website).- I think I signed up most of you this morning.- How many of you aren’t already on Piazza?

• Make sure to take the start-of-semester survey (link posted on Piazza).- We need your responses to schedule office hours for the rest of the semester.- 40 responses (about 60%) as of this morning.

• Office hours for this week only:- Yannis (Smith Hall Rm 225), Friday, Friday 5-7 pm.- Hours decided based on survey responses so far.

Page 3: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Overview of today’s lecture

• Types of image transformations.

• Point image processing.

• Linear shift-invariant image filtering.

• Convolution.

• Image gradients.

Page 4: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Slide credits

Most of these slides were adapted directly from:

• Kris Kitani (15-463, Fall 2016).

Inspiration and some examples also came from:

• Fredo Durand (Digital and Computational Photography, MIT).

• Kayvon Fatahalian (15-769, Fall 2016).

Page 5: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Types of image transformations

Page 6: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

What is an image?

Page 7: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

What is an image?

A (color) image is a 3D tensor of numbers.

Page 8: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

What is an image?red green blue

colorized for visualization

actual intensity values per channel

color image patch

How many bits are the intensity values?

Each channel is a 2D array of

numbers.

Page 9: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

What is an image?

A (grayscale) image is a 2D

function.

domainWhat is the range of the image function f?

grayscale image

Page 10: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

What types of image transformations can we do?

changes pixel values changes pixel locations

Filtering Warping

Page 11: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

What types of image transformations can we do?

changes range of image function changes domain of image function

Filtering Warping

Page 12: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

What types of image filtering can we do?

Point Operation

Neighborhood Operation

point processing

“filtering”

Page 13: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Point processing

Page 14: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Examples of point processingoriginal lower contrast non-linear lower contrastdarken

invert raise contrast non-linear raise contrastlighten

Page 15: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Examples of point processingoriginal lower contrast non-linear lower contrastdarken

invert raise contrast non-linear raise contrastlighten

How would you implement these?

Page 16: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Examples of point processingoriginal lower contrast non-linear lower contrastdarken

invert raise contrast non-linear raise contrastlighten

How would you implement these?

Page 17: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Examples of point processingoriginal lower contrast non-linear lower contrastdarken

invert raise contrast non-linear raise contrastlighten

How would you implement these?

Page 18: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Examples of point processingoriginal lower contrast non-linear lower contrastdarken

invert raise contrast non-linear raise contrastlighten

How would you implement these?

Page 19: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Examples of point processingoriginal lower contrast non-linear lower contrastdarken

invert raise contrast non-linear raise contrastlighten

How would you implement these?

Page 20: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Examples of point processingoriginal lower contrast non-linear lower contrastdarken

invert raise contrast non-linear raise contrastlighten

How would you implement these?

Page 21: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Examples of point processingoriginal lower contrast non-linear lower contrastdarken

invert raise contrast non-linear raise contrastlighten

How would you implement these?

Page 22: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Examples of point processingoriginal lower contrast non-linear lower contrastdarken

invert raise contrast non-linear raise contrastlighten

How would you implement these?

Page 23: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Many other types of point processing

camera output image after stylistic tonemapping

[Bae et al., SIGGRAPH 2006]

Page 24: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Many other types of point processing

Page 25: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Linear shift-invariant image filtering

Page 26: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Linear shift-invariant image filtering

• Replace each pixel by a linear combination of its neighbors (and possibly itself).

• The combination is determined by the filter’s kernel.

• The same kernel is shifted to all pixel locations so that all pixels use the same linear combination of their neighbors.

Page 27: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Example: the box filter

• also known as the 2D rect (not rekt) filter

• also known as the square mean filter

1 1 1

1 1 1

1 1 1

• replaces pixel with local average

• has smoothing (blurring) effect

kernel

Page 28: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

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

1 1 1

1 1 1

kernel

image output

filter image (signal)output

Let’s run the box filter

note that we assume that the kernel coordinates are

centered

Page 29: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

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

1 1 1

1 1 1

1 1 1

image output

filter image (signal)output

Let’s run the box filter

kernel

Page 30: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

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

1 1 1

1 1 1

1 1 1

image output

filter image (signal)output

Let’s run the box filter

kernel

shift-invariant: as the pixel

shifts, so does the kernel

Page 31: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

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

1 1 1

1 1 1

1 1 1

image output

filter image (signal)output

Let’s run the box filter

kernel

Page 32: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

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

1 1 1

1 1 1

1 1 1

image output

filter image (signal)output

Let’s run the box filter

kernel

Page 33: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

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

1 1 1

1 1 1

1 1 1

image output

filter image (signal)output

Let’s run the box filter

kernel

Page 34: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

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

1 1 1

1 1 1

1 1 1

image output

filter image (signal)output

Let’s run the box filter

kernel

Page 35: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

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

1 1 1

1 1 1

1 1 1

image output

filter image (signal)output

Let’s run the box filter

kernel

Page 36: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

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

1 1 1

1 1 1

1 1 1

image output

filter image (signal)output

Let’s run the box filter

kernel

Page 37: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

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

1 1 1

1 1 1

1 1 1

image output

filter image (signal)output

Let’s run the box filter

kernel

Page 38: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

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

1 1 1

1 1 1

1 1 1

image output

filter image (signal)output

Let’s run the box filter

kernel

Page 39: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

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

1 1 1

1 1 1

1 1 1

image output

filter image (signal)output

Let’s run the box filter

kernel

Page 40: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

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

1 1 1

1 1 1

1 1 1

image output

filter image (signal)output

Let’s run the box filter

kernel

Page 41: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

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

1 1 1

1 1 1

1 1 1

image output

filter image (signal)output

Let’s run the box filter

kernel

Page 42: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

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

1 1 1

1 1 1

1 1 1

image output

filter image (signal)output

Let’s run the box filter

kernel

Page 43: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

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

01 1 1

1 1 1

1 1 1

image output

filter image (signal)output

Let’s run the box filter

kernel

Page 44: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

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

1 1 1

1 1 1

image output

filter image (signal)output

Let’s run the box filter

kernel

Page 45: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

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 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 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 50 80 80 90 60 30

0 30 50 80 80 90 60 30

0 20 30 50 50 60 40 20

0 10 20 30 30 30 20 10

10 10 10 10 0 0 0 0

10

1 1 1

1 1 1

1 1 1

image output

filter image (signal)output

Let’s run the box filter

kernel

Page 46: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

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 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 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 50 80 80 90 60 30

0 30 50 80 80 90 60 30

0 20 30 50 50 60 40 20

0 10 20 30 30 30 20 10

10 10 10 10 0 0 0 0

10 10 10 10 0 0 0 0

1 1 1

1 1 1

1 1 1

image output

filter image (signal)output

Let’s run the box filter

kernel

Page 47: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

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 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 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 50 80 80 90 60 30

0 30 50 80 80 90 60 30

0 20 30 50 50 60 40 20

0 10 20 30 30 30 20 10

10 10 10 10 0 0 0 0

10 10 10 10 0 0 0 0

1 1 1

1 1 1

1 1 1

image output

filter image (signal)output

… and the result is

kernel

Page 48: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Some more realistic examples

Page 49: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Some more realistic examples

Page 50: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Some more realistic examples

Page 51: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Convolution

Page 52: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Convolution for 1D continuous signals

Definition of filtering as convolution:

filtered signal input signalfilter

notice the flip

Page 53: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Convolution for 1D continuous signals

Definition of filtering as convolution:

filtered signal input signalfilter

Consider the box filter example:

notice the flip

1D continuous box filter

filtering output is a blurred version of g

Page 54: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Convolution for 2D discrete signals

Definition of filtering as convolution:

filtered image input imagefilter

notice the flip

Page 55: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Convolution for 2D discrete signals

Definition of filtering as convolution:

filtered image input imagefilter

If the filter is non-zero only within , then

notice the flip

The kernel we saw earlier is the 3x3 matrix representation of .

Page 56: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Convolution vs correlation

Definition of discrete 2D convolution: notice the flip

Definition of discrete 2D correlation: notice the lack of a flip

• Most of the time won’t matter, because our kernels will be symmetric.• Will be important when we discuss frequency-domain filtering (lectures 5-6).

Page 57: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Separable filters

A 2D filter is separable if it can be written as the product of a “column” and a “row”.

=1

1

1

1 1 1

1 1 1

1 1 1

1 1 1

*

column

rowexample: box filter

What is the rank of this filter matrix?

Page 58: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Separable filters

A 2D filter is separable if it can be written as the product of a “column” and a “row”.

=1

1

1

1 1 1

1 1 1

1 1 1

1 1 1

*

column

rowexample: box filter

Why is this important?

Page 59: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Separable filters

A 2D filter is separable if it can be written as the product of a “column” and a “row”.

=1

1

1

1 1 1

1 1 1

1 1 1

1 1 1

*

column

rowexample: box filter

2D convolution with a separable filter is equivalent to two 1D convolutions (with the “column” and “row” filters).

Page 60: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Separable filters

A 2D filter is separable if it can be written as the product of a “column” and a “row”.

=1

1

1

1 1 1

1 1 1

1 1 1

1 1 1

*

column

rowexample: box filter

2D convolution with a separable filter is equivalent to two 1D convolutions (with the “column” and “row” filters).

If the image has M x M pixels and the filter kernel has size N x N:• What is the cost of convolution with a non-separable filter?

Page 61: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Separable filters

A 2D filter is separable if it can be written as the product of a “column” and a “row”.

=1

1

1

1 1 1

1 1 1

1 1 1

1 1 1

*

column

rowexample: box filter

2D convolution with a separable filter is equivalent to two 1D convolutions (with the “column” and “row” filters).

If the image has M x M pixels and the filter kernel has size N x N:• What is the cost of convolution with a non-separable filter? M2 x N2

• What is the cost of convolution with a separable filter?

Page 62: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Separable filters

A 2D filter is separable if it can be written as the product of a “column” and a “row”.

=1

1

1

1 1 1

1 1 1

1 1 1

1 1 1

*

column

rowexample: box filter

2D convolution with a separable filter is equivalent to two 1D convolutions (with the “column” and “row” filters).

If the image has M x M pixels and the filter kernel has size N x N:• What is the cost of convolution with a non-separable filter? M2 x N2

• What is the cost of convolution with a separable filter? 2 x N x M2

Page 63: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

A few more filters

do you see any problems in this image?

original 3x3 box filter

Page 64: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

The Gaussian filter

• named (like many other things) after Carl Friedrich Gauss

• kernel values sampled from the 2D Gaussian function:

• weight falls off with distance from center pixel

• theoretically infinite, in practice truncated to some maximum distance

Any heuristics for selecting where to truncate?

Page 65: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

The Gaussian filter

• named (like many other things) after Carl Friedrich Gauss

• kernel values sampled from the 2D Gaussian function:

• weight falls off with distance from center pixel

• theoretically infinite, in practice truncated to some maximum distance

Any heuristics for selecting where to truncate?• usually at 2-3σ

1 2 1

2 4 2

1 2 1

116

kernel

Is this a separable filter?

Page 66: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

The Gaussian filter

• named (like many other things) after Carl Friedrich Gauss

• kernel values sampled from the 2D Gaussian function:

• weight falls off with distance from center pixel

• theoretically infinite, in practice truncated to some maximum distance

Any heuristics for selecting where to truncate?• usually at 2-3σ

1 2 1

2 4 2

1 2 1

116

kernel

Is this a separable filter? Yes!

Page 67: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Gaussian filtering example

Page 68: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Gaussian vs box filtering

7x7 Gaussian

7x7 box

original

Which blur do you like better?

Page 69: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

How would you create a soft shadow effect?

Page 70: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

How would you create a soft shadow effect?

Gaussian blur

overlay

Page 71: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Other filters

0 0 0

0 1 0

0 0 0?

input filter output

Page 72: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Other filters

0 0 0

0 1 0

0 0 0?

input filter output

unchanged

Page 73: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Other filters

0 0 0

0 1 0

0 0 0?

input filter output

unchanged

0 0 0

0 0 1

0 0 0?

input filter output

Page 74: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Other filters

0 0 0

0 1 0

0 0 0?

input filter output

unchanged

0 0 0

0 0 1

0 0 0?

input filter output

shift to left by one

Page 75: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Other filters

?

input filter output

0 0 0

0 2 0

0 0 0

1 1 1

1 1 1

1 1 1

-

Page 76: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Other filters

?

input filter output

0 0 0

0 2 0

0 0 0

1 1 1

1 1 1

1 1 1

-

• do nothing for flat areas• stress intensity peaks

sharpening

Page 77: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Sharpening examples

Page 78: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Sharpening examples

Page 79: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Sharpening examples

Page 80: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Sharpening examples

do you see any problems in this image?

Page 81: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Do not overdo it with sharpening

original sharpened oversharpened

What is wrong in this image?

Page 82: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Image gradients

Page 83: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

What are image edges?

Very sharp discontinuities

in intensity.

domain

grayscale image

Page 84: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Detecting edges

How would you go about detecting edges in an image (i.e., discontinuities in a function)?

Page 85: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Detecting edges

How would you go about detecting edges in an image (i.e., discontinuities in a function)?

✓ You take derivatives: derivatives are large at discontinuities.

How do you differentiate a discrete image (or any other discrete signal)?

Page 86: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Detecting edges

How would you go about detecting edges in an image (i.e., discontinuities in a function)?

✓ You take derivatives: derivatives are large at discontinuities.

How do you differentiate a discrete image (or any other discrete signal)?

✓ You use finite differences.

Page 87: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Finite differences

High-school reminder: definition of a derivative using forward difference

Page 88: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Finite differences

High-school reminder: definition of a derivative using forward difference

Alternative: use central difference

For discrete signals: Remove limit and set h = 2

What convolution kernel does this correspond to?

Page 89: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Finite differences

High-school reminder: definition of a derivative using forward difference

Alternative: use central difference

For discrete signals: Remove limit and set h = 2

1 0 -1

-1 0 1 ?

?

Page 90: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Finite differences

High-school reminder: definition of a derivative using forward difference

Alternative: use central difference

For discrete signals: Remove limit and set h = 2

1 0 -1

1D derivative filter

Page 91: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

The Sobel filter

=1

2

1

1 0 -1

2 0 -2

1 0 -1

Sobel filter

1 0 -1

*

What filter is this?

1D derivative filter

Page 92: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

The Sobel filter

=1

2

1

1 0 -1

2 0 -2

1 0 -1

Sobel filter

1 0 -1

*

Blurring

1D derivative filter

In a 2D image, does this filter responses along horizontal or vertical lines?

Page 93: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

The Sobel filter

=1

2

1

1 0 -1

2 0 -2

1 0 -1

Sobel filter

1 0 -1

Blurring

1D derivative filter

Does this filter return large responses on vertical or horizontal lines?

*

Page 94: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

The Sobel filter

=1

2

1

1 0 -1

2 0 -2

1 0 -1

1 0 -1

*

Horizontal Sober filter:

What does the vertical Sobel filter look like?

Page 95: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

The Sobel filter

=1

2

1

1 0 -1

2 0 -2

1 0 -1

1 0 -1

*

Horizontal Sober filter:

Vertical Sobel filter:

=1

0

-1

1 2 1

0 0 0

-1 -2 -1

1 2 1

*

Page 96: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Sobel filter example

original which Sobel filter? which Sobel filter?

Page 97: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Sobel filter example

original horizontal Sobel filter vertical Sobel filter

Page 98: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Sobel filter example

horizontal Sobel filter

vertical Sobel filter

original

Page 99: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Several derivative filters

Scharr

3 0 -3

10 0 -10

3 0 -3

3 10 3

0 0 0

-3 -10 -3

Sobel

1 0 -1

2 0 -2

1 0 -1

1 2 1

0 0 0

-1 -2 -1

Prewitt

1 0 -1

1 0 -1

1 0 -1

1 1 1

0 0 0

-1 -1 -1

Roberts0 1

-1 0

1 0

0 -1

• How are the other filters derived and how do they relate to the Sobel filter?• How would you derive a derivative filter that is larger than 3x3?

Page 100: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Computing image gradients1. Select your favorite derivative filters.

1 2 1

0 0 0

-1 -2 -1

1 0 -1

2 0 -2

1 0 -1

Page 101: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Computing image gradients1. Select your favorite derivative filters.

1 2 1

0 0 0

-1 -2 -1

1 0 -1

2 0 -2

1 0 -1

2. Convolve with the image to compute derivatives.

Page 102: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Computing image gradients1. Select your favorite derivative filters.

1 2 1

0 0 0

-1 -2 -1

1 0 -1

2 0 -2

1 0 -1

2. Convolve with the image to compute derivatives.

3. Form the image gradient, and compute its direction and amplitude.

gradient direction amplitude

Page 103: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Image gradient example

original

gradient amplitude

vertical derivative

horizontal derivative

How does the gradient direction relate to these edges?

Page 104: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

How do you find the edge of this signal?

intensity plot

Page 105: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

How do you find the edge of this signal?

intensity plot

derivative plot

Using a derivative filter:

What’s the problem here?

Page 106: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Differentiation is very sensitive to noise

Gaussian

derivative of blurred

input

blurred

When using derivative filters, it is critical to blur first!

How much should we blur?

Page 107: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Derivative of Gaussian (DoG) filter

derivative of Gaussian

output (same as before)

input

• How many operations did we save?

• Any other advantages beyond efficiency?

Derivative theorem of convolution:

Page 108: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Basically a second derivative filter.• We can use finite differences to derive it, as with first derivative filter.

Laplace filter

?

first-orderfinite difference 1 0 -1

1D derivative filter

second-orderfinite difference

Laplace filter

Page 109: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Basically a second derivative filter.• We can use finite differences to derive it, as with first derivative filter.

Laplace filter

first-orderfinite difference 1 0 -1

1D derivative filter

second-orderfinite difference 1 -2 1

Laplace filter

Page 110: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

As with derivative, we can combine Laplace filtering with Gaussian filtering

Laplacian of Gaussian (LoG) filter

Laplacian of Gaussian

output

input

?

Page 111: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

As with derivative, we can combine Laplace filtering with Gaussian filtering

Laplacian of Gaussian (LoG) filter

Laplacian of Gaussian

output

input

“zero crossings” at edges

Page 112: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Laplace and LoG filtering examples

Laplacian of Gaussian filtering Laplace filtering

Page 113: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Laplacian of Gaussian vs Derivative of Gaussian

Laplacian of Gaussian filtering Derivative of Gaussian filtering

Page 114: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Laplacian of Gaussian vs Derivative of Gaussian

Zero crossings are more accurate at localizing edges (but not very convenient).

Laplacian of Gaussian filtering Derivative of Gaussian filtering

zero-crossing peak

Page 115: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

2D Gaussian filters

Gaussian

Derivative of Gaussian

Laplacian of Gaussian

how does this relate to this lecture’s cover picture?

Page 116: Introduction and course overvie16385/lectures/lecture2.pdf · Course announcements • Make sure you are on Piazza (sign up on your own using the link on the course website). - I

Basic reading:• Szeliski textbook, Section 3.2

References