05_Spatial_operations
05_Spatial_operations
Spatial operations
Filtering:
1) Pixel neighborhood, e.g. a small rectangle
2) Operation, e.g., linear or nonlinear
𝑎𝑎 𝑏𝑏
Convolution
with impulse
Spatial correlation and convolution
Correlation:
𝑎𝑎 𝑏𝑏
Convolution:
𝑎𝑎 𝑏𝑏
= � 𝑤𝑤𝑘𝑘 𝑧𝑧𝑘𝑘
𝑘𝑘=1
= 𝑤𝑤 𝑇𝑇 𝑧𝑧
= � 𝑤𝑤𝑘𝑘 𝑧𝑧𝑘𝑘
𝑘𝑘=1
= 𝑤𝑤 𝑇𝑇 𝑧𝑧
Generating spatial filter masks
9
1
Averaging: 𝑅𝑅 = � 𝑧𝑧𝑖𝑖
9
𝑖𝑖=1
𝑥𝑥 2 +𝑦𝑦 2
2D Gaussian: ℎ(𝑥𝑥, 𝑦𝑦) =
−
𝑒𝑒 2𝜎𝜎2
3 × 3 mask:
𝑤𝑤1 = ℎ(−1, −1)
𝑤𝑤2 = ℎ(−1,0)
⋮
𝑤𝑤9 = ℎ(1,1)
Smoothing filters: Averaging masks
Averaging Weighted
(box filter) averaging
Original n=3
n=5 n=9
n=15 n=35
Choosing the size of the mask
In this example:
On the image borders, the median is found after mirroring the
section under the window with respect to the central element
Comparison of averaging and median filters
1 1
Image row
0
Comparison of averaging and median filters
1 1
Image row
0
1
2/3
Averaging 1/3 1/3
Comparison of averaging and median filters
1 1
Image row
0
1
2/3
Averaging 1/3 1/3
1
Median
Comparison of averaging and median filters
Sharpening differentiation
-1st derivative:
𝜕𝜕𝑓𝑓
= 𝑓𝑓 𝑥𝑥 + 1 − 𝑓𝑓(𝑥𝑥)
𝜕𝜕𝜕𝜕
-2nd derivative:
𝜕𝜕 2 𝑓𝑓
2
= 𝑓𝑓 𝑥𝑥 + 1 + 𝑓𝑓 𝑥𝑥 − 1 − 2𝑓𝑓(𝑥𝑥)
𝜕𝜕𝑥𝑥
Sharpening filters
Implementation of second-order derivative
𝜕𝜕 2 𝑓𝑓
2
= 𝑓𝑓 𝑥𝑥 + 1, 𝑦𝑦 + 𝑓𝑓 𝑥𝑥 − 1, 𝑦𝑦 − 2𝑓𝑓(𝑥𝑥, 𝑦𝑦)
𝜕𝜕𝑥𝑥
𝜕𝜕 2 𝑓𝑓
2
= 𝑓𝑓 𝑥𝑥, 𝑦𝑦 + 1 + 𝑓𝑓 𝑥𝑥, 𝑦𝑦 − 1 − 2𝑓𝑓(𝑥𝑥, 𝑦𝑦)
𝜕𝜕𝑦𝑦
Negative difference
equations used
Blurred Laplacian
Scaled Sharpened
Laplacian Image
(c=-1)
Simplification
𝑔𝑔(𝑥𝑥, 𝑦𝑦) = 𝑓𝑓(𝑥𝑥, 𝑦𝑦) − 𝛻𝛻 2 𝑓𝑓(𝑥𝑥, 𝑦𝑦)
= 𝑓𝑓(𝑥𝑥, 𝑦𝑦) − [𝑓𝑓(𝑥𝑥 + 1, 𝑦𝑦) + 𝑓𝑓(𝑥𝑥 − 1, 𝑦𝑦) + 𝑓𝑓(𝑥𝑥, 𝑦𝑦 + 1) + 𝑓𝑓(𝑥𝑥, 𝑦𝑦 − 1)] + 4𝑓𝑓(𝑥𝑥, 𝑦𝑦)
= 5𝑓𝑓(𝑥𝑥, 𝑦𝑦) − [𝑓𝑓(𝑥𝑥 + 1, 𝑦𝑦) + 𝑓𝑓(𝑥𝑥 − 1, 𝑦𝑦) + 𝑓𝑓(𝑥𝑥, 𝑦𝑦 + 1) + 𝑓𝑓(𝑥𝑥, 𝑦𝑦 − 1)]
Scanning
Electron
Image
Without With
Diagonal Diagonal
Elements Elements
Unsharp masking and high-boost filtering
̄ 𝑦𝑦)
𝑔𝑔𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚 (𝑥𝑥, 𝑦𝑦) = 𝑓𝑓(𝑥𝑥, 𝑦𝑦) − 𝑓𝑓(𝑥𝑥,
Blurred
Sharpened
𝑔𝑔(𝑥𝑥, 𝑦𝑦) = 𝑓𝑓(𝑥𝑥, 𝑦𝑦) + 𝑘𝑘 ∗ 𝑔𝑔𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚 (𝑥𝑥, 𝑦𝑦)
𝑘𝑘 > 0
𝑘𝑘 = 1 Unsharp masking
𝑘𝑘 > 1 High-boost filtering
𝑘𝑘 < 1 Deemphasize mask
Unsharp masking
First-order derivatives
𝜕𝜕𝜕𝜕
𝑔𝑔𝑥𝑥
Gradient: 𝛻𝛻𝛻𝛻 = 𝑔𝑔
𝜕𝜕𝜕𝜕
= 𝜕𝜕𝜕𝜕
𝑦𝑦
𝜕𝜕𝜕𝜕
2 2 1/2
𝑀𝑀(𝑥𝑥, 𝑦𝑦) = 𝑧𝑧9 − 𝑧𝑧5 + 𝑧𝑧8 − 𝑧𝑧6