A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/python/image-resizing-using-opencv-python/ below:

Image Resizing using OpenCV | Python

Image Resizing using OpenCV | Python

Last Updated : 11 Aug, 2025

Resizing an image means changing its width and height, shrinking it for faster loading or enlarging it for better visibility. This is a common task in image processing and machine learning for various reasons:

Function Used

OpenCV provides a function called cv2.resize() to resize images easily. It supports different interpolation methods, which affect the quality and speed of resizing.

Syntax

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

Parameters:

Note: Use either dsize or fx/fy for scaling:
dsize: when you know exact width & height.
fx/fy: when you want to scale by a factor.
Don’t set both together (unless dsize=None)

Interpolation Methods

Interpolation is the method used to decide pixel colors when an image is resized. Below are some methods:

Method

When to Use

Description

cv2.INTER_AREA

Shrinking an image

Best for downsampling, minimizes distortion.

cv2.INTER_LINEAR

Zooming or general resizing

Default method, balances speed and quality.

cv2.INTER_CUBIC

Zooming (high-quality)

Slower but better quality for enlarging images.

cv2.INTER_NEAREST

Fast resizing

Fast but lower quality, can produce blocky results.

Example

This code demonstrates different ways to resize an image in OpenCV. It loads an image, then resizes it:

Finally, it displays all resized versions in a 2×2 grid using Matplotlib.

Python
import cv2
import matplotlib.pyplot as plt

image = cv2.imread(r"grapes.jpg", 1) # Load the image

# Resize to 10% of original size with INTER_AREA
half = cv2.resize(image, (0, 0), fx=0.1, fy=0.1, interpolation=cv2.INTER_AREA)

# Resize to fixed dimensions with INTER_CUBIC
bigger = cv2.resize(image, (1050, 1610), interpolation=cv2.INTER_CUBIC)

# Resize to specific size with INTER_LINEAR
stretch_near = cv2.resize(image, (780, 540), interpolation=cv2.INTER_LINEAR)

Titles = ["Original", "Resized 10%", "Resized to 1050x1610", "Resized 780x540"]
images = [image, half, bigger, stretch_near]
count = 4

# Plot all images in a 2x2 grid
for i in range(count):
    plt.subplot(2, 2, i + 1)  # Select subplot position
    plt.title(Titles[i])      # Set title for current image
    plt.imshow(cv2.cvtColor(images[i], cv2.COLOR_BGR2RGB))  # Convert BGR to RGB for display
    plt.axis('off')           # Hide axis ticks

plt.tight_layout()
plt.show()

Output

Output representing different way to resize image

Image Resizing using OpenCV in Python


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4