Added smooth and denoising with changes
Browse files
app.py
CHANGED
|
@@ -171,23 +171,24 @@ def inference(image):
|
|
| 171 |
image_path = image
|
| 172 |
|
| 173 |
image_tensor, orig_size = load_image(image_path, hypar)
|
| 174 |
-
|
| 175 |
|
| 176 |
-
# Process the mask
|
| 177 |
-
|
| 178 |
|
| 179 |
# Convert processed mask to PIL image
|
| 180 |
-
|
| 181 |
im_rgb = Image.open(image).convert("RGB")
|
| 182 |
|
| 183 |
im_dark = Image.new('RGB', im_rgb.size, (0, 0, 0))
|
| 184 |
|
| 185 |
-
# Apply mask to images
|
| 186 |
im_rgba = im_rgb.copy()
|
| 187 |
-
im_rgba.putalpha(
|
| 188 |
-
im_dark.putalpha(
|
| 189 |
|
| 190 |
-
return [im_rgba,
|
|
|
|
| 191 |
|
| 192 |
title = "Mysign.id - Signature Background removal based on DIS"
|
| 193 |
description = "ML Model based on ECCV2022/dis-background-removal specifically made for removing background from signatures."
|
|
|
|
| 171 |
image_path = image
|
| 172 |
|
| 173 |
image_tensor, orig_size = load_image(image_path, hypar)
|
| 174 |
+
original_mask = predict(net, image_tensor, orig_size, hypar, device)
|
| 175 |
|
| 176 |
+
# Process the original mask with smoothing and denoising
|
| 177 |
+
processed_mask = smooth_and_denoise(original_mask)
|
| 178 |
|
| 179 |
# Convert processed mask to PIL image
|
| 180 |
+
pil_processed_mask = Image.fromarray(processed_mask).convert('L')
|
| 181 |
im_rgb = Image.open(image).convert("RGB")
|
| 182 |
|
| 183 |
im_dark = Image.new('RGB', im_rgb.size, (0, 0, 0))
|
| 184 |
|
| 185 |
+
# Apply processed mask to images
|
| 186 |
im_rgba = im_rgb.copy()
|
| 187 |
+
im_rgba.putalpha(pil_processed_mask)
|
| 188 |
+
im_dark.putalpha(pil_processed_mask)
|
| 189 |
|
| 190 |
+
return [im_rgba, pil_processed_mask, im_dark]
|
| 191 |
+
|
| 192 |
|
| 193 |
title = "Mysign.id - Signature Background removal based on DIS"
|
| 194 |
description = "ML Model based on ECCV2022/dis-background-removal specifically made for removing background from signatures."
|