Erosion, dilation, opening, closing and boundaries in plain words, with every slide example and past question solved in answer-script form and a pixel-by-pixel simulator next to each.
Slide 3. Morphological image processing is used to extract image components for representation and description of region shape, such as boundaries, skeletons and the convex hull.
Slide 4. It relies only on the relative ordering of pixel values, not on their numerical values. We probe the image with a small shape or template called a structuring element. The language of mathematical morphology is set theory.
Slide 5. Morphology applies simple rules and shapes (squares, circles, diamonds, cubes, spheres) to process images. The objective is usually to identify features of interest, as a prelude to high-level inspection or machining. Two kinds: binary morphology and grey-level morphology. Four basic operations for binary images: erosion, dilation, opening and closing.
Slide 6. Binary image convention: each pixel is 0 or 1; foreground (object) = 1 (white), background = 0 (black).
A structuring element is a small image or template, a small binary array, that produces a new image from the old one. It is a shape mask used in the basic morphological operations. It can be any shape and size that is digitally representable (box, hexagon, disk, any shape), and each has an origin.
It works as a moving window, so non-rectangular shapes are stored as rectangular arrays (padded with 0s). For simplicity we use rectangular SEs with their origin point; the origin can be at the middle or at any position, and by default it is at the centre.
| 1 | 1 | 1 |
| 1 | 1 | 1 |
| 1 | 1 | 1 |
| 0 | 1 | 0 |
| 1 | 1 | 1 |
| 0 | 1 | 0 |
| 0 | 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 1 | 0 |
| 1 | 1 | 1 | 1 | 1 |
| 0 | 1 | 1 | 1 | 0 |
| 0 | 0 | 1 | 0 | 0 |
| 1 | 1 | 1 |
| 1 | 1 | 1 |
| 1 | 1 | 1 |
Slide 11. Put the SE on the image:
All morphological processing operations are based on these simple ideas: erosion uses fit, dilation uses hit.
Slide 12. Fundamentally, morphological processing is very like spatial filtering: the SE is moved across every pixel and gives one pixel of the new image, whose value depends on the operation performed. The two basic operations are erosion and dilation.
Fill in the fit/hit table for the three positions A, B, C of the binary image, with s1 = 3×3 square and s2 = 3×3 cross (origin at the centre).
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 |
| 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 1 | 1 | 1 |
| 1 | 1 | 1 |
| 1 | 1 | 1 |
| 0 | 1 | 1 |
| 1 | 1 | 1 |
| 1 | 1 | 1 |
| 0 | 0 | 0 |
| 0 | 0 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
| 1 | 1 | 1 |
| 1 | 1 | 1 |
| 0 | 1 | 0 |
| 1 | 1 | 1 |
| 0 | 1 | 0 |
| position | fit s1 | fit s2 | hit s1 | hit s2 |
|---|---|---|---|---|
| A | yes | yes | yes | yes |
| B | no | yes | yes | yes |
| C | no | no | yes | no |
A is all 1s, so both fit and both hit. B has a 0 in one corner: the square does not fit (that corner), but the cross does (it ignores corners). C has a single 1 in a corner: the square hits it, the cross misses it completely.
Slides 14–15. Erosion shrinks the object: it shrinks the foreground and enlarges the background. One of its simplest uses is eliminating irrelevant details from a binary image.
Slide 16. Definition 1 (does the SE fit the set?). Erosion of a set A by SE B is the set of all points z such that B translated by z is contained in A:
Slide 17. Definition 2. The SE s is positioned with its origin at (x, y) and the new pixel value is
Slide 18. How to compute: for each foreground pixel (the input pixel), superimpose the SE so that its origin coincides with the input pixel. If every SE pixel lies on a foreground pixel of the image, the input pixel stays as it is; if any of them lies on background, the input pixel is set to background.
Input 1 0 0 0 1 1 1 0 1 1, SE [1 1 1] with the origin at the centre. At each position take the minimum of the three values under the SE (superimpose and multiply: all three must be 1). The two end pixels are ignored.
| position | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|---|---|---|---|---|---|---|---|---|
| window | 1 0 0 | 0 0 0 | 0 0 1 | 0 1 1 | 1 1 1 | 1 1 0 | 1 0 1 | 0 1 1 |
| minimum | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 |
Output: 0 0 0 0 1 0 0 0. Only the middle of the 1 1 1 run survives.
Try it, step by step: the 1-D example, position by position (switch the menu to dilation for slides 50–57).
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
| 0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 |
| 0 | 1 | 1 | 1 | 1 | 0 | 0 | 0 |
| 0 | 1 | 1 | 1 | 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 1 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 1 | 1 |
| 0 | 1 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
Only 5 pixels keep the whole cross inside the object. Every boundary pixel had at least one cross arm on background.
Try it, step by step: erosion example 1, every one of the 64 positions (slides 27–38).
Slide 39. Erosion can split apart joined objects and strip away extrusions. Watch out: erosion shrinks objects.
Slide 40. Typical uses: removes isolated noisy pixels; smoothes the object boundary (removes spiky edges); removes the outer layer of object pixels, so the object becomes slightly smaller (sets contour pixels to the background value).
Slide 41. Effects: shrinks the size of foreground (1-valued) objects; smoothes object boundaries; removes small objects. Rule: in a binary image, if any pixel in the neighbourhood defined by the SE is 0, the output is 0.
Slide 42. Eroding four times with an 11-pixel disk: the hole in the middle of the square grows as the border shrinks. A disk SE tends to round concave boundaries but preserves the shape of convex boundaries.
Count the number of coins in the given image by performing an erosion operation.
Slides 45–46. Dilation grows the object: it enlarges the foreground and shrinks the background. It takes two inputs: the binary image to be dilated and the SE (kernel) that decides the behaviour.
Slide 47. Definition 1 (does the SE hit the set?). Dilation of A by B is the set of all z such that the reflected B̂, translated to z, overlaps A by at least one element:
Slide 48. Definition 2:
Slide 49. How to compute: for each background pixel, superimpose the SE with its origin on the input pixel. If at least one SE pixel coincides with a foreground pixel, the input pixel becomes foreground; if all of them are background, it stays background. (B̂ = B for the symmetric square and cross, so you can skip the reflection.)
Same input 1 0 0 0 1 1 1 0 1 1, SE [1 1 1]. Now take the maximum of the three values under the SE (border pixels ignored).
| position | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|---|---|---|---|---|---|---|---|---|
| window | 1 0 0 | 0 0 0 | 0 0 1 | 0 1 1 | 1 1 1 | 1 1 0 | 1 0 1 | 0 1 1 |
| maximum | 1 | 0 | 1 | 1 | 1 | 1 | 1 | 1 |
Output: 1 0 1 1 1 1 1 1. Only position 2, whose window 0 0 0 has no 1 at all, stays 0.
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
| 0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 |
| 0 | 1 | 1 | 1 | 1 | 0 | 0 | 0 |
| 0 | 1 | 1 | 1 | 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 1 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 1 | 1 |
| 0 | 1 | 0 |
| 0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
| 0 | 0 | 1 | 1 | 1 | 1 | 1 | 0 |
| 0 | 1 | 1 | 1 | 1 | 1 | 1 | 0 |
| 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 |
| 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 |
| 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 |
| 0 | 1 | 1 | 1 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
The dilated pixels (the slide's green cells) are A ⊕ B − A: 16 new pixels, one layer all round.
Try it, step by step: dilation example 1, every position.
Slide 59. Bridging gaps: a low-resolution text with broken characters, dilated with the 3×3 cross [0 1 0; 1 1 1; 0 1 0]: the broken segments were joined.
Slide 60. Dilation can repair breaks and repair intrusions. Watch out: dilation enlarges objects.
Slide 61. Edge detection: 1. dilate the input image; 2. subtract the input image from the dilated image; 3. edges remain.
Slide 62. Typical uses: fills in holes; smoothes object boundaries; adds an extra outer ring of pixels onto the object boundary, so the object becomes slightly larger.
Slide 63. Effects: expands the size of foreground objects; smoothes object boundaries; closes holes and gaps. Rule: if any pixel in the neighbourhood defined by the SE is 1, the output is 1.
Dilation and erosion are duals: one can be written in terms of the other (they are not opposites). We can obtain the erosion of A by dilating its background Ac with the same SE and complementing the result.
Slide 71. Combinations of erosions and dilations give more interesting compound operations; the most used are opening and closing.
Slides 72–73. Opening of A by B, A ∘ B, is an erosion followed by a dilation:
| 0 | 0 | 0 | 0 | 1 | 1 | 1 | 0 |
| 0 | 0 | 0 | 0 | 1 | 1 | 1 | 0 |
| 0 | 0 | 0 | 0 | 1 | 1 | 1 | 0 |
| 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 |
| 0 | 1 | 1 | 1 | 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 1 | 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 1 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 1 | 1 |
| 0 | 1 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 |
| 0 | 0 | 0 | 0 | 1 | 1 | 1 | 0 |
| 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 1 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
Erosion leaves only the two centres where the whole cross fits, (1,5) and (5,2). Dilation puts a cross back on each. The narrow link between the two blobs (row 3) and the blob corners are gone: they were thinner than the SE.
Try it, step by step: the slide 74–87 opening: erosion pass, then dilation pass. Use “Next phase” to jump between them.
Slides 88–92. Effect of opening:
Examples: the letter j with noise specks loses the tiny spots without changing its core size. Opening a lines-and-circles image with an 11-pixel disk separates the circles from the lines: the lines are almost completely removed, the circles stay.
Slides 93–94. Closing of A by B, A • B, is a dilation followed by an erosion:
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 1 | 1 | 1 | 0 |
| 0 | 0 | 0 | 0 | 1 | 1 | 1 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 1 | 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 1 | 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 1 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 1 | 1 |
| 0 | 1 | 0 |
| 0 | 0 | 0 | 0 | 1 | 1 | 1 | 0 |
| 0 | 0 | 0 | 1 | 1 | 1 | 1 | 1 |
| 0 | 0 | 0 | 1 | 1 | 1 | 1 | 1 |
| 0 | 1 | 1 | 1 | 1 | 1 | 1 | 0 |
| 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 |
| 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 |
| 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 |
| 0 | 1 | 1 | 1 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 1 | 1 | 1 | 0 |
| 0 | 0 | 0 | 0 | 1 | 1 | 1 | 0 |
| 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 |
| 0 | 1 | 1 | 1 | 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 1 | 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 1 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
Dilation joins the two blobs across the gap. Erosion shrinks them back to their original outlines, but the new pixels (3,3) and (3,4) in the gap survive: closing bridged the gap without growing the objects.
Try it, step by step: the slide 95–108 closing: dilation pass, then erosion pass.
Slides 109–113. Effect of closing:
Examples: closing with a 22-pixel disc closes the small holes in the foreground (pizza image); threshold a telephone photo, then close with a disc of size 20 to fill the reflections.
The input map of Africa (white land) has black text "Northern Africa", "South Africa" written on it; the output is the solid white shape. Which operation was applied?
Closing. The black letters are small dark holes and gaps inside the white foreground. Dilation fills them (the SE touches the white on both sides of each stroke), and the following erosion restores the coastline, so the outline and the size of the continent are unchanged. Opening would not remove holes.
Slide 115. Applications of morphology: noise removal in scanned documents; medical imaging (blood vessel extraction); industrial inspection (defect detection); computer vision (object segmentation).
Slide 116. Opening is the dual of closing: opening the foreground pixels with a particular SE is equivalent to closing the background pixels with the same element. (A ∘ B)c = Ac • B̂.
Slides 118–120. Contours can be extracted by subtracting the eroded image from the original. First erode A by B, then take the set difference between A and the erosion. The thickness of the contour depends on the size of the SE.
Slide 121. Edge detection by dilation: (A ⊕ B) − A gives the pixels just outside the object (outer edge).
Construct a 6×6 binary image A and a 3×3 structuring element B. Using fundamental morphological operations, formulate an edge-detection algorithm for A with B, and demonstrate the procedure systematically with mathematical expressions.
Choose A = a 4×4 square in a 6×6 image; B = 3×3 square, origin at the centre.
| 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 1 | 1 | 0 |
| 0 | 1 | 1 | 1 | 1 | 0 |
| 0 | 1 | 1 | 1 | 1 | 0 |
| 0 | 1 | 1 | 1 | 1 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 |
| 1 | 1 | 1 |
| 1 | 1 | 1 |
| 1 | 1 | 1 |
Algorithm (inner boundary): 1. erode: A ⊖ B = {z | (B)z ⊆ A}; 2. subtract: β(A) = A − (A ⊖ B) = A ∩ (A ⊖ B)c.
Step 1: B fits only where the pixel and all 8 neighbours are 1, i.e. the inner 2×2. Step 2: removing those from A leaves the one-pixel ring.
| 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 | 0 | 0 |
| 0 | 0 | 1 | 1 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 1 | 1 | 0 |
| 0 | 1 | 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 0 | 1 | 0 |
| 0 | 1 | 1 | 1 | 1 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 |
Alternative (outer edge): (A ⊕ B) − A, dilation then subtraction, gives the ring just outside the square:
| 1 | 1 | 1 | 1 | 1 | 1 |
| 1 | 1 | 1 | 1 | 1 | 1 |
| 1 | 1 | 1 | 1 | 1 | 1 |
| 1 | 1 | 1 | 1 | 1 | 1 |
| 1 | 1 | 1 | 1 | 1 | 1 |
| 1 | 1 | 1 | 1 | 1 | 1 |
| 1 | 1 | 1 | 1 | 1 | 1 |
| 1 | 0 | 0 | 0 | 0 | 1 |
| 1 | 0 | 0 | 0 | 0 | 1 |
| 1 | 0 | 0 | 0 | 0 | 1 |
| 1 | 0 | 0 | 0 | 0 | 1 |
| 1 | 1 | 1 | 1 | 1 | 1 |
Try it, step by step: both edge algorithms: erode then subtract, or dilate then subtract.
Convention used: outside the image counts as background (0). Write the set definition before each operation; it earns the equation marks.
F (5×6) and B = 3×1 vertical [1; 1; 1] with the origin at the centre. Compute (i) the reflection of B (ii) F ⊕ B (iii) Fc ⊖ B (iv) (F ⊕ B) − F (v) the opening of F by B (vi) the closing of F by B, with equations.
| 0 | 0 | 0 | 0 | 0 | 1 |
| 0 | 0 | 1 | 1 | 1 | 0 |
| 0 | 1 | 1 | 1 | 1 | 0 |
| 0 | 1 | 1 | 1 | 0 | 0 |
| 1 | 0 | 0 | 0 | 0 | 0 |
| 1 |
| 1 |
| 1 |
(i) B̂ = {w | w = −b, b ∈ B}. B = {(−1,0), (0,0), (1,0)} → B̂ = {(1,0), (0,0), (−1,0)} = B. B is symmetric about its origin, so B̂ = B.
(ii) F ⊕ B = {z | (B̂)z ∩ F ≠ ∅}: a pixel becomes 1 if it, the pixel above or the pixel below is 1.
| 0 | 0 | 1 | 1 | 1 | 1 |
| 0 | 1 | 1 | 1 | 1 | 1 |
| 0 | 1 | 1 | 1 | 1 | 0 |
| 1 | 1 | 1 | 1 | 1 | 0 |
| 1 | 1 | 1 | 1 | 0 | 0 |
(iii) Fc ⊖ B = {z | (B)z ⊆ Fc}: complement F, then keep a pixel only if it and both vertical neighbours are 1 in Fc.
| 1 | 1 | 1 | 1 | 1 | 0 |
| 1 | 1 | 0 | 0 | 0 | 1 |
| 1 | 0 | 0 | 0 | 0 | 1 |
| 1 | 0 | 0 | 0 | 1 | 1 |
| 0 | 1 | 1 | 1 | 1 | 1 |
| 0 | 0 | 0 | 0 | 0 | 0 |
| 1 | 0 | 0 | 0 | 0 | 0 |
| 1 | 0 | 0 | 0 | 0 | 1 |
| 0 | 0 | 0 | 0 | 0 | 1 |
| 0 | 0 | 0 | 0 | 0 | 0 |
(iv) (F ⊕ B) − F = the pixels added by the dilation (an outer edge above and below the object):
| 0 | 0 | 1 | 1 | 1 | 0 |
| 0 | 1 | 0 | 0 | 0 | 1 |
| 0 | 0 | 0 | 0 | 0 | 0 |
| 1 | 0 | 0 | 0 | 1 | 0 |
| 0 | 1 | 1 | 1 | 0 | 0 |
(v) F ∘ B = (F ⊖ B) ⊕ B:
| 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 | 0 | 0 |
| 0 | 0 | 1 | 1 | 0 | 0 |
| 0 | 0 | 1 | 1 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 |
(vi) F • B = (F ⊕ B) ⊖ B:
| 0 | 0 | 1 | 1 | 1 | 1 |
| 0 | 1 | 1 | 1 | 1 | 1 |
| 0 | 1 | 1 | 1 | 1 | 0 |
| 1 | 1 | 1 | 1 | 1 | 0 |
| 1 | 1 | 1 | 1 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 | 1 | 0 |
| 0 | 1 | 1 | 1 | 1 | 0 |
| 0 | 1 | 1 | 1 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 |
Notice: the opening kept only the columns where the object is at least 3 pixels tall (columns 2–3), so everything thinner than B vertically is gone. The closing kept the whole object; the two isolated pixels (0,5) and (4,0) disappeared because they sit on the image border, where the erosion needs the pixel outside the image, which counts as 0.
Try it, step by step: SP22 / F23: every part, switch the Operation menu.
Images X and Y are given. (i) Design a structuring element B so that Y = X ⊕ B; mark the origin. (ii) Write the mathematical expression of the dilation. (iii) Erode Y with the same SE and show the eroded image. (iv) Explain erosion mathematically.
| 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 1 | 1 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 | 0 | 0 |
| 0 | 0 | 0 | 1 | 0 | 0 |
| 0 | 0 | 0 | 0 | 1 | 0 |
| 0 | 1 | 1 | 1 | 1 | 0 |
| 0 | 1 | 1 | 1 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 |
| 1 | 0 | 1 | 0 | 0 | 0 |
| 1 | 1 | 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 0 | 1 | 0 |
| 0 | 0 | 1 | 1 | 0 | 0 |
(i) Take an isolated pixel of X, e.g. (6,4). In Y it has become (5,4), (6,3), (6,2), (5,2), and (6,4) itself is gone. So B holds the offsets (−1,0), (0,−1), (0,−2), (−1,−2) relative to its origin, and the origin itself is not part of B (value 0). Every other pixel of X gives the same pattern, which confirms it.
| 1 | 0 | 1 |
| 1 | 1 | 0 |
Check: X ⊕ B reproduces Y exactly.
(ii) X ⊕ B = {z | (B̂)z ∩ X ≠ ∅} = {x + b | x ∈ X, b ∈ B}.
(iii) Y ⊖ B = {z | (B)z ⊆ Y}: z survives only if all four offsets from z land on 1s in Y.
| 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 1 | 1 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 | 0 | 0 |
| 0 | 0 | 0 | 1 | 0 | 0 |
| 0 | 0 | 0 | 0 | 1 | 0 |
Here Y ⊖ B gives back X exactly (this image is lucky; in general (X ⊕ B) ⊖ B is the closing, which can also fill gaps).
(iv) A ⊖ B = {z | (B)z ⊆ A}: the set of all origin positions z where the SE translated by z lies completely inside A. Equivalently, g(x,y) = 1 if B fits A at (x,y), else 0.
Try it, step by step: SP23 (i): X ⊕ B gives Y. The SE is not symmetric, so watch the reflected cells.
Try it, step by step: SP23 (iii): Y ⊖ B.
Binary image of the Greek letter θ. Which morphological operation(s) turn θ into the digit 0? Four SEs are given: SE1 horizontal 1×2, SE2 cross, SE3 vertical 2×1 (origin + below), SE4 vertical 3×1. Use any as many times as needed; explain the choice and show the outputs.
| 0 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 |
| 0 | 1 | 1 | 0 | 0 | 0 | 0 | 1 | 1 | 0 |
| 0 | 1 | 1 | 0 | 0 | 0 | 0 | 1 | 1 | 0 |
| 0 | 1 | 1 | 0 | 0 | 0 | 0 | 1 | 1 | 0 |
| 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 |
| 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 |
| 0 | 1 | 1 | 0 | 0 | 0 | 0 | 1 | 1 | 0 |
| 0 | 1 | 1 | 0 | 0 | 0 | 0 | 1 | 1 | 0 |
| 0 | 1 | 1 | 0 | 0 | 0 | 0 | 1 | 1 | 0 |
| 0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 |
| 0 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 | 0 |
What must go: the middle bar (row 6) is only 1 pixel tall. Every part of the ring is at least 2 pixels thick in the vertical direction. So an opening with SE3 (vertical, 2 pixels) removes the bar and keeps the ring: θ ∘ SE3 = (θ ⊖ SE3) ⊕ SE3.
Why not the others: SE1 is horizontal and the bar is long horizontally, so the bar survives. The cross (SE2) needs 3 pixels in both directions, which also deletes the thin ring corners. SE4 needs 3 pixels vertically, which deletes the 2-row top and bottom of the ring.
Step 1, erosion θ ⊖ SE3 (keep a pixel only if it and the pixel below are both 1). Step 2, dilation by SE3 (put back the pixel below every survivor).
| 0 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 | 0 | 0 | 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 0 | 0 | 0 | 0 | 1 | 1 | 0 |
| 0 | 1 | 1 | 0 | 0 | 0 | 0 | 1 | 1 | 0 |
| 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 |
| 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 |
| 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 |
| 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 |
| 0 | 1 | 1 | 0 | 0 | 0 | 0 | 1 | 1 | 0 |
| 0 | 1 | 1 | 0 | 0 | 0 | 0 | 1 | 1 | 0 |
| 0 | 0 | 1 | 0 | 0 | 0 | 0 | 1 | 0 | 0 |
| 0 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 |
| 0 | 1 | 1 | 0 | 0 | 0 | 0 | 1 | 1 | 0 |
| 0 | 1 | 1 | 0 | 0 | 0 | 0 | 1 | 1 | 0 |
| 0 | 1 | 1 | 0 | 0 | 0 | 0 | 1 | 1 | 0 |
| 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 |
| 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 |
| 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 |
| 0 | 1 | 1 | 0 | 0 | 0 | 0 | 1 | 1 | 0 |
| 0 | 1 | 1 | 0 | 0 | 0 | 0 | 1 | 1 | 0 |
| 0 | 1 | 1 | 0 | 0 | 0 | 0 | 1 | 1 | 0 |
| 0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 |
| 0 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 | 0 |
Try it, step by step: SP24: the opening with SE3, both passes.
Define dilation mathematically for a binary image. Explain the opening and closing operations. What happens when you apply closing to an image with small holes?
Dilation: A ⊕ B = {z | (B̂)z ∩ A ≠ ∅}: the set of all displacements z such that the reflected SE B̂, translated to z, overlaps A in at least one pixel. It grows objects, fills small holes and bridges gaps.
Opening A ∘ B = (A ⊖ B) ⊕ B, an erosion followed by a dilation: removes objects and protrusions smaller than B, breaks thin bridges and smooths the outline, without changing the size of the remaining objects.
Closing A • B = (A ⊕ B) ⊖ B, a dilation followed by an erosion: fills small holes and gaps, joins nearby objects, and smooths indentations, again without changing the core size.
Closing on small holes: the dilation fills every hole smaller than B (the SE reaches the object on all sides of the hole); the following erosion shrinks the object back to its original outline, but the filled holes cannot reopen because the SE now fits there. So the small holes disappear and the object's size and boundary stay the same (e.g. the pizza image closed with a 22-pixel disc).
Give the equations of erosion and dilation; describe opening and closing. / Describe two basic morphological operations with equations, effects and applications. / Define dilation and erosion in binary images; how do they affect object size and shape?
Erosion A ⊖ B = {z | (B)z ⊆ A}: a pixel stays 1 only where the SE fits inside the object. Effects: shrinks foreground objects (removes the outer layer), removes objects smaller than B, smooths the boundary by cutting spikes, can split touching objects, enlarges holes. Uses: removing isolated noise pixels, separating touching coins before counting, boundary extraction β(A) = A − (A ⊖ B).
Dilation A ⊕ B = {z | (B̂)z ∩ A ≠ ∅}: a pixel becomes 1 where the SE hits the object. Effects: expands foreground objects (adds an outer layer), fills small holes, bridges gaps, joins nearby objects, smooths intrusions. Uses: repairing broken characters in low-resolution text, filling holes, edge detection (A ⊕ B) − A.
Size and shape: erosion makes objects smaller and thinner (size shrinks by the SE radius); dilation makes them larger and thicker. The SE's shape decides the direction: a vertical SE acts only vertically, a disk rounds corners.
Opening (A ⊖ B) ⊕ B removes small objects and thin bridges, keeps size. Closing (A ⊕ B) ⊖ B fills small holes and gaps, keeps size. Both are idempotent.
What is a structuring element? What are the effects of erosion and dilation? Explain briefly with applications.
A structuring element is a small binary image (template) of any shape and size (square, cross, disk, line) with a defined origin. It is moved over the image like a filter mask, and at each position the fit or hit test between the SE and the image decides the output pixel.
Effects and applications of erosion and dilation: as in the answer above (erosion: shrink, remove noise, separate objects; dilation: grow, fill holes, bridge gaps, repair broken text).
Recipe: name the operation, give its equation, say what it does to this exact problem, and why the alternative would fail.
| the problem says… | use | why |
|---|---|---|
| small bright spots / specks on dark background | opening | erosion deletes specks smaller than B, dilation restores the real objects |
| small dark holes / pepper inside a white object | closing | dilation fills the holes, erosion restores the outline |
| broken characters, gaps in roads or lines | dilation, or closing to keep the width | the SE bridges the gap |
| touching coins / cells to count | erosion (repeated), then connected-component labeling | erosion breaks the thin necks between objects |
| remove small particles, keep big ones | opening with B larger than the small particles | small ones cannot contain B and vanish |
| outline / boundary of objects | β(A) = A − (A ⊖ B), or (A ⊕ B) − A | difference of the object and its eroded / dilated version |
| find corners, end points, a given shape | hit-or-miss transform (deck 12) | exact match of foreground and background pattern |
A satellite image of the AUST campus road network has noise (small bright spots), gaps in roads and overlapping structures. (i) Which morphological operation first removes the small bright spots, and why? (ii) After noise removal the roads are fragmented with small gaps: which operation connects them, and how? (iii) Develop the most suitable operation to highlight road boundaries. (iv) Can highlighting boundaries help distinguish roads from the background terrain?
(i) Opening, A ∘ B = (A ⊖ B) ⊕ B, with a small disk/square SE larger than the spots. The erosion deletes every bright spot that cannot contain B; the dilation then grows the roads back to their original width, so only the noise is removed. (Dilation first would enlarge the spots instead.)
(ii) Closing, A • B = (A ⊕ B) ⊖ B, with an SE a bit longer than the gaps (a line SE along the road direction works best). The dilation joins the road fragments across each gap; the erosion shrinks the roads back to their width, but the filled gaps stay filled, so the network becomes connected without fattening.
(iii) Boundary extraction β(A) = A − (A ⊖ B) with a 3×3 SE: erode the cleaned road image and subtract it from itself, leaving a one-pixel outline of every road. (Or (A ⊕ B) − A for the outer edge.)
(iv) Yes. The boundaries outline the road shapes sharply, separating them from the surrounding terrain; they can be used to segment, measure and map the road network.
(i) Automated coin counting: coins are circular blobs, but some touch. Which morphological operations separate touching coins for accurate counting, and why? (ii) A microscope image has small insignificant particles and larger ones: which operations remove the small ones but keep the large ones? Explain mathematically, with applications.
(i) Binarize the image, then apply erosion A ⊖ B = {z | (B)z ⊆ A} with a disk SE (repeated if needed). Touching coins are joined only by narrow necks; the disk cannot fit in a neck, so the necks disappear first and each coin becomes a separate, smaller blob. Then count the blobs with connected-component labeling (slides 43–44). Counting is not affected by the coins shrinking. (A dilation afterwards, i.e. an opening, would restore size, but could rejoin coins, so count after the erosion.)
(ii) Opening with an SE (disk) a little larger than the insignificant particles: A ∘ B = (A ⊖ B) ⊕ B. Erosion removes every particle that cannot contain B, i.e. all the small ones; the larger particles survive as shrunken cores, and the dilation grows them back to almost their original shape and size. Applications: cleaning cell or particle images before counting, removing dust in industrial inspection, removing noise in scanned documents.
An image is corrupted by salt-and-pepper noise in the object part only. Which morphological operation would you use to remove it? Explain the process.
Inside a white object, the visible noise is the pepper: small black dots, i.e. tiny holes in the foreground. Use closing A • B = (A ⊕ B) ⊖ B with a small (3×3) SE: the dilation fills each black dot because the SE touches white on all sides; the erosion then restores the object's outline. Any white specks left outside the object could then be removed with an opening (open–close filtering). The background is untouched because it has no noise.
Coins image: which morphological operation can be used to count the coins? Explain the process.
Erosion followed by connected-component labeling: binarize; erode with a disk to separate the touching coins (and remove small noise); label the connected components; the number of labels = number of coins.
(i) A text image has broken characters: which morphological operation joins them? (ii) Define opening and closing mathematically, with applications.
(i) Dilation with a small SE such as the 3×3 cross [0 1 0; 1 1 1; 0 1 0] (slide 59): any background pixel whose SE touches a character pixel becomes foreground, so the 1–2 pixel breaks are bridged and the characters become whole. A closing (dilation then erosion) joins the breaks the same way but returns the strokes to their original thickness.
(ii) Opening A ∘ B = (A ⊖ B) ⊕ B: removes small noise and thin bridges (cleaning scanned documents, separating objects). Closing A • B = (A ⊕ B) ⊖ B: fills small holes and gaps (repairing broken text, filling reflections in a thresholded object).
| operation | equation | effect |
|---|---|---|
| erosion | A ⊖ B = {z | (B)z ⊆ A} | shrink, remove small objects, split joins |
| dilation | A ⊕ B = {z | (B̂)z ∩ A ≠ ∅} | grow, fill holes, bridge gaps |
| opening | A ∘ B = (A ⊖ B) ⊕ B | remove specks and thin bridges, keep size |
| closing | A • B = (A ⊕ B) ⊖ B | fill holes and gaps, keep size |
| boundary | β(A) = A − (A ⊖ B) | inner outline |
| edge (outer) | (A ⊕ B) − A | ring outside the object |
| duality | (A ⊖ B)c = Ac ⊕ B̂ | erosion via the background |