Image Scaling

Image scaling is a process used to resize a digital image. We perform two things in the image scaling either we enlarge the image or we shrink the image, OpenCV has a built-in function cv2.resize() for image scaling.

Shrinking an image:

img_shrinked = cv2.resize(image, (350, 300),
                          interpolation = cv2.INTER_AREA) 

Note:  Here 350 and 300 are the height and width of the shrunk image respectively

Enlarging Image:

img_enlarged = cv2.resize(img_shrinked, None,
                          fx=1.5, fy=1.5,
                          interpolation=cv2.INTER_CUBIC)

Python3




import numpy as np
import cv2 as cv
img = cv.imread('girlImage.jpg', 0)
rows, cols = img.shape
img_shrinked = cv.resize(img, (250, 200),
                         interpolation=cv.INTER_AREA)
cv.imshow('img', img_shrinked)
img_enlarged = cv.resize(img_shrinked, None,
                         fx=1.5, fy=1.5,
                         interpolation=cv.INTER_CUBIC)
cv.imshow('img', img_enlarged)
cv.waitKey(0)
cv.destroyAllWindows()


Output:

 

Image Transformations using OpenCV in Python

In this tutorial, we are going to learn Image Transformation using the OpenCV module in Python.

Similar Reads

What is Image Transformation?

Image Transformation involves the transformation of image data in order to retrieve information from the image or preprocess the image for further usage. In this tutorial we are going to implement the following image transformation:...

What is OpenCV?

OpenCV (Open Source Computer Vision Library) is an open-source computer vision and machine learning software library. OpenCV was built to provide a common infrastructure for computer vision applications and to accelerate the use of machine perception in commercial products.  By using it, one can process images and videos to identify objects, faces, or even the handwriting of a human. When it is integrated with various libraries, such as NumPy, Python is capable of processing the OpenCV array structure for analysis....

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....

Image Reflection

...

Image Rotation

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....

Image Scaling

...

Image Cropping

Image rotation is a common image processing routine with applications in matching, alignment, and other image-based algorithms, in image rotation the image is rotated by a definite angle. It is used extensively in data augmentation, especially when it comes to image classification....

Image Shearing in X-Axis

...

Image Shearing in Y-Axis

Image scaling is a process used to resize a digital image. We perform two things in the image scaling either we enlarge the image or we shrink the image, OpenCV has a built-in function cv2.resize() for image scaling....