Monday, July 21, 2008

Activity 9: Binary Operations

original image:**Our task: to estimate the cell (punched paper circles) size in pixels.

First, the image is cut up into 9 256x256 images using GIMP to save memory. On the assumption that all the sub-images have the same PDF and CDF, the histogram of one is processed to find the threshold for the next step, and fix the contrast if neccessary.
(The program used is simply that used in activity 4)

Next, in a loop where each sub-image is processed then analyzed individually before returning the final result (thanks to jeric's help with the strcat() function); the following program:
stacksize(4e7);
pre='cir';
counter=1;

for i=1:9

im=imread(strcat([pre,string(i),'.jpg']));
imb=im2bw(im,0.79);

//imshow(imb,[]);


se=[0 1 0; 1 1 1; 0 1 0];

//se=ones(2,2);
dil=dilate(imb,se,[1,1]);

ero=erode(dil,se,[1,1]);

//imshow(ero,[]);


//se1=[0 1 0; 1 1 1; 0 1 0];

se1=ones(3,3);
ero1=erode(ero,se1,[1,1]);

dil1=dilate(ero1,se1,[1,1]);

//imshow(im,[]);


[L,n]=bwlabel(dil1);

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>400);
scf(11)
histplot(length(x), area(x));
a=area(x);
a=sum(a)/length(x) //area
y=stdev(area(x)) //error


i.e. ...first converts the sub-image into binary using the previously determined threshold;
...the CLOSING operator (a morphological operator expressed as a composition of 2 morphological transformations, namely first dilation then erosion using the same structural element, in this case a 3-pixel long, 1-pixel wide cross) is then used to effectively get rid of the "pepper noise" in the image;...after which, the OPENING operator (the dual of the closing operator which is characterized by the use of the tranformation erosion before dilation, using the structural element 2px by 2px square in this case) is used to get rid of the "salt noise" in the image, as well as attempting to separate the nearly-touching "cells" from each other;...the scilab function bwlabel() is then used to label each individual cell, then regions are scanned to obtain the histogram that lays out the measured areas of all the "blobs"/"cells"/circles;**as we can see, the values are spread out a little because of leftover salt noise not totally erased by opening, and the tendency of the program to consider cells that are right next to each other to be just one big blob; to find the actual mean area we get rid of these outliers by only considering those values that range between 400 to 600, an estimate of the parameters wherein the mean area is most likely to be inferred from the above histogram

...this last gives the considered histogram range:and an estimated mean cell area value of 534.51064, with a standard deviation of 22.431415

From the process used, to the obtained histogram and standard deviation value, this is a reasonable estimate. Sources of error are possibly the truncation of a few image details when the image was converted to binary before the opening and closing, and the slight distortion of the circles caused by the choice of structural element/s.


**i give myself a grade of 10 for this activity because the objective was achieved and the obtained final values were quite plausible, not to mention the extra effort benj and i put in initially to enhance the images to separate the stubborn circles. if i actually get that done, i might put that up here as an update.
*thank you to benj,mark leo, jeric

EDIT: for some reason this was saved as a draft while just my initial program from last week was published,i didn't even notice until just now. problem fixed, every picture once again painstakingly uploaded, actual report posted.

No comments: