Thursday, September 23, 2010

Erosion and Dilation: Changing Morphology using Patterns

One way of altering an image is to use morphological operations. The idea of eroding and dilation stems from set theory. To better understand this, an image can be eroded and dilated using a certain pattern or structuring element (strel).

By using the strel, we erode the image or reduce the size of the foreground image by comparing a center pixel and its neighbors using the strel to define the neighboring rule.

Similarly, we dilate an image or increase the size of the foreground by taking a center pixel and filling the neighbor pixels as defined by the strel.

To better understand these operations, let us apply erode and dilate of different strels to different structures.

First the Structuring Elements.

Strel Vertical Strel Square Strel Horizontal Strel Diagonal
Strel Cross

Next the images.
Triangle Square Plus Hollow Square

Now, let us examine what happens when we use a strel to erode the different images. The following pairs are matched as prediction then actual output.

Vertical on Triangle Prediction Vertical on Triangle
Vertical on Square Prediction Vertical on Square
Vertical on Plus Prediction Vertical on Plus
Vertical on Square Prediction Vertical on Square
Square on Triangle Prediction Square on Triangle
Square on Square Prediction Square on Square
Square on Plus Prediction Square on Plus
Square on Hollow Square Prediction Square on Hollow Square
Horizontal on Triangle Prediction Horizontal on Triangle
Horizontal on Square Prediction Horizontal on Square
Horizontal on Plus Prediction Horizontal on Plus
Horizontal on Hollow Square Prediction Horizontal on Hollow Square
Diagonal on Triangle Prediction Diagonal on Triangle
Diagonal on Square Prediction Diagonal on Square
Diagonal on Plus Prediction Diagonal on Plus
Diagonal on Hollow Square Prediction Diagonal on Hollow Square
Cross on Triangle Prediction Cross on Triangle
Cross on Square Prediction Cross on Square
Cross on Plus Prediction Cross on Plus
Cross on Hollow Square Prediction Cross on Hollow Square

We can see that predictions were correct for almost all strel-image pairs. This is due to the adjustment of the center pixels to the (1,1) coordinate rather than the center of the strel for those with even pixel sides. The only problem encountered is the use of diagonal as the strel. The problem is that the error is not symmetric and any logical flipping of the strel does not give out proper results.

Next, we examine the dilation of the images using the different strel. Again, the same change in center pixel is used as in erode.
Vertical on Triangle Prediction Vertical on Triangle
Vertical on Square Prediction Vertical on Square
Vertical on Plus Prediction Vertical on Plus
Vertical on Hollow Square Prediction Vertical on Hollow Square
Square on Triangle Prediction Square on Triangle
Square on Square Prediction Square on Square
Square on Plus Prediction Square on Plus
Square on Hollow Square Prediction Square on Hollow Square
Horizontal on Triangle Prediction Horizontal on Triangle
Horizontal on Square Prediction Horizontal on Square
Horizontal on Plus Prediction Horizontal on Plus
Horizontal on Square Prediction Horizontal on Square
Diagonal on Triangle Prediction Diagonal on Triangle
Diagonal on Square Prediction Diagonal on Square
Diagonal on Plus Prediction Diagonal on Plus
Diagonal on Hollow Square Prediction Diagonal on Hollow Square
Cross on Triangle Prediction Cross on Triangle
Cross on Square Prediction Cross on Square


Cross on Plus Prediction Cross on Plus


Cross on Hollow Square Prediction Cross on Hollow Square

Now, we can see disparities between my predictions and the actual input. But here is the trick. My images were created as large as the defined shapes, no more no less. In dilation, most of the time an increase in the number of pixels of the output. Unfortunately, Scilab does not increase the size of the image. Instead, it crops out the last columns and the last rows until the output image is the same size as the input image. If we examine the predictions, we can see that they predict the output of the function less the last columns and last rows.

Now, let us explore other types of morphological operations. Another pair of morphological operations that will be extremely useful in the future is the Opening and Closing. From their names, they open and close images with holes or discontinuities in them. Or they can join or separate different shapes near each other. The process of Opening and Closing uses both eroding and dilating in different orders. Opening erodes first then dilates while Closing dilates first then erodes. The idea of using both is to change the image then return the regions that are not of interest back to their original state. For example, if we take a annulus and close it, we will result in a circle with the same radius as its outer radius. While if we open it, we will have an annulus with a larger hole inside by same outer radius (granted both opening and closing is dependent on the strel used).

For this exercise I give myself a grade of 9 because of the lateness of my submission. The exploration of how Scilab cuts the image during dilation can be very useful for future exercises.

No comments:

Post a Comment