1 of 29

Lecture 21: Convolutions

Autumn 2026

1

Sli.do

#cse163

Questions?

Icebreaker

Favorite beverage?

CSE 163

CSE 163: Convolutions

​

​

2 of 29

Announcements

  • Programming Practice 7 due Sunday, November 22 at 11:59pm on Gradescope
  • Project Part 2 (EDA) due tonight, November 18 at 11:59pm on Gradescope
  • Homework 5 due Wednesday, November 25 at 11:59pm on Gradescope
  • Project Part 3 (Report + Code) due Friday, December 11 at 11:59pm on Gradescope

2

Questions?

CSE 163: Convolutions

​

​

3 of 29

(Grey-scale) Images as Matrices

3

Grey-scale: 255

Grey-scale: 0

data = iio.imread(‘...’)�

data[rows, columns] = #

CSE 163: Convolutions

​

​

4 of 29

Color Images

  • When you overlap each color channel, it creates a picture!
    • Pixels on your monitor let out specific RBG light

4

data[rows, columns, channels] = #

CSE 163: Convolutions

​

​

5 of 29

Convolution

  • When wanting use “local” information, we commonly use a sliding scale window approach (or a convolution)
  • Move the sliding window across the image, then compute the sum of the element wise product of the window (e.g. kernel) and image

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

​

​

6 of 29

Convolution Example

6

CSE 163: Convolutions

​

​

7 of 29

7

9

8

7

6

5

4

3

2

1

Image

2

1

Kernel

CSE 163: Convolutions

​

​

8 of 29

8

9

8

7

6

5

4

3

2

1

Image

2

1

Kernel

​

​

​

​

​

​

Output

CSE 163: Convolutions

​

​

9 of 29

9

9

8

7

6

5

4

3

2

1

Image

2

1

Kernel

​

​

​

​

​

​

Output

2

1

CSE 163: Convolutions

​

​

10 of 29

10

18

8

7

6

5

4

3

2

1

Image

2

1

Kernel

​

​

​

​

​

​

Output

CSE 163: Convolutions

​

​

11 of 29

11

18

8

7

6

5

4

3

2

1

Image

2

1

Kernel

​

​

​

​

​

​

Output

26

CSE 163: Convolutions

​

​

12 of 29

12

18

8

7

6

5

4

3

2

1

Image

2

1

Kernel

26

​

​

​

​

​

Output

26

CSE 163: Convolutions

​

​

13 of 29

13

18

8

7

6

5

4

3

2

1

Image

2

1

Kernel

26

​

​

​

​

​

Output

CSE 163: Convolutions

​

​

14 of 29

14

9

16

7

6

5

4

3

2

1

Image

2

1

Kernel

26

23

​

​

​

​

Output

23

CSE 163: Convolutions

​

​

15 of 29

15

9

8

7

12

5

4

3

2

1

Image

2

1

Kernel

26

23

17

​

​

​

Output

17

CSE 163: Convolutions

​

​

16 of 29

16

9

8

7

6

10

4

3

2

1

Image

2

1

Kernel

26

23

17

14

​

​

Output

14

CSE 163: Convolutions

​

​

17 of 29

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 of 29

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 of 29

19

9

8

7

6

5

4

3

2

1

Image

2

1

Kernel

26

23

17

14

8

5

Output

CSE 163: Convolutions

​

​

20 of 29

How many times can we fit this kernel in the image?

20

​

​

​

​

​

​

​

​

​

​

​

Image

Kernel

CSE 163: Convolutions

​

​

21 of 29

How many times can we fit this kernel in the image?

21

​

​

​

​

​

​

​

​

​

​

​

CSE 163: Convolutions

​

​

22 of 29

How many times can we fit this kernel in the image?

22

​

​

​

​

​

​

​

​

​

​

​

2

CSE 163: Convolutions

​

​

23 of 29

How many times can we fit this kernel in the image?

23

​

​

​

​

​

​

​

​

​

​

​

2

CSE 163: Convolutions

​

​

24 of 29

How many times can we fit this kernel in the image?

24

​

​

​

​

​

​

​

​

​

​

​

2

3

CSE 163: Convolutions

​

​

25 of 29

How many times can we fit this kernel in the image?

25

​

​

​

​

​

​

​

​

​

​

​

2

3

2

3 x

​

​

​

​

​

​

CSE 163: Convolutions

​

​

26 of 29

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

​

​

27 of 29

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

​

​

28 of 29

Common Kernels

28

Identity

Edge Detection

Sharpen

Box Blur

CSE 163: Convolutions

​

​

29 of 29

Image Classification

  • Is this a solved problem?
    • We get pretty decent error rates on challenges like ImageNet
  • What can’t we do?
    • Sometimes we can’t generalize to other real-world data sets
    • Adversarial attacks

29

CSE 163: Convolutions

​

​