Lecture 21: Convolutions
Autumn 2026
1
Sli.do
#cse163
Questions?
Icebreaker
Favorite beverage?
CSE 163
CSE 163: Convolutions
Announcements
2
Questions?
CSE 163: Convolutions
(Grey-scale) Images as Matrices
3
Grey-scale: 255
Grey-scale: 0
data = iio.imread(‘...’)�
data[rows, columns] = #
CSE 163: Convolutions
Color Images
4
data[rows, columns, channels] = #
CSE 163: Convolutions
Convolution
5
3 | 3 | 2 | 1 | 0 |
0 | 0 | 1 | 3 | 1 |
3 | 1 | 2 | 2 | 3 |
2 | 0 | 0 | 2 | 2 |
2 | 0 | 0 | 0 | 1 |
Image
0 | 1 | 2 |
2 | 2 | 0 |
0 | 1 | 2 |
Kernel
CSE 163: Convolutions
Convolution Example
6
CSE 163: Convolutions
7
9 | 8 | 7 |
6 | 5 | 4 |
3 | 2 | 1 |
Image
2 | 1 |
Kernel
CSE 163: Convolutions
8
9 | 8 | 7 |
6 | 5 | 4 |
3 | 2 | 1 |
Image
2 | 1 |
Kernel
| |
| |
| |
Output
CSE 163: Convolutions
9
9 | 8 | 7 |
6 | 5 | 4 |
3 | 2 | 1 |
Image
2 | 1 |
Kernel
| |
| |
| |
Output
2
1
CSE 163: Convolutions
10
18 | 8 | 7 |
6 | 5 | 4 |
3 | 2 | 1 |
Image
2 | 1 |
Kernel
| |
| |
| |
Output
CSE 163: Convolutions
11
18 | 8 | 7 |
6 | 5 | 4 |
3 | 2 | 1 |
Image
2 | 1 |
Kernel
| |
| |
| |
Output
26
CSE 163: Convolutions
12
18 | 8 | 7 |
6 | 5 | 4 |
3 | 2 | 1 |
Image
2 | 1 |
Kernel
26 | |
| |
| |
Output
26
CSE 163: Convolutions
13
18 | 8 | 7 |
6 | 5 | 4 |
3 | 2 | 1 |
Image
2 | 1 |
Kernel
26 | |
| |
| |
Output
CSE 163: Convolutions
14
9 | 16 | 7 |
6 | 5 | 4 |
3 | 2 | 1 |
Image
2 | 1 |
Kernel
26 | 23 |
| |
| |
Output
23
CSE 163: Convolutions
15
9 | 8 | 7 |
12 | 5 | 4 |
3 | 2 | 1 |
Image
2 | 1 |
Kernel
26 | 23 |
17 | |
| |
Output
17
CSE 163: Convolutions
16
9 | 8 | 7 |
6 | 10 | 4 |
3 | 2 | 1 |
Image
2 | 1 |
Kernel
26 | 23 |
17 | 14 |
| |
Output
14
CSE 163: Convolutions
17
9 | 8 | 7 |
6 | 5 | 4 |
6 | 2 | 1 |
Image
2 | 1 |
Kernel
26 | 23 |
17 | 14 |
8 | |
Output
8
CSE 163: Convolutions
18
9 | 8 | 7 |
6 | 5 | 4 |
3 | 4 | 1 |
Image
2 | 1 |
Kernel
26 | 23 |
17 | 14 |
8 | 5 |
Output
5
CSE 163: Convolutions
19
9 | 8 | 7 |
6 | 5 | 4 |
3 | 2 | 1 |
Image
2 | 1 |
Kernel
26 | 23 |
17 | 14 |
8 | 5 |
Output
CSE 163: Convolutions
How many times can we fit this kernel in the image?
20
| | |
| | |
| | |
| |
Image
Kernel
CSE 163: Convolutions
How many times can we fit this kernel in the image?
21
| | |
| | |
| | |
| |
CSE 163: Convolutions
How many times can we fit this kernel in the image?
22
| | |
| | |
| | |
| |
2
CSE 163: Convolutions
How many times can we fit this kernel in the image?
23
| | |
| | |
| | |
| |
2
CSE 163: Convolutions
How many times can we fit this kernel in the image?
24
| | |
| | |
| | |
| |
2
3
CSE 163: Convolutions
How many times can we fit this kernel in the image?
25
| | |
| | |
| | |
| |
2
3
2
3 x
| |
| |
| |
CSE 163: Convolutions
How many times can we fit this kernel in the image?
26
| | |
| | |
| | |
| |
| |
| |
| |
Kernel
(3x3)
(1x2)
Output
(3x2)
(image_height – k_height + 1, image_width – k_width + 1)
CSE 163: Convolutions
Generic Formula for Result Size
27
Image
Kernel
width
height
k_height
k_width
(0, 0)
k[0]
k[1]
(1, 0)
…
(width - k_width, 0)
k[width - k_width]
Total of (width - k_width + 1) kernels because of zero based indexing!
So the shape of the result will be (height - k_height + 1, width - k_width + 1)
CSE 163: Convolutions
Common Kernels
28
Identity
Edge Detection
Sharpen
Box Blur
CSE 163: Convolutions
Image Classification
29
CSE 163: Convolutions