Convolution in 1D and 2D
Convolution in 1D and 2D
Convolution in 1D and 2D
Dr S.Natarajan
Professor and Key Resource Person
Department of Computer Science and Engineering
PES University
Bengaluru
India
[email protected]
9945280225
output image
Convolution in 1D
pixel at index j
Convolution in 1D
H sliding
As drawn kernel H has
a width, w = 3 so n = 1
-n 0 n
H
G …. with N elements
i-n i i+n
1D Example: Convolution G*H
width of H = 3, so n = 1
original
and N here is 7 pixels, indexed 0 to 6
flipped
Example from: The Digital Image by Dr. Donald House at Texas A&M University, Figure 8.11
1D Example: Convolution G*H
original
flipped
Example for i = 3
Example from: The Digital Image by Dr. Donald House at Texas A&M University, Figure 8.11
Why Flip the Kernel?
Example with no flip:
H G G*H
2 1 0 3 4 5 3 10 13
3 4 5 2 1 0 13 10 3
H*G
Example from: The Digital Image by Dr. Donald House at Texas A&M University, Figure 8.11
Why Flip the Kernel?
Example with no flip:
H G G*H
2 1 0 3 4 5 3 10 13
3 4 5 2 1 0 13 10 3
H*G
Example with flipped kernel:
H G G*H
0 1 2 3 4 5 11 14 5
G*H == H*G
5 4 3 2 1 0 11 14 5
H*G
Example from: The Digital Image by Dr. Donald House at Texas A&M University, Figure 8.11
Convolution: 1D to 2D
• Convolution extends to 2D in straightforward fashion
– Assume kernel H is rectangular array of
width, w=2n+1
and height, h=2m+1
– Assume image G is of width M and height N
– Then…
i is column
j is row
M
i, j
j+n j
+ + +
+ + +
j-n N
i-m i+m
As drawn i
w = 3 and h = 3
Thus n = 1 and m = 1
2D kernel from a 1D kernel
H2 = H1 Ht1
tent
1 2 1
1 1 2 1
[] 2 [1
1
2
[
1 ]= 2
1
4
2
2
1 ]
2D kernel
that yields results
similar to 1D kernel
2D Kernel Separability
• 2D kernels can be separated
– Apply filtering twice using the 1D filter
• once “horizontally”
• once “vertically”
– Get same results as applying the 2D filter once
1D: 1 1 1
1 1 1 1
2D: [] 1 [1
1
1
[
1 ]= 1
1
1
1
1
1 ]
Box * Box = Tent
• Convolution of box kernel with itself
– Gives a tent filter
0 1 1 1 0 * 1 1 1 = 1 2 3 2 1
*
Low Pass Filter: 2D Tent
1D: 1 2 3 2 1
2D: 1 1 2 3 2 1
[] 2
3 [1
2
1
2 3 2
[ 2
1 ]= 3
2
1
4
6
4
2
6
9
6
3
4
6
4
2
2
3
2
1
]
Tent * Tent = Bell
• Convolution of tent kernel with itself
– Gives a Bell filter
0 0 1 2 3 2 1 0 0 * 1 2 3 2 1
= 1 4 10 16 19 16 10 4 1
Low Pass Filters
• The more convolutions with self
– The better smoothing you achieve continue
towards Gaussian
1 1 1 1 2 3 2 1 1 4 10 16 19 16 10 4 1
Note:
Tent and Bell
have better quality
than just a “bigger” box
Example Results
They more cleanly
blur the edges…
…less muddy in appearance Big Box Tent
1 1 1 1 1 1 2 3 2 1
Original Image
1 1 1 1 1 1 1 1 1 1 1 1 1 4 10 16 19 16 10 4 1
Example from: The Digital Image by Dr. Donald House at Texas A&M University, Figure 8.11
Note:
Tent and Bell
have better quality
than just a “bigger” box
Example Results
They more cleanly
Big Box Tent
blur the edges…
…less muddy in appearance 1 1 1 1 1 1 2 3 2 1
Original Image
1 1 1 1 1 1 1 1 1 1 1 1 1 4 10 16 19 16 10 4 1
Example from: The Digital Image by Dr. Donald House at Texas A&M University, Figure 8.11