Module 3: Image Processing Fundamentals

1. Learning Objectives

2. Key Concepts

3. Common Image Filters

Filter Type Description Example Kernel
Mean (Average) Blurs image by averaging surrounding pixels
1/9 * [[1,1,1],
        [1,1,1],
        [1,1,1]]
Gaussian Smooths image with Gaussian-weighted average cv2.GaussianBlur(image, (5,5), sigmaX)
Laplacian Detects rapid intensity changes cv2.Laplacian(image, cv2.CV_64F)
Sobel Finds gradients in x or y direction cv2.Sobel(image, cv2.CV_64F, dx, dy)

4. Edge Detection Algorithms

5. Hands-on Examples (OpenCV)

!pip install opencv-python-headless matplotlib

import cv2
import numpy as np
import matplotlib.pyplot as plt
from google.colab import files
from google.colab.patches import cv2_imshow

uploaded = files.upload()
img_path = next(iter(uploaded))
image = cv2.imread(img_path)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
cv2_imshow(gray)

# 1. Smoothing (Gaussian Blur)
blur = cv2.GaussianBlur(gray, (5, 5), 0)
cv2_imshow(blur)

# 2. Sobel Edge Detection
sobelx = cv2.Sobel(gray, cv2.CV_64F, 1, 0, ksize=3)
sobely = cv2.Sobel(gray, cv2.CV_64F, 0, 1, ksize=3)
cv2_imshow(cv2.convertScaleAbs(sobelx))
cv2_imshow(cv2.convertScaleAbs(sobely))

# 3. Canny Edge Detection
canny = cv2.Canny(gray, 100, 200)
cv2_imshow(canny)

# 4. Histogram Equalization
equalized = cv2.equalizeHist(gray)
cv2_imshow(equalized)

6. Real-World Example

In industrial inspection, edge detection is used to verify product shape, completeness, or detect defects in manufacturing lines.

7. Assignment

Objective: Practice edge detection and image enhancement with OpenCV.

Due: End of Week 3