Assuming a lambertian surface, the intensity at a given pixel is given by
where is the reflectance coefficient at that point on the face,
is the ambient light intensity, and
, the foreshortened contribution from
the directional or point light source (incorporating shadow calculations).
There are 2 unknowns in this
equation,
and
. Hence we require at least 2 equations
independent in
and
. More equations could be
used, and the best solution sought by a least squares technique. The
independence of equations will be ensured if
is different for each
equation, which is equivalent to saying that the points have different
normals (assuming a directional light source). Note also that there are
actually 3 channels, one for each of red, green and blue. However the
treatment of each of these may be treated independently, and the discussion
applies equally well to any one channel.
As discussed among the assumptions above, we do not have 2 equations for each
point. Hence we seek to find an average for a block, use this
to determine
(which is constant), and then invert
equation (1) at each pixel to obtain
for individual pixels.
To find an average for the block, we identify regions of the block
that have the same
value. All the shadowed regions of the block provide
an equation in which
is 0. The set of pixels belonging to one flat face
also have the same value for
. Ultimately we construct 2 equations of the
form
where is the average intensity of the face, measurable from
the image, and
is the (unknown) average reflectance of
the block. Note that there is no guarantee that 2 independent equations
exist. In fact, there will never be 2 equations if the image was taken
on a cloudy day, with no directional lighting effects. We discuss this
case shortly.
Taking 2 equations of the form above, and solving for we obtain
where = average intensity of region 1,
= average intensity of
region 2,
,
.
The value is an estimate for the ambient light on
the target block. To obtain the global ambient light,
we simply
average these values.
With knowledge of , it is possible to invert equation (1)
to obtain the reflectance coefficient of individual pixels. However,
rather than directly calculate this value, we choose instead to calculate
the quantity
for each pixel. This value is the intensity of the
pixel under ambient light.
Note that, because we are using a global , we can remove lighting
effects from faces even if we were not able to solve for an
for those faces. If there were no lit faces in the scene, we simply
choose a value of 1.0 for
.
We create a new image using these values, the ambient image. We also store
the value of for the image.