Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Blending] OpenCV - SeamlessClone Method #2

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions syntheticdataset/image_blending.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,23 @@ def poisson_blending(img, smoke, offset=(0, 0)):
mask[dy : dy + smoke_mask.shape[0], dx : dx + smoke_mask.shape[1]] = smoke_mask

return result, mask


def seamless_clone_blending(img, smoke, offset=(0, 0), clone_type=cv2.MIXED_CLONE):
"""Add smoke on image using OpenCV with SeamlessClone method

Args:
img (np.array): background image
smoke (np.array): smoke image
offset (tuple, optional): smoke location offset (dy, dx). Defaults to (0, 0).
clone_type (any): type of clone : NORMAL_CLONE, MIXED_CLONE, MONOCHROME_TRANSFER.

Returns:
_type_: _description_
"""

mask = ((smoke > 0) * 255).astype("uint8")

blended_img = cv2.seamlessClone(smoke, img, mask, offset, clone_type)

return blended_img, mask