Home > Image Processing > 9. Morphological Operations

9. Morphological Operations

Morphological operations, such as erosion and dilation, transform images such that each output pixel is defined by the application of a rule on the input pixel and its neighbors.  The following table (adapted from Mathworks) summarizes the rules for these basic operations:

Operation Rule
Erosion The value of the output pixel is the minimum value of all the pixels in the input pixel’s neighborhood. In a binary image, if any of the pixels is set to 0, the output pixel is set to 0.
Dilation The value of the output pixel is the maximum value of all the pixels in the input pixel’s neighborhood. In a binary image, if any of the pixels is set to the value 1, the output pixel is set to 1.

The neighborhood of a certain pixel is defined by the structuring element used in the operation.  The function applies the rule to the input pixel and its neighbors based on the center point of the structuring element, and then assigns a value to the corresponding output pixel.  Figure 1 illustrates dilation with a 3-pixel horizontal line.

Figure 1. Morphological dilation operation with a horizontal line.  Courtesy of Mathworks.

Morphological erosion and dilation operations follow the Set Theory.  The erosion of A by structuring element B is expressed as:

This results to the reduction of the image by the shape of B.

On the other hand, the dilation of A by structuring element B is denoted by:

This results to the expansion or elongation of A in the shape of B.


In the succeeding sections, we will see the actual effect of these morphological operations on images with certain shapes when they are operated with particular strels (shortcut for structuring elements).  We have the following initial shapes:

  1. a 5×5 square
  2. a triangle (base = 4 boxes, height = 3 boxes)
  3. a 10×10 square hollow (2 boxes thick)
  4. a plus sign (one box thick, 5 boxes along each line)

The structuring elements with which we will apply the morphological rules with will be the following:

  1. 2×2 ones
  2. 2×1 ones
  3. 1×2 ones
  4. a cross (3 pixels long, one pixel thick)
  5. a diagonal line (2 pixels long, i.e. [0 1; 1, 0])

We apply the operations using Scilab’s erode() and dilate() functions, which are implemented through the following:

E = erode(Img, [SE, center])

where Img is the MxN binary image to be eroded, SE the arbitrary structuring element represented as a binary array, and center the origin of the structuring element.  Similar implementation is done with the dilate() function.

Note that the center of each structuring element should be assigned to a pixel of value 1 or “ON”.  The center for the cross strel will be pixel [2, 2].  For strels with even-numbered dimensions such as first three items listed, the center can be assigned to pixel [1, 1], while diagonal strel can have the pixel [2, 1] as center.


The transformations resulting after erosion are shown in Figure 2, where the first row displays the initial shapes and the leftmost column displays the structuring elements.

Figure 2. Morphological erosion of basic shapes by certain structuring elements.

On binary images, erosion reduces the figures by the shape of the structuring element.  On grayscale images, the operation reduces the brightness of objects.  On certain practical applications, it is able to remove small irregularities from the image by subtracting objects that are of smaller radius compared to the structuring element.


The results for morphological dilation is shown below (Figure 3).

Figure 3. Morphological dilation of basic shapes by certain structuring elements.

The dilation of binary images connects sections that are parted by spaces smaller compared to the structuring element.  On grayscale images, this function increases the brightness of objects.  Practical applications of this is usually to increase the size of objects and remove holes and broken areas.

Other operations such as skel and thin also impose different rules in processing images.

Using thin performs thinning of the image by means of border deletion using the Zhang-Suen technique.  The function gives an output similar to Figure 4, which was implemented simply by:

out = thin(img)
Figure 4. Morphological thinning of a stick figure.

The function skel, on the other hand, does a skeletonization of the image using the Medial Axis Transform.  Some optional parameters for processing include side [interior (default), exterior or both] and algorithm [fast euclidean (default) or exact euclidean].  It can be performed with the following script:

[skl,dt,lbl] = skel(img, 'interior', 'fast euclidean'])

Below are the figures resulting from varying the side parameter.

Figure 5. Morphological skeletonization of a stick figure using fast euclidean algorithm. Left to right: interior side, exterior side, both sides.

The fast and exact euclidean algorithm make little difference in their results.  It is only that the exact method runs relatively slower than the other.

These basic morphological operations are often used for further image processing and/or extracting information from the image.  An article following this post (soon) aims to make useful application of these methods.

I would rate myself 11 for this activity for completing the tasks and investigating for other morphological functions.

[1] Soriano, 2010. Morphological operations. Applied Physics 186.
[2] Mathworks, 2010. Morphology fundamentals: Dilation and erosion. Image processing toolbox.
[3] IDL Astronomy User’s Library, 2007. Eroding and dilating image objects. NASA Goddard Space Flight Center.
[4] Wikipedia, 2010. Mathematical morphology.
[5] SIP, 2010. Scilab Image Processing Toolbox. Sourceforge Reference.

Categories: Image Processing Tags: ,
  1. Ralph Dratman
    July 21, 2012 at 9:46 am

    This is helpful. Thank you! You have explained this very effectively. I like your blog.

    Do you recommend any software package for such work?

    I have been doing some binary image morphology processing in Mathematica, which has a good set of functions for operating on images from a worksheet. However, I would also like to know about any other applications (preferably open source!) which can handle scripted image processing. I ask for “scripted” because I need a set of processing steps I which can be repeated on various images.

  1. August 31, 2010 at 12:17 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: