Saturday, July 19, 2008

Activity 9: Binary Operations

In this activity, application of what we have learned so far were applied to determine the best estimate of the area (in pixel count) of simulated cells. These cells are represented as images of scattered holes as shown below.




To start with the activity, the first image was used and was subdivided into 256x256 images. For each grayscaled subimage, its histogram was plotted to determine its threshold value, thus allowing the cell to be separated from its background. Then, the images were binarized using 'im2bw' from Scilab.

Morphological operations such as dilation and erosion were then applied to perform the opening and closing operations to the images. In opening, erosion followed by dilation were applied to an image. Whereas in closing, dilation followed by erosion were applied to the image. The opening and closing operations were done to clean images of isolated pixels or small holes in the cells that may interrupt with the estimation of the cell area.

A subimage is shown here with its: binarized form, with the application of closing operation, then by opening operation, and lastly, with the application of bwlabel to label each blob with different colors.



Using 'for loop', the estimated area for each blob of all the subimages were determined. The histogram showing the area vs. frequency is shown below.


From the histogram, it can be seen that the calculated blob area with the highest frequency is below 1000. This histogram however cannot clearly show what exactly is the most frequent area.

By tallying all the areas for each subimage, the estimated area of each blob was found to have a value of '489.75 pixels' and a standard deviation of '31.5' which agrees with the plotted histogram above.

The program used for this activity is:

chdir('F:\186\activity9');
agray = gray_imread('c1-1.jpg');
abin = im2bw(agray, 211/256);
imshow(abin);
se1=ones(4,4);

squareimg = imread('bin-c1-2.bmp');
img=img(:,:,1);
scf(1);
subplot(2,2,1);
imshow(img);

dil1=dilate(img,se1);
er1=erode(dil1, se1); //closing
subplot(2,2,2);
imshow(er1);
cl1=erode(img, se1); //opening
di1=dilate(cl1, se1);
subplot(2,2,3);
imshow(cl1);

[L,n] = bwlabel(cl1);
for j = 1:n //area
r= (L==j);
A(c) = sum(r);
c = c + 1;endend
histplot(length(A),A);

x= find(A>450 & A<600);>
a = sum(A(x))/length(x)
stdev = stdev(A(x))
----------------------------
rating- 8, because the estimated area has a 7.5% difference with respect to the theoretical value which is 530.

Acknowledgements: Marge, paul and angel for helping me with the opening and closing concepts of the activity.




No comments: