Sakar Ghimire

1 min read 154 views

Image Translation

The translation of an image is the process of moving or relocating of an image or object from one location to another. Using a predefined transformation matrix, we can relocate the image in any direction. The following is a transformation matrix that can be used for image translation. 

\(\begin{bmatrix} 1 & 0 & t_x\\ 0 & 1 & t_y \end{bmatrix} \)

where tx and ty are the shift distance.

If the value of tx is negative, the image will be shifted to the left and the image will be shifted to the right for positive value of tx. Similarly, the image will be shifted up for negative values of ty and the image will be shifted down for positive value of ty.

To find the pixel value in the translated image, we just have to find the dot product between the current pixel and this transformation matrix. This will give us the pixel value for the translated pixel. 

Below I provide a Python implementation for image translation. 

The given pictures show the ranslation_img() function in action, where the image are shifted using a shift distance of (50,50). 

Before:

After:



Code