Quiz: erosion and dilation
Before this unit: Day 12: Thresholding.
Short questions to test your understanding. Try each on paper first, then open the answer. A is the object (foreground) of a binary image, B the structuring element (SE) with its origin; erosion A \ominus B keeps the pixels where B fits inside A, dilation A \oplus B the pixels where the reflected \check B hits A.
Q1. A mask has isolated noise pixels in the background. Which of erosion and dilation with a 3 \times 3 square removes them, and what does it do to the real objects?
Can a 3 \times 3 square fit inside a single pixel?
Erosion: the square does not fit inside an isolated pixel (or any object narrower than 3 pixels), so those disappear. But every real object also loses a one-pixel layer all round, and thin parts vanish. The next unit’s opening (erode, then dilate) gives most of the size back.
Q2. Dilate a single object pixel by an SE B. What is the result? And the erosion of a 1 \times 1 object?
Dilation = a copy of B placed on every object pixel.
The dilation is a copy of B placed with its origin on that pixel. The erosion is empty unless B is a single pixel: if B = \{0\} the pixel survives; if B = \{(1, 0)\} the result is the pixel one step to the left (where the SE, shifted right by one, lands on the object). With more than one SE pixel, nothing fits.
Q3. Why does an SE that does not contain its origin behave strangely? Give an example.
Try B = \{(1, 0)\}, a single pixel one step to the right of the origin.
Then A \ominus B = \{x : x + (1, 0) \in A\} is A shifted one pixel to the left, and A \oplus B is A shifted to the right. Neither is contained in the other, so “erosion shrinks, dilation grows” no longer holds. The inclusions A \ominus B \subseteq A \subseteq A \oplus B need 0 \in B.
Q4. Erosion with the min, dilation with the max over a window: why is erosion not a convolution, although it uses the same sliding window?
What does a convolution do with the sum of two images?
A convolution is linear: the result for f + g is the sum of the results. The min is not: on a two-pixel window, \min(0, 1) + \min(1, 0) = 0 but \min(0 + 1, 1 + 0) = 1. Erosion is shift-invariant like a convolution, but not linear, so there is no impulse response that describes it and no frequency response.
Q5. State the duality between erosion and dilation in words. Why does the SE get reflected?
When is a pixel not in the erosion?
“Eroding the object is dilating the background”: (A \ominus B)^c = A^c \oplus \check B. A pixel is not in the erosion when B, placed there, has at least one pixel on the background, i.e. B_x hits A^c. Dilation tests whether the reflected SE hits, so to write “B_x hits A^c” as a dilation we must use \check B, whose reflection is B again.
Q6. You need to dilate a large image with a 21 \times 21 square. How many max operations per pixel does the direct method need, and how many with the decomposition into a row and a column?
A \oplus (B_1 \oplus B_2) = (A \oplus B_1) \oplus B_2.
Directly, 441 values per pixel (440 comparisons). The square is a row of 21 dilated by a column of 21, so two passes of 21 values each: 42 values (40 comparisons). With the van Herk / Gil–Werman running min/max, each line costs about 3 comparisons per pixel, whatever its length.
Q7. The inner boundary A \setminus (A \ominus B) is computed once with the cross and once with the 3 \times 3 square. Which boundary is thicker, and which one is 4-connected?
Which SE removes more pixels when eroding?
The square erodes more (a pixel must have all 8 neighbours in A to survive), so its boundary contains more pixels: it is thicker and 4-connected (every boundary pixel touches the next by an edge). The cross only removes pixels with a 4-neighbour in the background; its boundary is thinner and 8-connected (it can step diagonally).
Q8. (math) Show that dilation distributes over union: (A \cup C) \oplus B = (A \oplus B) \cup (C \oplus B). Does erosion distribute over union too?
Use A \oplus B = \{a + b : a \in A, b \in B\}. For erosion, try two objects that are each too small for B.
z \in (A \cup C) \oplus B \iff z = a + b with a \in A \cup C, b \in B \iff z \in A \oplus B or z \in C \oplus B. Erosion does not: let B be a row of 2 pixels, A and C two single pixels side by side. Each erosion is empty, but A \cup C is a row of 2, whose erosion is one pixel. Erosion distributes over intersection instead: (A \cap C) \ominus B = (A \ominus B) \cap (C \ominus B).