Image resizing refers to the scaling of images. Scaling comes 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 more is the number of pixels in an image more is the number of input nodes that in turn increases the complexity of the model.
It also helps in zooming in images. Many times we need to resize the image i.e. either shirk it or scale up to meet the size requirements. OpenCV provides us several interpolation methods for resizing an image.
Choice of Interpolation Method for Resizing –
cv2.INTER_AREA: This is used when we need need to shrink an image.
cv2.INTER_CUBIC: This is slow but more efficient.
cv2.INTER_LINEAR: This is primarily used when zooming is required. This is the default interpolation technique in OpenCV.
Below is the code for resizing.
Note: One thing to keep in mind while using the
cv2.resize() function is that the tuple passed for determining the size of new image ((1050, 1610) in this case) follows the order (width, height) unlike as expected (height, width).
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.
- Image resizing using Seam carving using OpenCV in Python
- Node.js | Image Upload, Processing and Resizing using Sharp package
- Image Resizing in Matlab
- Mahotas - Resizing Image
- Dynamically Resize Buttons When Resizing a Window using Tkinter
- OpenCV - Facial Landmarks and Face Detection using dlib and OpenCV
- PyQt5 – How to stop resizing of window | setFixedSize() method
- PyQt5 QSpinBox - Resizing it according to value
- MoviePy – Resizing Video File
- PYGLET – Setting Size / Resizing of Window
- Transition from OpenCV 2 to OpenCV 3.x
- OpenCV Python Program to analyze an image using Histogram
- Python Program to detect the edges of an image using OpenCV | Sobel edge detection method
- Reading an image in OpenCV using Python
- Python | Detect corner of an image using OpenCV
- Image Pyramid using OpenCV | Python
- Negative transformation of an image using Python and OpenCV
- Python | Image blurring using OpenCV
- Find Circles and Ellipses in an Image using OpenCV | Python
- Image Translation using OpenCV | Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.