Skip to content
Search

Seamless Cloning

lastmod 2024-07-03created 2024-07-031 edits

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()

Pros and cons

Pros
Seamless cloning lets you naturally remove or copy objects in an image.
It can be used in many application areas; for example, it is useful for adding special effects in films or advertisements.
Cons
The boundary of the object may not blend in naturally.
Depending on differences in color, lighting, etc. between the object to remove and the background, the result may look somewhat unnatural.

Favorite site

author Zer0 sitemap