Full search page →

IP 11 · Does the snake find the edge, or get stuck?

AdvancedIP 11 · Image Segmentation II: Active Contours — Snakes and Level SetsImage lab

Description

Run a real snake, the Kass–Witkin–Terzopoulos contour of IP 11, on a photograph of coins: start a circle around one coin and see how far from its rim the circle may begin before the snake settles in the wrong place.

Try this: The default circle has radius 40 and the coin about 23: the snake ends 17.7 px from the coin boundary, caught by the neighbouring coins. (1) Lower the start radius to 28: it finds the rim (0.5 px). (2) Back at radius 40, raise the smoothness to 1.0: now it finds the coin too (0.4 px). Why does a stiffer, more contracting snake reach the coin from farther away? (3) Keep smoothness 2.0 and start inside the coin at radius 12: the snake shrinks to a small curve (17.4 px). (4) With smoothness 0.05, a start at radius 12 reaches the rim at σ = 3 (1.1 px) but stays inside at σ = 2 (10.2 px). What does the blur remove?

Predict first

The start circle has radius 40 pixels; the coin has radius about 23. With the default settings, will the snake still find the coin?

Hints

The chapter section that uses this lab:

Explanation

Answer the prediction first, or open the explanation when you are ready.

Show the explanation

The snake does not find the coin. Tension pulls the circle inwards only a little before the edges of the neighbouring coins catch it: 74 of its 100 points end within 3 px of a neighbour’s boundary, and the mean distance to the coin boundary is 17.7 px. It has stopped moving (after 871 iterations), so it sits in a local minimum of the energy, but a poor one: its energy, −266.2, is higher than −283.4, the energy of a circle on the coin. A snake that does find the coin (start radius 28) reaches −298.9. Energies are in arbitrary units.

Lab · IP 11 · Does the snake find the edge, or get stuck?

Predict first

The start circle has radius 40 pixels; the coin has radius about 23. With the default settings, will the snake still find the coin?

Loading image…

Coins with the start circle (white dashed), snapshots at 10, 30, 100 and 300 iterations (orange), the final snake (yellow) and the true coin boundary (cyan dashed). Click or drag to set the start radius
Edge map e = |∇(G_σ ∗ image)| (dark blue: strong edge) with the start circle (dashed) and the final snake (orange)
Snake energy against iteration
Mean distance to the true coin boundary against iteration

Try this: The default circle has radius 40 and the coin about 23: the snake ends 17.7 px from the coin boundary, caught by the neighbouring coins. (1) Lower the start radius to 28: it finds the rim (0.5 px). (2) Back at radius 40, raise the smoothness to 1.0: now it finds the coin too (0.4 px). Why does a stiffer, more contracting snake reach the coin from farther away? (3) Keep smoothness 2.0 and start inside the coin at radius 12: the snake shrinks to a small curve (17.4 px). (4) With smoothness 0.05, a start at radius 12 reaches the rim at σ = 3 (1.1 px) but stays inside at σ = 2 (10.2 px). What does the blur remove?

Real image: a 144 × 144 crop of skimage.data.coins, centred on one coin and showing parts of the eight coins around it (credit below). The snake follows IP 11 and its figure code: a closed contour of 100 points, the semi-implicit step x(t) = (A + γI)⁻¹(γ x(t−1) + f) with A built from [β, −α−4β, 2α+6β, −α−4β, β], γ = 1, α = β = the smoothness slider, and the force f = κ∇e with κ = 4, where the edge map e = |∇(G_σ ∗ image)| is scaled to a maximum of 1 and sampled by bilinear interpolation. There is no resampling, no balloon force and no step cap; points stay inside the image. It stops when no point moves more than 0.05 px in one step, or after 1500 iterations. This is not scikit-image’s active_contour: that function builds the same matrix A, but takes a Sobel gradient of the image you pass in, a spline for the force and caps every step at one pixel. The true boundary is the circle fitted by least squares to the boundary pixels of the coin’s Otsu mask (holes filled); the coin is not a perfect circle, so a snake sitting on the rim is still about half a pixel from it. Distance is the mean over the 100 points of |distance from the circle’s centre − its radius|; “found” means at most 2 px. Energy is E = ½ Σ(α|v(i+1) − v(i)|² + β|v(i+1) − 2v(i) + v(i−1)|²) − κ Σ e(v(i)), in arbitrary units; the orange dashed line is E for the fitted circle itself. A click or drag on an image sets the start radius so that the circle passes through the pointer; the circle always stays centred on the coin. Click positions are rounded to whole pixels.

Method and image sources

Open in the Playground →