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.
- 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:
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/
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course