Image processing operations often use both dilation and erosion at the same time. For example, the definition of a morphological opening of an image is erosion followed by dilation, using the same structuring element for both operations. The related operation, morphological closing of an image is the reverse: it consists of a dilation followed by erosion with the same structuring element.
The opening is a composite operator, constructed from the two basic operators’ dilation and erosion as described above. Dilation expands an image object and erosion shrinks it. Opening generally smooths a contour in an image, breaking narrow necks and eliminating thin protrusions.
Opening of the set, A by set B is achieved by first eroding set A by B, then dilating the resulting set by B. The opening of A by B, denoted by , is given by the erosion by B, followed by the dilation by B, that is
So, the Opening is
An erosion followed by a dilation.
breaks narrow isthmuses, and eliminate thin protrusions.
can open a gap between two regions joined by a narrow bridge of pixels.
can be used to separate two regions that should be distinct.
the advantage over erosion is that the regions are returned to their original size, minus the connecting pixels.
The closing, like the opening, is also a composite operator. The closing of set A by set B is achieved by first dilating of set A by B, then eroding the resulting set by B. Closing tends to narrow smooth sections of contours, fusing narrow breaks and long thin gulfs eliminating small holes, and filling gaps in contours. Closing is the dual operation of opening and is denoted by A●B
In the following figure the closing (given by the dark dashed lines) of A (given by the solid lines). The structuring element B is a disk. The external dashed structure is A dilated by B. This is like 'smoothing from the outside'. Holes are filled in and narrow valleys are closed'