Morphological operations uses Set Theory to manipulate matrices. Since we now know that images are just matrices of values with layers of channels, it is appropriate that certain algorithms can be devised to do morphological operations with pictures.
This activity deals primarily with some basic shape alteration and recognition. For basic operations, binary "flattened" versions of multi-chanelled images are used. To start off, let's examine how these 2 operations work.
Note: Since the images are in their binary form, zeros are considered as background while ones are the object. Background is ignored by the operations, and is thus useful since the operations would only work if the matrices compared have the same dimensions.
First, matrix A (one containing the original pattern) is scanned with another matrix B (one containing the mask). Then, a new zero matrix C (transformed image) with the same dimensions as matrix A & B are mapped depending on the operation used:
- erosion: All coordinates of the anchor point for when the mask is entirely enclosed by the object is set to one in matrix C.
Figure 1. Erosion. The anchor point is the center of matrix B.
- dilation: All coordinates of the anchor point for when at least one element of the mask intersects with the object is set to one.
Figure 2. Dilation. The anchor point is the center of matrix B.
Thus, the anchor element of the mask in matrix B determines how the transformed image will be shifted in matrix C with respect to matrix A.
Using 4 original patterns and 5 masks, erosion and dilation are employed and their effects were observed. The anchor points for the masks are as follows:
- 2x2 square: Top-left pixel
- 2x1: Top pixel
- 1x3: Left pixel
- 3x3 cross: Top-most pixel
Figure 3. Original Patterns: 5x5 square, 3x4 right triangle, 10x10 square annulus 2 pixels thick, 5x5 cross
Mask: 2x2 square, 2x1 , 1x2, 3x3 cross and a 2 pixel long diagonal.
erode()
Figure 4. My hand drawn predictions for erosion.
Figure 5. scilab's erode() operator results.
My prediction would've been perfect if not for my careless error on the diagonal mask of the square annulus. However, I now fully understand how erosion works. Since erosion "trims" by fitting the mask entirely, it is possible to have completely blank images. We can see this with the cross mask for the 3x4 triangle and the 2x2 mask for the 5x5 cross patterns.
dilate()
Figure 6. My hand drawn predictions for erosion.
Figure 7. scilab's dilate() operator results.
Again, like with my erosion predictions, this would've been perfect if not for the 1x2 mask of the square annulus.
thin() & skel()
Lastly, I examine the thin() and skel() operators of scilab. These are more complex than the erode() and dilate() operators. From the help file, the implementation of thin() on an image of text produces:
Figure 8. Above: Original image. Below: thin() results
thin() seems to trace lines and curves by "thinning" them until they are only one pixel wide. The deviations from straight lines came as a consequence of not using a perfectly binary image. The above image was just converted using im2bw(), in which the conversion led to some unstraightened lines when thin() was used.
As we can see, this may be problematic when we have lots of line nodes in our image. For this, we use the more complex skel().
Figure 9. L-R: Original image, result of skel() superimposed with the original and the distance transform.
skel() successfully traced a quite rounded and thick image. These characteristics would have resulted to a poor trace, had we used thin() for the image. skel() seems to average the whole network of lines and deduce the "skeletal" frame of the image. As such, it also has a distance mapping output. This seems to be a pixel population distribution map of the image with respect to skel()'s traced path.
This was a good introductory activity for morphological transforms of images.
Self-Assessment: 9/10