elon mask is seamlessly cloned on mars surface
mask
#seamlessClone.py
import cv2
import numpy as np
# Read images : src image will be cloned into dst
dst = cv2.imread("assets/mars.jpg")
src = cv2.imread("assets/elon mask.jpg")
print(dst.shape, src.shape, src.dtype, dst.dtype)
# Create an all white mask
mask = src.copy()
mask = cv2.cvtColor(mask, cv2.COLOR_BGR2GRAY)
#set white pixel to black, and the rest to white
mask = np.where(mask == 255, 0, 255).astype("uint8")
mask = cv2.cvtColor(mask, cv2.COLOR_GRAY2BGR)
#remove salt and pepper noise
mask = cv2.medianBlur(mask, 15)
#mask dilation
kernal = np.ones((5, 5), np.uint8)
mask = cv2.dilate(mask, kernal, iterations=1)
cv2.imshow("mask", mask)
# The location of the center of the src in the dst
width, height, channels = dst.shape
center = (int(height / 2) - 200, int(width / 2))
# Seamlessly clone src into dst and put the results in output
normal_clone = cv2.seamlessClone(src, dst, mask, center, cv2.NORMAL_CLONE)
mixed_clone = cv2.seamlessClone(src, dst, mask, center, cv2.MIXED_CLONE)
cv2.imshow("seamless clone", mixed_clone)
cv2.waitKey(0)
reference:
No comments:
Post a Comment