Tuesday, July 21, 2009

Activity 8 - Morphological Operations

We have applied the basic image morphological operations dilation and erosion to some basic shapes in this activity. In Scilab, there are already built-in image morphological functions namely dilate and erode which are used here. Also, different structural elements are implemented in the dilation and erosion of images.

Dilation is defined by the expression


It states that the intersection of the translation of the reflection of B translated at z for all z's to A is not an empty set. Here, A is the image to be dilated by the structuring element B and z is the coordinate of image A.
Image dilation operates in the following algorithm. A certain location of B, which in this activity is its geometric center, is to be superimposed to every z in A. If at least one element of B coincides with the foreground of A, then the location in A being superimposed by the geometric center of B is to be replaced by one. Thus, if no elements of B coincide with any element in the foreground of A, then it is retained to zero. Recall that the background of A is equal to zero and the object or its foreground under morphological operation is equal to one.
Meanwhile, erosion is defined as the expression below



This means that all elements of B translated at z for all z's are contained in A.
Image erosion then has the following algorithm. The geometric center of B is to be superimposed to all z in A. If all elements of B are contained in A then the location in A being superimposed by the geometric center of B is to be retained to one and otherwise, if at least one element of B coincides with the background of A, it is replaced by zero.

The shapes that have been created and morphologically operated are a square with size 50 x 50, a right triangle with base 50 pixels long and height 30 pixels long, a circle with 25 pixels radius, a hollow square with size 60 x 60 and its edges are 4 pixels thick, and a plus sign with 50 pixels long for each line having thickness of 8 pixels. They are all made in Paint.
Meanwhile, the following structuring elements are used in dilating and eroding the images. A 4 x 4 ones, 2 x 4 ones, 4 x 2 ones, and a cross with 5 pixels long and 1 pixel thick. These are generated in Scilab as matrices shown below respectively.



Before simulating the effects of the morphological operations in the images, we have first predicted the outcome and draw this in yellow paper which is submitted to our professor Dr. Maricor Soriano.
Now, the following sets of figures are the results of the simulated morphological operations in the five images.

Square (Original Image)


Dilation
Structuring Element: 4 x 4, 2 x 4, 4 x 2, cross



Erosion
Structuring Element: 4 x 4, 2 x 4, 4 x 2, cross



Triangle (Original Image)



Dilation
Structuring Element: 4 x 4, 2 x 4, 4 x 2, cross



Erosion
Structuring Element: 4 x 4, 2 x 4, 4 x 2, cross



Circle (Original Image)



Dilation
Structuring Element: 4 x 4, 2 x 4, 4 x 2, cross



Erosion
Structuring Element: 4 x 4, 2 x 4, 4 x 2, cross



Hollow Square (Original Image)



Dilation
Structuring Element: 4 x 4, 2 x 4, 4 x 2, cross



Erosion
Structuring Element: 4 x 4, 2 x 4, 4 x 2, cross



Plus Sign (Original Image)



Dilation
Structuring Element: 4 x 4, 2 x 4, 4 x 2, cross



Erosion
Structuring Element: 4 x 4, 2 x 4, 4 x 2, cross



My predictions exactly match the simulated results. These are verified by measuring the pixel dimensions of the dilated and eroded images in Paint.

We also tried other two image morphological operations in Scilab namely thin and skel which mean thinning and skeletonization respectively. The following results are obtained.

Square (Original Image), Thinning, Skeletonization



Triangle (Original Image), Thinning, Skeletonization



Circle (Original Image), Thinning, Skeletonization



Hollow Square (Original Image), Thinning, Skeletonization



Plus Sign (Original Image), Thinning, Skeletonization



It can be observed that the image morphological operations thinning and skeletonization are quite complicated compared to dilation and erosion. The apparent effects of these are in thinning, the images are left with single pixel lines that do not always follow the contour of the object. Meeanwhile in skeletonization, the images are converted to its skeleton or framework but some areas in the foreground are retained. Due to its unconsistent effects, these two operations are thus sensitive to the image to be morphologically transformed.

Since I fully understand how the two basic image morphological operations dilation and erosion work, and my predictions match the simulated results then I grade myself 10/10 for this activity.

I have successfully finished this activity individually but I have shared what I learned with my other classmates.

Appendix
The whole Scilab code below is utilized in this activity.

sq = gray_imread('square.bmp');
tr = gray_imread('triangle.bmp');
ci = gray_imread('circle.bmp');
hsq = gray_imread('hollow square.bmp');
pl = gray_imread('plus.bmp');

A = [1 1 1 1; 1 1 1 1; 1 1 1 1; 1 1 1 1];
B = [1 1; 1 1; 1 1; 1 1];
C = [1 1 1 1; 1 1 1 1];

cross = [0 0 1 0 0; 0 0 1 0 0; 1 1 1 1 1; 0 0 1 0 0; 0 0 1 0 0];

//scf(0);
dilated_sq = dilate(sq, A);
//imshow(dilated_sq);
//imwrite(dilated_sq, 'dilated_sq4x4.bmp');

//scf(1);
eroded_sq = erode(sq, A);
//imshow(eroded_sq);
//imwrite(eroded_sq, 'eroded_sq4x4.bmp');

//scf(2);
dilated_tr = dilate(tr, A);
//imshow(dilated_tr);
//imwrite(dilated_tr, 'dilated_tr4x4.bmp');

//scf(3);
eroded_tr = erode(tr, A);
//imshow(eroded_tr);
//imwrite(eroded_tr, 'eroded_tr4x4.bmp');

//scf(4);
dilated_ci = dilate(ci, A);
//imshow(dilated_ci);
//imwrite(dilated_ci, 'dilated_ci4x4.bmp');

//scf(5);
eroded_ci = erode(ci, A);
//imshow(eroded_ci);
//imwrite(eroded_ci, 'eroded_ci4x4.bmp');

//scf(6);
dilated_hsq = dilate(hsq, A);
//imshow(dilated_hsq);
//imwrite(dilated_hsq, 'dilated_hsq4x4.bmp');

//scf(7);
eroded_hsq = erode(hsq, A);
//imshow(eroded_hsq);
//imwrite(eroded_hsq, 'eroded_hsq4x4.bmp');

//scf(8);
dilated_pl = dilate(pl, A);
//imshow(dilated_pl);
//imwrite(dilated_pl, 'dilated_pl4x4.bmp');

//scf(9);
eroded_pl = erode(pl, A);
//imshow(eroded_pl);
//imwrite(eroded_pl, 'eroded_pl4x4.bmp');

//scf(10);
thinned_sq = thin(sq);
//imshow(thinned_sq);
//imwrite(thinned_sq, 'thinned_sq.bmp');

//scf(11);
skeletonized_sq = skel(sq);
//imshow(skeletonized_sq);
//imwrite(skeletonized_sq, 'skeletonized_sq.bmp');

No comments:

Post a Comment