Thursday, August 28, 2008

A15 – Color Image Processing

In this activity we invoke two well-known white balancing algorithms, the Reference White Algorithm (RW) and the Gray World Algorithm (GW). The first part is to examine different kinds of white balancing and their images. I took pictures of the same object using different white balancing settings. The object that I used were a rubix cube, a green Bible and a handkerchief. The objects were placed on top of a bond paper which is our white reference. The images are shown below.


Auto WB and Cloudy WB

Daylight WB and Flourescent WB

Tungsten WB

We could see that not all WB have satisfactory accuracy in the image color. This is obvious because the bond paper that was supposed to be white appears to be colored. That is why we use the white balancing algorithm discussed. The first would be the RW algorithm. We take the RGB value of the white reference and call the values Rw, Gw and Bw. Then for each pixels of the image we divide Rw, Gw, and Bw to the corresponding values (R value divided by Rw, G by Gw and B by Bw). If there are values that exceed 1 then we change that value to 1. The resulting images are shown below.


Previously Auto WB and Cloudy WB

Previously Daylight WB and Flourescent WB

Previously Tungsten WB

We can observe that all our images are greatly improved using the RW algorithm. Also, it seems that the images are almost identical. This may be due to the fact that different white balancing in cameras are in fact just multiplying certain RGB coefficients to the corresponding RGB values of the image. This means that if we divide it by those RGB coefficients we get the original pixel value that the camera measured (original meaning unprocessed or no white balancing). That is just what we did when we divided the RGB value of the white reference. That is why we just ended up having the original image that the camera captured.

Now we try using the GW algorithm. The concept is the same as in the RW algorithm. The only difference is the RGB values of the white reference is the mean of the RGB values of the image. We get Rw by getting the mean of the R values of the image. This is the same for Gw and Bw. The resulting images using the GW algorithm are shown below.


Previously Auto WB and Cloudy WB

Previously Daylight WB and Flourescent WB

Previously Tungsten WB

The images are still greatly improved compared to the original image. It seems that the images are almost the same. This may have the same explanation as in the RW algorithm. At this stage I cannot determine which is better. It seems that both algorithm have promising results. We proceed further by taking a picture of objects of the same hue using the wrong white balancing setting. Then we perform both the RW and GW algorithm on the image. The image is shown below as well as the resulting image using RW algorithm and the resulting image using GW algorithm.


Original Image

Image using RW algorithm and GW algorithm

Both images are better than the original image. I think that the image using RW algorithm is better in this case. The image using GW algorithm seems very bright and has poor contrast. This may be because the reference of for the GW algorithm is dependent on which RGB values are prominent in the image. This is due to the fact that the GW algorithm uses the mean of the RGB values of the image. For example if the color dominant in the image is green then the reference would be closer to the RGB values of the green. When we apply the GW algorithm on that image the green would appear closer to white. This explains why our image using the GW algorithm appeared brighter. If all the major hues are represented in the image then I think the GW algorithm would have better results since the average of the RGB values would most likely represent the average color of the world which is assumed to be gray.

I give myself a grade of 10 for this activity since I have done the algorithms and also included possible explanations for the results. Thank you for Billy Narag for helping me in this activity.


Tuesday, August 26, 2008

A14 – Stereometry

Problem with using splin2d...Tried since the beginning of activity but failed...I guess 5 points for trying...

Monday, August 11, 2008

A13 – Photometric Stereo

In this activity, we would reconstruct a 3D object by using photometric stereo. An object is illuminated by the same point source with 4 different locations with respect to the object. The matlab file Photo.mat contains the 4 images corresponding to the 4 different locations.

According to the PDF file that Ma'am Jing sent us:
We can estimate the shape of the surface by capturing multiple images of the surface with the sources at different locations. The information about the surface will be coded in the shadings obtained from the images.
If there are N images in 3D space. We can define a matrix

where each row is a source, each column is the x,y,z component of the source. If we take N images of the surface using each of these N sources, then for each point (x,y) on the surface we have

Since I and V are already given we could compute for the matrix g by using the equation given below.

Then we get the normal vector by the equation below.

We can now calculate the shape of the object using the following equations.
We were given the matrix V.
V1 = {0.085832, 0.17365, 0.98106}
V2 = {0.085832, -0.17365, 0.98106}
V3 = {0.17365, 0, 0.98481}
V4 = {0.16318, -0.34202, 0.92542}

The data within the matlab file contains the intensity of the four images the intensities are in 128*128 matrices. We reshape these matrices into a row matrices in order to obtain the matrix I. Then when we finally get df/dx and df/dy by using the normal vector we reshape these back to a 128*128 matrices for us to reconstruct the 3D object. The four images below are the ones used in the activity. The following image is the reconstructed 3D object.






We see that the reconstructed 3D image is a sphere with a cross structure. This 3D image is similar to the 4 2D images which means that our reconstruction was successful.

I give myself a grade of 10 for successfully doing the activity.
Thank you for Rafael Jaculbia, Jorge Presto and Billy Narag for helping me in this activity. Also thanks to Cole and Jeric.

Sunday, August 10, 2008

A12 – Correcting Geometric Distortions

This activity aims to correct geometric distortions which are a natural occurrence when taking pictures with a camera. The image below clearly shows a distorted image. We observe that the lines are not straight. What we aim here is to make the lines appear straight.

The instructions given can be summarized as follows:
1. Count the number of pixels down and across one box from the most undistorted grid of the image.
2. From the obtained data, we create an ideal and compute c1 to c8. We compute c1 to c8 by picking four points in the distorted image and then taking their respective coordinates in the ideal grid coordinate. Then using the equations below.

3. Per pixel in the ideal grid calculate the corresponding coordinate in the distorted grid. This can be done by using the equations below.

4. If the calculated coordinate is integer valued copy the grayscale value at that point onto the ideal grid pixel location. If the calculated coordinate is not integer valued then do interpolation by using the equation below.

I measured the size of a box with the most undistorted part of the image. The size was 9 pixels by 11 pixels. Then I created the ideal grid using scilab. The calculation of c1 to c8 were supposed to be per rectangle but it would take an eternity to do that so I picked a fairly large rectangle from the distorted image and took the coordinates of vertices and their corresponding coordinates in the ideal grid. Below is the table of the data that was recorded.

Ideal Coordinates Real Coordinates
Xi Yi Xr Yr
54 33 48 30
54 187 52 183
99 33 95 31
99 187 97 183

I calculated c1 to c8 and used it to know the corresponding location of each pixel in the ideal grid in the distorted grid. Then since it is more likely that the answer would be a non-integer I used interpolation. I did not use the round command since it is better to use the int command which gives the greatest integer value. I used this because I need the 4 nearest neighbors. For example if the coordinate was (9.5,10.6) I know that its nearest neighbors would be (9,10), (10,10), (9,11) and (10,11). If I used the round command it would be more difficult since I would have two cases which are round up or down so I used the int command. Using the int command the nearest neighbors of (x,y) would just be (int(x),int(y)), (int(x)+1,int(y)), (int(x),int(y)+1) and (int(x)+1,int(y)+1). The corrected image is shown below.



The resulting image is much less distorted than the original. We could improve the correction if we section the image and then calculate the corresponding c1 to c8 of each section which was the original instruction. Nevertheless, the correction was still successful and the interpolation was also done.

It took me quite a while to blog this activity so I give myself a grade of 8. Even though I was successful in doing the correction as well as the interpolation, I was still late. Sorry for the late posting but I did this activity on the day it was given. In fact I did it even though I was sick at that time laying in my bed with my laptop.

Thanks for everyone who helped me in this activity. Thank you Ma'am Jing because you chatted with me while I was sick. Thanks to Cole, Jeric and Julie. Special thanks for SPP and Bio 11 for preventing me to post this blog on time.