Transformation

Transformation

What is it?

Transformation is not so much an effect as a method of reordering pixels into a different pattern. By doing this, images can be flipped in either direction, or rotated to some arbitrary angle.

Our applet uses two different approaches, depending on whether the user wants to flip or rotate. Since our image matrix is one-dimensional, it is much easier (not to mention computationally "cheaper") to simply reverse every image data line (horizontal flip), or every image data column (vertical flip).

How do you rotate an image?

That is the fun part :) When representing coordinates, there are several systems that you can use. One system, known as Cartesian coordinates, gives the (x,y) value in relation to an origin, usually (0,0). Another system is known as polar coordinates. This system uses the distance between the center point and the angle created by drawing the radius. So, to rotate an image, polar form is necessary to easily accomplish the task.

When the applet was originally written, it took every coordinate, converted it to polar form, added the angle value, reconverted it to rectangular form (Cartesian), and mapped it to the appropriate matrix location based on the coordinate. Sounds good in theory, huh? Well, it didn't work very well, because the images were always missing spots, and the more rotation occurred, the more spots were missing. This was clearly unacceptable, so the applet was rewritten.

Have you figured out what's wrong? Because of the numerical accuracy, you will almost always have pixels missing in your image. The solution, however, is much simpler than you may think. All you really have to do, it turns out, is do the same procedure in reverse. Rather than starting mapping to the matrix from the original data, we mapped from the matrix. This meant that every pixel either had some corresponding pixel in the data or was colored black to be part of the background.

You're finished with the explanation! What better time to try out these effects?
Show Me the Java


Return to main page.