VOOZH about

URL: https://www.geeksforgeeks.org/python/image-resizing-using-opencv-python/

⇱ Image Resizing using OpenCV | Python - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Image Resizing using OpenCV | Python

Last Updated : 30 Oct, 2025

OpenCV provides the cv2.resize() function, which allows you to resize images efficiently. By selecting different interpolation methods, you can control the balance between image quality and resizing speed.

Syntax:

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

Parameters:

  • src: Source/input image.
  • dsize: Desired size (width, height). Order is width first, then height.
  • dst(Optional): Output image, rarely used explicitly.
  • fx(optional): Scale factor along the horizontal axis.
  • fy(optional): Scale factor along the vertical axis.
  • interpolation(optional): Interpolation method to use.

Return Value: Returns a resized image as a NumPy array, which can be displayed, saved, or further processed.

Note: Use either dsize or fx/fy for scaling, dsize: when you know exact width & height and fx/fy: when you want to scale by a factor. Do not 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

Minimizes distortion while downscaling.

cv2.INTER_LINEAR

General resizing

Balances speed and quality

cv2.INTER_CUBIC

Enlarging

Higher quality for upscaling

cv2.INTER_NEAREST

Fast resizing

Quick but lower quality

Example: Resizing images using OpenCV

Output

👁 imageResizing_output
Output representing different way to resize image

Explanation:

  • cv2.imread(): Loads the image in BGR format.
  • cv2.resize(): Resizes the image using either scale factors (fx, fy) or exact dimensions (dsize). INTER_AREA: Downscaling, INTER_CUBIC: Upscaling (smooth results) and INTER_LINEAR: General resizing
  • cv2.cvtColor(): Converts image from BGR to RGB for correct Matplotlib display.
  • plt.subplot(): Arranges multiple images in a 2×2 grid.
  • plt.title(): Adds a title for each image.
  • plt.axis("off"): Hides axis lines and labels.
  • plt.tight_layout(): Adjusts spacing between images.

Related Articles:

Comment