Joshu Leonardy
輪 · 郭 · と · 分 · 割

Edges & Segmentation Lab

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.

— 01 —
微 · 分 · と · 輪 · 郭

Derivatives and edge models

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.

∂f/∂x = [f(x+1) − f(x−1)] / 2    ∂²f/∂x² = f(x+1) − 2f(x) + f(x−1)

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.

Edge model
Ramp width
Noise σ
Smooth first
Profile f(x), first derivative, second derivative

Points and lines on a real image

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.

Kernel
Threshold
Show
— 02 —
検 · 出 · 器

Marr–Hildreth and Canny, step by step

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.

Detector
Gaussian σ
High threshold TH
TH : TL
Zero-crossing threshold
Stage
— 03 —
ハ · フ · 変 · 換

Linking edges: the Hough transform

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.

x cos θ + y sin θ = ρ
Hover over the accumulator.

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.

Lines to find
Minimum votes
Edges and detected lines
Accumulator · θ across, ρ down · click to add or remove a line
— 04 —
閾 · 値 · 処 · 理

Thresholding, beyond a single T

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.

Method
Window n
c
Histogram · thresholds marked
— 05 —
領 · 域 · 分 · 割

Regions: growing, clustering, flooding

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.

Method
Similarity T
Seeds
Clusters k
Smoothing σ
This is where classical segmentation ends and learned segmentation begins. Every method in this lab relies on a rule a person chose: a threshold, a similarity test, a σ. The Segmentation Lab in the Computer Vision series asks a network to learn those rules from examples instead.