CSE 163
Convolutions�
Suh Young Choi�
🎶 Listening to: Shang-Chi soundtrack
💬 Before Class: Buffalo buffalo buffalo buffalo Buffalo buffalo buffalo. Weird how that’s a grammatically correct sentence.
Announcements
Reading Assignment 5 now out!
THA 5 due on Thursday (last one of the quarter!)
Remaining Project/Portfolio Components
2
Bonus Resubmission Opportunity
Possibility of Bonus Resubmission Period
3
Remaining Due Dates
To assist with planning:
4
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
Feb 22 | 23 | 24 | 25 | 26 THA 5 due | 27 | 28 |
Mar 1 | 2 RA 5 due | 3 Resubs due (THA 4) | 4 | 5 | 6 | 7 |
8 | 9 CP 5 due Report/Code due | 10 Resubs due (THA 5) | 11 | 12 Presentations (in section) | 13 Last day to submit CP/RA | 14 |
15 Peer feedback due | 16 | 17 | 18 | 19 Final Reflection | 20 | 21 |
This Time
Last Time
5
Images as
Matrices
6
Grey-scale images can be represented as matrices.
Grey-scale: 255
Grey-scale: 0
data = imageio.imread(‘...’)�
data[rows, columns] = #
Color Images
When you overlap each color channel, it creates a picture we are used to seeing.
7
data[rows, columns, channels] = #
Convolution
When wanting to use “local” information, we commonly use a sliding window approach (i.e. a convolution)
Move the sliding window across the image, and compute the sum of the element wise product of the window (kernel) and image
8
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
Convolution Example
9
Convolutions!
an unconvoluted example
9 | 8 | 7 |
6 | 5 | 4 |
3 | 2 | 1 |
Image
2 | 1 |
Kernel
9 | 8 | 7 |
6 | 5 | 4 |
3 | 2 | 1 |
Image
2 | 1 |
Output
| |
| |
| |
Kernel
9 | 8 | 7 |
6 | 5 | 4 |
3 | 2 | 1 |
Image
2 | 1 |
Output
| |
| |
| |
2
1
Kernel
18 |
8 |
2
1
18 | 8 | 7 |
6 | 5 | 4 |
3 | 2 | 1 |
Image
2 | 1 |
Output
| |
| |
| |
Kernel
8 |
18 |
2
1
18 | 8 | 7 |
6 | 5 | 4 |
3 | 2 | 1 |
Image
2 | 1 |
Output
| |
| |
| |
26
Kernel
8 |
18 |
2
1
18 | 8 | 7 |
6 | 5 | 4 |
3 | 2 | 1 |
Image
2 | 1 |
Output
| |
| |
| |
26
Kernel
8 |
18 |
2
1
9 | 8 | 7 |
6 | 5 | 4 |
3 | 2 | 1 |
Image
2 | 1 |
Output
| |
| |
| |
26
2
1
Kernel
2
1
8 |
18 |
2
1
9 | 16 | 7 |
6 | 5 | 4 |
3 | 2 | 1 |
Image
2 | 1 |
Output
| |
| |
| |
16 |
7 |
26
Kernel
7 |
16 |
2
1
8 |
18 |
2
1
9 | 16 | 7 |
6 | 5 | 4 |
3 | 2 | 1 |
Image
2 | 1 |
Output
| |
| |
| |
26
23
Kernel
7 |
16 |
2
1
8 |
18 |
2
1
9 | 16 | 7 |
6 | 5 | 4 |
3 | 2 | 1 |
Image
2 | 1 |
Output
| |
| |
| |
26
23
Kernel
7 |
16 |
2
1
8 |
18 |
2
1
9 | 8 | 7 |
6 | 5 | 4 |
3 | 2 | 1 |
Image
2 | 1 |
Output
| |
| |
| |
26
23
2
1
17
Kernel
7 |
16 |
2
1
8 |
18 |
2
1
9 | 8 | 7 |
6 | 5 | 4 |
3 | 2 | 1 |
Image
2 | 1 |
Output
| |
| |
| |
26
23
2
1
17
Kernel
7 |
16 |
2
1
8 |
18 |
2
1
9 | 8 | 7 |
6 | 5 | 4 |
3 | 2 | 1 |
Image
2 | 1 |
Output
| |
| |
| |
26
23
2
1
17
14
Kernel
7 |
16 |
2
1
8 |
18 |
2
1
9 | 8 | 7 |
6 | 5 | 4 |
3 | 2 | 1 |
Image
2 | 1 |
Output
| |
| |
| |
26
23
2
1
17
14
Kernel
7 |
16 |
2
1
8 |
18 |
2
1
9 | 8 | 7 |
6 | 5 | 4 |
3 | 2 | 1 |
Image
2 | 1 |
Output
| |
| |
| |
26
23
2
1
17
14
8
Kernel
7 |
16 |
2
1
8 |
18 |
2
1
9 | 8 | 7 |
6 | 5 | 4 |
3 | 2 | 1 |
Image
2 | 1 |
Output
| |
| |
| |
26
23
2
1
17
14
8
Kernel
7 |
16 |
2
1
8 |
18 |
2
1
9 | 8 | 7 |
6 | 5 | 4 |
3 | 2 | 1 |
Image
2 | 1 |
Output
| |
| |
| |
26
23
2
1
17
14
8
5
Kernel
7 |
16 |
2
1
8 |
18 |
2
1
9 | 8 | 7 |
6 | 5 | 4 |
3 | 2 | 1 |
Image
2 | 1 |
Output
| |
| |
| |
26
23
2
1
17
14
8
5
Kernel
How many times can we fit the kernel into the image?
| | |
| | |
| | |
| |
“
How many times can we fit the kernel into the image?
| | |
| | |
| | |
| |
“
How many times can we fit the kernel into the image?
| | |
| | |
| | |
| |
2
“
How many times can we fit the kernel into the image?
| | |
| | |
| | |
| |
2
“
How many times can we fit the kernel into the image?
| | |
| | |
| | |
| |
2
3
“
How many times can we fit the kernel into the image?
| | |
| | |
| | |
| |
2
3 x
| |
| |
| |
“
General formula:
| | |
| | |
| | |
| |
| |
| |
| |
image
(3x3)
kernel
(1x2)
output
(3x2)
(image_height – k_height + 1, image_width – k_width + 1)
“
More Generic Formula for Result Size
36
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)
Common Kernels
What do the numbers in the kernel do?
37
Identity
Edge Detection
Sharpen
Box Blur
Image Classification
For a really long time, image classification was done by painstakingly crafting these features (like edge detectors), by hand.
This kind of worked, but we quickly hit our peak using this method.
Then came the buzz-word… deep learning
38
Image Classification
39
Before Next Time
Next Time
40