Simple Geometrical Transformations

Reflections (image flip)

horizontal fliporiginal image
inverted imagevertical flip

Source code: hflip.cpp and vflip.cpp

A horizontal flip (hflip) reflects the image about a vertical axis through the center of the image. A vertical flip (vflip) reflects the image about a horizontal axis. Image flips are an in-place operation. The output image replaces the input image. Successive hflip - vflip operations produce an inverted image (equivalent to a 180-degree rotation). An odd number of flips produces a left-handed (mirror) image. An even number of flips produces a right-handed (normal) image.

90-degree Rotations

90-degree left original image
180-degree90-degree right

Source code: rot90.cpp, rot180.cpp and rot270.cpp

90-degree rotations are one-to-one transformations for which the total number of pixels is constant.

180-degree rotations are equivalent to successive hflip - vflip operations (see image flips) and can be performed in-place,

90-degree right and 90-degree left (270-degree) rotations require that we read columns and write rows. This can be very time-consuming if we are strict about working with images stored on disk. So we compromise by reading a strip of columns into memory and writing them sequentially to the output file. For a 90-degree rotation we must work from right to left if we are to write the output from top to bottom. In the 270-degree routine we work from left to right.

A 90-degree left rotation is equivalent to a transpose and vflip, and a 90-degree right rotation is a transpose and hflip.

Transpose

original imagetranspose

Source code: tpose.cpp.

The transpose of a matrix interchanges the rows and columns of the matrix. The operation is very similar to a 90-degree rotation. We are required to read columns and write rows, and as in rotations we compromise by reading the image into memory in bands instead of one column at a time.

If the number of rows and columns are the same and equal to a power of two, we can do an in-place transpose using a algorithm due to Eklundh (IEEE Trans. Comp., July 1972). The algorithm makes a series of m passes through the file (where m is the power of two), interchanging rows and pixels within a row. The sequence below illustrates the process.

128 x 128pass 1 pass 2pass 3
pass 7pass 6 pass 5pass 4

Source code: transpos.cpp.

Scaling

Image reduction through pixel averaging

The images below have been reduced in size by the indicated factors.

full size2 x 2 3 x 34 x 4

source code: reduce.cpp

Image reduction through sampling

Sampling reduces the size of an image by extracting pixels on a periodic sample grid, every 4th pixel in every 4th row, for example. Sampling produces a different reduced image than averaging, especially in patterned regions. Compare the hat and hair in the examples below.

averagedsampled

source code: subsamp.cpp

Image enlargement through pixel replication

The images above have been restored to full size by pixel replication. Each image is labeled by its pixel block size

1 x 12 x 2 3 x 34 x 4

source code: dupl.cpp

Image enlargement through bilinear interpolation

The original image below was reduced in size by 4 x 4 and then restored to full size, first by bilinear interpolation then by pixel replication.

originalbilinear pixel replication

source code: resize.cpp

Translation

Cyclic translation

The pixels and rows of the images below have been shifted with wraparound. Pixels shifted off the image to the right are inserted on the left. Rows moved down off the image are inserted at the top. Horizontal shifts are easily generated in place because only one line is needed in memory at a time. General shifts are easiest to perform by reading the rows of the input image in the order needed to sequentially create the output image.

shift 40 0shift 40 40

source code: ishift.cpp

Tiling

A tiling operation replicates and translates the input image to create a rectangular array output image.

tile 5 3

source code: tile.cpp


Written by: John Loomis
E-Mail address: loomis@udri.udayton.edu
Last updated: 20 Nov 1996