Friday, October 14, 2011

sixteen

This activity is similar to the previous one.  The difference is that only two classes are used for each instance and LDA classification is used.  . 

Here, the same samples used in the previous activity are utilized here and are shown below.

1peso_thumb2

Figure 1. Class: 1-peso coin

25cents_thumb2
Figure 2. Class: 25-cent coin

chizcurlz_thumb2
Figure 3. Class: Chiz Curlz

piattos_thumb2
Figure 4. Class: Piattos

Shown below are the accuracy results, in percent of the LDA classification of two classes.  Only when the coins are compared side-by-side does the LDA classification not have a 100% accuracy rate.  This may be due to the fact that the general shape and structure of the two classes are very similar.

Table 1. Results of the LDA classification between classes
Class 1 Class 2 Accuracy
1-peso 25-cents 90
1-peso Chiz Curlz 100
1-peso Piattos 100
25-cents Chiz Curlz 100
25-cents Piattos 100
Chiz Curlz Piattos 100

Over-all grade: 9/10

REFERENCES:
1. A19 – Probabilistic Classification, Applied Physics 186 Manual
2. Pattern Recognition 2, prepared by Dr. S. Marcos

fifteen

In the world of image processing, a class is a set of patterns that share common properties and a pattern can be considered a set of features – color, shape and size for example.  These features can numerically be called feature vectors and can be used in pattern recognition to determine if a pattern belongs to a specific class. 

To perform pattern recognition, one has to define the features that will be able to separate classes from each other and then use these features to create a classifier.

In this activity, we use minimum distance classification to tell if objects belong in one class or another.  When you have a set of W classes, the mean feature vector of a class Wj is then defined as
eq1
where xj is the set of all feature vectors in the respective class and there are Nj samples in this class.  For the equation below, a sample must belong to a class if for an unknown vector x, it produces the smallest distance.
eq3

The following images were the different object classes and samples used in this activity.  The training set are presented in the top rows while the testing sets are shown in the bottom rows.

1peso
Figure 1. Class: 1-peso coin

25cents
Figure 2. Class: 25-cent coin

chizcurlz
Figure 3. Class: Chiz Curlz

piattos
Figure 4. Class: Piattos

The classifier used in this activity was the Minimum Distance Classification system.  The overall accuracy rate is 60%.  However, the accuracy for the 1-peso coin class was 100%; the 25-cents coin class, 60%; the Chiz Curlz class, 20% and the Piattos class, 60%.  This may have something to do with the morphology of the samples in the objects themselves.  It’s funny to note that the four mistakenly classified samples had been identified as a 1-peso coin and, thrice, a Piattos chip. 

Overall grade: 9/10

REFERENCES
1. A14 – Pattern Recognition, Applied Physics 186 Manual

fourteen

The main goal of this activity is to separate a colored region from a separately colored background.  To do this, each pixel coordinate can be normalized by the equations shown below and thus become Normalized Chromaticity Coordinates (NCC)

ncc equation

Shown below are the corresponding colors of the r and g values.

ncc fig
Figure 1. Normalized chromaticity space where the x-axis is r and y-axis is g.

Before any color segmentation can occur, a region of interest (ROI) is obtained from the selected image.  The image below is from the My Pictures folder of my computer.  Thank you again, Windows. 

tulips
roi_enlarged
Figure 2. (top) The original image and (bottom) the corresponding region of interest (ROI).

When the NCC and Gaussian histograms of the ROI are taken and compared with Figure 1, we can see that the location corresponds to the red and orange colors.

histogram
Figure 3. (left) Non-parametric: 2D histogram of NCC of ROI and (right) Parametric: Gaussian distribution fit of NCC values for the ROI.

From these histograms, masks were created to filter only the pixels of the color we’re interested in. 

gmask
Figure 4. Binarized Masks: (left) Non-parametric and (right) Parametric.

These masks were applied to the original image, hence only the colored ROI are seen.

gimage
Figure 5. Color Segmentation: (left) Non-parametric and (right) Parametric.

Well, there.  That was fun.  In conclusion, I think that the Parametric method is better than the Non-Parametric Method.

Grade: 9/10

REFERENCES:
1. A13 – Color Image Segmentation, Applied Physics 186 Manual

thirteen

In compression, you have to find the balance between things.  You must find a means of compressing that saves both data and space without sacrificing either.  In this activity, we use Principal Components Analysis or PCA to compress images. 

PCA basically allows one to obtain the eigenimages, their relative significance and principal components. For a more in-depth discussion on PCA, see this. Forgive me for pointing you to a Wikipedia entry, but I must since I’m not that good at briefly explaining complicated concepts, I’d rather not attempt to do so.

The image I will attempt to compress is a gray-scale version of an image of a jellyfish.  This image is from the My Pictures folder of my computer.  Thank you, Windows.

Jellyfish
Jellyfish_gray
Figure 1. Image of a jelly fish in (top) True Color and (bottom) gray scale.

PCA was done on this gray-scale image for different numbers of eigenvectors and the results are shown below.  Truthfully, when 20 eigenvectors are used, the image quality is actually not so different from the original gray scale image.

Jellyfish_all
Figure 2. Results of PCA on the gray-scale image of a jellyfish for (left to right, top to bottom) 1, 3, 5, 10, 15, 20, 25 and 30 eigenvectors.

I actually performed PCA with numerous eigenvector values with the maximum number of eigenvectors set at 100.  Looking at the file compression size, a 5% reduction for this image using 20 eigenvectors seems acceptable. 

Jellyfish_graph
Figure 3. Plot of the percent reduction versus the number of eigenvectors for the jellyfish image.

One of the things I wondered about this technique was if the same number of eigenvectors could produce a compressed image of good quality for another image.  Turns out, this technique is image specific as shown by PCA done on the image of a koala taken from the same folder as the jellyfish picture.  When using 20 eigenvectors, the image quality is not very good.  Even at 30 eigenvectors, the quality is still not as good as it was with the previous data set.  It’s also laughable that a negative reduction happens when you use 20 eigenvectors or more.  In that case, the image wasn’t being compressed but it was becoming enlarged.

Koala
Koala_gray
Figure 3. Image of a koala in (top) True Color and (bottom) gray scale.

Koala_all
Figure 5. Results of PCA on the gray-scale image of a koala for (left to right, top to bottom) 1, 3, 5, 10, 15, 20, 25 and 30 eigenvectors.

Koala_graph
Figure 6. Plot of the percent reduction versus the number of eigenvectors for the jellyfish image.

Overall, I think PCA is cool and all but I still think there’s the problem of not having one number of eigenvectors be suitable for all images. 

Contrary to popular belief about the title and unlike my previous entry, the thirteenth activity seems to be lucky for me.  I mean, I was able to do something at the least.  I think a 10/10 would be a suitable score for being able to finish the activity and do more than what was required albeit having finished it beyond the allotted time.

REFERENCES:
1. A14 – Image Compression, Applied Physics 186 Manual
2. “Principal Component Analysis”, http://en.wikipedia.org/wiki/Principal_component_analysis

twelve

Allow me to prepare you for disappointment.  I didn’t get far with this activity.  In my opinion, I didn’t go anywhere at all. 

This is all so ironic since this was actually an activity I was excited about.  When I learned we would be processing text from images, my mind immediately jumped to the infinite number of things I could do – create a typewritten of the notes I’d accumulated over the years, decipher the chicken scratch of most doctors, etc. etc.  That was a happier, simpler time, before I knew that the actual  implementation would make me want to throw dreams out the window.

Shown below is a document that an unidentified person with semi-illegible handwriting prepared.  The white spaces at the corners are present because of the rotation that the original image underwent to make the horizontal lines appear horizontal. 

orig_rotated
Figure 1. Rotated image of a form that was filled out with handwriting. 

The handwritten text that I wanted to extract are shown below along with, what I can say, is the best I can do.  I’m not sure if it’s what I’m supposed to see or if I’m half there or nowhere near there. 

text
Figure 2.  Handwritten text to be processed.

clim
Figure 3.  Results of the processing on the handwritten text.

So, I’ll just say what I did.  I binarized the image and removed the horizontal line using a mask.  Maybe the horizontal lines are too thick or maybe the mask I used was wrong.  Either way, I’ve spent too long on this activity.  A real scientist must know when something is beyond their capabilities.

I am aware that I gave up on this activity and that it’s late so I’m just giving myself a measly 7/10.

Sigh.

REFERENCES:
1. A12 – Preprocessing Text – Applied Physics 186 Manual.

eleven

For this activity, we add another dimension to the image processing and add some audio into the mix.  The main goal of this activity is, well, to play music from a music sheet – a task that I can surprisingly do when equipped with a laptop and the right software. 

Before any tunes can be heard though, a music sheet had to be obtained.  I chose Rain, Rain Go Away because, although I love the soothing sound of rain, the recent string of typhoons actually made me miss school.

music_sheet
Figure 1. Music sheet obtained from [1].

I cropped out one bar and the selection process wasn’t that hard since there;s only one bar to the whole song.  In the same way, a musical note was selected.  Shown below are the binarized and log-scale Fourier Transforms of these two (Figures 2 and 3).

music
1a sheet music
1b sheet music FT
Figure 2. Cropped musical sheet shown in its (top) original and (middle) binarized form along with its(bottom) log-scale Fourier Transform.

note
2a music note
2b music note FT
Figure 3. Musical note shown in its (top) original and (middle) binarized form along with its(bottom) log-scale Fourier Transform.

I was naïve enough to think that simply correlating the two images would be enough for me to isolate the individual notes in Figure 2.  Life isn’t like that though, as you can see from the first image in Figure 4, it looks like something I would see without my glasses (background info: I have really bad eyesight).  It’s out of focus, migraine-inducing and, I thought so at the time, depressing.

But we must forge on!  I used the binarized correlation image as a mask and multiplied this with the correlation matrix.  Using edge detection, the peak location of each note was found but for better visualization, a convolution with a circle was done.

3a correlation results
3b filtering ROI
3c isolated peaks
Figure 4. Summary of image processing. (top) correlation, (middle) filtering and (bottom) peak identification

To know what note should be played when, the x- and y-values relative to the first note are obtained.  The x-values can tell when the note should be played and the y-value, the specific note to be played. 

Finally, here’s the finished product.  I saved the file twice for two reasons.  First, because I’m not sure the first go lets you hear enough of the song.  Second, because in my head the lyrics are “Rain, rain, go away, come again another day.  Rain, rain, go away, little children want to play.”  My mother or my kindergarten teacher must not have taught me right – or I must not have remembered the right words.  Or, those could actually be the right words.  None the less, enjoy this ten-second computer-generated rendition of Rain, Rain Go Away.

Figure 5. Scilab generated music file of Rain, Rain Go Away

I shouldn’t have been surprised that Scilab can play audio music.  It’s slightly infuriating that I had piano lessons and came out of them, not fully knowing how to read notes or play music from a music sheet but that with technology, I can.  I should feel empowered by this added modern musical appendage, but I don’t.  I can’t help but mourn for the money that went into all those lessons when I could have just taken up a computer class to learn Scilab since the end results are pretty much the same.

With a smile, I have to say that I’ve only had to press the Upload button on my YouTube account homepage for this class.  Doesn’t that make you feel all giddy inside? Another 9/10 for me for finishing the activity but not doing so on time.

REFERENCES:
1. “Rain Rain Go Away Sheet Music”, http://www.gmajormusictheory.org/Freebies/FirstPieces/0Rainrai.pdf

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