Skip to content

Seamless Cloning

Example

import cv2
import numpy as np
import matplotlib.pylab as plt

img1 = cv2.imread('1.jpg')
img2 = cv2.imread('2.jpg')

mask = np.full_like(img2, 255)

height, width = img2.shape[:2]
center = (width//2, height//2)

normal = cv2.seamlessClone(img2, img1, mask, center, cv2.NORMAL_CLONE)
mixed = cv2.seamlessClone(img2, img1, mask, center, cv2.MIXED_CLONE)

# 이미지 크기 조절 x 0.2 배율, y 0.2 배율로 조정
resize_normal = cv2.resize(normal, dsize=(0, 0), fx=0.2, fy=0.2, interpolation=cv2.INTER_LINEAR)
resize_mixed = cv2.resize(mixed, dsize=(0, 0), fx=0.2, fy=0.2, interpolation=cv2.INTER_LINEAR)

cv2.imshow('normal', resize_normal)
cv2.imshow('mixed',resize_mixed)
cv2.waitKey()
cv2.destroyAllWindows()

장단점

장점
Seamless cloning을 통해 이미지에서 객체를 자연스럽게 제거하거나 복사할 수 있습니다.
다양한 응용 분야에서 활용할 수 있으며, 예를 들어 영화나 광고에서 특수 효과를 추가할 때 유용합니다.
단점
객체의 경계 부분이 자연스럽게 합쳐지지 않을 수 있습니다.
제거할 객체와 배경 사이의 색상, 조명 차이 등에 따라서 결과가 다소 부자연스러울 수 있습니다.

Favorite site