Resize Multiple Images using OpenCV-Python Last Updated : 03 Jan, 2023 Comments Improve Suggest changes Like Article Like Report In this article, we are going to write a python script using the OpenCV library to Resize Multiple Images and save them as an image file. Resizing the image refers to the growth of the images. Measurement works best in the use of multiple images and in machine learning applications. It helps to reduce the number of pixels from an image and that has several benefits e.g. It can reduce neural network training time as the number of pixels in the image greatly increases the number of input nodes which also improves the model difficulty. Approach: Firstly, load the required libraries into a Python file (argparse, OpenCV, etc.).We are using argparse() function to get the path of the directory of images on which we need to perform the resizing.Use for loop to iterate every image in the directory.Load image in a variable using cv2.imread() function.Define a resizing scale and set the calculated height and width.Resize the image using cv2.resize() function.Place the output file inside the output folder using cv2.imwrite() function. All the images inside the Images folder will be resized and will be saved in an output folder. Below is the implementation: Python3 # Required Libraries import cv2 import numpy as np from os import listdir from os.path import isfile, join from pathlib import Path import argparse import numpy # Argument parsing variable declared ap = argparse.ArgumentParser() ap.add_argument("-i", "--image", required=True, help="Path to folder") args = vars(ap.parse_args()) # Find all the images in the provided images folder mypath = args["image"] onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))] images = numpy.empty(len(onlyfiles), dtype=object) # Iterate through every image # and resize all the images. for n in range(0, len(onlyfiles)): path = join(mypath, onlyfiles[n]) images[n] = cv2.imread(join(mypath, onlyfiles[n]), cv2.IMREAD_UNCHANGED) # Load the image in img variable img = cv2.imread(path, 1) # Define a resizing Scale # To declare how much to resize resize_scaling = 50 resize_width = int(img.shape[1] * resize_scaling/100) resize_hieght = int(img.shape[0] * resize_scaling/100) resized_dimensions = (resize_width, resize_hieght) # Create resized image using the calculated dimensions resized_image = cv2.resize(img, resized_dimensions, interpolation=cv2.INTER_AREA) # Save the image in Output Folder cv2.imwrite( 'output/' + str(resize_width) + str(resize_hieght) + str(n) + '_resized.jpg', resized_image) print("Images resized Successfully") Open the terminal in the folder where this Python Script is saved and type the below command. python resize.py --image path/to/images/folder/ Output: Comment More infoAdvertise with us Next Article Resize Multiple Images using OpenCV-Python idevesh Follow Improve Article Tags : Python OpenCV Python-OpenCV Practice Tags : python Similar Reads Image Resizing using OpenCV | Python Image resizing refers to the scaling of images. Scaling comes in handy in many image processing as well as machine learning applications. It helps in reducing the number of pixels from an image and that has several advantages e.g. It can reduce the time of training of a neural network as the more th 3 min read Draw Multiple Rectangles in Image using Python-Opencv In this article, we are going to see how to draw multiple rectangles in an image using Python and OpenCV. Function used:imread(): In the OpenCV, the cv2.imread() function is used to read an image in Python. Syntax: cv2.imread(path_of_image, flag) rectangle(): In the OpenCV, the cv2.rectangle functio 2 min read Python | Create video using multiple images using OpenCV Creating videos from multiple images is a great way for creating time-lapse videos. In this tutorial, weâll explore how to create a video from multiple images using Python and OpenCV. Creating a video from images involves combining multiple image frames, each captured at a specific moment in time, i 5 min read Reading an image in OpenCV using Python Prerequisite: Basics of OpenCVIn this article, we'll try to open an image by using OpenCV (Open Source Computer Vision) library.  Following types of files are supported in OpenCV library:Windows bitmaps - *.bmp, *.dibJPEG files - *.jpeg, *.jpgPortable Network Graphics - *.png WebP - *.webp Sun raste 6 min read Image Translation using OpenCV | Python Translation refers to the rectilinear shift of an object i.e. an image from one location to another. If we know the amount of shift in horizontal and the vertical direction, say (tx, ty) then we can make a transformation matrix e.g. \begin{bmatrix} 1 & 0 & tx \\ 0 & 1 & ty \end{bmatr 2 min read Image Transformations using OpenCV in Python In this tutorial, we are going to learn Image Transformation using the OpenCV module in Python. 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 5 min read Image Steganography using OpenCV in Python Image Steganography is the process of hiding secret data in some image. In this post, we will hide one image inside another and convert it into another image and then extract back both the images from the previous image. The idea behind image-based Steganography is very simple. Images are composed o 3 min read Multiple Color Detection in Real-Time using Python-OpenCV For a robot to visualize the environment, along with the object detection, detection of its color in real-time is also very important. Why this is important? : Some Real-world ApplicationsIn self-driving car, to detect the traffic signals.Multiple color detection is used in some industrial robots, t 4 min read Storing OpenCV Image in SQLite3 with Python OpenCV is a huge open-source library for computer vision, machine learning, and image processing. OpenCV supports a wide variety of programming languages like Python, C++, Java, etc. It can process images and videos to identify objects, faces, or even the handwriting of a human. When it is integrate 3 min read Measure Size of an Object Using Python OpenCV In this article, we will learn about how to measure the size of an object using OpenCV which is implemented in Python. It is implemented by finding the contours around it. This can be done by first loading an image of an object, converting it to grayscale, and applying a threshold to separate the ob 3 min read Like