In image filtering, a kernel is a matrix of weights that slides across an image. It multiplies each local pixel window by corresponding weights, sums the products, and produces an output pixel through convolution. This matrix-based meaning is different from a compiled low-level executable kernel. section 3.1.4
Typical filtering kernels include:
- A normalized 5×5 blur kernel gives every neighboring pixel equal weight. section 3.1.4
- A Gaussian kernel gives nearby pixels greater influence and supports image denoising. section 3.1.4
- A sharpening kernel combines negative surrounding weights with a strong positive center weight. section 3.1.4
Applying a kernel to a color image
A filtering function processes each of three color channels with convolve2d, clips values to the range 0.0–1.0, and stacks the channels back together. Applying a Gaussian kernel denoises the image but can leave it blurred; applying a sharpening kernel can restore detail. section 3.1.4
Listing 3.5 Matrix (or kernel) for a simple blur filter
kernel_blur = np.ones((5,5)) #1 kernel_blur /= np.sum(kernel_blur) #2 kernel_blur >>> array([[0.04, 0.04, 0.04, 0.04, 0.04], #3 >>> [0.04, 0.04, 0.04, 0.04, 0.04], #3 >>> [0.04, 0.04, 0.04, 0.04, 0.04], #3 >>> [0.04, 0.04, 0.04, 0.04, 0.04], #3 >>> [0.04, 0.04, 0.04, 0.04, 0.04]]) #3
Inspect a normalized 5×5 blur kernel whose entries are all 0.04. section 3.1.4


