Thursday, July 30, 2009

この学校は、好きですか? (Activity # 11)

Yey.. we finally had an activity which makes me feel that this is an image processing class.. why of course.. the best images are taken with a camera..

This activity is entitled Color Image Processing. We learned that the color captured by a digital color camera is an integral of the product of the spectral power distribution of the incident light source, the surface reflectance and the spectral sensitivity of the camera. We note that from these quantities, a White Balancing constant for the camera can be obtained and this constant explains why sometimes the colors taken by the camera just don't seem right.

There were two White Balancing Algorithms discussed in this activity: the White Patch algorithm which requires a patch or ROI in the image that looks white in the real world to calibrate the colors of the image, and the Gray World algorithm which basically takes the mean value of the pixels in the image for its definition for white.


The images displayed above shows a white-balanced photo (L) using AWB or Auto White Balancing and a poorly white-balanced photo (R) using the Tungsten Bulb setting in my phone's camera. We note that for tungsten, the camera tries to compensate for the orange tone produced by the tungsten bulb by adding more blue. However, Tungsten will make a daylight photo blue, resulting to a loss of color information in the red.

Using the White Patch algorithm, I was able to restore some of the red colors seen in the AWB image. For the Gray World algorithm however, since most of the pixels are cyan in nature--guess what their mean value is? My intuition however tells me that there just doesn't seem to be any point trying to make a bad image look good, so today's valuable lesson would be--Make sure to get your camera settings right!!

Now here's another set of images. To make it challenging, we added items of the same color but different shades in the images:

Guide to the pictures above: Auto-White Balanced (TL), Daylight setting (TR), White Patch (BL) and Gray World (BR). In terms of quality, the ones at the bottom lose unless we consider the fact that Scilab isn't actually equipped with good rendering backends.

The daylight setting is wrong in this case since the light source is mainly flourescent. The white patch algorithm did its best in restoring the original lighting, but I got a lot of noise from its attempt. Same goes for gray world but as expected, the lighting is still to the poorly-white balanced image. The white patch algorithm is definitely better than the gray world algorithm--but a good image taken by a good camera is tens of thousands of times better. ^_^

There goes another 10 for finishing the activity on time.. it's too bad the blog posts never make it in time. xD

Wednesday, July 29, 2009

がんばってね。(Activity # 10)


The title for this activity is Preprocessing Text. The lessons we learn in the activity is very useful in handwriting recognition where individual letters must be extracted.

We were given the task of extracting a group of text from a scanned image. We rotated the image by using mogrify(), a function in Scilab that can do almost anything that the Free Transform tool in Photoshop can do (although I favor the latter). We removed the lines using the techniques used in the moon photo and the canvas weave in the previous filtering activity, binarized and threshold the image, and then labeled using bwlabel().

This activity pretty much summarizes everything we learned so far, thus it's vital to show the resulting image for each step. Apparently, mogrify() returns a stack problem in my pc, causing SIP to go FUBAR.. I had no other choice but to make use of the Free Transform tool in photoshop.


By looking at the Fourier Domain of our image, we can get an idea on the type of filter we'll need. For this case, it's pretty much like the moon photo except this time, the lines are horizontal. From the Fourier Domain of the image as shown below, the best filter is a vertical line masking the white vertical line, but taking care not to touch the point at the center. Touching that point will result in a great loss of information.

The following sets of images are the images taken before (L) and after (R) the closing operator was used. We can note that the noisy signals inside the letters were significantly reduced.

Finally, here's the image with indexed values for each blob. Imaged in hotcolormap. xD

I'd like to acknowledge Neil for helping me out with this activity, especially since I needed to do it again.. all thanks to the recent USB disk loss. I'd also like to thank Hime for her support, and for keeping me awake last night through all the blog posts I needed to write. The post date might lie, but this is actually the last blog post I made in time for the deadline.

I get a 9 for this activity. Probably for the effort in trying to recover the lost files.

Monday, July 27, 2009

違う。違うよ。(Activity # 9)

Activity # 9 is entitled Binary Operations. It is very important in image-based measurements where a Region of Interest (ROI) is segmented from the background by means of edge detection or blob labelling. Some common problems in image processing where these operations are used include cell counting, tracking of fingerprint ridges and pattern recognition.

In this activity, we've been given the task of estimating the area (in pixels) of a typical puncher hole, using a reference image that looks like this:

In order to make life easier for both scilab and me, I divided the image into nine parts..

For the first subimage, the next step is thresholding. Using Photoshop (I'm working at home since I had to do this activity again.. why? Coz i lost my flash disk!!), I obtained the suitable threshold value of 230/255.

Once the threshold was found, I made use of the erosion and dilation operations from the previous activity, to perform the closing and opening operations. I used the closing operation (dilate then erode) to clean up my image, after which I used bwlabel() to label the blobs.

Finally, I used my routine for counting the pixels of the same label, tallied them into an array, and repeated the procedure for the rest of the subimages.

I tallied the areas for all the holes in the large image by appending the tallies for each of the sub-images, and I got this histogram:

I realize that as it is, there's still a lot of noise in the image. However, we are only after the area for each punch hole, thus we can also just trim our histogram by setting a tolerance level. I decided to set my tolerance between 300 and 700, the location at which the second peak is centered.

We can see that the peak is located between 512.5 and 525--but the mean value however tells us that it's 507.5. The histogram tells us that the size of the hole should be about 517 pixels, giving the mean an error estimate of around 3%.

I managed to finish the activity in a few minutes (when I had to do it again), so I definitely get a 10. hahaha.

Monday, July 20, 2009

ほら朝よ。おきておきて。 (Activity # 8)



Morphology refers to shape or structure. Just as the title implies, morphological operations for image processing shall be the focus of this activity. So what is it used for? Shapes can be expanded or thinned, holes can be closed, and disconnected blobs can be joined.

It makes use of the Set Theory. It makes use of the shape, as well as a structuring element for the direction of its growth or reduction. However, for our purposes, we only need to focus on the concepts of Dilation and Erosion.


Dilation results in an expansion of the shape following the morphology of the structuring element.

Erosion results in a reduction of the shape following the morphology of the structuring element.

In this activity, there was predicting involved. However, for the most part, you won't really see explanations. It's pictures galore once again. xD

Original Images:

Structuring Element (4x4 ones):
Dilation
Erosion

Structuring Element (2x4 ones):
Dilation
Erosion

Structuring Element (4x2 ones):
Dilation
Erosion

Structuring Element (cross):
Dilation
Erosion

This is probably the most tedious activity ever. So without further ado, I get a 10.