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