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

How to eliminate the white edge of mask? #12

Open
maxin-cn opened this issue Dec 13, 2020 · 2 comments
Open

How to eliminate the white edge of mask? #12

maxin-cn opened this issue Dec 13, 2020 · 2 comments

Comments

@maxin-cn
Copy link

Hi, I found there are some white edges of masks on faces. And how to eliminate this unexpected phenomenon? Thanks~

@diandianti
Copy link

diandianti commented Nov 10, 2021

Hi, I found there are some white edges of masks on faces. And how to eliminate this unexpected phenomenon? Thanks~

If you want to eliminate it, you can apply this patch

diff --git a/utils/aux_functions.py b/utils/aux_functions.py
index df556ba..40c7484 100644
--- a/utils/aux_functions.py
+++ b/utils/aux_functions.py
@@ -282,7 +282,7 @@ def get_angle(line1, line2):
 
 
 def mask_face(image, face_location, six_points, angle, args, type="surgical"):
 
     # Find the face angle
     threshold = 13
@@ -356,9 +356,22 @@ def mask_face(image, face_location, six_points, angle, args, type="surgical"):
 
     # Apply mask
     mask_inv = cv2.bitwise_not(mask)
-    img_bg = cv2.bitwise_and(image, image, mask=mask_inv)
-    img_fg = cv2.bitwise_and(dst_mask, dst_mask, mask=mask)
-    out_img = cv2.add(img_bg, img_fg[:, :, 0:3])
+    # img_bg = cv2.bitwise_and(image, image, mask=mask_inv)
+    # img_fg = cv2.bitwise_and(dst_mask, dst_mask, mask=mask)
+
+    img_bg = image.astype(np.float32)
+    _t = mask_inv.astype(np.float32) / 255
+    img_bg[:,:,0] *= _t
+    img_bg[:, :, 1] *= _t
+    img_bg[:, :, 2] *= _t
+
+    img_fg = dst_mask.astype(np.float32)
+    _t = mask.astype(np.float32) / 255
+    img_fg[:, :, 0] *= _t
+    img_fg[:, :, 1] *= _t
+    img_fg[:, :, 2] *= _t
+
+    out_img = cv2.add(img_bg.astype(np.uint8), img_fg[:, :, 0:3].astype(np.uint8))
     if "empty" in type or "inpaint" in type:
         out_img = img_bg
     # Plot key points

@leomessi17
Copy link

It seems to work well. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants