# Faculty example: a complete binary-image convolution

Subject: Deep Learning

Exam: TEE

Reader: https://deep-learning-study-room.vercel.app/#tee/read/7/tee-c7-s14

Canonical: https://deep-learning-study-room.vercel.app/read/dl/tee/section/tee-c7-s14/

**Question. Apply the shown 3 × 3 filter to the 5 × 5 image. Use stride 1, no padding and zero bias. Calculate every output value without flipping the filter. (Practice: 5 marks)**

### Given

Image X =  $\begin{bmatrix}1 & 1 & 1 & 0 & 0\\0 & 1 & 1 & 1 & 0\\0 & 0 & 1 & 1 & 1\\0 & 0 & 1 & 1 & 0\\0 & 1 & 1 & 0 & 0\end{bmatrix}$ .

Filter K =  $\begin{bmatrix}1 & 0 & 1\\0 & 1 & 0\\1 & 0 & 1\end{bmatrix}$ . These are the values in the Unit 4 lecture example.

### To find

The output shape and all nine feature-map values.

### Formula — which one and why

The output-size formula counts complete filter placements. At each placement, multiply matching image/filter cells and add the products. A filter entry of zero makes that particular product zero; it does not remove the image cell from the input.



$$
N_{\mathrm{out}}=\left\lfloor\frac{N+2P-K}{S}\right\rfloor+1
$$



Here N is input side, K is kernel side, P is padding per side and S is stride. The symbol K in the shape formula is the size 3, whereas the matrix K above contains the filter's coefficients.



$$
Y_{ij}=\sum_{u,v}X_{iS+u,jS+v}K_{uv}+b
$$



For this particular filter, only the four corners and the centre of each 3 × 3 window contribute. We can therefore write each sum using those five entries after explaining the four zero products. Below, their order is always **top-left, top-right, centre, bottom-left, bottom-right** within the current window.

![Each output cell corresponds to a different 3 × 3 window. The filter coefficients are reused at all nine positions.](https://deep-learning-study-room.vercel.app/assets/figures/u4_binary_windows.svg)

Diagram: Each output cell corresponds to a different 3 × 3 window. The filter coefficients are reused at all nine positions.. Labels: u4 binary windows | One filter, nine window positions | Input: 5 × 5 | 1 | 1 | 1 | 0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 | 1 | 1 | 0 | 0 | 1 | 1 | 0 | 0 | Shared filter: 3 × 3 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | → | Output: 3 × 3 | 4 | 3 | 4 | 2 | 4 | 3 | 2 | 3 | 4 | Orange window → orange output cell = 4. Move one cell at a time.

Each output cell corresponds to a different 3 × 3 window. The filter coefficients are reused at all nine positions. Tap the diagram to enlarge.

### Solution — step by step

**Step 1: find the shape.** (5 − 3)/1 + 1 = 3. The output is 3 × 3.

**Step 2: top-left output, showing all nine products.** 1×1 + 1×0 + 1×1 + 0×0 + 1×1 + 1×0 + 0×1 + 0×0 + 1×1 = 1+0+1+0+1+0+0+0+1 = **4**.

**Step 3: top-middle output.** Move the window one column right. Corners and centre are 1,0,1,0,1. Sum = 1+0+1+0+1 = **3**.

**Step 4: top-right output.** Move one more column right. Corners and centre are 1,0,1,1,1. Sum = 1+0+1+1+1 = **4**.

**Step 5: middle-left output.** Return to column 1 and move down one row. Corners and centre are 0,1,0,0,1. Sum = 0+1+0+0+1 = **2**.

**Step 6: middle-middle output.** Corners and centre are 1,1,1,0,1. Sum = 1+1+1+0+1 = **4**.

**Step 7: middle-right output.** Corners and centre are 1,0,1,1,0. Sum = 1+0+1+1+0 = **3**.

**Step 8: bottom-left output.** Corners and centre are 0,1,0,0,1. Sum = 0+1+0+0+1 = **2**.

**Step 9: bottom-middle output.** Corners and centre are 0,1,1,1,0. Sum = 0+1+1+1+0 = **3**.

**Step 10: bottom-right output.** Corners and centre are 1,1,1,1,0. Sum = 1+1+1+1+0 = **4**.

**Final answer:** Y =  $\begin{bmatrix}4 & 3 & 4\\2 & 4 & 3\\2 & 3 & 4\end{bmatrix}$ . All nine outputs use the same nine filter weights. They do not introduce nine different filters.

**Yaad rakho:** Window badalta hai; filter ke numbers same rehte hain.
