OpenCV Image Scaling with Python

In this Python OpenCV article we are going to learn about Image Scaling with OpenCV,

so Scaling is just resizing of the image. OpenCV comes with a function cv2.resize() for this

purpose. The size of the image can be specified manually, or you can specify the scaling factor.

Different interpolation methods are used. Preferable interpolation methods

are cv2.INTER_AREA for shrinking and cv2.INTER_CUBIC (slow) & cv2.INTER_LINEAR 

for zooming. By default, the interpolation method cv2.INTER_LINEAR is used for all resizing

purposes. You can resize an input image with either of following methods.

 

 

 

Learn How to Rotate an Image in OpenCV Python 

 

 

 

Read Image Smoothing Techniques in OpenCV

1: OpenCV Averaging Image Blurring in Python

2: OpenCV Gaussian Blurring for Images in Python

3: OpenCV Median Blurring for Images in Python

4: OpenCV Smooth Image with Bilateral Filtering

 

 

 

 

So now this is the complete code for OpenCV Image Scaling with Python

 

 

 

 

This  line of code is used for reading of the image, make sure that you have added an image

in your working directory.

 

 

 

So we can use cv2.resize() method for image resizing, you need to give some parameters like

image source , dsize, factor x and factor y also interpolation.

 

 

 

 

Notecv2.waitKey() is a keyboard binding function. Its argument is the time in milliseconds.

the function waits  specified milliseconds for any keyboard event. If you press any key in that

time, the program continues. If 0 is passed, it waits indefinitely for a key stroke.

 

 

 

 

 

So run the complete code and this is the result.

 

Linear Interpolation
Linear Interpolation

 

 

 

Scaling Cubic
Scaling Cubic

 

 

Scaling Skewed
Scaling Skewed

 

Subscribe and Get Free Video Courses & Articles in your Email

 

Share via
Copy link
Powered by Social Snap
×