fffiloni commited on
Commit
5e4c885
·
verified ·
1 Parent(s): 0c327c7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -17
app.py CHANGED
@@ -29,7 +29,7 @@ def get_point(point_type, tracking_points, trackings_input_label, first_frame_pa
29
  transparent_layer = np.zeros((h, w, 4))
30
  for index, track in enumerate(tracking_points.value):
31
  if trackings_input_label.value[index] == 1:
32
- cv2.circle(transparent_layer, track, 20, (0, 0, 255, 255), -1)
33
  else:
34
  cv2.circle(transparent_layer, track, 20, (255, 0, 0, 255), -1)
35
 
@@ -98,23 +98,19 @@ def show_masks(image, masks, scores, point_coords=None, box_coords=None, input_l
98
 
99
  plt.close() # Close the figure to free up memory
100
 
101
- # ---- Separate Mask Image ----
102
- plt.figure(figsize=(10, 10))
103
- mask_image = np.zeros_like(image, dtype=np.uint8) # Initialize a blank image
104
- show_mask(mask, plt.gca(), borders=False) # Draw the mask without borders
105
-
106
- plt.axis('off')
107
- plt.tight_layout()
108
- plt.gca().set_axis_off()
109
- plt.subplots_adjust(top=1, bottom=0, right=1, left=0,
110
- hspace=0, wspace=0)
111
- plt.margins(0, 0)
112
- plt.gca().xaxis.set_major_locator(plt.NullLocator())
113
- plt.gca().yaxis.set_major_locator(plt.NullLocator())
114
-
115
- # Save mask image
116
  mask_filename = f"mask_image_{i+1}.png"
117
- plt.savefig(mask_filename, format='png', bbox_inches='tight', pad_inches=0)
118
  mask_images.append(mask_filename)
119
 
120
  plt.close() # Close the figure to free up memory
 
29
  transparent_layer = np.zeros((h, w, 4))
30
  for index, track in enumerate(tracking_points.value):
31
  if trackings_input_label.value[index] == 1:
32
+ cv2.circle(transparent_layer, track, 20, (0, 255, 0, 255), -1)
33
  else:
34
  cv2.circle(transparent_layer, track, 20, (255, 0, 0, 255), -1)
35
 
 
98
 
99
  plt.close() # Close the figure to free up memory
100
 
101
+ # ---- Separate Mask Image (White Mask on Black Background) ----
102
+ # Create a black image
103
+ mask_image = np.zeros_like(image, dtype=np.uint8)
104
+
105
+ # The mask is a binary array where the masked area is 1, else 0.
106
+ # Convert the mask to a white color in the mask_image
107
+ mask_layer = (mask > 0).astype(np.uint8) * 255
108
+ for c in range(3): # Assuming RGB, repeat mask for all channels
109
+ mask_image[:, :, c] = mask_layer
110
+
111
+ # Save the mask image
 
 
 
 
112
  mask_filename = f"mask_image_{i+1}.png"
113
+ Image.fromarray(mask_image).save(mask_filename)
114
  mask_images.append(mask_filename)
115
 
116
  plt.close() # Close the figure to free up memory