Read further to learn how to perform image transformation using OpenCV.

In Part I, I have explained what is OpenCV, and few concepts of OpenCV (How to load an image, how to read an image as NumPy array, and drawing on empty canvas).

If you haven’t read the first part yet, here is the link(Fundamentals of OpenCV Part I).

In this blog, we are going to see some image transformations techniques such as translationrotationresizingflipping. So let’s begin.


Translation

Translation means the shifting of an image along the x and y-axis. Using translation, we can shift an image up, down, left, or right, in any direction we want! Below is the code showing the translation of an image.

import cv2
import numpy as np

image = cv2.imread('images/1.jpg')
cv2.imshow('Image',image)
M  = np.float32([[1,0,25],[0,1,50]]) 
shifted = cv2.warpAffine(image,M,(image.shape[1],image.shape[0]))
cv2.imshow('shifted down and right',shifted)
M  = np.float32([[1,0,-50],[0,1,-90]]) 
shifted = cv2.warpAffine(image,M,(image.shape[1],image.shape[0]))
cv2.imshow('shifted up and left',shifted)
cv2.waitKey(0)
cv2.destroyAllWindows()

Image for post

#python #opencv #image-processing

Fundamentals of OpenCV (Part-II)
2.45 GEEK