\subsection{The accidentally discovered compander}
Most cameras do not provide an output that
varies linearly with light input.  Instead, most cameras contain a
dynamic range compressor, as illustrated in Fig.~\ref{fig:imagingchain}.
\begin{figure*}
  \figc{imaging_chain_pointwise.idraw,width=6.5in}
  \caption[]{\small
           {\bf Typical camera and display:}
           light from subject matter passes through lens
           (typically approximated with simple algebraic projective
           geometry, e.g. an idealized ``pinhole'') and
           is quantified in units ``q''
           by a sensor array where noise $n_q$ is also added,
           to produce
           an output which is compressed in dynamic range by a
           typically unknown function $f$.  Further noise $n_f$
           is introduced by the camera electronics, including
           quantization noise if the camera
           is a digital camera and
           compression noise if the camera produces a compressed output
           such as a jpeg image, giving rise to an output image
           $f_1(x,y)$.  The apparatus that converts light rays into
           $f_1(x,y)$ is labelled CAMERA.
           The image $f_1$ is transmitted or
           recorded and played back into a DISPLAY system where
           the dynamic range is expanded again.
           Most cathode ray tubes exhibit a nonlinear response to
           voltage, and this nonlinear response is the expander.
           The block labelled ``expander'' is therefore not usually
           a separate device.
           Typical print media also exhibit a nonlinear response that
           embodies an implicit ``expander''.
          }
  \label{fig:imagingchain}
\end{figure*}
Historically, the dynamic range compressor in video
cameras arose because it was found that televisions did not produce
a linear response to the video signal.  In particular, it was found
that early cathode ray screens provided a light output approximately
equal to voltage raised to the exponent of $2.5$.  Rather than build
a circuit into every television to compensate for this nonlinearity,
a partial compensation (exponent of $1/2.22$)
was introduced into the television camera at much lesser
cost since there were far more televisions than television cameras in those
days before widespread deployment of video surveillance cameras
and the like.  Indeed, early television stations, with names such
as ``American Broadcasting Corporation''
and ``National Broadcasting Corporation'' suggest this one--to--many
mapping (one camera to many televisions across a whole country).
Thus certainly it was easier to introduce an inverse
mapping into the camera than to fix all the
televisions\footnote{It should be noted that some cameras, such as many
                     modern video surveillance cameras, operate linearly
                     when operating at very low light levels.
                    }.

Through a very fortunate and amazing coincidence, the logarithmic response
of human visual perception is approximately the same as
the inverse of the response of a television tube (e.g. human visual response
turns out to be approximately the same as the response of the
television camera)~\cite{poynton}\cite{gamma}.
For this reason, processing done on typical video signals will be
on a perceptually relevant tone scale.  Moreover, any quantization on
such a video signal (e.g. quantization into 8 bits) will be close to ideal
in the sense that each step of the quantizer will have associated with
it a roughly equal perceptual change in perceptual units.

Figure~\ref{fig:gammalogcomparison} shows plots
of the compressor (and expander) used in video systems
together with the corresponding logarithm
$log(q+1)$, and antilogarithm $exp(q)-1$,
plots of the human visual system and its inverse.
(The plots have been normalized so that the scales match.)
\begin{figure}
  \figc{definitionenhance/gammalogcomparisonfig.eps,width=6.5in}
  \caption[]{\small   The power law dynamic range compression
           implemented inside most cameras has approximately the same
           shape of curve as the logarithmic function, over the range of
           signals typically used in video and still photography.
           Similarly, the power law response of typical cathode ray tubes,
           as well as that of typical print media, is quite similar to the
           antilog function.  Therefore, the act of doing conventional
           linear filtering operations on images obtained from
           typical video cameras, or from still cameras taking pictures
           intended for typical print media, is, in effect,
           homomorphic filtering with an approximately logarithmic
           nonlinearity.
          }
  \label{fig:gammalogcomparison}
\end{figure}

With images in print media, there is a similarly expansive effect in which the
ink from the dots bleeds and spreads out on the printed paper,
such that the mid tones darken in the print.  For this reason printed
matter has a nonlinear response curve similar in shape to that of
a cathode ray tube (e.g. the nonlinearity expands the dynamic range
of the printed image).  Thus cameras designed to capture
images for display on video screens have approximately the same kind of
built--in dynamic range compression suitable for print media as well.

It is interesting to compare this naturally occurring (and somewhat
accidental) development in video and print media
with the deliberate introduction of companders
(compressors and expanders) in audio.  Both the accidentally occurring
compression and expansion of picture signals and the deliberate use of
logarithmic (or mu--law) compression and expansion of audio signals serve
to allow 8 bits to be used to often
encode these signals in a satisfactory manner.
(Without dynamic range compression, 12 to 16 bits would be needed to
obtain satisfactory reproduction.)

Most still cameras also provide dynamic range compression built into
the camera.  For example, the Kodak DCS--420 and DCS--460
cameras capture internally in 12 bits (per pixel per color)
and then apply dynamic range
compression, and finally output the range--compressed images in 8 bits
(per pixel per color).

%A good reference on the history and details of the nonlinearities
%of typical cameras and displays is provided in chapter~6
%of Charles Poynton's book on digital video~\cite{poynton}.
%A collection of hyperlinks dealing with related matter may also
%be found on the WWW~\cite{gamma}.

\subsection{Why Stockham was wrong}
When video signals are processed, using linear filters, there is an
implicit homomorphic filtering operation on the photoquantity.
As should be evident from Fig.~\ref{fig:imagingchain},
operations of storage, transmission, and image processing
take place between approximately reciprocal nonlinear functions of
dynamic range compression and dynamic range expansion.

Many users of image processing methodology are unaware of this fact,
because there is a common misconception that cameras produce a linear
output, and that displays respond linearly.  In fact there is a common
misconception that nonlinearities in cameras and displays arise from
defects and poor quality circuits, when in actual fact these nonlinearities
are fortuitously present in display media and deliberately present
in most cameras.

Thus the effect of processing signals such as $f_1$ in
Fig.~\ref{fig:imagingchain} with linear filtering
is, whether one is aware of it or not, homomorphic filtering.

Stockham advocated a kind of homomorphic filtering operation in which
the logarithm of the input image was taken, followed by linear filtering
(e.g. linear space invariant filters), followed by taking the
antilogarithm~\cite{stockham}.

In essence, what Stockham didn't appear to realize, is that such
homomorphic filtering is already manifest
in simply doing ordinary linear filtering on ordinary picture signals
(whether from video, film, or otherwise).
In particular, the compressor gives an image
$f_1 = f(q) = q^{1/2.22} = q^{0.45}$ (ignoring noise
$n_q$ and $n_f$) which has the approximate effect
of $f_1 = f(q) = log(q+1)$ (e.g. roughly the same shape of curve, and
roughly the same effect, e.g. to brighten the mid--tones of the image
prior to processing), as shown in Fig.~\ref{fig:gammalogcomparison}.
Similarly a typical video display has the effect of undoing (approximately)
this compression, e.g. darkening the mid--tones of the image after processing
with $\hat{q} = \tilde{f^{-1}} (f_1) = f_1 ^ {2.5}$.

Thus in some sense what Stockham did, without really realizing it, was
to apply dynamic range compression to already range compressed images,
then do linear filtering, then apply dynamic range expansion to images
being fed to already expansive display media.

\subsection{On the value of doing the exact opposite of what Stockham advocated}
There exist certain kinds of image processing for which it is preferable
to operate linearly on the photoquantity $q$.
Such operations include sharpening of an image to undo the effect of the
point spread function (PSF) blur of a lens.
It is interesting to note that many textbooks and papers that describe
image restoration (e.g. deblurring an image) fail to take into account
the inherent nonlinearity deliberately built into most cameras.

What is needed to do this deblurring
and other kinds of photoquantigraphic image processing is an
{\em anti--homomorphic filter}.  The manner in
which an anti--homomorphic filter is
inserted into the image processing path 
is shown in Fig.~\ref{fig:imagingchainphotoq}.
\begin{figure*}
  \figc{imaging_chain_pointwise_photoq.idraw,width=6.5in}
  \caption[]{\small   
           {\bf The anti--homomorphic filter:}
           Two new elements
           $\hat{f}^{-1}$ and  $\hat{f}$ have been inserted, as compared to
           Fig.~\protect\ref{fig:imagingchain}.
           These are {\em estimates} of the
           the inverse and forward nonlinear response function of the camera.
           Estimates are required because
           the exact nonlinear response of a camera is generally not
           part of the camera specifications.
           (Many camera vendors do not even disclose this information if asked.)
           Because of noise in the signal $f_1$, and also because of 
           noise in the estimate of the camera nonlinearity $f$,
           what we have at the output of $\hat{f}^{-1}$ is
           not $q$, but, rather, an estimate, $\tilde{q}$.
           This signal is processed using linear filtering,
           and then the processed result is passed through the
           estimated camera response function, $\hat{f}$, which returns it
           to a compressed tone scale suitable for viewing on a typical
           television, computer, or the like, or for further processing.
          }
  \label{fig:imagingchainphotoq}
\end{figure*}

Consider an image acquired through an imperfect lens that imparts a
blurring to the image, with a blurring kernel $B$.  The lens blurs the
actual spatiospectral (spatially varying and spectrally varying)
quantity of light $q_{ss}(x,y,\lambda)$, which is
the quantity of light falling on the sensor array just prior to being
{\em measured} by the sensor array:
\be
  \tilde{q}_{ss}(x,y,\lambda)
  = \int \int B(x-u,y-v) q_{ss} (u,v,\lambda) du dv
\ee

This blurred spatiospectral quantity of light
$\tilde{q}_{ss}(x,y,\lambda)$ is then photoquantified by the sensor array:
\bea
 q(x,y)
 = \int_0^\infty \tilde{q}_{ss}(x,y,\lambda) s(\lambda) \, d\lambda
\nonumber \\
 =\int_0^\infty \inti \inti B(x-u,y-v) q_{ss} (u,v,\lambda) s(\lambda)
   \, du \, dv \, d\lambda
\nonumber \\
 = \inti \inti B(x-u,y-v)
   \left( \int_0^\infty q_{ss} (u,v,\lambda) s(\lambda) \, d\lambda \right)
   \, du \, dv
\nonumber \\
 = \inti \inti B(x-u,y-v) q(u,v) du dv
\label{eq:blurredphotoq}
\eea
which is just the blurred photoquantity $q$.

Thus the anti--homomorphic filter of Fig.~\ref{fig:imagingchainphotoq}
can be used to better undo the effect of lens blur than traditional
linear filtering which simply applies linear operations
to the signal $f_1$ and therefore operates homomorphically rather than
linearly on the photoquantity $q$.

Thus we see that in many practical situations,
there is an articulable basis for doing exactly the opposite of what
Stockham advocated (e.g. expanding the dynamic range of the image before
processing and compressing it afterward as opposed to what Stockham advocated
which was to compress the dynamic range before processing and expand it
afterward).

