Quiz: opening, closing and the distance transform
Before this unit: Erosion and dilation (previous unit); Day 12: Thresholding.
Short questions to test your understanding. Try each on paper first, then open the answer. Opening A \circ B = (A \ominus B) \oplus B, closing A \bullet B = (A \oplus B) \ominus B; \mathrm{DT}(p) is the distance from an object pixel p to the nearest background pixel.
Q1. A mask of cells has isolated noise pixels in the background and small holes inside the cells. Which operation removes the noise pixels, and which fills the holes?
Which one rolls the SE inside the objects, and which outside?
An opening removes the noise pixels: the SE does not fit into them, so no copy of it reaches them. A closing fills the holes: the SE rolled around in the background cannot get into a hole smaller than itself. Both leave the cells larger than the SE essentially unchanged (apart from rounded corners).
Q2. You open a mask, and then open the result again with the same SE. What changes the second time? Which matrix property does this resemble?
The opening is the union of all copies of the SE that fit inside the object.
Nothing changes: the opening is idempotent. After one opening, every remaining pixel is covered by a copy of the SE that fits, and those copies still fit, so the second opening keeps everything. It resembles a projection matrix, P^2 = P.
Q3. Two cells are joined by a bridge 2 pixels wide. Which SE sizes separate them with an opening? What else happens to the cells?
Does a 3 \times 3 square fit across a 2-pixel bridge?
Any SE that does not fit in the bridge: a 3 \times 3 square or larger (or a disc of radius 1.5 or more). The cells themselves lose their corners and any protrusions thinner than the SE, but keep their size where the SE fits. If the cells are themselves thin somewhere, they may be cut there too.
Q4. A granulometry with discs gives a pattern spectrum with two peaks, at r = 3 and r = 9. What does that tell you about the image? What would a single long rod 4 pixels wide contribute?
“Size” in a granulometry is the largest disc that fits.
There are two populations of round-ish objects, with largest inscribed discs of radius about 3 and 9 (so diameters about 7 and 19 pixels), and the peak heights give their total areas. A rod 4 pixels wide fits only a disc of radius about 1.5, whatever its length, so its whole area appears at a small radius, near r = 1: granulometry measures thickness, not length.
Q5. Compute the city-block distance transform of a 1 \times 7 row of object pixels with background at both ends (outside the row counts as background): 0\,1\,1\,1\,1\,1\,1\,1\,0.
Count steps to the nearest 0.
0\,1\,2\,3\,4\,3\,2\,1\,0. The middle pixel is 4 steps from either end. The forward pass alone would give 0\,1\,2\,3\,4\,5\,6\,7\,0; the backward pass corrects the right half.
Q6. How do you get the erosion of a mask by discs of radius 2, 5 and 10 from one computation?
Where does a disc of radius r fit?
Compute the Euclidean distance transform once and threshold it: A \ominus D_r = \{\mathrm{DT} > r\} for r = 2, 5, 10. A disc of radius r centred at x fits exactly when no background pixel lies within distance r of x.
Q7. A mask is eroded with a 5 \times 5 square. Which distance transform and which threshold give the same result?
Which “disc” is a square?
The 5 \times 5 square is the disc of radius 2 in the chessboard metric \max(|\Delta x|, |\Delta y|). So the erosion is \{\mathrm{DT}_{\text{chessboard}} > 2\}, with the chessboard DT computed by two passes using all 8 neighbours.
Q8. (math) Show that the closing is extensive, A \subseteq A \bullet B, for every SE B (also one without its origin).
Use the adjunction A \oplus B \subseteq C \iff A \subseteq C \ominus B.
Take C = A \oplus B. Then A \oplus B \subseteq C holds trivially, so by the adjunction A \subseteq C \ominus B = (A \oplus B) \ominus B = A \bullet B. No property of the origin is needed. (At an image border this needs the adjoint convention: erosion treats the outside as object.)