Fix not working issues
Browse files
app.py
CHANGED
|
@@ -173,19 +173,20 @@ def inference(image):
|
|
| 173 |
image_tensor, orig_size = load_image(image_path, hypar)
|
| 174 |
mask = predict(net, image_tensor, orig_size, hypar, device)
|
| 175 |
|
| 176 |
-
|
| 177 |
-
processed_mask = smooth_and_denoise(
|
| 178 |
|
| 179 |
-
# Convert processed mask to PIL image
|
| 180 |
pil_mask = Image.fromarray(processed_mask).convert('L')
|
| 181 |
im_rgb = Image.open(image).convert("RGB")
|
|
|
|
| 182 |
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
im_rgba.putalpha(
|
| 188 |
-
im_dark.putalpha(
|
| 189 |
|
| 190 |
return [im_rgba, pil_mask, im_dark]
|
| 191 |
|
|
|
|
| 173 |
image_tensor, orig_size = load_image(image_path, hypar)
|
| 174 |
mask = predict(net, image_tensor, orig_size, hypar, device)
|
| 175 |
|
| 176 |
+
# Process the mask without cropping
|
| 177 |
+
processed_mask = smooth_and_denoise(mask)
|
| 178 |
|
| 179 |
+
# Convert processed mask to PIL image and resize to match original image
|
| 180 |
pil_mask = Image.fromarray(processed_mask).convert('L')
|
| 181 |
im_rgb = Image.open(image).convert("RGB")
|
| 182 |
+
pil_mask_resized = pil_mask.resize(im_rgb.size, Image.ANTIALIAS)
|
| 183 |
|
| 184 |
+
im_dark = Image.new('RGB', im_rgb.size, (0, 0, 0))
|
| 185 |
+
|
| 186 |
+
# Apply resized mask to images
|
| 187 |
+
im_rgba = im_rgb.copy()
|
| 188 |
+
im_rgba.putalpha(pil_mask_resized)
|
| 189 |
+
im_dark.putalpha(pil_mask_resized)
|
| 190 |
|
| 191 |
return [im_rgba, pil_mask, im_dark]
|
| 192 |
|