36
13.2. GEOMETRIC OPERATIONS
201
y. The input image is on the left side of Figure 13.5 with the output shown
on the right (x
cross
and y
cross
=0.01). Values much bigger than this distort
the output image to almost nothing.
Figure 13.5: Examples of Cross Products
Using higher order terms in equations (13.1) and (13.2) can cause greater
distortion to the input. You can add a third order term to equation (13.1)
(x x y x
doublecross
)and equation (13.2) (y y x y
doublecross
). Try this for
homework. It will be easy given the source code.
Figure 13.6 shows the result of using all four operations at once. This is
the result of displacing down and to the right, enlarging in both directions,
rotating 30 degrees, and using cross products. It is a simple matter of setting
the terms in the equations.
Listing 13.1 shows the geometry routine that implements these opera-
tions. It has the same form as the other image processing operators in this
series. The parameters are from equations (13.1) and (13.2). First, geometry
converts the input angle theta from degrees to radians and calculates the sine
and cosine. The next section prepares the stretch terms to prevent dividing
by zero.
The loops over i and j move through the input image. All the math uses
doubles to preserve accuracy. new
iand new
j are the coordinates of the
pixels in the input image to copy to the output image.
The nal section of geometry sets the output image to the new points
in the input image. If bilinear == 1, we will call the bi-linear interpolation
function described below. If bilinear == 0, we set the output image directly.