NitishBorthakur commited on
Commit
c3af435
·
verified ·
1 Parent(s): 799a4f5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -9
app.py CHANGED
@@ -59,17 +59,14 @@ def predict_from_landinglens(image_path):
59
  coverage_percentage = (mask_area / total_pixels) * 100
60
  label_name = bitmap_data.get("label_name", f"Mask {i}")
61
  coverage_info.append(f"{label_name}: {coverage_percentage:.2f}%")
 
62
 
63
- # Create colored overlay
64
- colored_mask = np.zeros_like(img_array)
65
- colored_mask[mask > 0] = [255, 0, 0] # Red overlay for mask
66
-
67
- # Combine original image with colored mask
68
- alpha = 0.5 # Transparency of the overlay
69
- combined = cv2.addWeighted(img_array, 1, colored_mask, alpha, 0)
70
 
71
- # Convert to PIL Image
72
- masked_image = Image.fromarray(combined)
 
 
 
73
  masked_images.append(masked_image)
74
 
75
  except Exception as e:
 
59
  coverage_percentage = (mask_area / total_pixels) * 100
60
  label_name = bitmap_data.get("label_name", f"Mask {i}")
61
  coverage_info.append(f"{label_name}: {coverage_percentage:.2f}%")
62
+
63
 
 
 
 
 
 
 
 
64
 
65
+ # Create colored overlay using Pillow
66
+ mask_image = Image.fromarray((mask > 0).astype(np.uint8) * 255)
67
+ overlay = Image.new("RGB", mask_image.size, (255, 0, 0)) # Red overlay
68
+ mask_image = mask_image.convert("RGB")
69
+ masked_image = Image.blend(original_img, overlay, alpha=0.5 * mask_image.convert("L").point(lambda x: x > 0 and 1))
70
  masked_images.append(masked_image)
71
 
72
  except Exception as e: