46 The Art and Science of Digital Compositing
The result of the application of this expression is shown in Plate 16. As you can
see, well-thought-out equations can quickly produce results that would otherwise
have required the combination of several different methods.
SPATIAL FILTERS
So far, all of the image manipulations that we have talked about involved a direct
mapping between a given input color and a given output color. This color mapping
could be described by a simple function, and the only thing necessary to compute
a pixel’s output color was the equation and the original color of the pixel. Now
we will look at a new class of tool that takes into account not just a single input
pixel, but also a small neighborhood of pixels surrounding the input pixel. This
type of tool is known as a spatial filter.
2
Convolves
The most common spatial filter is known as a spatial convolution, or simply a
convolve. It iteratively considers a specific pixel, as well as a specific number of
adjacent pixels, and then uses a weighted average to determine the value of the
output pixel. This group of pixels that will be considered is known as the kernel,
and is usually a square group of pixels that has an odd number of rows and
columns. By far the most common kernels are 3 ⳯ 3 and 5 ⳯ 5, but there are
occasions where larger kernels may be used. As we said, the convolve operator
uses a weighted average of the existing pixels to determine a new pixel value.
To control this weighting, we define a specific convolution filter that is used for
the computation. This filter is the same size as the kernel we plan to use and
contains a series of different numbers in the shape of a square matrix. The numbers
in this matrix will dramatically affect the resulting image.
Although usually the compositing artist won’t need to do much more than
choose a specific filter from a list of options and then allow the computer to apply
the convolve process, we’ll take a moment to look at an example of how the math
is actually applied for a simple 3 ⳯ 3 kernel. We start with the following matrix:
ⳮ1 ⳮ1 ⳮ1
ⳮ18ⳮ1
ⳮ1 ⳮ1 ⳮ1
2
The term ‘‘spatial filter’’ is actually rarely used in the digital compositing world. Very often you
will see packages try to group the operators that we discuss in this section under either color-correction
tools or geometric transformation tools. Since they do not really fit into either category, we have
decided to refer to them in a manner that is consistent with most image processing books.