Raster Methods for Transformation in Computer Graphics



So far in this tutorial, we have explored transformation matrices to perform transformations on points or vectors to be specific. To display images, we need rasterizations. We can apply these transformations on raster images as well.

Raster graphics are made up of tiny pixels arranged in a grid, and transformations are applied to these pixels to manipulate the images. We can apply the same rotate, scale, translate, or skew the image, among other operations. In this chapter, we will have a detailed explanation of how transformations work on raster images.

Basics of Raster Graphics

Raster graphics are images composed of a grid of pixels. Each pixel representing a small piece of the image. They are commonly used for photographs and complex images due to their ability to handle a wide range of colors and details.

Raster transformations are more challenging than vector graphics, because they use mathematical equations to define objects, but they are easier to apply due to the fixed grid of pixels.

Raster Transformation Methods

Like vectors, we also use raster transformations using mathematical operations on the pixel grid. Some common raster transformations are:

  • Translation − Moving the entire image by shifting all its pixels by the same amount.
  • Rotation − Rotating the image around a specific point.
  • Scaling − Enlarging or shrinking the image by adjusting the distance between pixels.
  • Shearing − Slanting the image in a particular direction.
  • Reflection − Flipping the image across an axis.

All these transformations involve adjusting the position or values of the pixels in the raster grid. The most common approach is to apply a transformation matrix to the pixel coordinates

In the following sections of this chapter, we will see the transformation applied on an image. The input image is −

Raster Transformation Methods

For raster images, since it is an array of pixels, the (0, 0) coordinate is the top left corner of the image.

Translation of Raster Images

Translation is the simplest raster transformation. It performs shifting all the pixels in the image by the same amount along the x-axis, y-axis, or both. For example, if we want to move an image 50 pixels to the right and 70 pixels down, we add 50 to the x-coordinate of each pixel and 70 to the y-coordinate.

Translation of Raster Images

Rotation of Raster Images

The next operation is rotating a raster image. It is is more complex than translation because we must adjust the position of each pixel based on the rotation angle. When we rotate an image, each pixel moves to a new position, and we need to calculate the new coordinates for every pixel.

This matrix is applied to the coordinates of each pixel, rotating them around the origin of the image. However, when we rotate an image, we often encounter a problem called aliasing, where the rotated pixels do not align perfectly with the grid, resulting in jagged edges or distorted shapes. To reduce aliasing, techniques like bilinear interpolation or bicubic interpolation can be used to smooth out the transitions between pixels.

Rotation of Raster Images

Here, the pivot is at (0, 0), then it is rotated 45.

Scaling of Raster Images

Scaling is another common transformation applied to raster images. It is just enlarging or reducing the image by adjusting the distance between pixels.

In the following figure, we are applying scaling factor of 1.5 and 1.5 for X and Y respectively.

Scaling of Raster Images

Where sx and sy are the scaling factors along the X and Y axes. Scaling an image can sometimes result in pixelation, where the individual pixels become visible, especially when enlarging the image by a large factor. To avoid this, smoothing techniques like anti-aliasing can be used.

Shearing of Raster Images

Shearing is a transformation that slants the image along the X or Y-axis. This creates a skewed effect. For example, horizontal shearing moves each pixel horizontally by an amount proportional to its y-coordinate.

Shearing of Raster Images

Here it is sheared on X-axis with ratio 0.5

Shearing of Raster Images 1

Here it is sheared on the Y-axis with ratio 0.5

Interpolation Methods for Raster Transformation

Let us see the idea of interpolation. It is one of the most challenges while we are using transformation on raster images. Sometimes we deal with pixels that do not align perfectly with the transformed grid. This happens during rotation, scaling, and shearing. To handle this, interpolation methods are used to estimate the color values of new pixels based on the surrounding pixels.

The most common interpolation methods are −

  • Nearest-Neighbour Interpolation − This is the simplest method, where each new pixel is assigned the color of the closest pixel in the original image. While fast, it often results in blocky or pixelated images.
  • Bilinear Interpolation − This method calculates the color of each new pixel by taking the weighted average of the four nearest pixels. It produces smoother images than nearest-neighbour interpolation.
  • Bicubic Interpolation − This method uses the eight nearest pixels to calculate the color of each new pixel. It produces even smoother results, making it ideal for high-quality transformations.

Interpolation is needed in maintaining the quality of an image during transformation. Without it, transformed images may appear jagged, pixelated, or distorted.

Conclusion

In this chapter, we explained the basics of raster graphics and covered key transformations like translation, rotation, scaling, and shearing. We also looked at interpolation methods that help maintain image quality during transformations. There are several methods including nearest neighbour method, bilinear method and the bi-cubic method.

Advertisements