Noel Jeffrey Pinton
Department of Computer Science
University of the Philippines Cebu
Noel Jeffrey Pinton
Department of Computer Science
University of the Philippines Cebu
By the end of this module, you will be able to:
Understanding image degradation
$$g(x,y) = f(x,y) + n(x,y)$$
$$g(x,y) = f(x,y) \cdot n(x,y)$$
What type of noise is best removed by a median filter?
Salt and pepper (impulse) noise, because the median operation ignores extreme outlier values.
Click the blurred area to reveal the answer
Spatial domain noise reduction
Comparison of mean, Gaussian, and median filters
1/9 * [[1,1,1],
[1,1,1],
[1,1,1]]1/16 * [[1,2,1],
[2,4,2],
[1,2,1]]Different filters have different strengths for various noise types
Smoothing without blurring edges
Bilateral Filter: Combines spatial proximity AND intensity similarity weights.
$$w(i,j,k,l) = \exp\left(-\frac{(i-k)^2+(j-l)^2}{2\sigma_s^2}\right) \cdot \exp\left(-\frac{|I(i,j)-I(k,l)|^2}{2\sigma_r^2}\right)$$
Why does the bilateral filter preserve edges while smoothing?
It uses intensity similarity weighting - pixels with very different intensities (across edges) receive low weights, so edges are not blurred.
Click the blurred area to reveal the answer
Enhancing edges and fine details
[[ 0,-1, 0],
[-1, 4,-1],
[ 0,-1, 0]][[-1, 0, 1],
[-2, 0, 2],
[-1, 0, 1]]$$g = f + k \cdot (f - f_{blurred})$$
where k controls sharpening strength
Comparison of Sobel, Prewitt, and Canny edge detectors
What makes the Canny edge detector superior to simple gradient methods?
Canny uses non-maximum suppression and hysteresis thresholding to produce thin, connected edges with reduced noise sensitivity.
Click the blurred area to reveal the answer
import cv2
import numpy as np
img = cv2.imread('image.jpg', 0)
# Gaussian blur
blurred = cv2.GaussianBlur(img, (5,5), 1.5)
# Median filter (good for salt & pepper)
median = cv2.medianBlur(img, 5)
# Bilateral filter (edge-preserving)
bilateral = cv2.bilateralFilter(img, 9, 75, 75)
# Sharpening with Laplacian
laplacian = cv2.Laplacian(img, cv2.CV_64F)
sharpened = img - 0.5 * laplacian
Key Takeaways
Thank you for your attention!
Next: Module 05 - Image Restoration
Questions?