Graphics Reference
In-Depth Information
Inline Exercise 18.2:
Consider convolving a grayscale image
f
with a filter
g
that's defined by
g
(
−
1,
−
1
)=
g
(
−
1, 0
)=
g
(
−
1, 1
)=
−
1,
g
(
1,
−
1
)=
4
g
(
1, 0
)=
g
(
1, 1
)=
1, and
g
(
i
,
j
)=
0 otherwise.
(a) Draw a plot of
g
.
(b) Describe intuitively where
f
g
will be negative, positive, and zero. You
might want to start out with some simple examples for
f
, like an all-gray image,
or an image that's white on its bottom half and black on the top, or white on
the left half and black on the right, etc. Then generalize.
2
0
1
0
0
y
x
1
We've defined convolution for two continuum functions (i.e., functions defined
on
R
) and for two discrete functions (i.e., defined on
Z
). There's a third class
of convolution that comes up in graphics: the discrete-continuum convolution. A
familiar instance of this is display on a grayscale LCD monitor. Recall that for
this chapter, the display pixel
(
i
,
j
)
is a small box
centered
at
(
i
,
j
)
. Figure 18.19
shows the result of displaying a 2
5
4.5
4
3.5
3
2 image
f
(shown as a stem plot) with a
“box” function
b
defined on
R
2
to produce a piecewise constant function on
R
2
representing emitted light intensity.
×
2.5
z
=
b
(
x
,
y
)
2
1.5
1
0.5
The emitted light at location
(
x
,
y
)
is given by
light
(
x
,
y
)=
f
(
i
,
j
)
box
(
x
0
1
0
−
i
,
y
−
j
)
.
(18.12)
y
0
1
x
This doesn't quite look like a convolution, because there's no summation. But we
can insert the summation without changing anything:
light
(
x
,
y
)=
ij
f
(
i
,
j
)
box
(
x
−
i
,
y
−
j
)
.
(18.13)
5
4.5
3.
4
3
There's no change because the box function is zero outside the unit box. In the
early days of graphics, when CRT displays were common, turning on a single
pixel didn't produce a little square of light, it produced a bright spot of light whose
intensity faded off gradually with distance. That meant that turning on pixel
(
4, 7
)
might cause a tiny bit of light to appear even at the area of the display we'd nor-
mally associate with coordinates
(
12, 23
)
, for instance, or anywhere else. In that
case, the summation in the formula for the light at position
(
x
,
y
)
was essential.
The general definition for the convolution of a discrete function
f
:
Z
2.5
1.
2
1
0.5
0
1
0
y
0
x
1
→
R
and a continuum function
g
:
R
→
R
is
∞
(
f
g
)(
x
)=
f
(
i
)
g
(
x
−
i
)
∈
for
x
R
.
(18.14)
i
=
−∞
The result is a continuum function. We leave it to you to define continuous-discrete
convolution, and to extend both definitions to the plane.
Figure 18.19: The values in a
2
2
grayscale image are con-
volved with a box function to get
a piecewise constant function on
a
2
×
2
square.
×
As mentioned in Section 18.2, convolution has several nice mathematical proper-
ties. First, for all forms of convolution (discrete, continuous, or mixed) it's linear
in each factor, that is,
(
f
1
+
cf
2
)
g
=(
f
1
g
)+
c
(
f
2
g
)
for any
c
∈
R
, and
(18.15)
(
g
1
+
cg
2
)=(
f
g
1
)+
c
(
f
g
2
)
.
f
(18.16)