Quiz: the flooding algorithm on a grid
Before this unit: Images as landscapes: watershed by flooding (previous unit); Day 14: Labelling.
See also: Day 2: Edges, blobs and ridges.
Short questions to test your understanding. Try each on paper first, then open the answer. Meyer’s flooding: a priority queue ordered by height (ties: first in, first out); pop the lowest pixel; label it if its labelled neighbours agree, otherwise it is a line pixel; push its unlabelled neighbours.
Q1. The queue holds (height 3, #7), (height 2, #12), (height 2, #9). Which is popped first?
Height first, then arrival.
(height 2, #9): the lowest height, and among the two of height 2 the one that arrived first.
Q2. The water level is 5 and a pixel of height 2 is pushed. When is it popped, and what does that mean in the flooding picture?
It is lower than everything else in the queue.
Immediately (next): it is the lowest entry. The water has spilled over a pass into an unmarked dip below the current level, and fills it at once: the dip is drowned and joins the region that reached it.
Q3. A popped pixel has labelled neighbours A, A and B. What happens with a watershed line, and what without one?
“All labelled neighbours the same?”
With a line: the labels disagree, so the pixel becomes a line pixel and pushes nothing. Without a line: it takes the label of the neighbour that queued it (the one that reached it first), and pushes its neighbours as usual.
Q4. Why are equal heights popped first in, first out?
Think of a flat plateau between two lakes.
On a plateau, height cannot decide; arrival order then makes each lake spread as a wavefront, one ring at a time, so two lakes that reach the plateau at the same level meet in its middle. With last in, first out, one lake would race across the plateau and the dam would end up next to the other lake’s entry.
Q5. Why is a one-pixel diagonal line enough to separate the regions with 4 neighbours, but not with 8?
Two pixels on either side of a diagonal line touch at a corner.
Across a diagonal line, pixels of the two regions are diagonal neighbours. With 4 neighbours that is not a contact, so the regions are separated. With 8 neighbours they would touch, so the line must be 4-connected (a staircase), which takes more pixels.
Q6. How many times is each pixel pushed and popped, and what does the flooding of an n-pixel 8-bit image cost with a bucket queue?
A pixel is marked “queued” when it is pushed.
At most once each. With one FIFO bucket per grey level, push and pop are constant time (plus at most 256 steps of the bucket pointer per upward sweep), so the flooding costs O(n + 256) = O(n). With a binary heap it is O(n \log n).
Q7. A marker sits halfway up a slope, not at a minimum. Is that a problem?
Where does its water go?
No. Its neighbours below it are popped first, so its water runs downhill into the basin below and claims it (any unmarked minimum it reaches is drowned). The region is the same as if the marker had been placed at the bottom, unless another marker’s water gets there first.
Q8. (math) What is the “distance” that Meyer’s flooding computes, and which classical algorithm is it?
Replace the sum of edge lengths by something else.
The minimax (bottleneck) distance from the markers: the smallest possible “highest point” on a path from a marker to the pixel. The flooding is Dijkstra’s algorithm with \max in place of +; equivalently, Prim’s algorithm growing a minimum spanning forest from all markers (watershed as a minimum spanning forest, day 29) at once.