The whole optimization process is done on a logarithmic image
histogram. A logarithmic and not a linear histogram is used, because
the clipping interval has a constant size for a given contrast on the
log scale. Another reason is the possibility of building a logarithmic
histogram from high contrast images with a relatively small
array. Throughout this chapter
is used, although any other
base would yield the same results (the base 2 is chosen in analogy to
photography). While forming the histogram, values below a certain
value
and above a value
should be clipped to these
values, as the
is not defined for 0, and the histogram
array is limited for huge luminance values. The histogram is an array,
in which each array member holds the number of pixels with the
corresponding luminance. The luminance values for each pixel in the
raw image are stored in float format, so actually each histogram
array member represents luminances in a certain interval. These
equidistant histogram intervals are arbitrarily long, but a finer
histogram yields a more precise result. We will
define the histogram array as H[k], where
, the
value
corresponds to H[1] and
to
. The luminance corresponding to H[k] will be called
and the
. The difference of the logarithms
of two adjacent grades, the elementary histogram interval
,
is

The size of the clipping interval for a given clipping contrast
C is called CLIP and

A possible choice for the above values could be:
,
,
,
,
, then d = 0.005 and CLIP = 1000. The histogram array is
initialized to zero, and then for each color component of all raw
image pixels, H[k] is incremented, where

and d stands for one r, g, or b color component. Note that the
raw image does not need to be stored. The histogram can be built
simultaneously with the calculation of pixel luminances. Note also
that the number of histogram entries (the sum of all H[k]) is three
times the number of pixels in the raw image. After the histogram is
formed, the optimum clipping interval has to be found.