Update app.py
Browse files
app.py
CHANGED
@@ -44,7 +44,7 @@ def get_masks(prompts, img, threhsold):
|
|
44 |
return masks
|
45 |
|
46 |
|
47 |
-
def extract_image(img, pos_prompts, neg_prompts, threshold, alpha_value
|
48 |
positive_masks = get_masks(pos_prompts, img, threshold)
|
49 |
negative_masks = get_masks(neg_prompts, img, threshold)
|
50 |
|
@@ -61,15 +61,19 @@ def extract_image(img, pos_prompts, neg_prompts, threshold, alpha_value=0.5):
|
|
61 |
mask_rgba = Image.new("RGBA", img.size, (0, 0, 0, 0))
|
62 |
mask_rgba.paste(final_mask_img, (0, 0), final_mask_img)
|
63 |
|
64 |
-
#
|
65 |
-
|
|
|
66 |
|
67 |
# extract the final image
|
68 |
-
|
69 |
-
|
70 |
|
71 |
-
|
|
|
|
|
72 |
|
|
|
73 |
|
74 |
|
75 |
title = "Interactive demo: zero-shot image segmentation with CLIPSeg"
|
|
|
44 |
return masks
|
45 |
|
46 |
|
47 |
+
def extract_image(img, pos_prompts, neg_prompts, threshold, alpha_value):
|
48 |
positive_masks = get_masks(pos_prompts, img, threshold)
|
49 |
negative_masks = get_masks(neg_prompts, img, threshold)
|
50 |
|
|
|
61 |
mask_rgba = Image.new("RGBA", img.size, (0, 0, 0, 0))
|
62 |
mask_rgba.paste(final_mask_img, (0, 0), final_mask_img)
|
63 |
|
64 |
+
# apply alpha value to final_mask
|
65 |
+
alpha_mask = Image.fromarray((final_mask * 255 * alpha_value).astype(np.uint8), "L")
|
66 |
+
inverse_alpha_mask = Image.fromarray(((1 - final_mask) * 255 * alpha_value).astype(np.uint8), "L")
|
67 |
|
68 |
# extract the final image
|
69 |
+
output_image = Image.new("RGBA", img.size, (0, 0, 0, 0))
|
70 |
+
output_image.paste(img, mask=alpha_mask)
|
71 |
|
72 |
+
# extract the inverse_mask
|
73 |
+
output_inverse_image = Image.new("RGBA", img.size, (0, 0, 0, 0))
|
74 |
+
output_inverse_image.paste(img, mask=inverse_alpha_mask)
|
75 |
|
76 |
+
return output_image, alpha_mask, inverse_alpha_mask
|
77 |
|
78 |
|
79 |
title = "Interactive demo: zero-shot image segmentation with CLIPSeg"
|