AI Lesson 84 – Convolutions & Kernels | Dataplexa

Lesson 84: Convolutions & Kernels

Convolutions and kernels form the mathematical foundation of image filtering. Almost every image operation you have learned so far — blurring, sharpening, and edge detection — is powered by convolution.

Understanding this concept is critical because convolution is also the backbone of Convolutional Neural Networks (CNNs), which dominate computer vision today.

Real-World Connection

When your phone camera sharpens photos, when medical scans highlight tissues, or when self-driving cars identify road boundaries — convolution is working behind the scenes.

Instead of looking at the whole image at once, convolution processes images locally, one small region at a time.

What Is a Kernel?

A kernel (also called a filter or mask) is a small matrix of numbers that is applied to an image to extract specific features.

  • Kernels usually have sizes like 3×3, 5×5
  • Each kernel serves a purpose: blur, sharpen, detect edges
  • The kernel slides over the image pixel by pixel

What Is Convolution?

Convolution is the process of placing a kernel over a region of an image, multiplying corresponding values, summing them, and assigning the result to a new pixel.

This operation is repeated across the entire image to produce a transformed output.

Simple Convolution Example

Below is a basic example of applying a custom kernel to an image using OpenCV.


import cv2
import numpy as np

image = cv2.imread("image.jpg", cv2.IMREAD_GRAYSCALE)

kernel = np.array([
    [0, -1, 0],
    [-1, 5, -1],
    [0, -1, 0]
])

convolved = cv2.filter2D(image, -1, kernel)

cv2.imshow("Original", image)
cv2.imshow("Convolved", convolved)
cv2.waitKey(0)
cv2.destroyAllWindows()
  

What This Code Is Doing

The kernel used above is a sharpening kernel. It emphasizes differences between neighboring pixels, making edges and details more visible.

The filter2D function slides the kernel over the image, performs convolution at each position, and generates a new image.

Understanding the Output

The output image appears sharper than the original. Fine details and boundaries become more visible because the kernel amplifies intensity changes.

Different kernels produce very different results even when applied to the same image.

Common Kernels and Their Purpose

  • Blur kernel: Smooths the image
  • Sharpen kernel: Enhances edges
  • Edge kernel: Detects boundaries

Why Convolution Matters in AI

In deep learning, convolution layers automatically learn kernels from data instead of manually defining them.

This allows models to detect edges, textures, shapes, and complex patterns efficiently.

Practice Questions

Practice 1: What is the small matrix used in convolution called?



Practice 2: What operation applies a kernel across an image?



Practice 3: What does convolution help extract from images?



Quick Quiz

Quiz 1: What is a common kernel size?





Quiz 2: Which OpenCV function applies convolution?





Quiz 3: Convolution is a core operation in which type of neural network?





Coming up next: Object Detection — how machines locate and identify objects inside images.