Activity 9: Binary Operations

July 17, 2008 at 11:26 am (Uncategorized) (, , , , , )

The goal of this activity is to find size of each “cell” in then image. We will be implementing the various techniques we have learned so far in solving the problem.

One of the relevant concepts that we will be implementing is the histogram thresholding to separate the background from the image. Another relevant concept is the opening and closing operations in morphological transformations. Opening is mathematically defined as

which simply means is the dilation of an erosion (see previous entry). Opening has the effect of removing small objects or noise. Closing on the other hand is defined as

which means the erosion of a dilation. It has the effect of removing small holes in the object.

The image above is divided into 9 images of size 256×256 to remove the burden of using too much memory.

My code for the activity is shown below.

getf(“imhist.sce”);
im=imread(‘circ01_01.jpg’);
stacksize(4e7);
pref=‘circ01_0’;

//create filter
se=ones(10,10);
se=mkfftfilter(se, ‘binary’, 4);

area=[];
counter=1

//scan images
for i=1:9
im=imread(strcat([pref,string(i),‘.jpg’]));
im=im2gray(im);
im=im2bw(im, 205/255);
im=erode(im, se); //opening
im=dilate(im, se);
im=dilate(im, se); //closing
im=erode(im, se);
[L,n]=bwlabel(im);
//scan regions
for j=1:n
area(counter)=length(find(L==j));
counter=counter+1;
end
end

scf(10);
histplot(length(area),area);
x=find(area<600 & area>450);
scf(11)
histplot(length(x), area(x));
a=area(x);
a=sum(a)/length(x) //area
y=stdev(area(x)) //error

The ‘pref’ variable is used to defined the prefix of the subimage, and concatenates it with a counter for loop with the 9 sub-images. We also used the ‘bwlabel’ command which looks for continuous regions in a binary image and labels them accordingly.

The histogram yields:

We can see that bwlabel has considered overlapping cells as one. However, we limit our interest to areas with less than 800 pixels  and greater than 400 pixels to increase the accuracy the calculation of the average of the cell. As can be seen below, there are regions that were labeled by bwlabel that was extremely small and some regions that were labeled were very large. Thus, setting a limit to the acceptable area is necessary.

The calculated areas is area=538.15 with std deviation of std=22.645. We are confident that this is indeed within the limits of the accepted area. To check the validity of our results, we took a subimage and calculated the area of the “cells”. The subimage that we took has completely separted cell, which ensures that the area we calculate is the area of a cell, and not the area of compounded/joint cells.

I gave myself a rating of 10 because i believe that i was able to do the activity right.

Collaborators: Cole, Julie.

Permalink Leave a Comment