CS559: Computer Graphics Lecture 3: Digital Image Representation Li Zhang Spring 2008.

43
CS559: Computer Graphics Lecture 3: Digital Image Representation Li Zhang Spring 2008

Transcript of CS559: Computer Graphics Lecture 3: Digital Image Representation Li Zhang Spring 2008.

Page 1: CS559: Computer Graphics Lecture 3: Digital Image Representation Li Zhang Spring 2008.

CS559: Computer Graphics

Lecture 3: Digital Image RepresentationLi Zhang

Spring 2008

Page 2: CS559: Computer Graphics Lecture 3: Digital Image Representation Li Zhang Spring 2008.

Today• Eyes• Cameras

Page 3: CS559: Computer Graphics Lecture 3: Digital Image Representation Li Zhang Spring 2008.

Image as a discreet function

Represented by a matrix

Page 4: CS559: Computer Graphics Lecture 3: Digital Image Representation Li Zhang Spring 2008.

What is image filtering?

• Modify the pixels in an image based on some function of a local neighborhood of the pixels.

5 14

1 71

5 310

Local image data

7

Modified image data

Some function

Page 5: CS559: Computer Graphics Lecture 3: Digital Image Representation Li Zhang Spring 2008.

Linear functions

• Simplest: linear filtering.– Replace each pixel by a linear combination of its

neighbors.

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

5 14

1 71

5 310

0.5

0.5 00

10

0 00

Local image data kernel

7

Modified image data

Page 6: CS559: Computer Graphics Lecture 3: Digital Image Representation Li Zhang Spring 2008.

Convolution

lk

lkglnkmIgInmf,

],[],[],[

I

Page 7: CS559: Computer Graphics Lecture 3: Digital Image Representation Li Zhang Spring 2008.

Linear filtering (warm-up slide)

original

0Pixel offset

coef

ficie

nt1.0 ?

Page 8: CS559: Computer Graphics Lecture 3: Digital Image Representation Li Zhang Spring 2008.

Linear filtering (warm-up slide)

original

0Pixel offset

coef

ficie

nt1.0

Filtered(no change)

Page 9: CS559: Computer Graphics Lecture 3: Digital Image Representation Li Zhang Spring 2008.

Linear filtering

0Pixel offset

coef

ficie

nt

original

1.0

?

Page 10: CS559: Computer Graphics Lecture 3: Digital Image Representation Li Zhang Spring 2008.

shift

0Pixel offset

coef

ficie

nt

original

1.0

shifted

Page 11: CS559: Computer Graphics Lecture 3: Digital Image Representation Li Zhang Spring 2008.

Linear filtering

0Pixel offset

coef

ficie

nt

original

0.3 ?

Page 12: CS559: Computer Graphics Lecture 3: Digital Image Representation Li Zhang Spring 2008.

Blurring

0Pixel offset

coef

ficie

nt

original

0.3

Blurred (filterapplied in both dimensions).

Page 13: CS559: Computer Graphics Lecture 3: Digital Image Representation Li Zhang Spring 2008.

0Pixel offset

coef

ficie

nt

0.3

original

8

filtered

2.4

impulse

Blur Examples

Page 14: CS559: Computer Graphics Lecture 3: Digital Image Representation Li Zhang Spring 2008.

0Pixel offset

coef

ficie

nt

0.3

original

8

filtered

4

8

4

impulse

edge

0Pixel offset

coef

ficie

nt

0.3

original

8

filtered

2.4

Blur Examples

Page 15: CS559: Computer Graphics Lecture 3: Digital Image Representation Li Zhang Spring 2008.

original

0

2.0

?0

1.0

Linear filtering (warm-up slide)

Page 16: CS559: Computer Graphics Lecture 3: Digital Image Representation Li Zhang Spring 2008.

original

0

2.0

0

1.0

Filtered(no change)

Linear Filtering (no change)

Page 17: CS559: Computer Graphics Lecture 3: Digital Image Representation Li Zhang Spring 2008.

original

0

2.0

0

0.33 ?

Linear Filtering

Page 18: CS559: Computer Graphics Lecture 3: Digital Image Representation Li Zhang Spring 2008.

(remember blurring)

0Pixel offset

coef

ficie

nt

original

0.3

Blurred (filterapplied in both dimensions).

Page 19: CS559: Computer Graphics Lecture 3: Digital Image Representation Li Zhang Spring 2008.

original

0

2.0

0

0.33

Sharpened original

Sharpening

Page 20: CS559: Computer Graphics Lecture 3: Digital Image Representation Li Zhang Spring 2008.

Sharpening example

coef

ficie

nt

-0.3original

8

Sharpened(differences are

accentuated; constantareas are left untouched).

11.21.7

-0.25

8

Page 21: CS559: Computer Graphics Lecture 3: Digital Image Representation Li Zhang Spring 2008.

Sharpening

before after

Page 22: CS559: Computer Graphics Lecture 3: Digital Image Representation Li Zhang Spring 2008.

Spatial resolution and color

R

G

B

original

Page 23: CS559: Computer Graphics Lecture 3: Digital Image Representation Li Zhang Spring 2008.

Blurring the G component

R

G

B

original processed

Page 24: CS559: Computer Graphics Lecture 3: Digital Image Representation Li Zhang Spring 2008.

Blurring the R component

original processed

R

G

B

Page 25: CS559: Computer Graphics Lecture 3: Digital Image Representation Li Zhang Spring 2008.

Blurring the B component

original

R

G

Bprocessed

Page 26: CS559: Computer Graphics Lecture 3: Digital Image Representation Li Zhang Spring 2008.

L

a

b

A rotation of the color coordinates into directions that are more perceptually meaningful: L: luminance, a: red-green, b: blue-yellow

Lab Color Component

Page 27: CS559: Computer Graphics Lecture 3: Digital Image Representation Li Zhang Spring 2008.

L

a

b

original processed

Bluring L

Page 28: CS559: Computer Graphics Lecture 3: Digital Image Representation Li Zhang Spring 2008.

original

L

a

b

processed

Bluring a

Page 29: CS559: Computer Graphics Lecture 3: Digital Image Representation Li Zhang Spring 2008.

original

L

a

b

processed

Bluring b

Page 30: CS559: Computer Graphics Lecture 3: Digital Image Representation Li Zhang Spring 2008.

Application to image compression• (compression is about hiding differences from the

true image where you can’t see them).

Page 31: CS559: Computer Graphics Lecture 3: Digital Image Representation Li Zhang Spring 2008.

Edge Detection

• Convert a 2D image into a set of curves– Extracts salient features of the scene– More compact than pixels

Page 32: CS559: Computer Graphics Lecture 3: Digital Image Representation Li Zhang Spring 2008.

How can you tell that a pixel is on an edge?

Page 33: CS559: Computer Graphics Lecture 3: Digital Image Representation Li Zhang Spring 2008.

Image gradient• The gradient of an image:

• The gradient direction is given by:

• The gradient points in the direction of most rapid change in intensity

– how does the gradient relate to the direction of the edge?

• The edge strength is given by the gradient magnitude

Page 34: CS559: Computer Graphics Lecture 3: Digital Image Representation Li Zhang Spring 2008.

Effects of noise• Consider a single row or column of the image

– Plotting intensity as a function of position gives a signal

• Where is the edge?

How to compute a derivative?

Page 35: CS559: Computer Graphics Lecture 3: Digital Image Representation Li Zhang Spring 2008.

• Where is the edge?

Solution: smooth first

• Look for peaks in

Page 36: CS559: Computer Graphics Lecture 3: Digital Image Representation Li Zhang Spring 2008.

Derivative theorem of convolution

• This saves us one operation:

Page 37: CS559: Computer Graphics Lecture 3: Digital Image Representation Li Zhang Spring 2008.

Laplacian of Gaussian• Consider

Laplacian of Gaussianoperator

• Where is the edge? • Zero-crossings of bottom graph

Page 38: CS559: Computer Graphics Lecture 3: Digital Image Representation Li Zhang Spring 2008.

Canny Edge Detector

• Smooth image I with 2D Gaussian:

• Find local edge normal directions for each pixel

• Along this direction, compute image gradient

• Locate edges by finding max gradient magnitude (Non-maximum suppression)

x

y

I

Iarctan

IG

IG

Page 39: CS559: Computer Graphics Lecture 3: Digital Image Representation Li Zhang Spring 2008.

Non-maximum Suppression

• Check if pixel is local maximum along gradient direction– requires checking interpolated pixels p and r

Page 40: CS559: Computer Graphics Lecture 3: Digital Image Representation Li Zhang Spring 2008.

The Canny Edge Detector

original image (Lena)

Page 41: CS559: Computer Graphics Lecture 3: Digital Image Representation Li Zhang Spring 2008.

The Canny Edge Detector

magnitude of the gradient

Page 42: CS559: Computer Graphics Lecture 3: Digital Image Representation Li Zhang Spring 2008.

The Canny Edge Detector

After non-maximum suppression

Page 43: CS559: Computer Graphics Lecture 3: Digital Image Representation Li Zhang Spring 2008.

Canny Edge Detector

Canny with Canny with original

• The choice of depends on desired behavior

– large detects large scale edges– small detects fine features