Image Translation
In computer vision or image processing, image translation is the rectilinear shift of an image from one location to another, so the shifting of an object is called translation. In other words, translation is the shifting of an object’s location.
Python3
import numpy as np import cv2 as cv img = cv.imread( 'girlImage.jpg' , 0 ) rows, cols = img.shape M = np.float32([[ 1 , 0 , 100 ], [ 0 , 1 , 50 ]]) dst = cv.warpAffine(img, M, (cols, rows)) cv.imshow( 'img' , dst) cv.waitKey( 0 ) cv.destroyAllWindows() |
In the above code, we have imported NumPy and OpenCV module then read the image by using imread() function, and then translation takes place with the warpAffine() method which is defined as follows:
In the first argument, we passed the image, in the second argument it takes a matrix as a parameter in the matrix we give x = 100, which means we are telling the function to shift the image 70 units on the right side and y= 50, which means we are telling the function to shift the image 50 units downwards. In the third argument, where we mentioned the cols and rows, we told the function to do not to crop the image from both the x and y sides.
dst = cv.warpAffine(img,M,(cols,rows))
Output:
Image Transformations using OpenCV in Python
In this tutorial, we are going to learn Image Transformation using the OpenCV module in Python.