Friday, October 14, 2011

Morphological Operations

In this post, we will be looking at operations that morph an image systematically: erode, dilate, skel, and thin.

When we say morph, the shape of an object is transformed by using a structural element or a 'strel'. Usually a strel is a pattern made of a few number of pixels. The choice of strel depends on the desired effect on the image. Depending on the morphological operation and strel used, two objects in an image can be separated,
holes can be patched, noise pixels could be removed, among other effects.


Erode
The erosion of an object/shape A by a strel B is denoted by
Don't worry, that's not a very complicated mathematical expression. It's just set theory. In human langauage, that equation means that the erosion (that is, the image that will remain after the erosion operation) is the set of pixels where B could be placed so that it is still inside A. It is important to set a 'center' z (denoted by the circle in the figures below) for the strel. To erode a shape A, move the center of the strel B through each pixel of A. If the pixel in A cannot contain the whole strel, remove that pixel. The resulting image is a reduced version of the original.

Step-by-step erosion process.
Dilate
The dilation of an object/shape A by a strel B is denoted by
The concept is similar to erosion, move the center of the strel through pixels of the image and dilate. But this time, the strel has to be reflected (in x and y) first. See the reflected strell in the step-by-step procedure below. As you move the reflected strel through A, add the pixels outside A covered by the strel. The resulting image is a bloated version of the original.

Step-by-step dilation process.

In Scilab, erode and dilate can be implemented using the functions erode and dilate. Of course, that wasn't the first thing I did to learn how erode and dilate works! I posted the ones I did on graphing paper and the ones made using erode and dilate on Scilab. Examine how a square annulus, a plus sign, a square and a (somewhat) triangular shape are eroded and dilated by 5 different strels. The centers I used for the strels are denoted by an o. The shapes are marked with a red border. Shaded regions are the pixels removed, and squares with broken line borders are added pixels.

EROSION

The Strels.
Erosion of a 10x10 square annulus.
Erosion of a 5x5 plus sign.
Erosion of a 5x5 square.
Erosion of a 3x4 triangle.
DILATION

The Reflected Strels.
Dilation of a 10x10 square box.
Dilation of a 5x5 plus sign.
Dilation of a 5x5 square.
Dilation of a 3x4 triangle.

There are other functions in Scilab that can morph an image. The functions thin and skel were also used to morph the 4 shapes I used above (box, plus, square, triangle). These two functions are operations that thins the image and gives its skeleton both using different rules and algorithm for the thinning operation. 







_________________________________________________________________________________
I think I deserve a 10 for the nice illustrations and the effort into drawing all that. :D

No comments:

Post a Comment