image convolution and edge detection

63
Image Convolution and Edge Detection

Upload: others

Post on 29-Apr-2022

10 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Image Convolution and Edge Detection

Image Convolution and

Edge Detection

Page 2: Image Convolution and Edge Detection

Edge Formation Factors

Depth discontinuity

Surface color discontinuity

Surface normal discontinuity

Illumination discontinuity

Page 3: Image Convolution and Edge Detection

What’s in front?

Page 4: Image Convolution and Edge Detection

What it is?

Page 5: Image Convolution and Edge Detection

http://www.cfar.umd.edu/~fer/optical/index.html

Cornelia Fermüller

Page 6: Image Convolution and Edge Detection

121 121 118 111 . . . 21

134 136 137 132 . . . 23

133 131 136 136 . . . 25

136 145 148 151 . . . 34

137 140 147 149 . . . 54

. . . . . . . . . . . . . . . . . .

231 233 243 244 . . . 179

i

j

Any 2D matrix can be seen as an image

Page 7: Image Convolution and Edge Detection

200 130 20

255 100 10

200 100 30

Image I

0.5 0 0

0 1.5 0.5

0 -0.5 0

Kernel f

205

Image filtering: Replacing each pixel value by

weighted average of its neighbors

Linear Filtering

Page 8: Image Convolution and Edge Detection

Simple Neural Network

521 5

22 2

I(x)=

f(x)=

161

0

g(x)=0

This leads to parallel computation

Page 9: Image Convolution and Edge Detection

Anatomy of eye

The macula is the center of vision (and retina) and

the fovea (FAZ) is the focal point approximately

only 0.4mm in diameter. Reading, driving, etc. is all

performed here.

http://www.retinatexas.com/Anatomy_eng.html

Page 10: Image Convolution and Edge Detection

Photo-sensors

1) Light pass through retina cells, excites Rod and Cone

2) Cone: color(spectral) sensitive, R,G,B, 6 Million

3) Rod: more photo sensitive, peak at 580nm(yellow), 120 M

4) What happens if you miss one type of Cone cells?

Page 11: Image Convolution and Edge Detection

100 0

10.3 0.6

I(x)=

f(x)=

0.60

0

g(x)=

Page 12: Image Convolution and Edge Detection

100 0

10.3 0.6

I(x)=

f(x)=

10.60

10.3 0.6

0

g(x)=

Page 13: Image Convolution and Edge Detection

100 0

10.3 0.6

I(x)=

f(x)=

10.60 0.3

10.3 0.6

10.3 0.6

0

g(x)=

Page 14: Image Convolution and Edge Detection

1

0 0 0

0

0 0

0

0

Image

Kernel

Linear Filter

Page 15: Image Convolution and Edge Detection

1

0 0 0

0

0 0

0

0

Image

Kernel

Linear Filter

Image no change

Page 16: Image Convolution and Edge Detection

1

0 0 0

0

0 0

0

0

Image

Kernel

Linear Filter

Page 17: Image Convolution and Edge Detection

Image

Kernel

Linear Filter

Image Shifted

1

0 0 0

0

0 0

0

0

Page 18: Image Convolution and Edge Detection

0.3

0 0 0

0 0 0

Image

Kernel

Linear Filter

0.30.3

Page 19: Image Convolution and Edge Detection

0.3

0 0 0

0 0 0

Image

Kernel

Linear Filter

0.30.3

Blurred

(horizontal)

Page 20: Image Convolution and Edge Detection

0.3

0

0

0

0

0

0

Image

Kernel

Linear Filter

0.3

0.3

Page 21: Image Convolution and Edge Detection

0.3

0

0

0

0

0

0

Image

Kernel

Linear Filter

0.3

0.3

Blurred

(vertical)

Page 22: Image Convolution and Edge Detection

Image

Filter

Kernel

Linear Filter

0.3

0 0 0

0 0 0

0.30.32

0 0 0

0

0 0

0

0-

Page 23: Image Convolution and Edge Detection

Image

Kernel Image

Linear Filter

0.3

0 0 0

0 0 0

0.30.32

0 0 0

0

0 0

0

0-

-

Page 24: Image Convolution and Edge Detection

Image

Kernel Image

Linear Filter

0.3

0 0 0

0 0 0

0.30.32

0 0 0

0

0 0

0

0-

-

Page 25: Image Convolution and Edge Detection

Image filtering

𝑔 𝑚, 𝑛 =

𝑘,𝑙

𝐼 𝑚 + 𝑘, 𝑛 + 𝑙 ∗ 𝑓(𝑘, 𝑙)

Output

Image

Input

Image

Kernal

Image

Page 26: Image Convolution and Edge Detection

2

8

3

9

3

9

3

9

3

9

3

9

3

9

2

4

3

3

4

5

4

5

4

5

4

5

4

5

4

5

2

7

3

3

4

5

4

5

4

5

4

5

4

5

4

5

2

7

1

6

2

1

2

1

2

1

2

1

2

1

2

1

1

2

5 6 6 6 6 6 6 3

0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0

Image filtering

1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1

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

Image I

1 2 3

4 5 6

7 8 9

Kernel f Output g8x83x3

Loop over every pixel

a b c

d e f

g h i

Register

Calculate result = a*1+b*2+…+i*9

Same position

𝑔 𝑚, 𝑛 =

𝑘,𝑙

𝐼 𝑚 + 𝑘, 𝑛 + 𝑙 ∗ 𝑓(𝑘, 𝑙)

Page 27: Image Convolution and Edge Detection

Special case: impulse function

1 2 3

4 5 6

7 8 9

Kernel fImage I

0 0 0

0 1 0

0 0 0

0 1 0

0 0 0

0 0 0

Register

9 8 7

6 5 4

3 2

Output g

Calculate result = 0*9+…+1*2+0*1

Page 28: Image Convolution and Edge Detection

Special case: impulse function

1 2 3

4 5 6

7 8 9

Kernel fImage I

0 0 0

0 1 0

0 0 0

1 0 0

0 0 0

0 0 0

Register

9 8 7

6 5 4

3 2 1

Output g

Calculate result = 0*9+…0*2+1*1

<Note> The output is the kernel flipped left-right, up-down!

Page 29: Image Convolution and Edge Detection

Convolution

• Let I be an Signal(image), Convolution kernel f,

𝑔 𝑚, 𝑛 =

𝑘,𝑙

𝐼 𝑚 − 𝑘, 𝑛 − 𝑙 ∗ 𝑓(𝑘, 𝑙)

𝐼⨂𝑓

Output

Image

Input

Image

Kernal

Image

Page 30: Image Convolution and Edge Detection

Convolution

• Convolution is filtering with kernel flipped

9 8 7

6 5 4

3 2 1

Kernel f

flipped

Image I

0 0 0

0 1 0

0 0 0

1 0 0

0 0 0

0 0 0

Register

1 2 3

4 5 6

7 8 9

Output g

=Kernel

Calculate result = 1*9+0*8+…+0*1

Page 31: Image Convolution and Edge Detection

Impulse functions shift images

a b c

d e f

g h i

Image I

1 0 0

0 0 0

0 0 0

Kernel f

0 0 0

0 0 0

0 0 1

Kernel f ’

e f 0

h i 0

0 0 0

Result 𝐼⨂𝑓

• In this case the resulting image shifted to the upper left

Page 32: Image Convolution and Edge Detection

Convolution is associative

a b c

d e f

g h i

I

1 0 0

0 0 0

0 0 0

f

e f 0

h i 0

0 0 0

𝐼⨂𝑓

a b c

d e f

g h i

1 0 0

0 0 0

0 0 0

e f 0

h i 0

0 0 0

f I f⨂𝐼

Page 33: Image Convolution and Edge Detection

9 8 7

6 5 4

3 2 1

Kernel f

flipped

Image I

2 0 0

0 3 0

0 0 0

37 32 21

22 17 12

9 6 3

Output g

1 0 0

0 0 0

0 0 0

0 0 0

0 1 0

0 0 0

Decompose

*2

*3

5 4 0

2 1 0

0 0 0

*2

9 8 7

6 5 4

3 2 1

*3

Intermediate

Add together

Linear independence

Page 34: Image Convolution and Edge Detection

Linear independence

0 1 0 1 0

0 1 0 1 0

0 1 0 1 0

0 1 0 1 0

0 1 0 1 0

Image I

1 0 0

0 1 0

0 0 0

Kernel f

0 1 0 1 0

0 1 0 1 0

0 1 0 1 0

0 1 0 1 0

0 1 0 1 0

Output g2

5x5

1 0 0

0 0 0

0 0 0

Kernel f1

0 0 0

0 1 0

0 0 0

Kernel f2

1 0 1 0 0

1 0 1 0 0

1 0 1 0 0

1 0 1 0 0

0 0 0 0 0

Output g1

1 1 1 1 0

1 1 1 1 0

1 1 1 1 0

1 1 1 1 0

0 1 0 1 0

Output g=g1+g2

Page 35: Image Convolution and Edge Detection

• Convolution has commutative property

1 0 0

0 0 0

0 0 0

0 0 0

1 0 0

0 0 0

0 0 0

0 0 0

1 0 0

0 0 0

0 0 0

0 1 0

a b c

d e f

g h i

Image I

a b c

d e f

g h i

Image I

𝐼⨂𝑓

Decompose

1 0 0

1 0 0

1 1 0

Kernel f

b c 0

e f 0

h i 0

0 0 0

b c 0

e f 0

0 0 0

a b c

d e f

e f 0

h i 0

0 0 0

Page 36: Image Convolution and Edge Detection

• Convolution has commutative property

1 0 0

1 0 0

1 1 0

Kernel f

1 0 0

0 0 0

0 0 0

0 0 0

1 0 0

0 0 0

0 0 0

0 0 0

1 0 0

0 0 0

0 0 0

0 1 0

Decompose

b c 0

e f 0

h i 0

0 0 0

b c 0

e f 0

0 0 0

a b c

d e f

e f 0

h i 0

0 0 0

a b c

d e f

g h i

Image I

𝑓⨂𝐼

a b c

d e f

g h i

Page 37: Image Convolution and Edge Detection

Proof of Commutative property

Page 38: Image Convolution and Edge Detection

Output Size of Image

Convolutionf g

f

g

f

g

f

g

Full Same Valid

filter2(g, f, shape) in MATLAB

Full: output_size = f_size + g_size – 1

Same: output_size = f_size

Valid: output_size = f_size – (g_size – 1)

Page 39: Image Convolution and Edge Detection

2D visualization of convolution (full)

1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1

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

Image I

1 2 3

4 5 6

7 8 9

Kernel f

1 3 6 6 6 6 6 6 5 3

5 1

2

2

1

2

1

2

1

2

1

2

1

2

1

1

69

1

2

2

7

4

5

4

5

4

5

4

5

4

5

4

5

3

3

1

8

1

2

2

7

4

5

4

5

4

5

4

5

4

5

4

5

3

3

1

8

11 2

4

3

9

3

9

3

9

3

9

3

9

3

9

2

8

1

5

7 1

5

2

4

2

4

2

4

2

4

2

4

2

4

1

79

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

0 0 0 0 0 0 0 0 0 0

Output g

8x8

3x3

10x10

Page 40: Image Convolution and Edge Detection

g : 10 x 10 Gaussian kernel

f : 640 x 360 resolution

Output Size of Image

Convolution

Full

filter2(g, f, shape) in MATLAB

Full: output_size = f_size + g_size – 1

>> full = filter2(g, im, 'full');

>> size(full)

ans =

369 649

Page 41: Image Convolution and Edge Detection

2D visualization of convolution

(same)

1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1

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

Image I

1 2 3

4 5 6

7 8 9

Kernel f

1

2

2

1

2

1

2

1

2

1

2

1

2

1

1

6

2

7

4

5

4

5

4

5

4

5

4

5

4

5

3

3

2

7

4

5

4

5

4

5

4

5

4

5

4

5

3

3

2

4

3

9

3

9

3

9

3

9

3

9

3

9

2

8

1

5

2

4

2

4

2

4

2

4

2

4

2

4

1

7

0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0

Output g

8x8

3x3

8x8

Page 42: Image Convolution and Edge Detection

g : 10 x 10 Gaussian kernel

f : 640 x 360 resolution

Output Size of Image

Convolution

Same

filter2(g, f, shape) in MATLAB

Full: output_size = f_size + g_size – 1

>>same = filter2(g, im, 'same');

>> size(same)

ans =

360 640

Same: output_size = f_size

Page 43: Image Convolution and Edge Detection

2D visualization of convolution

(valid)

1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1

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

Image I

1 2 3

4 5 6

7 8 9

Kernel f

4

5

4

5

4

5

4

5

4

5

4

5

4

5

4

5

4

5

4

5

4

5

4

5

3

9

3

9

3

9

3

9

3

9

3

9

2

4

2

4

2

4

2

4

2

4

2

4

0 0 0 0 0 0

0 0 0 0 0 0

Output g

8x8

3x3

6x6

Page 44: Image Convolution and Edge Detection

g : 10 x 10 Gaussian kernel

f : 640 x 360 resolution

Output Size of Image

Convolution

Valid

filter2(g, f, shape) in MATLAB

Full: output_size = f_size + g_size – 1

>> valid = filter2(g, im, 'valid');

>> size(valid)

ans =

351 631

Same: output_size = f_size

Valid: output_size = f_size – (g_size – 1)

Page 45: Image Convolution and Edge Detection

Image Boundary Effect

The filter window falls off at the edge of image.

Page 46: Image Convolution and Edge Detection
Page 47: Image Convolution and Edge Detection

Image Extrapolation

(Mirroring)

J = imread(‘image.bmp’);

figure; imshow(J);

Code

J

Page 48: Image Convolution and Edge Detection

Image Extrapolation

(Mirroring)Code

boarder = 40;

[nr,nc,nb] = size(J);

J_big = zeros(nr+2*boarder, nc + 2*boarder,nb);

J_big(boarder+1:boarder+nr,boarder+1:boarder+nc,:) = J;

40 nc

nr

J_big

Page 49: Image Convolution and Edge Detection

Image Extrapolation

(Mirroring)Code

for i=1:border,

for j=1:border,

J_big(i,j,:) = J(border-i+1,border-j+1,:);

end

end40 nc

nr

J_big

Mirroring with respect to the boarder

(i,j)

(border-i+1,border-j+1)

Page 50: Image Convolution and Edge Detection

Image Extrapolation

(Mirroring)Code

for i=1:boarder,

for j=border+1:border+nc,

J_big(i,j,:) = J(border-i+1,j-border,:);

end

end40 nc

nr

J_big

Mirroring with respect to the boarder

(i,j)

(border-i+1,j-border)

Page 51: Image Convolution and Edge Detection

Image Extrapolation

(Mirroring)Code

for i=nr+border+1:border*2+nr,

for j=border+1:border+nc,

J_big(i,j,:) = J(2*nr-i+border+1,j-border,:);

end

end40 nc

nr

J_big

Mirroring with respect to the boarder

Page 52: Image Convolution and Edge Detection

Image Extrapolation

(Mirroring)Code

for i=border+1:border+nr;

for j=1:border,

J_big(i,j,:) = J(i-border,border-j+1,:);

end

end40 nc

nr

J_big

Mirroring with respect to the boarder

Page 53: Image Convolution and Edge Detection

Examples of image operation as

convolution

Page 54: Image Convolution and Edge Detection

Gaussian Averaging

• Rotationally symmetric.

• Weights nearby pixels more than distant ones.

– This makes sense as probabalistic inference. • A Gaussian gives a good

model of a fuzzy blob

Page 55: Image Convolution and Edge Detection

2D filters, more on this later…

• is the Laplacian operator:

Laplacian of Gaussian

Gaussian derivative of Gaussian

Page 56: Image Convolution and Edge Detection

An Isotropic Gaussian

• The picture shows a

smoothing kernel

proportional to

• (which is a reasonable

model of a circularly

symmetric fuzzy blob)

Page 57: Image Convolution and Edge Detection

Smoothing with a Gaussian

Page 58: Image Convolution and Edge Detection

The effects of smoothing

Each row shows smoothing

with gaussians of different

width; each column shows

different realizations of

an image of gaussian noise.

Page 59: Image Convolution and Edge Detection
Page 60: Image Convolution and Edge Detection
Page 61: Image Convolution and Edge Detection

Image smoothing can remove noise, and also …

Page 62: Image Convolution and Edge Detection
Page 63: Image Convolution and Edge Detection