Movatterモバイル変換


[0]ホーム

URL:


Open In App
Next Article:
Python OpenCV | cv2.erode() method
Next article icon

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 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 on images. Many times we need to resize the image i.e. either shrink it or scale it up to meet the size requirements. OpenCV provides us several interpolation methods for resizing an image.

Choice of Interpolation Method for Resizing:

Syntax:cv2.resize(source, dsize, dest, fx, fy, interpolation)

Parameters:

Below is the code for resizing: 

Python
importcv2importmatplotlib.pyplotaspltimage=cv2.imread(r"D:\sims\eb\sim21\EB-ML-06-10-2022-Test-Output-15\PERFORATION\Overkill\Fail\Blister 1 2022-03-12 12-59-43.859 T0 M0 G0 3 PERFORATION Mono.bmp",1)# Loading the imagehalf=cv2.resize(image,(0,0),fx=0.1,fy=0.1)bigger=cv2.resize(image,(1050,1610))stretch_near=cv2.resize(image,(780,540),interpolation=cv2.INTER_LINEAR)Titles=["Original","Half","Bigger","Interpolation Nearest"]images=[image,half,bigger,stretch_near]count=4foriinrange(count):plt.subplot(2,2,i+1)plt.title(Titles[i])plt.imshow(images[i])plt.show()

Output: 


Note:One thing to keep in mind while using the cv2.resize() function is that the tuple passed for determining the size of the new image ((1050, 1610) in this case) follows the order (width, height) unlike as expected (height, width).


Image Resizing using OpenCV in Python
Improve

Similar Reads

We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood ourCookie Policy &Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences

[8]ページ先頭

©2009-2025 Movatter.jp