Tuesday, August 31, 2010

Morphological Operations

Morphology is a term that refers to shape or structure and hence morphological operations are operations that involve the manipulation of shapes and structures. In image processing, most of the operations are done on a binary image where the background (values that are equal to zero) can easily be distinguished from the foreground (values that are equal to one). In doing so, the shapes found in that 'binarized' image can then be expanded, thinned, or internal holes may be closed up, disconnected blobs may then be connected and more.

The main concepts of morphological operations make use of the Set Theory but for this activity the highlighted concepts are Erosion and Dilation. It is important to note that Logical Operations are complementary to morphological operations.

The dilation of a shape, A, by a structuring element B is mathematically defined as


In image processing, this simply corresponds to the translation of the structuring element B onto a pixel of the shape A. Doing this for every pixel of the shape A results in the dilation of the shape A by the structuring element B. The translation of B onto A involves placing the center of the structuring element B onto every pixel of A. The effect of dilation is to expand or elongate A in the shape of the structuring element B.

On the other hand, the Erosion of A by the structuring element B is defined as


The erosion of A by B is the set of all points z such that B translated by z is contained in A. Its main effect is to reduce A by the shape of B. In image processing, take the center of B and place it onto a pixel in A, if the entire structuring element B is contained in A, then retain that pixel where the center of B is placed, otherwise, remove it. Doing this for the entire A results in the erosion of A by the structuring element B.

Erosion and Dilation are duals of each other and can be related by the following equation.



Consider the following shapes.


Figure 1: 5x5 pixel square


Figure 2: A triangle with a base of 4 pixels and height of 3 pixels.


Figure 3: Hollow 10x10 pixel square, 2 pixels thick


Figure 4: A plus sign, 1 pixel thick and 5 pixels along each line

In the convention of what has been discussed earlier, consider the shapes shown in figures 1 to 4 as the A's. The results of performing Dilation and Erosion on these shapes by a series of structuring elements are shown in the following figures.

Consider first the effect of Dilation.


Figure 5: Dilation by a 2x2 structuring element. The leftmost column shows the original shapes. The middle column shows the 2x2 pixel structuring element. The rightmost column shows the results of Dilating A by the structuring element B


Figure 6: Dilation by a 1x2 structuring element. The leftmost column shows the original shapes. The middle column shows the 1x2 pixel structuring element. The rightmost column shows the results of Dilating A by the structuring element B.


Figure 7: Dilation by a 2x1 structuring element. The leftmost column shows the original shapes. The middle column shows the 2x1 pixel structuring element. The rightmost column shows the results of Dilating A by the structuring element B.


Figure 8: Dilation by a cross structuring element. The leftmost column shows the original shapes. The middle column shows the cross structuring element. The rightmost column shows the results of Dilating A by the structuring element B. The cross is 3 pixels long and 1 pixel thick.


Figure 9: Dilation by a diagonal structuring element. The leftmost column shows the original shapes. The middle column shows the diagonal structuring element. The rightmost column shows the results of Dilating A by the structuring element B. The diagonal line is two pixels long.

Now consider the effect of Erosion.

Figure 10: Erosion by a 2x2 structuring element. The leftmost column shows the original shapes. The middle column shows the 2x2 pixel structuring element. The rightmost column shows the results of eroding A by the structuring element B


Figure 11: Erosion by a 1x2 structuring element. The leftmost column shows the original shapes. The middle column shows the 1x2 pixel structuring element. The rightmost column shows the results of eroding A by the structuring element B


Figure 12: Erosion by a 2x1 structuring element. The leftmost column shows the original shapes. The middle column shows the 2x1 pixel structuring element. The rightmost column shows the results of eroding A by the structuring element B


Figure 13: Erosion by a cross structuring element. The leftmost column shows the original shapes. The middle column shows the cross structuring element. The rightmost column shows the results of eroding A by the structuring element B. The cross is 3 pixels long and 1 pixel thick.

Figure 14: Erosion by a diagonal structuring element. The leftmost column shows the original shapes. The middle column shows the diagonal structuring element. The rightmost column shows the results of eroding A by the structuring element B. The diagonal line is two pixels long.

It is important to note that for the structuring element, if it is an even structure (2x2, 4x4, 2x1), or any structure whose center is not that obvious, always consider the center of that structure to be the top-left non-zero pixel of the presumed center of the structure. In this activity, this convention is followed though this may not be the general case. Determining the center of the structuring element is important because, as stated earlier, this center will be the basis for translating or projecting the structuring element onto the shape to be dilated or eroded. Figure 15 shows the center of the structuring elements used in this activity.


Figure 15: The red colored pixel of the structure is considered to be the center of that structure.

Scilab also has the functions dilate() and erode(). Implementing these functions on the shapes given by figures 1 to 4 by the structuring elements in figure 15 should give the same results as shown in figures 5 to 14.


Figure 16: Dilating figures 1 to 4 by the structuring elements in figure 15. This is done in Scilab using the function dilate(). The first column is dilated with the 2x2 square. The second column is dilated with the 1x2 line. The third column is dilated with the 2x1 line. The fourth column is dilated with the 'plus' sign. The fifth column is dilated with the diagonal line.

Figure 17: Eroding figures 1 to 4 by the structuring elements in figure 15. This is done in Scilab using the function erode(). The first column is eroded with the 2x2 square. The second column is eroded with the 1x2 line. The third column is eroded with the 2x1 line. The fourth column is eroded with the 'plus' sign. The fifth column is eroded with the diagonal line.

The results using scilab's dilate() and erode() functions shown in figures 16 and 17 jive with the predictions shown in figures 5 to 14.

There are also other morphological operations that can be found in scilab such as the thin() and skel() functions. According to its description in scilab, the skel() function performs skeletonization of a binary object. Its resulting medial axis is multi-scale, meaning that it can be progressively pruned to eliminate detail, and this pruning can be done by thresholding the output skeleton image. The thin() function, on the other hand, is a de facto standard and simple technique, with the resulting image not guaranteed to always have connected blobs or shapes and this algorithm is also very sensible to noise. The advantage of thin() though is that it works faster and for thin shapes, it provides better quality.


Figure 18: Implementing the function thin() on the images in figures 1 to 4. Column 1 is the result of implementing thin() on figure 1, column 2 corresponds to figure 2, column 3 corresponds to figure 3 and column 4 corresponds to figure 4.


Figure 19: Implementing the function skel() on the images in figures 1 to 4. Column 1 is the result of implementing skel() on figure 1, column 2 corresponds to figure 2, column 3 corresponds to figure 3 and column 4 corresponds to figure 4.

Depending on the application, the skel() and thin() function can be used to effectively determine the 'skeleton' of a certain shape or figure.

--
Technical Correctness: 4/5 (late posting)
Quality of Presentation: 5/5