Quiz: hit-or-miss and thinning
Before this unit: Day 14: Labelling; Day 2: Edges, blobs and ridges.
See also: Day 15: Watershed; Day 16: Measurements.
Short questions to test your understanding. Try each on paper first, then open the answer. Templates are written as three rows, top to bottom: 1 = object, 0 = background, · = don’t care.
Q1. Why can an erosion not find the end points of a line, while a hit-or-miss transform can?
What does each one require of the background?
An erosion only asks whether the structuring element fits inside the object; it puts no condition on the background. An end point and a pixel in the middle of a line both pass any test that only looks at object pixels near them. The hit-or-miss template also demands background in some cells (all neighbours but one), and that is what distinguishes an end point.
Q2. The template 010 / 010 / 000 finds end points whose only neighbour is directly above. How many templates do you need to find all end points of a skeleton, and how do you get them?
Where can the single neighbour be?
Eight: the single neighbour can be in any of the 8 positions around the pixel. Turning the template by 45° at a time (moving the 1 one step round the centre) gives all of them; the union of the eight hit-or-miss results is the set of end points.
Q3. Is a pixel with neighbours 110 / 1·0 / 000 (centre = 1) simple? And one with 100 / 0·0 / 001?
Count the object parts among the neighbours (diagonal contact counts) and the background parts.
First: the object neighbours (top left, top, left) form one part, the background neighbours one part: simple. Removing it shaves a corner. Second: the two object neighbours are opposite corners and do not touch: two object parts, so not simple: removing the centre would split the object.
Q4. An end point is a simple pixel. Why does thinning keep it?
What happens to a straight line if all simple pixels are removed?
Removing simple pixels keeps the topology, but a line would lose a pixel at each end in every pass until a single pixel is left. The skeleton is supposed to keep the length and the branches, so end points are protected (the L templates simply never fit a pixel with one neighbour).
Q5. Thinning tests the 8 templates one after the other on the current image. What would go wrong if all 8 were tested on the same image and all matches removed at once?
Think of a line two pixels thick.
Both rows of a two-pixel-thick line match (the top row has background above, the bottom row background below). Each row is removable on its own, but removing both together deletes the line. Applying one template at a time, the second row is tested after the first is gone, and then it is the middle of a one-pixel line and is kept.
Q6. A shape with two holes is thinned. How many holes does the skeleton have, and how many loops does it contain?
What does removing only simple pixels preserve?
Two holes, so two independent loops: thinning removes only simple pixels, and removing a simple pixel never changes the number of objects or holes. Each hole stays surrounded by a one-pixel loop.
Q7. (math) Write the hit-or-miss transform as two erosions. What is the result if a cell is required to be both 1 and 0?
One erosion for the object, one for the background A^c.
A \circledast (B_1, B_2) = (A \ominus B_1) \cap (A^c \ominus B_2) with B_1 the 1-cells and B_2 the 0-cells. If B_1 \cap B_2 \ne \emptyset, some pixel would have to lie in A and in A^c: the result is empty for every image.
Q8. A thinned vessel shows a small two-pixel fork at a place where the vessel ends bluntly. Is this an error of the algorithm?
Look at the corners of a thinned rectangle.
No, it is expected: at a blunt end the shape has two corners, and thinning (like the medial axis of the next unit) sends a short branch towards each of them. Such forks and short spurs are removed later by pruning (third unit of the day), not by changing the thinning.