From the past two activities, we were able to use morphological operators to reduce and enlarge images. Now we will use the same method to filter out noise of images and identify the characteristics of the elements of the image such as area, etc.
Figure 1 is a simulated Image of Normal Cells in the blood. As one can see, the area of the cells (in white) are relatively equal in size. One can easily segment them from the background image using a certain threshold. The problem would be the clumped circles.
Figure 1: Simulated Image of Normal Cells |
Figure 1 was cropped into 6 different images each 256 x 256 pixels in width, length. The point is to locate the ROI which gives the best estimate of the area of the cells. Area??
Yes, essentially we are trying to compute the area of the cells. To do this we need to remove the clumped cells together and just obtain the average area of the individual cells.
Figure 2: Six 256 x 256 pixels from Figure 1 |
The histogram was obtained to determine what threshold number will remove the unnecessary noise of the cell.
Figure 3: Histogram of each cropped image |
Once the threshold was known, the cells were operated using the Opening and Closing Operator. It's apparent the threshold is around 200-240 form the histogram.
Closing Operator - retains light objects and removes dark objects the structuring element
does not fit in. [2]
Opening Operator - retains dark objects and removes light objects the structuring
element does not fit in [2]
The Opening operator was used to remove the small light objects and select only the larger ones. A structuring element of a circle was used.
Figure 4: Segmented with morphological operator |
Figure 4 shows the resulting image. There are still parts that need cleaning, but for the most they can be ignored. Image 6 (last image) needs cleaning up.
I then computed the average area of the cells and took its standard deviation. Now there are times when SearchBlobs gives out a number 0 to a non-existing blobs, or the blob is so large that the standard dev is greater than the average!
I figured a way or a workaround to this. I would re-run the loop, removing the abnormally large area (clumps of white cells), and recompute the area and standard deviation for each loop. I did this 3 times, in which I managed to decrease the standard deviation greatly. It's more of a cheat code I say.
Now, we use the computed areas of the normal cells, find them on the image with Cancer Cells.
What I did was if the Blob (cell) was less than or equal to the computer area, then that blob is off the picture. I do this through the whole image until all the abnormally large cells or clumped up cells remain.
Figure 5: Simulated Image with Cancer Cells |
Figure 6 show the results. The best images are images 5 and 6.
Figure 6: Image with only Cancer Cells |
bt = 0
for j = 1: 6
filename = 'C:\Users\Phil\Desktop\Academic Folder\Academic Folder 13-14 First Sem\AP 186\Activity 11\C1_0'+string(j)+'.jpg';
NormBC = double(imread(filename));
//Checks Histogram
pixel = max(NormBC);
val=[];
num=[];
counter=1;
for i=0:1:pixel
[x,y]=find(NormBC==i);
val(counter)=i; num(counter)=length(x);
counter=counter+1;
end
[n,m] = size(NormBC);
nor = num/(n*m);
plot(val,nor)
//Checks Histogram -endcode
Threshold = 200;
NormBC(find(NormBC<Threshold)) = 0;
StructureElement = CreateStructureElement('circle',5);
ResultImage = OpenImage(NormBC,StructureElement);
BinaryImage = SegmentByThreshold(ResultImage, CalculateOtsuThreshold(ResultImage));
//imshow(BinaryImage);
imwrite(BinaryImage,'C:\Users\Phil\Desktop\Academic Folder\Academic Folder 13-14 First Sem\AP 186\Activity 11\NormBC'+string(j)+'.jpg')
BlobImage = SearchBlobs(BinaryImage);
NumberofBlobs= max(BlobImage);
//imshow(mat2gray(BlobImage));
ct = 1
for i=1:1:NumberofBlobs
Area(ct) = size(find(BlobImage == i),2);
ct = ct+1;
end
average(j) = mean(Area);
sigma(j) = stdev(Area);
Area = Area(find(Area>0)); //eliminates annoying 0 blobs
at = 0
Checks = 3 //Does a re-computation of average and stdev after removing bad values
for l = 1:Checks
X = Area(find(Area>(average(j)-sigma(j)) & Area<(average(j)+sigma(j))));
clear average(j);
clear sigma(j);
clear Area(j);
average(j) = mean(X);
sigma(j) = stdev(X);
Area = X;
at = at +1;
end
Finalmean = mean(Area);
Finalsigma = stdev(Area)
ListofArea(j) = Finalmean;
Listofsigma(j)= Finalsigma;
end
//Cancer Blood Cells
CancerBC = double(imread('C:\Users\Phil\Desktop\Academic Folder\Academic Folder 13-14 First Sem\AP 186\Activity 11\Circles with cancer.jpg'));
CancerBC(find(CancerBC<Threshold)) = 0;
CancImage = OpenImage(CancerBC,StructureElement);
BinaryCancImage = SegmentByThreshold(CancImage, CalculateOtsuThreshold(CancImage));
imwrite(BinaryCancImage,'C:\Users\Phil\Desktop\Academic Folder\Academic Folder 13-14 First Sem\AP 186\Activity 11\CancBC.jpg');
Game = SearchBlobs(BinaryCancImage);
Cancerblobs = Game;
//imshow(mat2gray(Game));
NumberofCancBlobs= max(Cancerblobs);
dt = 1
for n=1: 6
for m=1:1:NumberofCancBlobs
if size(find(Cancerblobs == m),2) <= (ListofArea(n) + Listofsigma(n) )
Cancerblobs(find(Cancerblobs == m)) = 0;
h = m
else
Cancerblobs(find(Cancerblobs ==m)) = 255;
z = m
end
dt = dt+1;
end
imwrite(mat2gray(Cancerblobs),'C:\Users\Phil\Desktop\Academic Folder\Academic Folder 13-14 First Sem\AP 186\Activity 11\FinalCancBC' +string(n)+'.jpg')
clear Cancerblobs;
Cancerblobs = Game;
end
References
[1] Soriano, Jing, Applications of Binary Operations 1: Blob Analysis, 2013
[2] SciLab 5.4.1 - Help Browser - Image Processing Design