How to Scale Image with Python OpenCV

In this Python OpenCV lesson we are going to learn How to Scale Image with Python OpenCV, Scaling is the resizing of the image, and in opencv you can use cv2.resize() for scaling or resizing the  image. OpenCV provides a function called resize to achieve image scaling. If you don’t specify a size (by using None), then it expects the X and Y scaling factors. in our example, the image will be enlarged by a factor of 1.2, also 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.

 

This is the complete code for this lesson.

 

 

You can see that we have used cv2.resize() method for image resizing, you need to give some parameters like image source, dsize, factor x and factor y also interpolation.

 

 

 

If you run the code you will see that we have 3 different sizes of the image.

How to Scale Image with Python OpenCV
How to Scale Image with Python OpenCV

 

 

 

Python OpenCV Cubic Interpolation
Python OpenCV Cubic Interpolation

 

 

Python OpenCV Linear Interpolation
Python OpenCV Linear Interpolation

 

Thank you for visiting my website! If you enjoyed the free courses, please consider supporting my works on Patreon.