Resizing Image
Image resizing refers to the scaling of images. 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 shrink it or scale up to meet the size requirements.
OpenCV provides us with several interpolation methods for resizing an image. Choice of Interpolation Method for Resizing –
- cv2.INTER_AREA: This is used when we 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.
Example: Python OpenCV Image Resizing
Python3
import cv2 import numpy as np import matplotlib.pyplot as plt image = cv2.imread( "geeks.png" , 1 ) # Loading the image half = 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_NEAREST) Titles = [ "Original" , "Half" , "Bigger" , "Interpolation Nearest" ] images = [image, half, bigger, stretch_near] count = 4 for i in range (count): plt.subplot( 2 , 3 , i + 1 ) plt.title(Titles[i]) plt.imshow(images[i]) plt.show() |
Output:
Essential OpenCV Functions to Get Started into Computer Vision
Computer vision is a process by which we can understand the images and videos how they are stored and how we can manipulate and retrieve data from them. Computer Vision is the base or mostly used for Artificial Intelligence. Computer-Vision is playing a major role in self-driving cars, robotics as well as in photo correction apps.
OpenCV is the huge open-source library for computer vision, machine learning, and image processing and now it plays a major role in real-time operation which is very important in today’s systems. By using it, one can process images and videos to identify objects, faces, or even handwriting of a human. When it is integrated with various libraries, such as NumPy, python is capable of processing the OpenCV array structure for analysis. To Identify image patterns and their various features we use vector space and perform mathematical operations on these features.
In this article, we will discuss some commonly used functions in OpenCV along with their applications.
Note: The functions used in this article are common for different languages supported by OpenCV.