Morphological operations

What is morphology

Morphological operations on a image take as input a binary image (see page) and a structuring element (usually a3×33 \times 3matrix, also known as kernel) and use it to transform the image into another one.

The structuring element can be, for instance, the matrix (its central point is called the origin):

[111111111]\begin{bmatrix} 1 & 1 & 1 \\ 1 & 1 & 1 \\ 1 & 1 & 1 \end{bmatrix}

and it get passed over each pixel of the image in such a way that the origin is overlayed to the pixel, so that corresponding values are compared: if values match, the image pixel gets set to a pre-defined value. In the figure, the kernel is represented by the matrix in blue, shifted over the image matrix in black.

What are these operations

The main morphological operations are:

  • Dilation: enlarges objects

  • Erosion: shrinks objects

  • Opening: removes boundary pixels

  • Closing: fills boundary pixels

There are several other ones, and for some more comprehensive explanations refer to the references.

Dilation and erosion are the main morphological operations, all the other ones are combinations of these.

Consider the binary image in the figure as an example, there is a black background and a foreground object.

  • dilation dilates the borders of the object

  • erosion erodes the borders of object

In dilation, the borders of the foreground are expanded so the object appears enlarged; in erosion those borders get reduced, so the object appears shrunk.

The morphological gradient is the difference between dilation and erosion, the result of which is the outline of the object.

Opening consists in an erosion operation followed by dilation operation and it is used to remove noise. It is called like this because it can fill in ("open") a gap between bunches of pixels.

Closing on the other hand, is dilation followed by erosion and what it does is filling in the small holes in the objects.

Warning: note that in my drawing here, the one referring to closing, there shouldn't be any line between the two blocks of the closed image. You will forgive my mistake!

Other relevant operations are

  • Top hat is the difference between image and opening of image.

  • Black hat is the difference between image and closing of image

  • Hit or miss is done with two kernels: one used to erode the image and the other to erode the complement of image. Then an AND of the two results is performed.

References

  1. Morphology, page by the University of Edinburgh, School of Informatics