Thursday, August 7, 2008

Activity 13: Photometric Stereo

In this activity, we will use the concept of photometric stereo to reconstruct an object in 3D from image using shadow cues. The matlab file Photos.mat contains the 4 images that we will work with and the elements of matrix V is also given. These are the locations in space of the light source illuminating the object.

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. We can define a matrix V such that,
where each row is a source and each column corresponds to the x,y,z component of the source's location in space. 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,
We can now solve for g since I and V are known and we normalize g by its length in order to get the normal vector.After this, we calculate the object's shape from the normal vectors using the following equations.
source: M. Soriano, A13 - Photometric Stereo.pdf
____________________________________________________________________
//load images
loadmatfile('Photos.mat');

//enter V values
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];

V = [V1;V2;V3;V4];

//make matrix I
I1 = I1(:)';
I2 = I2(:)';

I3 = I3(:)';

I4 = I4(:)';

I = [I1;I2;I3;I4];

a = 1e-6; //additive factor
g = inv(V'*V)*V'*I;
mod = sqrt((g(1,:).*g(1,:))+(g(2,:).*g(2,:))+(g(3,:).*g(3,:)));
//length of g
mod = mod+a;

for i = 1:3
n(i,:) = g(i,:)./mod;
//calculate normal vectors
end

nz = n(3,:)+a;
dfx = -n(1,:)./nz;
//partial differentiation
dfy = -n(2,:)./nz;
z1 = matrix(dfx,128,128); //reshape the matrix to 128x128
z2 = matrix(dfy,128,128);
int1 = cumsum(z1,2); //a simpler way to integrate: cumulative sum
int2 = cumsum(z2,1);
z = int1+int2;

scf(0); plot3d(1:128, 1:128, z);
//show reconstruction
____________________________________________________________________

RESULTS:

4 sample images






reconstructed image
This 3D image clearly looks like a sphere. The cross mark at the center is also observed. Thus we can conclude that our image was properly reconstructed in 3d using the photometric stereo technique.






____________________________________________________________________

I give myself 10 points for this activity since the sphere was properly reconstructed. Thanks to Jeric Tugaff, Benj Palmares, and Mark Bejemino for their help in this activity.

0 comments: