Page 123 -
P. 123
102 3 Image processing
1 1 ··· 1 1 4 6 4 1
1 2 1 4 16 24 16 4 −1 0 1 1 −2 1
1 1 ··· 1
1 1 2 4 2 1 6 24 36 24 6 1 −2 0 2 1 −2 4 −2
K 2 . . . . . . 16 256 8 4
. . 1 .
1 2 1 4 16 24 16 4 −1 0 1 1 −2 1
1 1 ··· 1
1 4 6 4 1
1 1 1 1 1
K 1 1 ··· 1 4 1 2 1 16 1 4 6 4 1 2 −1 0 1 2 1 −2 1
(a) box, K =5 (b) bilinear (c) “Gaussian” (d) Sobel (e) corner
Figure 3.14 Separable linear filters: For each image (a)–(e), we show the 2D filter kernel (top), the corresponding
horizontal 1D kernel (middle), and the filtered image (bottom). The filtered Sobel and corner images are signed,
scaled up by 2× and 4×, respectively, and added to a gray offset before display.
In the computer graphics literature (Akenine-M¨ oller and Haines 2002, p. 124), these mech-
anisms are known as the wrapping mode (OpenGL) or texture addressing mode (Direct3D).
The formulas for each of these modes are left to the reader (Exercise 3.8).
Figure 3.13 shows the effects of padding an image with each of the above mechanisms and
then blurring the resulting padded image. As you can see, zero padding darkens the edges,
clamp (replication) padding propagates border values inward, mirror (reflection) padding pre-
serves colors near the borders. Extension padding (not shown) keeps the border pixels fixed
(during blur).
An alternative to padding is to blur the zero-padded RGBA image and to then divide the
resulting image by its alpha value to remove the darkening effect. The results can be quite
good, as seen in the normalized zero image in Figure 3.13.
3.2.1 Separable filtering
2
The process of performing a convolution requires K (multiply-add) operations per pixel,
where K is the size (width or height) of the convolution kernel, e.g., the box filter in Fig-
ure 3.14a. In many cases, this operation can be significantly sped up by first performing a
one-dimensional horizontal convolution followed by a one-dimensional vertical convolution
(which requires a total of 2K operations per pixel). A convolution kernel for which this is
possible is said to be separable.
It is easy to show that the two-dimensional kernel K corresponding to successive con-
volution with a horizontal kernel h and a vertical kernel v is the outer product of the two
kernels,
T
K = vh (3.20)
(see Figure 3.14 for some examples). Because of the increased efficiency, the design of