Spaces:
Sleeping
Sleeping
Commit ·
0342b70
1
Parent(s): fa09dc1
fix: remove deprecated method use
Browse files
app.py
CHANGED
|
@@ -46,16 +46,25 @@ def segment_image(image):
|
|
| 46 |
print("Prediction shape:", prediction.shape)
|
| 47 |
print("Unique values:", numpy.unique(prediction))
|
| 48 |
|
| 49 |
-
|
|
|
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
|
|
|
| 54 |
|
| 55 |
-
|
|
|
|
|
|
|
| 56 |
|
| 57 |
-
|
|
|
|
| 58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
overlay = (overlay * 255).astype(numpy.uint8)
|
| 60 |
|
| 61 |
return overlay
|
|
|
|
| 46 |
print("Prediction shape:", prediction.shape)
|
| 47 |
print("Unique values:", numpy.unique(prediction))
|
| 48 |
|
| 49 |
+
# Convert prediction to NumPy array
|
| 50 |
+
prediction_array = numpy.asarray(prediction, dtype=numpy.uint8)
|
| 51 |
|
| 52 |
+
# Resize the mask to match the original image size
|
| 53 |
+
original_size = image.size # (width, height)
|
| 54 |
+
prediction_resized = Image.fromarray(prediction_array).resize(original_size, Image.NEAREST)
|
| 55 |
+
prediction_resized = numpy.array(prediction_resized)
|
| 56 |
|
| 57 |
+
# Apply a colormap for visualization
|
| 58 |
+
colormap = cm.colormaps['jet']
|
| 59 |
+
colored_mask = colormap(prediction_resized / numpy.max(prediction_resized))[:, :, :3] # Normalize & remove alpha
|
| 60 |
|
| 61 |
+
# Convert PIL image to NumPy array
|
| 62 |
+
image_array = numpy.array(image).astype(numpy.float32) / 255.0 # Normalize to [0,1]
|
| 63 |
|
| 64 |
+
# Blend the original image and the mask
|
| 65 |
+
overlay = (image_array * 0.7) + (colored_mask * 0.3)
|
| 66 |
+
|
| 67 |
+
# Convert back to [0,255] uint8
|
| 68 |
overlay = (overlay * 255).astype(numpy.uint8)
|
| 69 |
|
| 70 |
return overlay
|