Activity 07: Morphological Operation


Morphology refers to shape.  This is usually done to images with blobs that form a specific shape.  What it can usually do is eliminated few pixels, fill gaps in between or even connect separate blobs of pixels to improve its shape.  The background is of the value zero, and the foreground is 1.  
Dilation and erosion are morphological operations to used in this activity.
Dilation of A by B is given by the equation:
B is the structuring element such that the effect of dilating is to EXPAND or ELONGATE A in the shape of B.  This is illustrated in the figure below.
Dilation by structuring element B on A, and the result of expansion of A.
Erosion, on the other hand, would REDUCE the shape A by the shape B.  This is given by the equation:
and is illustrated in the figure below.
Erosion be structuring element B on A, and the result of reduction of A.
Erosion and dilation are duals such that having a shape A, and structuring element B:
The following shapes considered are as follows:

  • 5 x 5 square
  • a triangle, base=4 boxes, height = 3 boxes
  • A hollow 10 by 10 square, 2 boxes thick
  • A plus sign, one box thick, 5 boxes along each line.

Now, the structuring elements to be used are:

  • 2 x 2 ones
  • 2 x 1 ones
  • 1 x 2 ones
  • cross, 3 pixels long, one pixel thick
  • a diagonal line, two boxes long, i.e. [0 1; 1 0]

The first part of the activity was to predict the resulting image if the structuring elements were used to erode and dilate the shapes.
Note that the shapes are shown below.
5 by 5 square, cross, hollow square, and a triangle shapes to be dilated and eroded.
The structuring elements to be used are shown below. (For reference)  Note that the black color indicate 1 in pixel value. (Black in figure to show the effectively show the structuring element).
Structuring elements to be used for dilation and erosion on the shapes above.

Predictions

The prediction was done using a graphing paper, a pencil, and a pentel pen.  My prediction are shown on the next figure.
Predictions for the possible outputs in dilating and eroding the shapes with the structuring elements.
For the application of dilation and erosion in Scilab, the first problem encountered was that I was using Scilab 5.3.3 which initially has no such functions.  What I needed to do was install Image Processing D (IPD) in order to have such functions.  I did try installing it but it was not successful.  My next option was to use SIP toolbox in Scilab 4.1.2.  I encountered errors on loading the toolbox.  However I must thank Aimee for letting me know what I must do to correct this.  I first loaded the siptoolbox, which will result to errors.  After which, I typed the following on the command line:
Then I reloaded the siptoolbox, and YEY! It was successfully loaded.  Now I used erode(), and dilate() functions to the shapes and structuring elements and saved it as an image.  The syntax is given by:
erode(shape, structuring_element)
dilate(shape, structuring_element).

Results

The next problem was that Scilab 4.1.2 siptoolbox does not have any imresize() function.  This therefore comes as an issue in displaying the results since it would be too small.  So I used Scilab 5.3.3 to resize all my results to 200 by 200 pixel size.
The results are are as below.
Dilation and erosion by the various structuring elements on a 5 by 5 square.
Dilation and erosion by the various structuring elements on the cross.
Dilation and erosion by the various structuring elements on the hollow box.
Dilation and erosion by the various structuring elements on the triangle.
Comparing my predicted results are similar to that of the expected.  The more difficult part was remembering which part of the structuring element must coincide with the pixel of shape in order to dilate or erode successfully.  It was a bit tricky when I was drawing it.

On different shape..

I also tried it on a figure that I created as shown in the figure below.  This shows that the morphological operations can either join parts or even eliminates small parts which can be useful in image processing if you wish to account only big blobs or such.
Erosion and dilation on a single image with various structuring elements.
For this activity, I give myself a 10/10 for successfully producing the results, and predicting the possible outcomes.  Again, I thank Aimee for your help in correcting the error in Scilab 4.1.2..


Reference:
"AP186 A7 - Morphological Operations", Dr. Maricor Soriano, 2012

Comments

Popular posts from this blog

Activity 2: Scilab Basics

Activity 10: Applications of Morphological Operations - Looping through Images

Activity 11: Color Image Segmentation