1/91/91/91/91/91/91/91/91/91import numpy as np2from scipy.signal import convolve2d3img = np.zeros((6, 6)); img[2:, 2:] = 94box = np.ones((3, 3)) / 95blur = convolve2d(img, box, "valid")6sx = np.outer([1, 2, 1], [1, 0, -1])7edge = convolve2d(img, sx, "valid")000000000000090090999090999090999999
0123450369n (column)brightnessROW 3: IMAGE AND BLURx[3, n]blur y[3, n]01234509182736n (column)edge valueROW 3: EDGES (SOBEL)edge y[3, n]0π/32π/3π0123ω (radians per pixel)|H|GAIN ALONG A ROW |H(ω)|blur [1 1 1]/3edge [−1 0 1]
Coloured parts: what the current step is about; everything else rests in whiteBlocks: the 6×6 image (tall = bright 9, low and shaded = dark 0), the 3×3 kernel, the 4×4 output and a Python cardPlots: row 3 of the image, the blur and the edges, and each kernel's gain along a rowThe frame slides over the image; chips carry each multiply-and-add result into the output, whose shade follows its valueA 6×6 image is convolved with a 3×3 box kernel (blur) and the Sobel kernel (edges), keeping the 4×4 places where the kernel fits. "valid" convolution keeps only outputs that need no padding, so a 6×6 image gives 4×4. Other modes pad the border (with zeros, or a copy of the edge) to keep the size; the padded border then shows fake edges.

An image is a signal

  1. A grey image is a grid of numbers. Pixel x[m, n] holds the brightness at row m, column n. Our 6×6 image is dark (0) with a bright (9) square at the bottom right. Two indexes instead of one time.

Blur by convolution

Frequency and speed

Edges

In code

The working

# step 1/11 · pixels

x[m, n]   m = row (0..5), n = column (0..5)

        n=0 1 2 3 4 5
  m=0    0 0 0 0 0 0
  m=1    0 0 0 0 0 0
  m=2    0 0 9 9 9 9
  m=3    0 0 9 9 9 9
  m=4    0 0 9 9 9 9
  m=5    0 0 9 9 9 9

brightness on a 0..9 scale for easy sums
(8-bit images use 0..255)

Brightness uses a 0 to 9 scale so the sums stay small; 8-bit images store 0 to 255 per pixel and the arithmetic is the same. Every number and curve in the figure is computed from this model and matches numpy 2.5.4 with SciPy 1.18.1. "valid" convolution keeps only outputs that need no padding, so a 6×6 image gives 4×4. Other modes pad the border (with zeros, or a copy of the edge) to keep the size; the padded border then shows fake edges. Sources write the Sobel kernel with either sign, and some libraries slide the kernel without flipping it (correlation). The flip only changes the sign of the edge value here, never where the edge is. In the row plot the two sets of stems are nudged sideways a little so both stay visible; each belongs to the whole-number column n under it.