Using the dlib
library I was able to mask the mouth feature from one image (masked).
masked
Similarly, I have another cropped image of the mouth that does not have the mask (colorlip).
colorlip
I had scaled and replaced the images (replaced) and using np.where
as shown in the code below.
replaced
#Get the values of the lip and the target mask
lip = pred_toblackscreen[bbox_lip[0]:bbox_lip[1], bbox_lip[2]:bbox_lip[3],:]
target = roi[bbox_mask[0]:bbox_mask[1], bbox_mask[2]:bbox_mask[3],:]
cv2.namedWindow('masked', cv2.WINDOW_NORMAL)
cv2.imshow('masked', target)
#Resize the lip to be the same scale/shape as the mask
lip_h, lip_w, _ = lip.shape
target_h, target_w, _ = target.shape
fy = target_h / lip_h
fx = target_w / lip_w
scaled_lip = cv2.resize(lip,(0,0),fx=fx,fy=fy)
cv2.namedWindow('colorlip', cv2.WINDOW_NORMAL)
cv2.imshow('colorlip', scaled_lip)
update = np.where(target==[0,0,0],scaled_lip,target)
cv2.namedWindow('replaced', cv2.WINDOW_NORMAL)
cv2.imshow('replaced', update)
But the feature shape (lip) in 'colorlip' does not match the 'masked' image. So, there is a misalignment and the edges of the mask look sharp as if the image has been overlayed. How to solve this problem? And how to make the final replaced image look more subtle and normal?
CodePudding user response:
**Update #2: OpenCV Image Inpainting to smooth jagged borders.
Output Images
**Update #1: Added Deep Image harmonization based blending methods.
Rough Mask Image
Destination Image
Final Image
Reference
- https://docs.opencv.org/4.5.4/df/da0/group__photo__clone.html
- https://learnopencv.com/seamless-cloning-using-opencv-python-cpp/
- https://learnopencv.com/face-swap-using-opencv-c-python/
- https://github.com/JiahuiYu/generative_inpainting
- https://docs.opencv.org/4.x/df/d3d/tutorial_py_inpainting.html
Deep Image Harmonization
- https://github.com/bcmi/Image-Harmonization-Dataset-iHarmony4
- https://github.com/wasidennis/DeepHarmonization
- https://github.com/saic-vul/image_harmonization
- https://github.com/wuhuikai/GP-GAN
- https://github.com/junleen/RainNet
- https://github.com/bcmi/BargainNet-Image-Harmonization
- https://github.com/vinthony/s2am