Update app.py
Browse files
app.py
CHANGED
|
@@ -30,21 +30,23 @@ def transcribe(audio):
|
|
| 30 |
def segment_image(image: Image.Image):
|
| 31 |
results = segmentation_pipeline(image)
|
| 32 |
|
| 33 |
-
#
|
| 34 |
overlay = np.array(image).copy()
|
| 35 |
annotations = []
|
|
|
|
| 36 |
for r in results:
|
| 37 |
-
mask = np.array(r["mask"]) #
|
| 38 |
label = r["label"]
|
| 39 |
|
| 40 |
-
# Random color
|
| 41 |
color = [random.randint(0, 255) for _ in range(3)]
|
|
|
|
| 42 |
|
| 43 |
-
#
|
| 44 |
-
|
| 45 |
|
| 46 |
-
|
| 47 |
-
|
| 48 |
|
| 49 |
overlay_img = Image.fromarray(overlay)
|
| 50 |
return (overlay_img, annotations)
|
|
|
|
| 30 |
def segment_image(image: Image.Image):
|
| 31 |
results = segmentation_pipeline(image)
|
| 32 |
|
| 33 |
+
# Make a copy for overlay
|
| 34 |
overlay = np.array(image).copy()
|
| 35 |
annotations = []
|
| 36 |
+
|
| 37 |
for r in results:
|
| 38 |
+
mask = np.array(r["mask"]) > 0 # ensure binary mask
|
| 39 |
label = r["label"]
|
| 40 |
|
| 41 |
+
# Random color for each object
|
| 42 |
color = [random.randint(0, 255) for _ in range(3)]
|
| 43 |
+
overlay[mask] = (0.6 * overlay[mask] + 0.4 * np.array(color)).astype(np.uint8)
|
| 44 |
|
| 45 |
+
# Append as (mask, label) where mask is np.ndarray
|
| 46 |
+
annotations.append((mask, label))
|
| 47 |
|
| 48 |
+
overlay_img = Image.fromarray(overlay)
|
| 49 |
+
return (overlay_img, annotations)
|
| 50 |
|
| 51 |
overlay_img = Image.fromarray(overlay)
|
| 52 |
return (overlay_img, annotations)
|