Combine 2 Images With Mask
I am attempting to paint a logo over the top of a landscape image in OpenCV python. I have found answers that can 'blend'/watermark images but I don't want to make the logo transpa
Solution 1:
I presume the following is what you had in mind.
Code:
room = cv2.imread('room.JPG' )
logo = cv2.imread('logo.JPG' )
#--- Resizing the logo to the shape of room image ---
logo = cv2.resize(logo, (room.shape[1], room.shape[0]))
#--- Apply Otsu threshold to blue channel of the logo image ---
ret, logo_mask = cv2.threshold(logo[:,:,0], 0, 255, cv2.THRESH_BINARY|cv2.THRESH_OTSU)
cv2.imshow('logo_mask', logo_mask)
room2 = room.copy()
#--- Copy pixel values of logo image to room image wherever the mask is white ---
room2[np.where(logo_mask == 255)] = logo[np.where(logo_mask == 255)]
cv2.imshow('room_result.JPG', room2)
cv2.waitKey()
cv2.destroyAllWindows()
Result:
Final result:
The following is the mask obtained from applying Otsu threshold on the blue channel of the logo:
Post a Comment for "Combine 2 Images With Mask"