sagar007 commited on
Commit
71905f5
·
verified ·
1 Parent(s): ad1a7ff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -4
app.py CHANGED
@@ -19,11 +19,19 @@ def segment_image(input_image, text_prompt):
19
  # Get the predicted segmentation
20
  preds = outputs.logits.squeeze().sigmoid()
21
 
22
- # Convert the prediction to a PIL image
23
- segmentation = (preds > 0.5).float()
24
- segmentation_image = Image.fromarray((segmentation.numpy() * 255).astype(np.uint8))
25
 
26
- return segmentation_image
 
 
 
 
 
 
 
 
 
27
 
28
  # Create Gradio interface
29
  iface = gr.Interface(
 
19
  # Get the predicted segmentation
20
  preds = outputs.logits.squeeze().sigmoid()
21
 
22
+ # Convert the prediction to a numpy array and scale to 0-255
23
+ segmentation = (preds.numpy() * 255).astype(np.uint8)
 
24
 
25
+ # Create a colored heatmap
26
+ heatmap = np.zeros((segmentation.shape[0], segmentation.shape[1], 3), dtype=np.uint8)
27
+ heatmap[:, :, 0] = segmentation # Red channel
28
+ heatmap[:, :, 2] = 255 - segmentation # Blue channel
29
+
30
+ # Blend the heatmap with the original image
31
+ original_image = np.array(input_image)
32
+ blended = (0.7 * original_image + 0.3 * heatmap).astype(np.uint8)
33
+
34
+ return Image.fromarray(blended)
35
 
36
  # Create Gradio interface
37
  iface = gr.Interface(