Wednesday, August 27, 2008

Activity 15: Color Camera Processing

The task: to investigate colors from images taken with a digital camera and different white-balancing techniques/settings.

The following images were of different-colored nail polish on white paper under a fluorescent light, taken with a Sony Ericsson DSC-T10 digital camera with an Exposure Value of -1.
automatic white balance setting

"daylight" setting

"cloudy" setting

"fluorescent" setting

"incandescent" setting

"flash" setting

**As we can see, the "best" settings for the set-up are the automatic white balance and fluorescent settings,as it should be; these show the colors as they are perceived by my eyes (albeit darker because of the low EV setting). The daylight setting makes them look dull (to balance out the bright sunlight), while the cloudy setting appears to increase their saturation. The incandescent white balance setting is by far the worst, giving a bluish tinge to the colors, evidenced by the now-light-blue paper background; this is to cancel out the yellow-orange tinge incandescent light usually casts on everything. The flash setting has the same effect as that of the daylight setting, though it makes them even darker, this is because light from the camera's flash bulb would be more intense than the diffused sunlight outdoors.


Next we use two popularly used automatic white balancing algorithms to enhance the most "wrongly balanced" image, which is of course the image taken using the Incandescent Light setting.

using the following code:
im=imread('act15v.jpg');

//im2=imread('white.jpg');

//r=mean(im2(:,:,1));
//g=mean(im2(:,:,2));

//b=mean(im2(:,:,3));

//im(:,:,1)=im(:,:,1)/r;

//im(:,:,2)=im(:,:,2)/g;
//im(:,:,3)=im(:,:,3)/b;

rg=mean(im(:,:,1));

gg=mean(im(:,:,2));

bg=mean(im(:,:,3));

im(:,:,1)=im(:,:,1)/rg;
im(:,:,2)=im(:,:,2)/gg;

im(:,:,3)=im(:,:,3)/bg;

imshow(im);

...the first (commented out) part employs the Reference White Algorithm. Basically, it takes the RGB values of a white reference part of the image and saves them as the variables r,g,b then divides the RGB layers of the image by the corresponding saved reference value. We obtained the following image:
image enhanced with Reference White Algorithm
**It effectively white balances the image, reverting the colors to more or less their real-world hues and shades. A few problems seen in the image include a few artifacts like the little dots on the paper and the big red ring on the bottom part which shouldn't be there, and the disappearance of the light yellow patch(7th from the last).

...the second part of the code employs the Grey World Algorithm, it assumes that the average color of the world is grey. Basically, the code takes the averages of the RGB values of the unbalanced image then divides the RGB layers of the image by the corresponding stored averages. We obtained the following image:
image enhanced with Grey World Algorithm
**This algorithm whites out the white and balances most of the others like the previous algorithm, it also has about the same specks and red ring. It is a poor choice for enhancing an
image though because it totally erases 3 of the patches, the orange and two shades of yellow, and most of the yellowgreen patch.

Now to see the effectiveness of the same algorithms on a wrongly-balanced image with just one hue (and a patch of white for reference). Below is a picture of the hems of shirts with different shades of purple(/violet), taken with the same digital camera and under the same light as the previous set of pictures, again using the "incandescent" white balance setting. This is followed by the same image after it has been white balanced using the Reference White Algorithm, then again using the Grey World Algorithm.

"Shades of Purple" after Grey World Algorithm balancing
**Looking at the above pictures, the Reference White is obviously the better algorithm, in this particular set-up at least. The Reference White gives almost the real-world shades, although it whites out the shirt with the lightest shade of purple; while the Grey World not only whites out the two shirts with the lightest shades of purple, the colors are very off, making them bluish, greyish, even making the top left one look more brown than purple.


**I give myself a grade of 10 for this activity, because the results were satisfactory and all the objectives were achieved.

**thank you to mark leo for the help.

Tuesday, August 19, 2008

Activity 13: Photometric Stereo


The task: to use photometric stereo concepts to build a 3d image solely from shadow cues.

The the surface shape can be determined by taking many images of the same object from different angles and distances.

This results in a v matrix similar to the following,
...where each row is a source and each column corresponds to the x,y,z component of the source's location in space. If you take N images of the surface using each of these N sources, then for each point (x,y) on the surface we have,

...g may now be solved for.

Then calculating for the normal vectors...we can the use these to calculate for the object's shape.

**The provided matlab file, photos.mat held 4 images to be used in this particular activity. Also given were the elements of the v matrix, the points in space where the light source is located.








Then, using the following code:
loadmatfile('Photos.mat');

v= [0.085832 0.17365 0.98106;0.085832 -0.17365 0.98106;0.17365 0 0.98481;0.16318 -0.34202 0.92542];
is1=I1(:)';
is2=I2(:)';
is3=I3(:)';
is4=I4(:)';
i=[is1; is2; is3; is4];

vt=v';

g = inv(vt*v)*vt*i;

new = sqrt((g(1,:).*g(1,:))+(g(2,:).*g(2,:))+(g(3,:).*g(3,:)));

for j = 1:3

n(j,:) = g(j,:)./new;

end

nz = n(3,:)+a;

dfx = -n(1,:)./nz;

dfy = -n(2,:)./nz;

z1 = matrix(dfx,128,128);

z2 = matrix(dfy,128,128);

int1 = cumsum(z1,2);

int2 = cumsum(z2,1);

z = int1+int2;

plot3d(1:128, 1:128, z);

The object seems to be a hemisphere with a + shaped indention on the surface.

**i give myself a grade of 9 for this activity because i successfully reconstructed the object into a shape that coincides with the apparent shape inferred from the images in photos.mat.

*thank you to cole.

***i'm having a lot of problems with my posts lately, with uploading the images and somehow my drafts got resetted. (i think they got wiped out when my virus-riddled laptop restarted and firefox restored my 10-13 pages and autosave kicked in with the blank page? unlikely, but it's the only explanation i can think of right now. i'm still working on trying to recover them but it seems like a lost cause.) i'm currently redoing this and the last two activities.