Monday, July 27, 2009

Activity 9 - Binary Operations


The objective of this activity is to estimate the area of the "cells" or the circles in the figure below by implementing several binary operations on the image. The image is 748x618 pixels (the image shown below is a rescaled version for easier upload).


The image is then divided into 9 256x256 subimages for easier processing. The subimages are overlapping, but it does not matter because the incomplete circles will not be counted in the end.



Panel assignment matrix
[ 1 2 3 ]
[ 4 5 6 ]
[ 7 8 9 ]

The region of interest in each subimage are the white circles, separated from the background by thresholding. Each image was opened in Gimp to find the best threshold for each. The threshold corresponding to each panel is given by:

TH = [0.803, 0.803, 0.83, 0.808, 0.784, 0.823, 0.784, 0.784, 0.839];

The resulting images after thresholding by
im2bw each panel is shown below:



The background is not a completely solid color with one grayscale value which is why some points in the background still appeared after thresholding. This is inevitable in most images after processing by thresholding.

The unwanted regions in each panel (the while pixels not part of the circles) can be removed using the opening operator. In wikipedia [1], the opening operator is defined as "the locus of translations of the structuring element
B inside the image A", which can be obtained by "the erosion of A by B, followed by dilation of the resulting image by B".



The opening operator was implemented in all subimages or panels, resulting in the images shown below. The structuring element used is an 11x11 disc.



The unwanted parts are now gone. This only works if the structuring element (SE) used is larger than the unwanted parts but smaller than the region of interest. In this case, the choice of an 11x11 disc is correct. Because it is larger than the unwanted parts, which are mostly floating pixels not larger than the SE. Erosion of the image by the SE, which is the first step in the opening operator, decreases the overall size of all the elements of the image. The small unwanted parts are removed at this stage, but the sizes of the ROI are also decrease. This is why we dilate the resulting image by the SE again, to restore the original sizes of the ROI.

At this point, we now have clusters of 1's or white pixels. We want to get the areas of each cluster in each panel. The Scilab function
bwlabel does this for us. The function returns the image with labels and the number of clusters in each subimage. The labels are the numbers 1 to n, where n is the number of clusters in the subimage.

The image below are the results of
bwlabel in each panel.



Because the cluster labels are just integers from 1 to n, it is easy to determine the area of each cluster. The sum of the pixels corresponding to that label is the area of the cluster.

The cluster sizes were obtained from each subimage and placed in a single array. The histogram of this areas or cluster sizes is shown in the figure below.

bin size = 6


bin size = 8


bin size = 10


The bin that will give the highest count is the most probable size of the “cell”. But finding the correct bin size is also important here. The uncertainty of the estimate is half of the bin size. Too large bin sizes would mean a large uncertainty, while too small bin sizes would result to low frequency counts of the bins. I tested several different bin sizes (6, 8, 10) to see if there would be any difference. For bins size 6 and 8, the bin with the maximum count is 534 and 536, respectively. Both have a maximum count of 18. This means that there are 18 clusters with that size. For the bin size 10, the maximum count is 25, belonging to the bin 530.

However, the histogram I made has bins as the lower limit. This means that areas within the range 530<=x<540>

Bin size Area Estimate

6 537 +- 3

8 536 +- 4

10 535 +- 5

The estimates are close to each other and the ranges overlap. This means that the methods presented above to estimate the area of a single “cell” have been successful.

Shown below are the same binary operators implemented in panel 5 for better comparison.



The methods used here are very generic and can be used for other applications such as counting actual biological cells in an image sample, determining sizes of objects in an image, or more general topics like cluster counting, area estimation, etc.

I have yet to try dividing the image into more subimages with more overlaps. This will probably yield a better results, with more frequency counts in the correct cluster size because the overlaps will increase the chance of counting the perfectly isolated circular cluster repeatedly.

I give myself 10 points for this activity. I was able to estimate the area of the "cell" with realistic results. The histogram showed that many of the cells have that area, and even if the bin width was varied, the results are robust.

[1] Mathematical Morphology (http://en.wikipedia.org/wiki/Mathematical_morphology)

0 comments:

Post a Comment