AI Course
Lesson 83: Filters & Edge Detection
Filters and edge detection are core image processing techniques used to highlight important structures in images. They help machines understand shapes, boundaries, and object outlines.
Before advanced models analyze images, filters often clean and enhance the image so meaningful information stands out.
Real-World Connection
Photo editing apps sharpen images, security systems detect object boundaries, and medical imaging systems highlight organ edges. All these rely on filters and edge detection.
Edges usually represent important transitions in an image, such as object boundaries.
What Are Image Filters?
An image filter modifies pixel values using a small matrix called a kernel. This kernel slides over the image and performs mathematical operations.
- Smoothing filters reduce noise
- Sharpening filters enhance details
- Edge filters detect intensity changes
Blurring an Image
Blurring reduces noise and small details by averaging neighboring pixel values.
import cv2
image = cv2.imread("image.jpg")
blurred = cv2.GaussianBlur(image, (5, 5), 0)
cv2.imshow("Blurred Image", blurred)
cv2.waitKey(0)
cv2.destroyAllWindows()
What This Code Does
The Gaussian blur smooths the image using a weighted average. It reduces noise while preserving overall structure.
Blurring is often applied before edge detection to avoid detecting noise as edges.
Edge Detection Basics
Edge detection identifies areas where pixel intensity changes sharply. These changes usually indicate object boundaries.
Common edge detection methods include Sobel, Prewitt, and Canny.
Canny Edge Detection Example
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
edges = cv2.Canny(gray, 100, 200)
cv2.imshow("Edges", edges)
cv2.waitKey(0)
cv2.destroyAllWindows()
Understanding the Output
The output image highlights edges in white against a black background. These edges represent strong intensity changes.
Canny edge detection is widely used because it is accurate and less sensitive to noise.
Why Edge Detection Is Important
- Helps detect object boundaries
- Used in object detection pipelines
- Improves feature extraction
Practice Questions
Practice 1: What is the main purpose of image blurring?
Practice 2: What do edge detection algorithms identify?
Practice 3: Which popular algorithm is used for edge detection?
Quick Quiz
Quiz 1: What do image filters operate on?
Quiz 2: Which algorithm is commonly used for edge detection?
Quiz 3: Why is blurring often applied before edge detection?
Coming up next: Convolutions & Kernels — the mathematical foundation behind image filters.