First, a scanned image of scattered punched papers is selected from the two images given by the activity. This is shown below.
The image above has size 748 x 618 and it is subdivided into 9 subimages each of which has size 256 x 256 pixels. Thus, some subimages overlap with the other which is better since it results to more area to be calculated and thus the result to be more accurate. Paint is used in cropping the scanned image.
A representative subimage that is the parcel labeled 'circles_2' located at the middle of the one-third topmost part of the whole original image is illustrated as follows.
The histogram of the grayscale values of each subimage is then analyzed using GIMP. This is where the threshold value is determined for the binarizing of the 9 subimages, that is, they only possess two values which are 0 for black corresponding to the background and 1 for white corresponding to the foreground or called the Region of Interest (ROI).
A threshold value of 0.85 is used in making the 9 subimages be of Binary-type. The binarized subimage 'circles_2' is the following.
Notice that binarizing alone is not enough to get the ROI for area calculation. Thus some image morphological operations are utilized in order to remove unnecessary noise and hence to connect overlapping cells which are coined blobs.
Closing and opening operators are then implemented here. The closing operator is defined to be the erosion of the dilated image A by a structuring element (SE) B to that same SE B. Meanwhile, the opening operator is equivalent to the dilation of the eroded image A by a SE B to that same SE B. Therefore, a series of dilation, erosion, erosion, and dilation operation is applied to each subimage for its further enhancement.
The SE used takes the form of a small circle as the matrix below.
The effect to the representative binarized subimage 'circles_2' after applying the closing and opening operations is shown as follows.
It can be observed that noise are eliminated, blobs are created due to the overlapping of some cells and in the same time single-cell units are more defined.
After applying the methods presented above to all the subimages, the blobs and the single-cell units are then isolated and labeled in preparation for area calculation using the built-in function in Scilab namely bwlabel. Thus, the area, which is the total number of white pixels, of blobs and single-cell units to all subimages are independently determined and gathered.
Now, the histogram of the calculated areas is shown below.
The occurrence of the area of a single-cell unit is found to be between 500 and 550 square pixels. Of course, the blobs and other cells that are not fully reconstructed give very large and very small areas respectively. Hence, these are eliminated in the process of determining the mean area and the standard deviation of the distribution.
The calculated mean area of the cell is 519.79 square pixels. This is derived from the sum of the elements within the interval of 500 to 550 square pixels divided by the number of elements in this range. Using the built-in function stdev in Scilab, the standard deviation attained is 12.12.
For validity of the result, the mean area is compared to the area of a single-cell unit which is not overlapping to other cell(s) and this is cropped from a subimage. This is also binarized but the closing and opening operations are not already implemented. The following images represent the basis of comparison to the calculated mean area.
Pixels of the cell are then summed for its area and the result is 517 square pixels. Finally, its percent difference to the calculated mean area is 0.54 %.
Since I have applied different image processing techniques for this activity to be successful, and obtained very small or almost insignificant percent difference for the area of a cell, I grade myself 10/10.
Before starting, Mimie has shared some insights to me on how this activity is handled. However, I have worked independently throughout its completion at the same time sharing my ideas to my classmates after I have finished this.
Appendix
The following Scilab code below is utilized in this activity.
circles = [];
binarycircles = [];
N = 9;
for i=1:N
circles1 = gray_imread('circles_'+string(i)+'.jpg');
binarycircles1 = im2bw(circles1, 0.85);
circles = [circles, circles1];
binarycircles = [binarycircles, binarycircles1];
end
M = 2;
graysubimage = circles(:,((M*256) - 255):(M*256));
binarysubimage = binarycircles(:,((M*256) - 255):(M*256));
//scf(0);
//imshow(graysubimage);
//scf(1);
//imshow(binarysubimage);
//imwrite(binarysubimage, 'binarysubimage2.bmp');
SE = [0 1 0; 1 1 1; 0 1 0];
newbinarysubimage = dilate(binarysubimage, SE);
newbinarysubimage = erode(newbinarysubimage, SE);
newbinarysubimage = erode(newbinarysubimage, SE);
newbinarysubimage = dilate(newbinarysubimage, SE);
//scf(2);
//imshow(newbinarysubimage);
//imwrite(newbinarysubimage, 'newbinarysubimage2.bmp');
[L, n] = bwlabel(newbinarysubimage);
A = [];
for j = 1:n
b = (L == j);
A(j) = sum(b);
end
Area = fscanfMat('area data.txt');
//scf(3);
//histplot(length(Area), Area);
//title('Histogram of Calculated Cell Areas');
//xlabel('Area');
//ylabel('Frequency');
index_goodArea = find(Area>500 & Area<550);
mean_Area = sum(Area(index_goodArea))/length(index_goodArea);
stddev_Area = stdev(Area(index_goodArea));
gray1circle = gray_imread('1circle.bmp');
//scf(4);
//imshow(gray1circle);
binary1circle = im2bw(gray1circle, 0.85);
//scf(5);
//imshow(binary1circle);
//imwrite(binary1circle, 'binary1circle.bmp');
theo_Area = sum(binary1circle);
percent_error = abs((theo_Area - mean_Area)/(theo_Area))*100;
No comments:
Post a Comment