Home > other >  How to automatically detect a specific feature from one image and map it to another mask image? Then
How to automatically detect a specific feature from one image and map it to another mask image? Then

Time:11-08

Using the dlib library I was able to mask the mouth feature from one image (masked).

masked

enter image description here

Similarly, I have another cropped image of the mouth that does not have the mask (colorlip).

colorlip

enter image description here

I had scaled and replaced the images (replaced) and using np.where as shown in the code below.

replaced

enter image description here

#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.

enter image description here enter image description here enter image description here enter image description here

Output Images

enter image description hereenter image description here enter image description hereenter image description here enter image description hereenter image description here

**Update #1: Added Deep Image harmonization based blending methods.

Try enter image description here

Rough Mask Image

enter image description here

Destination Image

enter image description here

Final Image

enter image description here

Reference

Deep Image Harmonization

  • Related