Finding shapes

Thresholding with Otsu's method and adaptive thresholds, morphology to clean masks, and connected components to count, measure and outline objects.

About 5 hours of study

Learning objectives

Lessons

  1. 1

    Thresholding and Otsu's method Intermediate

    Thresholding splits an image into foreground and background. Apply global and inverse thresholds, let Otsu's method choose the threshold from the histogram, and use adaptive thresholds when the lighting is uneven.

  2. 2

    Morphology: erosion, dilation, opening and closing Intermediate

    Clean up binary masks by growing and shrinking shapes. Apply erosion and dilation with a structuring element, combine them into opening and closing to remove specks and fill holes, and extend the idea to greyscale images with the top-hat transform.

  3. 3

    Connected components and contours Intermediate

    Turn a mask into separate objects. Label connected regions with flood fill, compare 4- and 8-connectivity, measure each object's area, bounding box and centroid, and find its boundary pixels, the idea behind contours.

Module practice

Module quiz

1. What does a threshold produce?
2. Which operation fills small holes inside objects?
3. Where does Otsu's threshold fall on a histogram with two clear humps?
4. Two pixels touch only at a corner. When are they in the same object?
5. A page is lit from one side. Why does an adaptive threshold work where a global one fails?
6. An object has area 12 and a 4 x 6 bounding box. What is its fill ratio?

‹ FilteringGeometry and matching ›