Q8Digital Image Processing
Question
Q.4. (a) Apply image erosion on the following 5x5 input image by using 3x3 cross-shaped structuring element (origin at center): Input image = [[1,1,0,1,1],[0,1,1,1,0],[1,1,1,0,1],[0,1,1,1,0],[1,1,0,1,0]]. Structuring element = [[0,1,0],[1,1,1],[0,1,0]] with origin marked at center. [8]
(b) Discuss image closing morphological operation by using its mathematical representation. [8]
Answer
Eroding the given 5x5 image with the 3x3 cross-shaped structuring element leaves only one surviving pixel at row index 2, column index 1, since it is the only position whose entire cross-shaped neighborhood is all 1s, giving output [[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]]; image closing (dilation followed by erosion) fills small holes/gaps while preserving overall object shape.
(a) Numerical: Erosion with a Cross-Shaped Structuring Element
We are given the 5x5 binary image [[1,1,0,1,1],[0,1,1,1,0],[1,1,1,0,1],[0,1,1,1,0],[1,1,0,1,0]] and the 3x3 cross-shaped structuring element [[0,1,0],[1,1,1],[0,1,0]] with its origin at the center. Erosion with this cross-shaped structuring element sets an output pixel to 1 only if the pixel itself AND all of its 4-connected neighbors (up, down, left, right) are equal to 1 in the input image; if any of these five positions is 0, or falls outside the image boundary, the output pixel becomes 0.
Checking the surviving pixel at row index 2, column index 1
At position (row index 2, column index 1), the center value is (2,1) = 1. Its four orthogonal neighbors are: up = (1,1) = 1, down = (3,1) = 1, left = (2,0) = 1, right = (2,2) = 1. All five positions (center plus four neighbors) are equal to 1, so this pixel survives erosion and remains 1 in the output.
Example of a failing pixel for contrast
Consider position (row index 1, column index 1), value (1,1) = 1. Its neighbors are: up = (0,1) = 1, down = (2,1) = 1, left = (1,0) = 0, right = (1,2) = 1. Since the left neighbor (1,0) = 0, this position fails the erosion test and becomes 0 in the output, even though the center pixel itself was 1. This illustrates that erosion requires the entire cross-shaped neighborhood, not just the center pixel, to be 1.
Checking every other position in the image similarly (each interior position's full cross neighborhood, and noting that all border positions automatically fail since part of their cross-shaped neighborhood falls outside the image boundary and is treated as 0) confirms that no other position besides (row index 2, column index 1) has its entire five-position cross neighborhood equal to 1. Therefore only this single pixel survives the erosion operation.
- Erosion rule with cross SE: output pixel = 1 only if center AND all 4 orthogonal neighbors = 1 in input
- Surviving pixel at (row 2, col 1): center=1, up=(1,1)=1, down=(3,1)=1, left=(2,0)=1, right=(2,2)=1, all 1s
- Failing example at (row 1, col 1): center=1 but left neighbor (1,0)=0, so this pixel fails and becomes 0
- Border pixels automatically fail since part of their cross neighborhood lies outside the image
- Final eroded output: only (row index 2, col index 1) remains 1; all other 24 positions become 0
(b) Image Closing
Closing is the dual morphological operation to opening, defined as dilation followed by erosion using the same structuring element B, written mathematically as:
The initial dilation step grows object A outward, filling in small holes, narrow gaps, and concavities within or between object regions, since the expanding structuring element bridges across these small gaps. The subsequent erosion step, using the same structuring element, then shrinks the dilated result back down, restoring the overall size and outer boundary of the object regions to approximately their original dimensions.
The net effect of closing is that small holes and gaps are permanently filled (since they were closed during the dilation step and cannot reopen during the subsequent erosion), while the overall shape and size of the object is largely preserved. Closing smooths object contours from the inside, filling in small concave notches and holes. It is commonly used to fill small holes within segmented objects and to connect nearby object fragments or touching-but-disconnected shapes into a single coherent region.
Relating this back to the erosion numerical example in part (a): the eroded output there is almost entirely 0, with only a single surviving 1 pixel at (row index 2, column index 1); if closing (dilation followed by erosion) were instead applied to the original input image using the same cross-shaped structuring element, the initial dilation step would first grow the many scattered 1-regions of the original image outward, very likely filling in several of the small isolated 0-valued gaps that exist between nearby 1-pixels throughout the image, and the subsequent erosion step would then shrink this dilated result back down, but any gaps that were completely filled during dilation would remain filled after erosion, since erosion cannot recreate a hole that dilation has already closed. This demonstrates concretely how closing, unlike erosion alone (which only shrinks and removes structure), can both fill small gaps and largely preserve the overall size of the surviving 1-regions, which is precisely the intended purpose of the closing operation in cleaning up small imperfections in a binary image without destroying the primary shapes present.
The single surviving pixel result in this example directly illustrates erosion's fundamental shrinking/thinning behavior: only a pixel whose ENTIRE structuring-element-shaped neighborhood (in this case, the pixel itself plus its four cross-adjacent neighbors) consists entirely of foreground (1) values survives the erosion operation unchanged; every other pixel, including many that are themselves foreground pixels in the original image, is set to 0 in the output if even a single position within its structuring-element neighborhood happens to be a background (0) value or lies outside the image boundary. This demonstrates why erosion is so effective at removing small objects, thin protrusions, and isolated noise pixels entirely (since such small/thin features generally cannot satisfy the requirement that their full neighborhood, in every direction covered by the structuring element, also be foreground), while only substantial, sufficiently thick regions of connected foreground pixels can survive erosion with at least some pixels remaining, exactly as observed in this problem where only the single, most centrally-embedded qualifying pixel location survives out of the original 5x5 image's many foreground pixels.
This single-surviving-pixel example similarly illustrates erosion applied to a comparatively densely-populated input image, showing that even a seemingly foreground-rich 5x5 image can erode down to almost nothing once the structuring element requires simultaneous agreement across its full cross-shaped footprint at every candidate position.
As with the companion dilation example, students should verify erosion results by explicitly checking each candidate pixel position against the full structuring-element footprint rather than estimating visually, since erosion outcomes can be highly sensitive to small differences in the input image near object boundaries.
Both erosion and closing, being fundamental morphological operations, are frequently combined in practical image-processing pipelines - erosion alone is useful for removing small noise artifacts and shrinking object boundaries, while closing (dilation followed by erosion) is specifically useful for filling small holes and gaps within objects and smoothing outward-facing boundary irregularities without significantly changing the overall object size, illustrating how the four basic morphological operations (erosion, dilation, opening, and closing) are typically combined in sequence to achieve a desired shape-processing outcome that no single basic operation alone could achieve.