Morphological Operations

In this activity the aim is to understand and apply morphological operations, which are operations that affects an image’s shape, to enhance an image and extract information from it.

First, I apply dilation and erosion on a set of images. The dilation of a shape A by a structure element B is defined as:

A \quad \text{d} \quad B = \{z|(\hat{B})_z \cap A \neq \emptyset \}

It includes all translations z‘s of a reflected shape B such that it has an intersection with the shape A.  It expands A in the shape of B [1]. Erosion works in the opposite way and is defined by:

A \quad \text{e} \quad B = \{z|(B)_z \subset A \}

These are translations z’s of B such that it is contained in A. It reduces A in the shape of B [1]. I tried to predict the resulting dilation and erosion of different shapes by hand on graphing paper:

The objects are in the left most side, followed by the structure element, the erosion, and the dilation. Using the same shapes and structure elements, I checked the the correct results in Scilab using the IPD toolbox. I used the functions ErodeImage and DilateImage. I got the results:

In my predictions, I made a few mistakes with the erosion and dilation of the hollow square with the last structure element. Using Scilab is easier and faster because mistakes can easily be made when manually checking each pixel.

Next, I tried to apply morphological operations on images of circles:

We can imagine that these circles are cells in an absorbing medium. I tried to find a best estimate of the size of normal cells from the left picture, and then isolate the abnormal sized cells in the right picture.

First, I divided the left picture into 256 x 256 sized subimages. Here is one subimage:

sub1

After looking at its histogram to estimate the pixel value of the background, I binarized the image using a threshold:

ResultImage = Image > 200

This resulted in:

binary

The image is still dirty because of some isolated pixels and small holes in the cell. The morphological operators close, open, and tophat, which utilize dilation and erosion, can be used to clean images such as this [2]. They are implemented in the IPD toolbox with the functions: CloseImage, OpenImage, and TopHat. Using a circle with a radius of 10 pixels as a structure element, the resulting image using close, open, and tophat are:

binary     open     tophat

To clean the image, the opening operator is the most appropriate operator to be used. This operator removes light objects and retains dark objects where the structure element does not fit. After cleaning all the subimages by thresholding and opening, I got:

clean

Next, I identified each blob in the above image using the function SearchBlobs. I then calculated the area of each blob and at the same time produced a histogram of the areas. This was done using the lines:

BlobImage = SearchBlobs(finalimage);
[sizes, bins] = CreateSizeHistogram(BlobImage);

This resulted with the histogram:

histogram

Majority of the blobs are found within the bins 375 to 598. These are the areas of the normal sized cells. I calculated the mean and standard deviation of these areas and acquired the best estimate area: 507.1 \pm 51.2.

Then, I tried to isolate the abnormally large cells in the other picture. After cleaning the image using the same method, I filtered out blobs that are smaller than the largest value of the best estimate, 558.3, and are smaller than the area of blobs made of touching cells. I got the latter area by looking at the histogram of the blob areas. I implemented the filter using the line:

FilteredImage = FilterBySize(BlobImage, ave+std, 1050);

where ave + std results in the largest value of the best estimate. This resulted in:

filtered

There are still some normal sized cells that were not eliminated. Most of them are made of touching cells. These can be eliminated by opening the image again, but now using a larger structure element. Compared with the original image, this resulted in:

Circles with cancer     final

Using the best estimate of the area eliminated most of the normal sized cells, but a final touch of opening the image again completely isolated the abnormally large cells.

Since I was able to demonstrate the dilation and erosion of different shapes with different structure elements, and apply morphological operations to isolate distinct shapes in an image, I rate my self with 10/10. Thanks to my classmate Jk for helping me understand the SearchBlobs function and in creating a histogram.

References:

  1. M. Soriano, “A8 – Morphological Operations,” Applied Physics 186, National Institute of Physics, 2014.
  2. opencv dev team, “More Morphology Operations,” OpenCV 2.4.12.0 documentation, 2014. Retrieved from: http://docs.opencv.org/2.4/doc/tutorials/imgproc/opening_closing_hats/opening_closing_hats.html at 26 November, 2015.

 

Leave a comment