Page 478 - AI Ver 3.0 class 10_Flipbook
P. 478

Copying a Portion of the Image on to another Image

              This can be done by copying a portion extracted by using cropping and then pasting in a pixel area of another
              image by using img[rows range,columns range] as shown below:

                 [1]:   import cv2 # import OpenCV
                        from matplotlib import pyplot as plt # import matplotlib
                        import numpy as np # import numpy
                        img = cv2.imread('D:/Cat.jpg')
                        face = img[55:265,215:400]
                        img[55:265,10:195] = face
                        img[55:265,415:600] = face
                        plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))#display image with given shade
                        plt.title('Cat Face Placed on the Main Image') #Display this title on the top of the
                        image
                        plt.axis('off')
                        plt.show()




















              Resizing an Image


              Resizing means increasing or decreasing the size of the image in the given frame. It can be done by using
              resize() function:

                 [1]:   import cv2 # import OpenCV
                        from matplotlib import pyplot as plt # import matplotlib
                        import numpy as np # import numpy
                        img = cv2.imread('D:/Cat.jpg') #Load the image file into memory
                        resized = cv2.resize(img, (200, 400))
                        plt.imshow(cv2.cvtColor(resized, cv2.COLOR_BGR2RGB))
                        plt. title('Image Resized' )
                        plt.axis('off')
                        plt. show()




















                    476     Touchpad Artificial Intelligence (Ver. 3.0)-X
   473   474   475   476   477   478   479   480   481   482   483