This activity aims to used our knowledge in morphological and binary operations previously discussed in the last activity.
Figure 1. Circles002
Figure 2. Circles with cancer
I. Segment by Thresholding
First I cut the 823x658 image of Figure 1, to 12 subimages that are overlapping at some parts using the following code
im = imread('C:\Users\Jazz\Desktop\Binary Operations\Circles002.jpg');
//Part 1
Circle11 = im(1:256,1:256);
Circle12 = im(1:256,201:456);
Circle13 = im(1:256,403:658);
Circle21 = im(189:444,1:256);
Circle22 = im(189:444,201:456);
Circle23 = im(189:444,403:658);
Circle31 = im(378:633,1:256);
Circle32 = im(378:633,201:456);
Circle33 = im(378:633,403:658);
Circle41 = im(568:823,1:256);
Circle42 = im(568:823,201:456);
Circle43 = im(568:823,403:658);
imwrite(Circle11,'C:\Users\Jazz\Desktop\Binary Operations\C1_01.jpg');
imwrite(Circle12,'C:\Users\Jazz\Desktop\Binary Operations\C1_02.jpg');
imwrite(Circle13,'C:\Users\Jazz\Desktop\Binary Operations\C1_03.jpg');
imwrite(Circle21,'C:\Users\Jazz\Desktop\Binary Operations\C1_04.jpg');
imwrite(Circle22,'C:\Users\Jazz\Desktop\Binary Operations\C1_05.jpg');
imwrite(Circle23,'C:\Users\Jazz\Desktop\Binary Operations\C1_06.jpg');
imwrite(Circle31,'C:\Users\Jazz\Desktop\Binary Operations\C1_07.jpg');
imwrite(Circle32,'C:\Users\Jazz\Desktop\Binary Operations\C1_08.jpg');
imwrite(Circle33,'C:\Users\Jazz\Desktop\Binary Operations\C1_09.jpg');
imwrite(Circle41,'C:\Users\Jazz\Desktop\Binary Operations\C1_10.jpg')
imwrite(Circle42,'C:\Users\Jazz\Desktop\Binary Operations\C1_11.jpg')
imwrite(Circle43,'C:\Users\Jazz\Desktop\Binary Operations\C1_12.jpg')
The code resulted to this following images. Take note that some parts of each image may be overlapping with the other. The image are labeled as Circle11, Circle12, Circle13, Circle21,Circle22, and so on. The number index represents their position in the image(like a matrix).
Figure 3. 12 subimages of Circles002.png labeled from C1_01 to C1_12.
to segment it by threshold, there is a built-in function in Image Processing Design(IPD) Module of Scilab under AnalyzeBlobs, that can be used. The function is depicted by the following code implementing threshold segmentation.
Threshold = CalculateOtsuThreshold(Circle12);
SegmentedImage = SegmentByThreshold(Circle12, Threshold+10);
imshow(SegmentedImage)
I picked Circle12 as the first sample and the code resulted to the following image. Take note that I segmented it slightly higher to its threshold to produce this better result.
Figure 4. Thresholding using the built-in function SegmentByThreshold()
Alternative to the built-in function of calculating the threshold is by studying first the image's histogram to find the grayscale threshold that will separate the background from the cells.
Figure 5. Histogram plot of Circle12 with 10 bins
Using this image, the average threshold of the image is around 200, which almost equal to the calculated threshold of the built-in function CalculateOtsuThreshold, which is 193. It is also advised to us that we would segment the image slightly higher than the threshold value.
Another easier method of thresholding is by using im2bw function of SIVP, that is already used to my previous activities.
II. Morphological Operations
In this part I tried to enhance the binary image so that it could be analyzed easier for the later parts. It consists of three morphological operations such as Closing, Opening and TopHat, where there is a very convenient built-in function again in IPD.
The enhancement is done by using the following code (varying the morphological function as well as the radius of the SE which is a circle).
//Part3 Morphological Operations
SE = CreateStructureElement('circle', 15)
Blobs = TopHat(SegmentedImage, SE);
imwrite(Blobs,'C:\Users\Jazz\Desktop\Binary Operations\tophat15.jpg')
imshow(Blobs)
Figure 6. Closing of image Circle12 using a circle SE of radius 3(left) and radius 15(right)
Figure 7.Opening of image Circle12 using a circle SE of radius 3(left) and radius 15(right)
Figure 8. TopHat of image Circle12 using a circle SE of radius 3(left) and radius 15(right)
We could clearly see the distinction of the different morphological operations. For example, the CloseImage function with a larger radius connects all the circles while in contrast it is all eroded in the OpenImage function. The TopHat on the other hand preserved a lot of details in the image. Now to further understand this morphological operations,As another requirement, we are asked to research these functions.
CloseImage -Performs morphological closing (dilation followed by erosion).[2]
OpenImage - Performs morphological opening (erosion followed by dilation).[2]
TopHat - Performs morphological "top hat" operation, returning the image minus the morphological opening of the image (erosion followed by dilation).[2]
You may visit the reference for a lot more different morphological operations. The only problem is they are in MATLAB, as built-in functions, but its really helpful to learn other morphological operations.
III. Area Calculations
In this part I, repicked another subimage to be studied; which is the 4th row and 1st column subimage denoted by Circle41.
Using the everything we did previously and enhancing the image using the OpenImage function with the correct SE circle radius, I produced the following.
Figure 9. Cleaned image using morphological operations
Right now what we lack is the analyis of this circles in the image. But surprisingly, these is all covered under one function in IPD, which is the SearchBlobs function, and there are still some more related function to this.
Blobindexed = SearchBlobs(Blobs);
imshow(mat2gray(Blobindexed));
imwrite(mat2gray(Blobindexed),'C:\Users\Jazz\Desktop\Binary Operations\blobs.jpg')
Figure 10. Blob image using built-in function SearchBlobs in IPD
With the previous code, we can now specify which blobs do we want to analyze. Virtually, after doing the previous code, the blobs where numbered accordingly. All we need to do is to call them by their number. And this is implemented by the following code, which also displays their Area.
Area = size(find(Blobs==2),2);
disp(Area)
Given these I averaged the Area and get their standard deviation using the simple loop code.
blobmax = max(Blobindexed);
disp(blobmax);
arealist = zeros(max(blobmax),1);
for i=1:blobmax
Area = size(find(Blobs == i),2)
arealist(i,1) = Area;
end
disp(mean(Area));
disp(std2(Area));
The results displayed that the average area = 554.1667, with the standard deviation of 13.19084.
Take note that this is only true to image Circle41.
IV. Identifying Abnormal Cells.
Lastly to achieve the main objective of this activity, we analyze the image in Figure 2 and we do everything we've done previously.
Figure 11. Cleaned Image (upper) and SearchBlob image(lower) of Figure 2.
Knowing the average size of the a normal cell, we could separate the abnormal cells
Figure 11. Identified abnormal cells
References
[1][1]AP 186 Handouts. Activity 11 - Binary Operations. Maricor Soriano 2013