Computer Vision · Beginner level

Beginner level · Module 4: Image Filtering and Edge Detection · Lesson 1 of 3

Convolution and Blurring Filters

Learners compute a convolution by hand, then apply box, Gaussian and median filters to reduce different kinds of noise.

In this lesson you will

  • Compute a convolution by hand and with filter2D
  • Choose a blur filter for a type of noise

Key concepts

kernelconvolution / correlationcv2.filter2DGaussianBlurmedianBlur

The lesson

A filter slides a small grid of weights (a kernel) over the image. At each position, it multiplies the kernel by the pixels underneath and adds the results; the sum becomes the output pixel. cv2.filter2D applies any kernel. Strictly, this is correlation; true convolution flips the kernel, which makes no difference for symmetric kernels.

A 3×3 box kernel with all weights 1/9 averages neighbours, which smooths noise but also blurs edges. A Gaussian blur weights nearby pixels more and looks more natural. A median blur replaces each pixel with the median of its neighbours, which removes salt-and-pepper specks while keeping edges sharp.

Blurring is often the first step before edge detection or thresholding, because noise creates false edges and specks.

Step by step

  1. Compute the output of a 3×3 box filter on a 5×5 array by hand.
  2. Check your result with cv2.filter2D.
  3. Add salt-and-pepper noise to an image and apply Gaussian and median blur.
  4. Compare which filter keeps the edges better.

Practice activity

Compare three blur filters on noisy images and recommend one for each noise type.

Expected result: A correct hand calculation and a reasoned recommendation backed by images.

Check your understanding

  1. Which filter removes salt-and-pepper noise best while keeping edges?

    Show answer

    The median filter.

  2. Why blur before edge detection?

    Show answer

    Noise creates false edges, and blurring reduces it.

Further learning

Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.