Date: Tue, 10 Dec 1996 17:44:38 GMT Server: NCSA/1.4.2 Content-type: text/html Last-modified: Tue, 05 Mar 1996 23:23:43 GMT Content-length: 8011
:IMPORTANT NOTE: In this programming environment, the lower-lefthand corner of an image corresponds to pixel coordinates (0,0), and the upper-righthand corner of an image corresponds to pixel coordinates (n-1,m-1) where n is the width and m is the height of the image.
x' = x + dx
y' = y + dy
The line of code used in XLISP-STAT to perform this transformation on a source image source1 is
(xform '(source1 (+ x dx) (+ y dy)))
where dx and dy are the translation amounts in the x and y dimensions, respectively. Also, notice that dx and dy can be negative values. The following example translation moves the image 20 units to the right on the x axis and 30 units down the y axis.
(xform '(source1 (+ x -20) (+ y 30)))
![]() |
![]() |
x' = x * sx
y' = y * sy
The line of code used in XLISP-STAT to perform this transformation on a source image source1 is
(xform '(source1 (* x sx) (* y sy)))
where sx and sy are the scaling factors in the x and y dimensions, respectively. Note again that sx and sy can be negative values. The following illustrates a scaling transformation that stretches the image along the x axis (by a factor of 2) and shrinks the image along the y axis (by a factor of .5).
(xform '(source1 (* x .5) (* y 2)))
![]() |
![]() |
x' = (x * cos theta) - (y * sin theta)
y' = (x * sin theta) + (y * cos theta)
The line of code used in XLISP-STAT to perform this transformation on a source image source1 is
(xform '(source1 (- (* x costheta) (* y sintheta)) (+ (* x sintheta) (* y costheta))))
Before entering this line of code, it is necessary to define sintheta and costheta. This can be accomplished with the following 2 lines of code.
(setq costheta (cos theta))
(setq sintheta (sin theta))
If instead of radians, you prefer to use degrees, the following 2 lines of code can replace the above 2 lines.
(setq costheta (cos (/ (* (* theta 2) 3.14) 360)))
(setq sintheta (sin (/ (* (* theta 2) 3.14) 360)))
The following illustrates a rotation transformation that rotates the image 30 degrees from the y axis (clockwise).
(setq costheta (cos (/ (* (* 30 2) 3.14) 360)))
(setq sintheta (sin (/ (* (* 30 2) 3.14) 360)))
(xform '(source1 (- (* x costheta) (* y sintheta)) (+ (* x sintheta) (* y costheta))))
![]() |
![]() |
(trans_scale_rot transX transY scaleX scaleY rotTheta)
The following line of code illustrates the application of this function to an image. The image is first translated 50 units right on the x axis and 50 units up on the y axis. It is then scaled by a factor of .5 in the x and y direction (shrinking the image to 1/4 its original size). Finally, the image is rotated 30 degrees clockwise from the y axis.
(trans_scale_rot -50 -50 2 2 30)
In order to use this function, you must first open three windows by selecting "Child" from the Windows menu. Then tile the windows by selecting "Tile" from the Windows menu. The function trans_scale_rot will now put the translated image in window 1, the translated and scaled image in window 2, and the translated, scaled, and rotated image in window 3. Try using different parameters to the function, and see how they change the resulting images.
Geometric transformations also have important real world applications. For example, an architect may visually apply transformations to some object, say a beam, to figure out its best position in some design. If the beam isn't quite long enough to fill a gap, it may need to be scaled to increase its length (Of course, this can only be done during the design process on a computer or paper, since we are all aware that you can't stretch a real beam.).
What other applications can you think of for geometric transformations?
This tutorial was created by Marla Baker (marla@cs.washington.edu)