Take 2 images and combine it to form a single image & Take 2 images, crop some part of both the images and swap them.
To make a Collage using two images.
Step1: In this step, we have Import the libraries.
import cv2
import matplotlib.pyplot as plt
Step2: In this step, we have read the images.
img1 =cv2.imread(“msd.jpg”)
img2 =cv2.imread(“msd1.jpg”)
Step3: In this step, we have resize the image because Both image shapes must be the same.
img3= cv2.resize(img1,(194,260))
Step4: In this step we have used hstack function because hstack function is useful to combine both the images. and ‘plt.imshow’ is used to show the output.
img_collage= np.hstack((img2,img3))
plt.imshow(img_collage)
we have taken 2 images for crop and swap the cropping images.
first, we have import the libraries.
import cv2
import matplotlib.pyplot as plt
Step2: we have read two images
img1= cv2.imread(‘msd2.jpg’)
img2 = cv2.imread(‘virat.jpg’)
Step3: This syntax is used to crop the images
img3= img1[0:100, 75:145]
img4= img2[15:145, 40:140]
Step4: In this step, we have to reshape/resize the images according to the x and y coordinates.
img4= cv2.resize(img4,(70,100))
img3= cv2.resize(img3,(100,130))
Step5: In this step, The cropped part of the second image has been put on top of the first image we had. and the same as another image
img1[0:100, 75:145] = img4
img2[15:145, 40:140] = img3
Step6:In this step first we use the function cv2.imshow to show the image, then we use cv2.waitKey() to hold the image then we use cv2.destroyAllWindows() to stop the showing output.
cv2.imshow(‘Task 4.2 Make Collage’,img1)
cv2.waitKey()
cv2.destroyAllWindows()
cv2.imshow(‘Task 4.2 Make Collage’,img2)
cv2.waitKey()
Comments
Post a Comment