Page 260 - Ai Book - 10
P. 260
To resize an image, we can write the following code: Output
import cv2
from matplotlib import pyplot as plt
import numpy as np
image = cv2.imread(‘F:\Softwares\Setups\
DataScience\Deepa\img1.jpg’)
image_afterresisizing = cv2.resize(image, (100,
100))
plt.imshow(cv2.cvtColor(image_afterresisizing,
cv2.COLOR_BGR2RGB))
plt.axis(‘on’)
plt.show()
print(image_afterresisizing.shape)
Here, the resize function of OpenCv library is used to resize an image. The output of the above code is as follows:
Saving an image
In many application based programs, you can save the files through Save As or Save options. In this section, we
will learn how to save an image using the imwrite () function in Jupyter notebook.
To save the resized image, we can write the following code in the Jupyter Notebook window:
import cv2
from matplotlib import pyplot as plt
import numpy as np
image = cv2.imread(‘F:\Softwares\Setups\DataScience\Deepa\img1.jpg’)
image_afterresisizing = cv2.resize(image, (100, 100))
plt.imshow(cv2.cvtColor(image_afterresisizing, cv2.COLOR_BGR2RGB))
plt.axis(‘on’)
plt.show()
print(image_afterresisizing.shape)
cv2.imwrite(‘image_afterresisizing.jpg’,image_afterresisizing)
CONVOLUTION NETWORK
Nowadays, you have seen that after capturing images from your smartphones, you are able to see them in
different modes or modify the appearance of images using different types of filters. As you know, changing the
pixel value of an image creates a new image of different colorus. The technique of changing the pixel value in an
image is called filter. Or, we can say that filters are just systems that form a new, and preferably enhanced, image
from a combination of the original image’s pixel values. Let us understand the concept of filters with the help of
the figure given below:
134
134