Image Reflection
Image reflection is used to flip the image vertically or horizontally. For reflection along the x-axis, we set the value of Sy to -1, Sx to 1, and vice-versa for the y-axis reflection.
Python3
import numpy as np import cv2 as cv img = cv.imread( 'girlImage.jpg' , 0 ) rows, cols = img.shape M = np.float32([[ 1 , 0 , 0 ], [ 0 , - 1 , rows], [ 0 , 0 , 1 ]]) reflected_img = cv.warpPerspective(img, M, ( int (cols), int (rows))) cv.imshow( 'img' , reflected_img) cv.imwrite( 'reflection_out.jpg' , reflected_img) cv.waitKey( 0 ) cv.destroyAllWindows() |
To flip the image horizontally:
M = np.float32([[1, 0, 0], [0, -1, rows],[0, 0, 1]])
To flip the image vertically:
M = np.float32([[-1, 0, cols], [0, 1, 0], [0, 0, 1]])
Output:
Image Transformations using OpenCV in Python
In this tutorial, we are going to learn Image Transformation using the OpenCV module in Python.