Page 306 - AI Computer 10
P. 306

Dispaly an image in Jupyter notebook with the help of the following code:

                 import cv2 from matplotlib                                                   Output
                 import pyplot as plt
                 import numpy as np
                 image = cv2.imread(‘F:\Softwares\Setups\
                 DataScience\
                 Deepa\img1.jpg’)
                 plt.imshow(cv2.cvtColor(image,cv2.COLOR_
                 BGR2RGB))
                 plt.title(‘Summer Camp 2025’)
                 plt.axis(‘on’)
                 plt.show( )
            Now, copy a specific part of an image i.e. the Dance Callout. To do so, we can write the following code:
                 import cv2 from matplotlib                                                    Output
                 import pyplot as plt
                 import numpy as np
                 image      =    cv2.imread(‘F:\Softwares\Setups\
                 DataScience\
                 Deepa\img1.jpg’)
                 extract_part = image[150:300,50:260]
                 plt.imshow(cv2.cvtColor(extract_part,
                 cv2.COLOR_BGR2RGB))
                 plt.axis(‘on’)
                 plt.show( )
            Now, we want to insert the extracted part in the image at a particular location. To do this, we can write the
            following code:

                 import cv2 from matplotlib                                                     Output
                 import pyplot as plt
                 import numpy as np
                 image = cv2.imread(‘F:\Softwares\Setups\
                 DataScience\Deepa\img1.jpg’)
                 extract_part = image[150:300,50:260]
                 image[50:200,0:210] = extract_part
                 plt.imshow(cv2.cvtColor(image, cv2.COLOR_
                 BGR2RGB))
                 plt.axis(‘on’)
                 plt.show( )
            Resizing An Image

            Resizing an image is an important part of image processing technique because on resizing an image, its pixel
            information is changed. For example, when an image is reduced in size, any unneeded pixel information will be
            discarded by the photo editor like Photoshop. When an image is enlarged, the photo editor must create and add
            new pixel information on the basis of its best guesses to achieve a larger size which typically results in either a
            very pixelated or very soft and blurry looking image. In case of AI systems, resizing images is important especially
            when we want to train a model having the same size and aspect ratio.




                172
                172
   301   302   303   304   305   306   307   308   309   310   311