# Morphological Operations: An Overview

Mathematical morphology is a tool for extracting image components useful in the represation and description of region shape, such as boundaries, skeletons and convex hulls. The language of mathematical morphology is set theory, and as such it can apply directly to binary (two-level) images: a point is either in the set (a pixel is set, or put to foreground) or it isn't (a pixel is reset, or put to background), and the usual set operators (intersection, union, inclusion, complement) can be applied to them.

Basic operations in mathematical morphology operate on two sets: the first one is the image, and the second one is the structuring element (sometimes also called the kernel, although this terminology is generaly reserved for convolutions). The structuring element used in practice is generally much smaller than the image, often a 3x3 matrix.

It is possible, however, to make a generalization to greylevel images.

## Morphological Operations on Binarized Images

### Erosion and Dilation

Erosion and dilation are two basic operators in mathematical morphology. The basic effect of erosion operator on a binary image is to erode away the boundaries of foreground pixels (usually the white pixels). Thus areas of foreground pixels shrink in size, and "holes" within those areas become larger.

Mathematically, erosion of set A by set B is a set of all points x such that B translated by x is still contained in A.

Let foreground pixels be represented by logical 1's, and background pixels by logical 0's. As a practical example, we take a 3x3 matrix of logical 1's, with the middle point chosen as the origin of the set is used as the structuring element B (see the picture).

To compute the erosion of a binary input image by this structuring element, we consider each of the foreground pixels in the input image in turn. For each input pixel we superimpose the structuring element on top of the input image so that the origin of the structuring element coincides with the input pixel coordinates.

1. If the input pixel is set to foreground and all its 8 neighbours are also set to foreground, then the pixel remains set to foreground.
2. If the input pixel is set to foreground, but at least one of its 8 neighbours is not, the pixel is set to background.
3. Input pixels set to background remain such.

With the structuring element chosen as above, the effect of this operation is to remove any foreground pixel that is not completely surrounded by other foreground pixels, assuming 8-connectedness. We can also see that this operation can be performed on binary images simply by applying a logical AND function.

Here is an example of image erosion:

On the left side there is the original image, on the right side is the eroded image.

The dilation is the other of the two basic operators in mathematical morphology, the first one being erosion. The basic effect of dilation on binary images is to enlarge the areas of foreground pixels (i.e. white pixels) at their borders. The areas of foreground pixels thus grow in size, while the background "holes" within them shrink.

Mathematically, erosion of A by B is the set of all x displacement such that B and A overlap by at least one non-zero element.

Again let us take a 3x3 matrix for the structuring element, with the center pixel used as the origin of the set. B, then the dilation can be performed using the logical OR function:

1. If the pixel is set to foreground, it remains such.
2. If the pixel is set to background, but at least one of its eight neighbours is set to foreground, the pixel is converted to foreground.
3. If the pixel is set to background and none of its eight neighbours is set to foreground, the pixel remains set to background.

An illustration of binary image dilation:

On the left side there is the original image, on the right side is the dilated image.

### Opening and Closing

The opening is a composite operator, constructed from the two basic operators described above. Opening of set A by set B is achieved by first the eroding set A by B, then dilating the resulting set by B.

Here is an example of binary image closing:

On the left side there is the original image, on the right side is the opened image.

The closing, like 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.

Here is an example of binary image closing:

On the left side there is the original image, on the right side is the closed image.

### Boundary Extraction

The boundary of set A can be found by first eroding A by B, then taking the set difference between the original A and the eroded A.

Here is an example of binary image outlining:

On the left side there is the original image, on the right side is the outlined image.

## Generalization to Greyscale Images

The ideas above can be extended to greyscale images as well. In greyscale images, each pixel can have the value in a certain range, i.e. 0 to 255, with 0 representing black and 255 representing white.

### Greyscale Erosion and Dilation

Greyscale erosion is analogous to its binary counterpart. Greyscale erosion darkens small bright areas, and very small bright areas like noise spikes or small spurs might be totally removed.

Working with a 3x3 structuring element as above, greyscale erosion is implemented as follows:

• the numerical values of the point and its eight neighbours are evaluated
• minimal value of these 9 values is found
• the new value of the point is set to the minimal value

On the left side there is the original image, on the right side is the eroded image.

Greyscale dilation is analogous to its binary counterpart. Greyscale dilation brightens small dark areas, and very small dark "holes" might be totally removed.

Working with a 3x3 structuring element as above, greyscale dilation is implemented as follows:

• the numerical values of the point and its eight neighbours are evaluated
• maximal value of these 9 values is found
• the new value of the point is set to the maximal value

On the left side there is the original image, on the right side is the dilated image.

### Greyscale Opening and Closing

Greyscale opening is, like its binary counterpart, achieved by first eroding the image with the structuring element, and then dilating the resulting image by the structuring element. The process darkens small bright areas, and may entirely remove very small bright spots like noise spikes.

On the left side there is the original image, on the right side is the opened image.

Greyscale closing is, like its binary counterpart, achieved by first dilating the image with the structuring element, and then eroding the resulting image by the structuring element. The process brightenes small dark areas, and may entirely remove very small dark "holes".

On the left side there is the original image, on the right side is the closed image.

### Top-Hat and Well Transformations

The Top-Hat Transform or peak detector is another composite operation: the image opened by the structuring element is subtracted from the original image. The brightest spots on the original image are highlighted using this transformation.

On the left side there is the original image, on the right side is the image after top-hat transform.

The Well Transform or valley detector is another composite operation: the image closed by the structuring element is subtracted from the original image. The darkest areas on the original image are highlighted using this transformation.

On the left side there is the original image, on the right side is the image after well transform.