Showing posts with label morphological operations. Show all posts
Showing posts with label morphological operations. Show all posts

Friday, October 14, 2011

ten

In certain situations, it is desirable to separate certain features from the rest of an image.  Normally, these features are called regions of interest (ROI).  Here, the closing and opening morphological operations that were previously used (see here) were utilized to differentiate cancer cells from normal cells.

Note that the closing morphological operation is actually an erosion operation followed by a dilation while opening is a dilation followed by an erosion [1].  If you can remember, the erosion and dilation operations require a structuring element.  In this case, I simply weaved a snippet of code into the while chunk that was the SCILAB program needed for the activity so I could generate a circle which I then took as the structuring element.

Since cancer cells are larger than normal cells (probably because they destroy – a.k.a. eat healthy cells), the normal cell size had to be determined so that you could actually tell which is which.  Call it a calibration of sorts but an image (Fig. 1) was divided into subimages, each with a size of 256 x 256 pixels (Fig. 2).  These subimages were then converted to binary images based on their histogram values.  Since there weren’t pictures of cells lying around, images of paper puncher cutouts were used.

Circles002
Figure 1. Original image of circles used to determine normal cell size.

a_1
Figure 2.  Subimages of size 256 x 256 pixels, shown in their respective locations to the original image

a_3
Figure 3.  Results of the binarized subimages obtained through each subimage’s histogram value.

The binarized subimages then went through the two morphological operations, first closing and then opening (Figures 4 and 5).  If I say so  myself, the opening operation cleans up the subimages while the closing operator combines overlapping circles.

a_4
Figure 4.  Results of the binarized subimages undergoing the opening morphological operation.

a_5
Figure 5. Results of each subimage in Figure 3 undergoing the closing morphological operation.

To determine the actual normal cell size, the area (in pixels2) of each circle – at least each distinguishable area in the image – is obtained (Figure 6).  We can take the peak in the left region to be the percentage of the individual cells and not the clumps which are taken into account by the other histogram peaks, especially those beyond the 2000 pixel count.  The normal size cell is then taken from the assumed individual cells, returning a value of 525. 

a_histogram
Figure 6. The histogram of the number of pixels in each distinguishable area of the image for (top) all pixel numbers and (bottom) zoomed in at 470 to 570 pixels.

The next, and most crucial, part of this whole activity is to detect cancer cells when it’s surrounded by normal cells (Figure 7). 

Circles with cancer
Figure 7.  Images of normal cells with cancer cells located within them.

Much like the previous step, the image of the cancer and normal cells was binarized based on the histogram values and applied with the opening then closing morphological operation.  Unlike the previous procedure though, the structuring element that was used was a circle that contained more than 525 pixels but lesser than what the approximated size of the cancer cells would be.  I have to say so myself, I isolated those cancer cells pretty well.  But then, I only had my visual count to compare it with.

b_4
Figure 8.  Image of the isolated cancer cells from Figure 7.

This activity reminded me so much of the many CSI and Bones episodes I’ve glued my eyes to over the years.  Now, I kind of want to apply this technique on actual medical images.  You can’t always imagine that, in medical images, the cancer cells will be photographed separately from normal cells.  That’s something to look forward to.

9/10 for being able to complete the objectives with the 1-point deduction for being late.

REFERENCES:
1. A10 – Binary Operations, Applied Physics 186 Manual

Thursday, July 28, 2011

nine

A little forewarning before we dive into the figures down below.  If you’re a loyal reader of this blog, you might notice later on that figure numbers aren’t present here.  Forgive me for that but I really wasn’t in the mood to keep track of such a large number.  I also thought it wouldn’t be pretty to have a Figure 24 (hypothetically).  Also, I’m not including a copy of my Scilab codes for this report because (i) there are too many figures as it is and (ii) it’s quite simple and not an object of awe.

The morphology of an object refers to its shape or structure.  From the name itself, morphological operations are operations that vary the structure of an object.  Binary images are composed of pixels that may only have two possible values – 0 and 1.  The former refers to the background of an image while the latter refers to the foreground. 

For this activity, we first give an extensive look into the dilate and erode morphological operations.  These two, mathematically, can be stated as:

equations
Equations for Dilation and Erosion, respectively.

Basically, the results of a dilation is an image that is the union of two images with respect to the origin of the second image.  On the other hand, the erosion is looks similar to the first image just with the intersections (again with respect to the second image’s origin) removed.  Four images were to be dilated and eroded by five different structuring elements.  For each pairing, we were tasked to give a prediction before using the corresponding Scilab functions. 

A
Four binary images to be dilated and eroded.  A (A1) 5x5 square, (A2) a triangle with base 4 and height 3, (A3) a hollow 10x10 square with a 2 pixel thickness and (A4) a 5x5 cross

BB_vertex
Four structuring elements to be used in the dilation and erosion process.  
From left to right, a (B1) 2x2, (B2) 2x1, (B3) 1x2, (B4) 3x3 cross and (B5) diagonal matrix of 1’s.

Before you get confused, the two rows of structuring elements represent the two methods I used in my predictions.  I’d like to call the first a non-origin-based prediction and the second, an origin-based prediction.  The non-origin based prediction allows any of the structuring element’s points to interact with the binary image whilst the opposite was set for the origin-based prediction.  I have two methods because the first was taught by Mr. Timothy Joseph Abregana which I followed for a while.  Upon seeing that my results varied from Ms. Eloise Anguluan’s, I asked her to explain her process to me.  Because these two methods gave different results, I wanted to see which one gave the right (or at least closest to the right) results.  From the results below the non-origin based prediction (a.k.a. Method 1) is less accurate as compared to the origin-based prediction (a.k.a. Method 2). 

For the predictions, the light blue represents the original image while the purple pixels represent the areas changed by the morphological operation.  In the case of dilation, the purple pixels are added to the image as a whole and thus, the final image a person should see was the combination of the two color pixels.  On the other hand, the erosion predictions are quite different.  The person should only see the light blue pixels as the purple pixels – the ones changed by the said morphological operation – are removed from the image itself.  I attempted to aid the visibility for the Scilab results by placing them all in front of a light blue background (because it goes with the colors for the prediction and we can’t have clashing colors now, can we?).

D1 M1D1 M2D1
From top to bottom, predictions using Method 1 and 2 and the results of the Scilab simulation. 
From left to right, the original image A1 and the corresponding results for the dilation with B1, B2, B3, B4 and B5, respectively.

D2 M1D2 M2D2
From top to bottom, predictions using Method 1 and 2 and the results of the Scilab simulation. 
From left to right, the original image A2 and the corresponding results for the dilation with B1, B2, B3, B4 and B5, respectively.

D3 M1D3 M2D3
From top to bottom, predictions using Method 1 and 2 and the results of the Scilab simulation. 
From left to right, the original image A3 and the corresponding results for the dilation with B1, B2, B3, B4 and B5, respectively.

D4 M1D4 M2D4
From top to bottom, predictions using Method 1 and 2 and the results of the Scilab simulation. 
From left to right, the original image A4 and the corresponding results for the dilation with B1, B2, B3, B4 and B5, respectively.

E1 M1E1 M2E1
From top to bottom, predictions using Method 1 and 2 and the results of the Scilab simulation. 
From left to right, the original image A1 and the corresponding results for the erosion with B1, B2, B3, B4 and B5, respectively.

E2 M1E2 M2E2
From top to bottom, predictions using Method 1 and 2 and the results of the Scilab simulation. 
From left to right, the original image A2 and the corresponding results for the erosion with B1, B2, B3, B4 and B5, respectively.

E3 M1E3 M2E3
From top to bottom, predictions using Method 1 and 2 and the results of the Scilab simulation. 
From left to right, the original image A3 and the corresponding results for the erosion with B1, B2, B3, B4 and B5, respectively.

E4 M1E4 M2E4
From top to bottom, predictions using Method 1 and 2 and the results of the Scilab simulation. 
From left to right, the original image A3 and the corresponding results for the erosion with B1, B2, B3, B4 and B5, respectively.

I mentioned earlier that there were two other morphological operations that this activity asked us to look into.  If you ask me, the skel function makes things more groovy and the thin function makes things look like they were drawn by a two-year-old.  Kidding! Those morphological operations don’t really do that.  As you can see below, the skel function draws the skeleton of an image using numerous lines and the thin function reduces an image to minimally connected strokes.

circles
Image to undergo skel and thin morphological operations.

circles_skel
From top to bottom and left to right, Result of skel morphological operation – exterior, interior and both.

circles_4_thin
Result of thin morphological operation.

I honestly spent most of yesterday (July 27) on this and even though I had the whole day to finish it, I wasn’t able to do so.  Most of that had to do with my complete shading of my predictions for both methods and with that, I have to thank Ms. Aven Perez (Hi, roommate!) for volunteering to shade.  With all the effort I placed into this activity, I think I deserve an eleven out of a ten, yes?

SOURCES:
A9 – Morphological Operations 2011, Applied Physics 186 Manual
Scilab Help