"Geometric" based Image Processing Alogrithms

Some of the common and simple image processing algorithms include: Scaling, Rotation, Translation and Mirroring. This is not a substitute for class lecture or reading.

All of these processes can be thought of as geometric transformations. These kinds of transformations do not necessarily alter the pixel values but, intead alter the position of the pixels. In other words the locations of a particular pixel value is altered. However, it may be the case that a side effect of the algorithm is that the pixel values may also change.


Scaling

This is what happens when you resize an image. If you transform the image from an MxN to a PxQ image where PM and Q>N, then we call this magnification.

Example:
Suppose we want to shrink our image from MxN to M/2xN/2. The following algorithm will do this, notice that we simply average 2x2 blocks of pixels to get a value for each pixel in the new smaller image. Instead, a faster, but, arguably not as good in quality, would be to simply choose one of the pixels in the 2x2 block of the original image as the pixel value for the corresponding pixel in the new smaller image.
/*SHRINKING BY FACTOR of 2*/
/*Visit each pixel of the new smaller*/
/* image and calculate its value*/
S= 2;  /*the scale factor*/
for(r=0; r<M/S; r++)
for(c=0; c<N/S; c++)
{
   Pnew[r,c] = (P[r*S, c*S] + P[r*S+1, c*S] + P[r*S, c*S+1] + P[r*S+1, c*S+1])/4;
}

The above algorithm, averages or interpolates the values in a 2x2 block to get a single value. This kind of interpolation is called linear interpolation

Consider the following


Rotation

Suppose that you wanted to rotate and image. What does it mean to say you want to rotate an image by 45 degrees? You must apply the laws of trigonometry to rotate an image around its center point by the angle desired. The following equations govern the relationship between the old position (r,c) and the new position (r',c'):
r' = r*cos(angle) + c*sin(angle)
c' = c*cos(angle) - r*sin(angle)
Consider the following:



Translation

When performing translation, usually you are moving parts of images to different locations within the same image. To specify a translation, you specify the portion of the image and the destination in row, column values of this portion. This destination is usually signified as the new location of the upper left corner the rectangular image portion specified. Given this is the case, the following algorithm will implement the translation operation. Note that really a copying of the portion is what is achieved. You may choose to set the original portion of the image not overlapping with the coppied version to black as is done by programs such as Photoshop.
Rd = Row value of destination;
Cd = Column value of destination;
Rs,Cs = Upper left hand corner of image portion want to translate;
Re,Ce = Lower right hand corner of image portion.

for(r=Rs; r<Re; r++)
for(c=CS; c<Ce; c++)
{
   Pnew[Rd + r, Cd + c] = P[r,c];
}
Consider the following:



Mirroring

The process of mirroring is that of "reflecting" the image values around a horizontal or vertical line going through the center of the image. Below is the algorithm for doing a vertical mirroring.
/*Vertical Mirroring*/

for(r=0; r<M; r++)
for(c=0; c<N; c++)
{
   Pnew[r,c] = P[r, N-c];
}
Consider the following: