Activity 7: Morphological Operations

In image processing, Morphological operations are used to understand the form of an image. It is based on the Mathematical morphology theory. But this activity won’t be dealing much with the mathematical part since we are more concerned with how it is applied in images.

Basically, what we’ll be doing is binary morphology . This is done by having an image, say a shape, then another image which is (another) pre-defined arbitrary shape, which is called a Structural element (s.e.). The s.e. is used to probe the shape and in the process, a conclusion is drawn on how the s.e. fits or misses the shape. To show a clearer image on how it is done we look at the two morphological operations: (1) Erosion and (2) Dilation.

Erosion

It can be described by the mathematical expression.

wherein all points z such that when B is translated in z is contained in A [1]. An example is shown in figure 1. The shape is a 5×5 square (bottom) and the s.e. is a 2×1 (ones) pixel.  A reference pixel from the s.e. was selected shown as the blue area. We also call this as the output pixel for easier demonstration. The rest of the other pixels are taken as surrounding pixels. For erosion, all the surrounding pixels must be 1 for the output pixel to be 1. This function is usually used in eliminating white noise in black background.

Figure 1. Erosion of a 5x5 square  with a 2x1 ones pixel.

Dilation

It can be described by the mathematical expression.

wherein all points z such that when B is translated in z  and is coincided with A will not give an empty set [1]. Dilation is the opposite erosion. As long as any of the surrounding pixels have the value of 1, the output pixel becomes 1. Similarly, it also means that ass long as all the surrounding pixels are black, the output pixel is black.

Figure 2. Dilation of a 5x5 square  with a 2x1 ones pixel.

For more demonstrations (Yay!), we have these shapes that was generated using Microsoft Paint (fig. 3). The grids in paint were relatively small so I decided to use 2×2 square grids as 1 pixel representation. (Note: The minimal size of the grids in the images causes distortion once posted in this blog. You might have to open the image to clearly see it. Also, this was supposed to be hand-drawn in graphing paper as suggested in the activity but to save paper I decided to do it via computer. :P)

Figure 3. Paint-generated shapes

Also, 5 different structural elements were generated: 2×2 square, 2×1 ones, 1×2 ones, 3×3 plus sign, and a diagonal pixel line. Just like what was shown in the first two examples, the reference pixels are highlighted blue.

Figure 4. Paint-generated structural elements

We can say that the method is fairly simple. With that, we can predict the resulting images by eroding and dilating it manually. Eroding the shapes with each of the s.e., the images shown in fig.5 is obtained.

Figure 5. (Paint-generated) Predicted images (bottom) of the different shapes eroded with its corresponding structural elements (top). The original image is shown at the leftmost part.

The s.e. and its corresponding eroded/dilated image are aligned vertically. The original image is also shown (bottom leftmost) for reference/comparison. In figure 5, the blue area of the resulting image, which is is the remaining part of the eroded original image, is now the output image. On the other hand, in figure 6, the blue area + white area of the resulting image comprises the output image. Think of the blue areas as extended pixels of the image.

Figure 6. (Paint-generated) Predicted images (bottom) of the different shapes dilated with its corresponding structural elements (top). The original image is shown at the leftmost part.

Now to confirm if the predicted outputs are right, we simulate using Scilab. I used Scilab 4.1.2 + SIP toolbox for this one since it has the erode() and dilate() functions. First off, we create the shapes and structural elements (again..) but this time using Scilab.

Then using the said functions, the erosion and dilation was done. Some of the code snippets are shown below.

//Erosion
//erosion of 5x5 square by 2x2 square
sq_er = erode(sq, se1);
scf()
imshow(sq_er);

//Dilation
//dilation for 3x4 triangle by 3x3 plus sign
tri_di = dilate(tri, se4);
scf()
imshow(tri_di);

The functions both require two inputs: the binary shape and the binary s.e.. Then voila! we have the eroded/ dilated image, of course with the use of the imshow() function.

For better comparison, the shapes, structural elements and their corresponding eroded and dilated images were show in tabular form.

Figure 7. Scilab-generated eroded shapes with corresponding structural elements

Figures 5 and 6  shows all the resulting images. The rows show the different shapes while the columns are the structural elements and their intersections are the output images.

Figure 8. Scilab-generated dilated shapes with corresponding structural elements

Comparing the predicted images from the resulting images , it can be seen that indeed they are the same! 😀 It can be observed that dilating/eroding the shapes with a certain structural element results to an image that more or less resembles the shape of the said s.e.

From all of this, it can be concluded that generally, eroding an image reduces its shape by making it ‘thinner’ while dilating the image increases the shape by making it ‘thicker’. But the change in shape actually depends on the structural element used. This can be observed in its applications. For erosion, a scanned image of a paper that seems to have blotted pen writings can be read more clearly by eroding the text. While for dilation, a unseen detail in an image due to it’s thinness can be seen by dilating the image.

For this activity, I give myself a happy 10/10. ^_^  

Reference:

1. M. Soriano, AppPhysics 186 Manual – Activity 7 Morphological Operations 2012.

2 Comments (+add yours?)

  1. sofa beds Queensland
    Oct 30, 2012 @ 14:59:01

    Magnificent goods from you, man. I have keep in mind your stuff prior to and you’re simply too wonderful. I really like what you’ve received here, certainly
    like what you are saying and the best way by which you assert it.
    You are making it entertaining and you still care for to
    stay it wise. I can not wait to read far more from you. This is
    actually a great website.

    Reply

  2. binary options trading signals
    Mar 04, 2014 @ 13:49:03

    Thank you forr anyy other magnificent post. Where
    else could anyone get that kind of information in such a perfect means
    of writing? I havve a presentation next week, and I am at thhe search for
    such information.

    Reply

Leave a comment