L19 Convolution
L19 Convolution
Blurring/Smoothing
→
What Spatial Filters Can Do
Sharpening
→
What Spatial Filters Can Do
Weird Stuff
→
Example: The Mean of a Neighborhood
Consider taking the mean in a 3 × 3 neighborhood:
v-1
v
v+ 1
u-1 u u+1
1 1
0 1XX
I (u, v) = I(u + i, v + j)
9
i=−1 j=−1
How a Linear Spatial Filter Works
0 0 0
0 1 0
0 0 0
1 1 1
1
1 1 1
9
1 1 1
0 0 0
0 0 1
0 0 0
-1 -1 -1
1
-1 17 -1
9
-1 -1 -1
Mean Filters:
Original 7×7 15 × 15 41 × 41
What To Do At The Boundary?
What To Do At The Boundary?
I Crop
What To Do At The Boundary?
I Crop
I Pad
What To Do At The Boundary?
I Crop
I Pad
I Extend
What To Do At The Boundary?
I Crop
I Pad
I Extend
I Wrap
Convolution
Definition
Convolution of an image I by a kernel H is given by
X
I 0 (u, v) = I(u − i, v − j) · H(i, j)
(i,j)∈RH
This is denoted: I 0 = I ∗ H
Definition
A linear operator F on an image is a mapping from one
image to another, I 0 = F(I), that satisfies:
1. F(cI) = cF(I),
2. F(I1 + I2 ) = F(I1 ) + F(I2 ),
where I, I1 , I2 are images, and c is a constant.
Ω=Z×Z
This is denoted I 0 = I ∗ H .
Infinite Image Domains
Commutativity:
I∗H =H∗I
Associativity:
(I ∗ H1 ) ∗ H2 = I ∗ (H1 ∗ H2 )
Linearity:
(a · I) ∗ H = a · (I ∗ H)
(I1 + I2 ) ∗ H = (I1 ∗ H) + (I2 ∗ H)
Shift-Invariance:
Let S be the operator that shifts an image I :
S(I)(u, v) = I(u + a, v + b)
Then
S(I ∗ H) = S(I) ∗ H
160
140
120
100
80
60
40
20
0
0 20 40 60 80 100 120
20
-20
-40
-60
-80
0 20 40 60 80 100 120
df f (x + ) − f (x)
(x) = lim
dx →0
f(x)
f(x)
f(x)
f(x)
Backward Difference
Central Difference
1
∆ f (x) = ( f (x + 1) − f (x − 1)) average slope
2
Finite Differences as Convolutions
Forward Difference
∆+ f (x) = f (x + 1) − f (x)
∆+ f = f ∗ H
Central Difference
1
∆ f (x) = ( f (x + 1) − f (x − 1))
2
1
0 − 21
Convolution kernel here is: H = 2
∆ f (x) = f ∗ H
∆x I = I ∗ Hx , and ∆y I = I ∗ Hy ,
−0.5
where Hx = [0.5 0 −0.5] and Hy = 0
0.5
Derivatives of Images
1
0 − 12
∗ 2 =
Derivatives of Images
0.5
∗ 0 =
−0.5
Combining x and y Derivatives
w1 w2 w3
w4
w7
w5
w8
w6
w9
?
http://towardsdatascience.com/