Segmentation divides an image into the regions it is made of. There are two ways in. One looks for discontinuities, the edges where brightness changes abruptly. The other looks for similarity, groups of pixels that belong together. This last lab of the series follows Chapter 10 of Gonzalez & Woods through both approaches. It also returns to the uneven page that no single threshold could handle in lab 02.
Gonzalez & Woods, 4th ed. §10.2: Background (p. 702), Detection of Isolated Points (p. 706), Line Detection (p. 707), Edge Models (p. 710), eqs. 10-4 to 10-15
Every edge detector is built from derivatives, so start with a single row of pixels. The first derivative is nonzero along the whole slope of an edge. The second derivative gives a pair of spikes, one positive and one negative, and the point where it crosses zero between them marks the middle of the edge. Now add a little noise and watch what happens to each derivative.
These are the central differences of eqs. 10-6 and 10-7. Noise that is barely visible in f becomes large in the first derivative and overwhelming in the second, because each difference subtracts neighbouring values and so strengthens any rapid change, including noise. That is why every serious edge detector smooths the image first.
A point detector is the Laplacian (eq. 10-14) followed by a threshold on |Z| (eq. 10-15). A line detector weights one direction more heavily: a line running in the same direction as the kernel gives the strongest response.
Gonzalez & Woods, 4th ed. §10.2: More Advanced Techniques for Edge Detection (p. 724), eqs. 10-27 to 10-41
Lab 03's Sobel magnitude gave thick edges that were broken and noisy. The two detectors here repair those problems in different ways. Marr–Hildreth smooths the image, takes the Laplacian, and marks where the result changes sign. Canny smooths the image, then thins each edge to its single strongest pixel, and finally links edges using two thresholds. Step through each stage with the buttons below the controls.
Gonzalez & Woods, 4th ed. §10.2: Linking Edge Points (p. 735), eq. 10-44
An edge map is still just a scatter of pixels. The Hough transform asks which straight lines those pixels support. Every edge pixel votes for all the lines that could pass through it. In the (ρ, θ) plane those votes trace out a sinusoid, one per pixel. Where many sinusoids cross, many pixels share one line. Hover over the accumulator to see which line a point stands for, and click to add it or take it away.
This is the normal form of a line (eq. 10-44). Unlike y = ax + b, it can also describe vertical lines. θ runs from −90° to 90°, and ρ from −D to D, where D is the image diagonal. As in lab 03, x runs across the columns here, whereas the book measures it down the rows. The edge map is the Canny output from section 02, with its current settings.
Gonzalez & Woods, 4th ed. §10.3: Basic Global Thresholding (p. 746), Multiple Thresholds (p. 757), Variable Thresholding (p. 761), eqs. 10-46, 10-66 to 10-77, 10-80, 10-83
Lab 02 introduced Otsu's method. This section covers three things around it. The first is the book's simple iterative method, which usually lands close to Otsu's threshold. The second extends Otsu to two thresholds, which splits the image into three classes. The third is the fix promised in lab 02: a threshold that changes across the image, computed from a moving average of nearby pixels. Try it on Uneven page.
Gonzalez & Woods, 4th ed. §10.4: Region Growing (p. 764); §10.5: Region Segmentation Using K-Means Clustering (p. 770), eq. 10-85; §10.7 Segmentation Using Morphological Watersheds (p. 786)
These methods build regions directly instead of looking for edges. Region growing starts from seeds you click and keeps adding neighbouring pixels that pass a similarity test. k-means sorts every pixel into one of k groups by brightness. The watershed treats the gradient image as a landscape and floods it from its lowest points. Each flooded basin becomes a region, and dams are built where two basins would merge.