Photometric stereo is a technique in computer vision for estimating the surface normals of objects by observing that object under different lighting conditions. Having this surface normals, we can recreate the shape of the object in 3D. Theoretically, a minimum of three light directions are required to fully recover the 3D shape surface normal, but because there are noises, more than 3 light sources will improve the accuracy of the recovery. There are some limitations to this method: 1. the light source needs to be far away so that it can be approximated as a point light source. 2. Specular (bright reflective spot) or dark spots don't give accuracy results because the camera sensor clip the signal. 3. This model do not take into account for shadow.
Image brightness received by the camera at each pixel in each colour channels v = R, G, B, is given by
where a is the albedo of the surface at pixel , is the surface normal and is the direction of the light source.
The first step before doing any 3D surface recovering is calibration. To do this, we used a chrome sphere, a camera with fixed position and several light sources with fixed position as well. We then use the images taken with one light source turn on a time.
We can turn the light on and capture the chrome sphere shape and produce a mask image.
Using equation (1) and the two images, we can figure out this one light source's direction. This is because we know the surface normal of the chrome sphere at any one pixel of the image, the surface albedo of the chrome sphere (~1 in grayscale) and the light intensity (given by the pixel brightness).
After figuring out several light source direction, we can now apply the light to different objects. We first need to find out the surface normal using a grayscale image first because we can simplify the albedo to only 1 unknown.
We use the minimize square error method,
Where k is the number of light sources. We take the derivative of the square error with respect to the surface normal and set the derivative equal to 0 (to find the minimum). We then end up with the following equation:
a now is just a scale factor for the surface normal (because it is in grayscale), so we can simply just ignore it because we are only interested in the unit vector of the surface normal. Equation (3) is essentially in matrix form, we can use the least square method to solve for the surface normal. Similarly, we can solve for the RGB albedo after the light source directions have been calculated.
Sample input images (I only show 1 input image per object here, but I actually have 11 different images per object. All have light source in different direction):
This is written in Matlab.