Tuesday, August 20, 2013

Activity 11 - Application of Binary Operations

For this activity we want to obtain a best estimate (mean and standard deviation) for several object in a small region of interest. In our case an image of scattered punched paper serves as the subject image, with the punched paper acting as "cells", and we want to find the average cell size in the image. The first thing to do is to divide the image into smaller 256x256 regions using GIMP. Here are some sample subimages.


Figure 1. Sample subimages. I used GIMP to crop several 256x256 images
to be used in this activity.


Then I load the images onto Scilab and display its histogram. Zooming in, we see that we can binarize the image to separate the cells from the background by using 0.75 as threshold. Upon inspection, however, I saw that 0.77 threshold does a little better. Here are sample binarized images.

Figure 2. Binarized images of the sample subimages above.
The threshold value used is 0.77.
im = imread(C:\mypath\image.png);
im = mat2gray(im);
im = im2bw(im, 0.77);
Figure 3. (a) Histogram of the original image. (b) Zoomed in histogram.
We see here that the ideal threshold value is from 0.74 to 0.7

Next, I have to clean this image up to remove the unwanted portions of the image, such as the salt-and-pepper noise around the cells. We apply a combination of morphological filters such as opening, closing and tophat filters to obtain a satisfactory image. Before that, here is a summary of the three mentioned morphological operations [1,2]:
  1. opening - erosion followed by dilation
  2. closing - dilation followed by erosion
  3. top hat - extracts smaller details, has two types:
    • white top-hat - difference of opening and input images, extracts light features
    • black top-hat - difference of closing and input images, extracts dark features
With some poking around, I observed that the best morphological operation is opening. The structuring element that I used is a circle with an area that is slightly smaller than the cells. To have an idea about the size, I extracted first a single cell and computed for the area using the techniques we have learned in Activity 5. This involves finding the edge and computing for the area using Green's theorem. In the end I obtained 549 px as a first estimate of the area, and so my structuring element is a slightly smaller circle, so that all blobs with a smaller area than the structuring element will be removed. Here is the result of opening.

 
Figure 4. Binarized image of the subimages in Figure 1, with the 
opening operator applied to extract the individual cells.
struc_open = CreateStructureElement('circle',12);
opened = OpenImage(im,struc_open);

imshow(opened);
From this, I used SearchBlobs to label all blobs in the images and compute for the area of all blobs. I looped through all subimages and listed the computed areas. From this, I could get the mean and standard deviation, so I can now remove the abnormally large or abnormally small blobs that were still picked up even after processing the image. According to my results, the average area of a cell in the image is 500 +/- 29 pixels.
blobs = SearchBlobs(opened);
Area = zeros(max(blobs));            //array containing all blob areas
for i=1:max(blobs)
    Area(i)=length(find(blobs==i));  //loops through all blobs
end
disp(Area);
Using this information, I tried extracting abnormally large "cancerous" cells in another image by applying the opening operator again, but this time with a structuring element with an area that is slightly larger than the average area that I was able to calculate earlier. And here is the result.

Figure 5. Binarized image of the extracted "cancerous"
cells in the second image provided.

Grade I give myself: 10/10. I was able to apply the different morphological operations and obtain the wanted results.

Sources:
[1] Theobald, C. Mathematical Morphology. Retrieved from www.bioss.ac.uk/people/chris/ch5.pdf‎. Electronic document.
[2] A. Bousseau. Mathematical Morphology: a non exhaustive overview. Retrieved from maverick.inria.fr/Members/Adrien.Bousseau/morphology/morphomath.pdf‎. Electronic document.

No comments:

Post a Comment