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:
Converting grayscale to binary
Binary Thresholding:
$$g(x,y) = \begin{cases} 1 & \text{if } f(x,y) > T \\ 0 & \text{otherwise} \end{cases}$$
Simple but requires manual threshold selection.
Otsu's Method: Automatically find optimal threshold by maximizing between-class variance.
$$\sigma^2_B = \omega_0 \omega_1 (\mu_0 - \mu_1)^2$$
Works well for bimodal histograms.
When does Otsu's method work well, and when might it fail?
Otsu's works well when the histogram is bimodal (two distinct peaks). It may fail with uneven illumination, multiple objects at different intensities, or when foreground/background have similar intensities.
Click the blurred area to reveal the answer
Grouping similar pixels
Region Growing Algorithm:
What is over-segmentation in watershed, and how can it be addressed?
Over-segmentation occurs when noise creates too many basins, resulting in many small regions. It can be addressed by: 1) pre-smoothing the image, 2) using marker-based watershed with fewer seed points, 3) merging small regions post-processing.
Click the blurred area to reveal the answer
Shape-based image processing
Structuring Element: Small shape used as a probe. Common shapes: square, disk, cross, diamond.
$$A \ominus B$$
Shrinks objects, removes small protrusions
$$A \oplus B$$
Expands objects, fills small holes
$$A \circ B = (A \ominus B) \oplus B$$
Removes small objects, smooths contours
$$A \bullet B = (A \oplus B) \ominus B$$
Fills small holes, connects nearby objects
What is the difference between erosion and opening?
Erosion shrinks ALL parts of the object uniformly. Opening (erosion + dilation) removes small protrusions and noise but largely preserves the size of larger objects, since dilation restores the eroded boundaries.
Click the blurred area to reveal the answer
Morphological Gradient:
$$G = (A \oplus B) - (A \ominus B)$$
Dilation minus erosion = edge detection using morphology
Practical uses of segmentation and morphology
Comparing morphological gradient with other edge detection methods
Top-hat and bottom-hat transforms for texture analysis
Different structuring element sizes capture features at different scales
import cv2
import numpy as np
img = cv2.imread('image.jpg', 0)
# Otsu's thresholding
_, binary = cv2.threshold(img, 0, 255,
cv2.THRESH_BINARY + cv2.THRESH_OTSU)
# Adaptive thresholding
adaptive = cv2.adaptiveThreshold(img, 255,
cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 11, 2)
# Morphological operations
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (5,5))
opened = cv2.morphologyEx(binary, cv2.MORPH_OPEN, kernel)
closed = cv2.morphologyEx(binary, cv2.MORPH_CLOSE, kernel)
Key Takeaways
Thank you for your attention!
Next: Module 09 - Computer Vision & Deep Learning I
Questions?