"Geometric" based Image Processing Alogrithms
Some of the common and simple image processing algorithms include: Scaling, Rotation, Translation and Mirroring.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
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
- What if the scale is not 2?
- What if the scale factor is not the same in the row and column directions? What will happen to the image?
- What would be the algorithm if you were magnifying the image?
Rotation
r' = r*cos(angle) + c*sin(angle) c' = c*cos(angle) - r*sin(angle)Consider the following:
- What will you do if the r',c' calculated are not integer values?
- How would you implement this algorithm in a discrete MxN image?
- What happens to the corners of an image when you rotate it 45 degrees?
Translation
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:
- What would you do if the designated destination region was either partly or wholey outside of the image boundaries?
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:
- How would you write a program to mirror the image around an arbitrary line specified by two endpoints?