Member-only story
Geometric Transformations using OpenCV (python)
Geometric transformations are a common image processing technique that have numerous applications, such as rescaling images for different screen sizes, aligning features on different images, augmenting data for machine learning, animating sprites programmatically, etc..
Remember that images are represented as matrices, oftentimes resources on the internet, software documentation, and other sources will refer to the dimensions of the image using different terms. It's important to keep the following in mind:
- x = width = number of columns
- y = height = number of rows
Translation
Translation is the process of moving an image from its original location by shifting it in x and y directions. To carry out this operation, you need to specify how much movement in the x and y direction is required (lets call this tx, ty).
A transformation matrix will then need to be created. Given tx and ty, a transformation matrix M can be defined as:
Lets define a python function for this transformation:
def ImageTranslation(image, xOffset, yOffset):
# Translate the image by x and y offset
# image - input image as a matrix
# xOffset - offset in x direction
# yOffset - offset in y direction…