Page 307 - AI Computer 10
P. 307

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.

        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)
        CONVOLUTIONAL 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 with different colours. The technique of changing the pixel value in
        an image is called Filtering. We can say that filters are 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:















        In the figure, you can see the four images in which the visual appearance of each image is different. This is
        possible only due to the changing in pixel values. The process of Convolution and the Convolution operator (*)


                                                                                                             173
                                                                                                             173
   302   303   304   305   306   307   308   309   310   311   312