Thursday, September 23, 2010

AP 186 Activity 14: Image Compression

Eigenvalues and eigenvectors remind me of our Mathematical Physics series, especially 112. I sometimes miss doing just math, without any big idea in mind just solving away.



Fig 1. Original image


Fig 2. Reconstructed images with different eigenvalues:(a) 1, (b) 10, (c) 30, (d) 50, (e) 80.

--
AP 186 handout
Wiki
--
I give myself 8.

AP 186 Activity 13: Color Image Segmentation

I've been meaning to use a picture of my brother Miguel for a long time, just for fun. In this activity, I finally did. I like this picture of him because he's annoyed and laughing at the same time, plus it's quite perfect for image segmentation because a number of colors in the image really stand out. For this activity, let's focus on the corn he's holding. This was taken using my cellphone camera, at 2MP. I love you dear K770i.

Fig 1. My brother Miguel.

Let's have an overview first of the two segmentation techniques we'll be using in this activity. First is Parametric Segmentation; it's basically getting a region of interest (ROI) in the image then transform its color RGB into normalized chromaticity coordinates using the equation below:



Then the probability function of r and g is solved to test the likelihood that a pixel belongs to the ROI. We used the Gaussian function to compute these probabilities.
As for Non-Parametric Segmentation, the 2d histogram of the image was taken and then using this we back project to segment the image. The results are below:

Fig 2. Parametric (left) and Non-Parametric (right) segmentation.

I observed that Parametrically segmented images are cleaner, and the matching parts in the image with regards to the ROI really shine. On the other hand, Non-Parametrically segmented images have a lot of noise and unwanted data. However since I used a colorful picture, and colors all have red, green and blue, the Non-Parametric method was more sensitive to the presence of the hues in the ROI that were present in the image itself.

--
AP 186 handout

--
I give myself 10 for this activity because I think I understood well the concept of these two techniques of color segmentation, plus I got to use a picture of my brother.

AP 186 Activity 12: Color Image Processing

A few days earlier, I became so giddy because of an LX3 promo I saw at Trinoma. For a while, I've wanted to buy a Panasonic Lumix LX3 (may LX5 na, hehe) but I've had fluctuating discipline in saving money and then my Tio gave me a point and shoot. So for this activity, hurrah goes to my Lumix FS8 and its six white balance configurations.

Below are the original images captured using the six white balance setups in the camera. These were captured around lunchtime, with ambient light as the governing light source.
Fig 1. From a-b: white set, auto white balance, daylight, cloudy, shade, halogen

Before processing, I cropped the images to lessen the size as well as to limit the image with the parts we only want to see. There are two white balancing techniques used in this activity, the White Patch Algorithm (WPA) and the Gray World Algorithm (GWA). The WPA makes use of a known white object as a basis for sort of normalizing the whole image. The GWA on the other hand assumes the that the average color of the world is gray. By getting the average RGB value for each pixel, we can use it as the balancing constant.

Fig 2. From a-b: auto white balance, daylight, cloudy, whiteset, shade, halogen.

Then in another setup, we utilize an inept white balance setting and process the images using the two algorithms, shown below. I think, though, that my WPA is a failure. :/
Fig 3. In the halogen white balance setting, for colors red, blue, green and yellow.

--
Thanks to BA and the AP 186 handout :)

--
I give myself 9/10 because I think my White Patch Algorithm did not give me the best results

AP 186 Activity 11: Playing notes by image processing

The first hindrance for me in this activity is that I can't read notes. I think we were taught how to read back in highschool but I don't quite remember. I'm not that much musically inclined, my relationship with music is basically me being able to hear and knowing the tunes that I like. I wish it were more, but oh well.

So here, we are to extract the notes in a simple score and play it using Scilab. Seems pretty easy, until I realized there is so much in a musical score. First, I binarized the image of the score through thresholding, and I inverted the values. Also took samples of the notes, a half note and a quarter note, from the score music and binarized and inverted it as well. My idea is to clean these images by morphological operations and then segment them and take out the notes as needed.

Fig 1. Line from Are You Sleeping musical score (top) then binarized and inverted (bottom).


Fig 2. Segmented musical score.


Fig 3. Quarter notes (above) and half notes (below)

I turned the image clockwise to get the index of the notes in order. I fished out the next quarter notes and the half notes to give them their respective durations. I also thought about using template matching for this but I think this is also a good alternative in determining notes using image analysis.


--
Thanks to BA, I got ideas from discussions with him
AP 186 manual

--
I give myself 9/10 for this because I think my method is too crude. There are more eloquent ways to solve this.



AP 186 Activity 8: Enhancement in the Frequency Domain

Sometimes there are unwanted things present in our work, and it is of course better to have only the things we need to be there. Noise reduction  makes a sample more pure, assumptions that can be made more valid, or just make things more beautiful. In this activity, we will be using the ubiquitous Fourier Transform to tone down unwanted specks and enhance the parts we want, err need.

First, we need to understand convolution. Mathematically, it is defined as below.
If f(x) and g(x) are two functions with Fourier transforms F(u) and G(u), then the Fourier transform of the convolution f(x)*g(x) is simply the product of the Fourier transforms of the two functions, F(u) G(u).
Now,  let us understand this through these examples.
Figure 1.

Figure 2.

Figure 3.

Figure 4.

Figure 5.


Finger print



Finger print
FT of finger print in log scale



--
convolution
http://www.cs.cf.ac.uk/Dave/Vision_lecture/node19.html

finger print
http://archgraphics.pbworks.com/f/finger%20print_blue%20copy.jpg
http://www.cogs.susx.ac.uk/courses/acv/matlab_demos/fft_image_demo.html

--
I'd give myself 7 for this activity because I didn't get to finish it.

Wednesday, September 22, 2010

AP 186 Activity 10: Binary Operations





This is a culminating activity of all the methods we have learned so far. We are to get the area of normal cells and be able to discriminate cancer cells (which are really just abnormal cells) as very important application of image processing.


First, a little practice. We are given an image with punched circles. This is to measure the average size of a punched circle.The image is segmented and binarized for simplicity. However, there are still unwanted specks in the image. We use the morphological operations opening and closing to remove these unwanted attributes.

Fig 1. Counterclockwise from top left: original segment, black and white conversion, 
cleaning by morphological operators, cleaning using bwlabel.

To keep track of the blobs, we use bwlabel. It turns out that this function is very useful in not only identifying the number of blobs in the image but also in indexing these blobs. I used the sample code in the bwlabel Help article to get rid of other smaller (those left from opening and closing perhaps) and larger (stacks of cells) articles in the image.
Fig 2. The same segment as in Fig. 1 but here the blobs are filtered and labeled.






From the counted an indexed blobs, the cell areas were tallied. My computed average circle area is: 575.31 pixels. This is now used to isolate the 'cancer' cells in the given image Cells_with_cancer.jpeg.

Fig 3. Image of cells with cancer cells (left) and image of isolated cancer cells (right).

--
Thanks to BA and Che, my 'seatmates' in 186. :)
AP 186 Handout
Scilab Help
--
I give myself 10 in this activity because I did what has to be done and I enjoyed making this activity.

Thursday, August 26, 2010

AP 186 Activity 9: Morphology




Above is the first image you shall see in Wiki's mathematical morphology page, the shape in blue is the input image and the resulting morphological erosion with a diamond shaped structuring element is in yellow and dilation in green . I used this to open this entry because, maybe like the people who created the page, I think it's a pretty illustration and it draws you to this idea of morphology. 

In image morphology, an input image and a structuring image are compared, the result of this operation is the output image. The foundation of morphology is basically Set Theory, where operations are used to compare and contrast different sets.

I had a hard time applying the concept of dilation and erosion, but thanks to Google I found several helpful sites (plus having helpful friends) that made me understand how I should use these two. The rest can be found in the acknowledgement section and the most helpful was from a lecture at Brigham Young University. First, there are two things that need to be set clear: the object and the structuring element. The object is the image to be operated upon, while the structuring element is the shape that will operate on the former. From this aforementioned lecture, it explained erosion and dilation as translations of each of the pixels of the structuring element, shown below:
Fig 1. Structuring elements

Fig 2. Objects

For example, the structuring element of a square of four pixels against an image of a square that is of 5x5 pixels, the image is translated for every pixel in the structuring element. To get the dilated image, the union of these translations is taken. Consequently, the intersection of these translations is taken to get the erosion of the image. I must say that this process is tedious, but this is the clearest explanation I've seen yet. And I do believe that it's better to go slowly but surely rather than being too nonchalant and not understanding things thoroughly.

After predicting the results, we used Scilab to check our guesses. Below are the results of erosion and dilation of four shapes, a cross, a square, a triangle, and a hollow square (first column of Fig. 3 and 4).

Fig 3. Erosion

Fig 4. Dilation

There are several other methods used in morphology. Some of them are:
1. Opening
2. Closing
3. Skeletonization
4. Thinning

--
Thanks are in order!
BA
wiki http://en.wikipedia.org/wiki/Mathematical_morphology
http://homepages.inf.ed.ac.uk/rbf/CVonline/LOCAL_COPIES/MORSE/morph1.pdf
http://www.mathworks.com/help/toolbox/images/f18-12508.html;jsessionid=4pkLMBrfWQfNyYSR1352k82kQyJxh3pSrRJvZkrtyLhPJpw3Fc9V!974718655

--
It took me a long time to complete this, but I think I deserve a 10.

Tuesday, August 10, 2010

AP 187 Activity 7: Properties of the 2D Fourier Transform

Our household WiFi is called FFT. Wala lang. I set it up, and I wanted to use a name that sticks but is not really common. That was two years ago, when I first encountered the Fourier Transform, and also the Fast Fourier Transform. Now, what was then a mathematical tool is now being realized as a very flexible means in image analysis.

This activity is a foray into the properties of the 2D FT. First, we were asked to get the FTs of basic 2D patterns.


Next we observed the anamorphic properties of the Fourier Transform.

Figure 1. FT of sinusoids

In the figure above it is shown that the higher frequency,  the more distant the dots of the FTs became. While when the patterns were rotated, below left with theta being 30 degrees and below right with theta being 30 degrees with the addition of another sinusoid. The change in theta caused a shift of the FT, in these cases to the left.
Figure 2. Rotated patterns

On the other hand, when two sinusoids are mulitplied their FT is an addition of their separate FT.
Figure 4. multiplication of multiple sinusoids


Figure 5. Addition of sinusoids


--
Some help:
http://how-to.wikia.com/wiki/How_to_plot_in_Scilab

--
10

Sunday, August 8, 2010

AP 186 Activity 6: Familiarization with Discreet FFT

The Fourier tranform has ubiquitous applications, and in this activity we apply it to image processing. In any typical tansformation, the FT is in the frequency domain. According to wiki, the domain of the new function is typically called the frequency domain, and the new function itself is called the frequency domain representation of the original function. A more preferred method of FT is the fast Fourier Transform (FFT).

To familiarize with FFT, we observe its effect on a centered circle. Going clockwise, the topmost left is the original circle, then applied fft2 then shifted, then taken the inverse fft.
 For the image of the text A, the same procedure was done. Notice that the last image (topmost right) is inverse of the original image (topmost left). The FT has rendered its matrices shifted, resulting to an inverted image.

Next we consider the FT in terms of viewing an object. Let circles of different sizes be the apertures, and the image of the text 'VIP' be the object. As can be expected, the larger the aperture size, the sharper the image.


Another feature of the FT is the ability to compare a template and an image. In this example, a text image was correlated with the text image of a single letter 'A'. This will be to determine which letters in the text image check out with the 'A' template.

The bright spots in the transformed image (right) are the points where A is present in the text image, note that the transformed image is flipped though.

Lastly, the FT was used for edge detection.
 Horizontal pattern
Vertical pattern

Spot pattern

--
186 handout
BA

-- 
10 

Monday, July 26, 2010

AP 186 Activity 5: Enhancement by Histogram Manipulation

There are so many digital ways to manipulate images. Basically, an image can be represented by sets of numbers and from there controlled as wanted. Paint, Photoshop and Gimp are among the mainstream image editing software available today.

I used two pictures in this activity, one from my personal library and one from the internet. However, I used the latter image as my main image in analysis because it is smaller. (Faster! :p)

Sunset at the beach.


The Fray.

Below is the initial conversion to grayscale of the 'fray' image.
Now, a quantitative property of grayscale images are Probability Distribution Functions (PDFs) and Cummulative Distribution Functions (CDFs). The PDF of an image is basically the distribution of the pixels in the image corresponding to the gray levels equal to 0-255. On the other hand, the CDF on an image is the like the cummulative summation of the PDF. Below are the normalized PDF and CDF of the grayscale fray image.

With this information, we can remap the CDF to correspondingly adjust the levels of the image. Below are the transformed CDFs and images, linearly, exponentially and parabolically (coined term? hehe) respectively.
I also did this for the sunset image, from left to right and then top to bottom: the original conversion to grayscale, the linear CDF, the exponential CDF, and the prabolic CDF.
Histogram manipulation can also be done using software available, such as GIMP. Open an image, set its mode to grayscale and then go to Colors  > Curves.


I must admit that I did this activity in MATLAB. It's too costly to run a virtual Windows on Mac and to process images at the same time. I was not very much progressive during the time we did this in class, so I finished this at home.

--

I'd like to thank Aivin, Che and BA for the helpful discussions. Also to Kuya Jeric and Tisza for their codes.

http://www.aiaccess.net/English/Glossaries/GlosMod/e_gm_distribution_function.htm
--
Technical Correctness: 5
Quality of Presentation: 4
Initiative: processed other images to see the effects