
We still use opencv’s warpAffine function to get the rotation of the image but instead of translation matrix as in previous case here we use the rotation matrix. Where the θ is the angle of rotation, measured in anti-clockwise direction.Īlso there is one thing to note that OpenCV allows you to sale and rotate image at the same time using the function, cv2.getRotationMatrix2D(rotation_center_x, rotation_center_y, angle of rotation, scale) Rotation of the image is rotating an image about a point or the point in the center of the image, just as the rotating point acts like a pivot.Īs in translation we have T matrix, likely in rotation we have M matrix


import cv2 import numpy as np image = cv2.imread('input.jpg') # store the height and width of image height,width = image.shape print(image.shape) quater_height, quater_width = height/4, width/4 T = np.float32(,]) img_translation=cv2.warpAffine(image,T,(width,height)) print(T) cv2.imshow('original_image', image) cv2.waitKey(0) cv2.imshow('Translation',img_translation) cv2.waitKey(0) cv2.destroyAllWindows()Ĭonsole Output - (183, 275) – height and widthģ. T Y is shift along Y-axis (Vertical) # this is an affine transformation that simply shifts the position of an image # we use cv2.warpAffine to implement these transformations. Wherein the T X is shift along X-axis (Horizontal) T X, T y are the directions in which the image shifts takes place. Now for performing image translations we use opencv’s warpAffine function, cv2.warpAffine is used to implement these translations but for that we need a translation matrix. Image translation is moving the image up, down, left and right and even diagonal if we implement x and y translation at the same time. Image Translations – Moving image up, down, left and right Non-affine or projective transformations are also called homography.Ģ. Non-Affine transformations are very much common in computer vision and are generated from different camera angles. Non-Affine transformations or projective transformations doesn’t preserve parallelism, length or angle, it does however preserves the collinearity and incidence, collinearity means that the two points lie on the same straight line. There are two Types of image transformations – Affine and Non-AffineĪffine transformations are of three types scaling, rotation and translation, the important thing in affine transformations is that lines are parallel before and after image transformations. Transformations are geometric distortions enacted upon an image, distortions certainly here not mean mistakes but a correction type to correct the perspective issues arising from the point where the image was captured. Image Transformations – Affine and Non-Affine Transformation Arithmetic operations for Brightening and Darkening of imagesġ.Cropping – Cutting out the image region you want.Image Pyramids – Another way of resizing.

#CV2 RESIZE IMAGE MAC#
As told in the previous tutorial, OpenCV is Open Source Commuter Vision Library which has C++, Python and Java interfaces and supports Windows, Linux, Mac OS, iOS and Android. In the previous tutorial, we have learned about OpenCV and done some basic image processing using it like grey scaling, color saturation, histogram, color spaces, RGB component etc.
