resize image in opencv python code example

Example 1: cv2.resize()

import cv2
 
img = cv2.imread('/home/img/python.png', cv2.IMREAD_UNCHANGED)
 
print('Original Dimensions : ', img.shape)
 
scale_percent = 60 # percent of original size
width = int(img.shape[1] * scale_percent / 100)
height = int(img.shape[0] * scale_percent / 100)
dim = (width, height)
# resize image
resized = cv2.resize(img, dim, interpolation = cv2.INTER_AREA)
 
print('Resized Dimensions : ',resized.shape)
 
cv2.imshow("Resized image", resized)
cv2.waitKey(0)
cv2.destroyAllWindows()

Example 2: cv2 resize

resized_image = cv2.resize(image, (100, 50))

Example 3: python opencv imresize

im = cv2.resize(im, None, fx=1/3, fy=1/3, interpolation=cv2.INTER_AREA)

Example 4: cv2 .resie

import cv2 

cv2.resize(src, dsize[, dst[, fx[, fy[, interpolation]]]])


src	[required] 				source/input image

dsize	[required] 			desired size for the output image

fx	[optional] 			scale factor along the horizontal axis

fy	[optional]          scale factor along the vertical axis

interpolation	[optional] 			      flag that takes one of the following methods. INTER_NEAREST – a nearest-neighbor 
interpolation INTER_LINEAR – a bilinear interpolation (used by default) INTER_AREA – resampling using pixel area
relation. It may be a preferred method for image decimation, as it gives moire’-free results.
But when the image is zoomed,it is similar to the INTER_NEAREST method. INTER_CUBIC – a bicubic interpolation 
over 4×4 pixel neighborhood INTER_LANCZOS4 – a Lanczos interpolation over 8×8 pixel neighborhood