csosa106 commited on
Commit
8604668
1 Parent(s): 293a2dd

masked image now has color with a transparent background

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -775,13 +775,13 @@ def run_anything_task(input_image, text_prompt, task_type, inpaint_prompt, box_t
775
  # PROCESSING MASKS AND LABELS AND SEGMENTS
776
  for i, mask in enumerate(masks):
777
  show_mask(mask.cpu().numpy(), plt.gca(), random_color=True)
 
 
778
 
779
- np_mask = mask.cpu().numpy().astype(np.uint8)
780
- color = np.array([255, 255, 255])
781
- h, w = np_mask.shape[-2:]
782
- mask_input = np_mask.reshape(h, w, 1) * color.reshape(1, 1, -1)
783
 
784
- mask_and_phrase.append((mask_input, pred_phrases[i]))
785
  for box, label in zip(boxes_filt, pred_phrases):
786
  phrase_to_box[label] = list(box.cpu().numpy())
787
  show_box(box.cpu().numpy(), plt.gca(), label)
 
775
  # PROCESSING MASKS AND LABELS AND SEGMENTS
776
  for i, mask in enumerate(masks):
777
  show_mask(mask.cpu().numpy(), plt.gca(), random_color=True)
778
+ np_mask = mask.cpu().numpy()[0]
779
+ np_mask = np.expand_dims(np_mask, axis=-1)
780
 
781
+ masked_array = np.where(np_mask, np.array(image_pil.convert("RGBA")), [0, 0, 0, 0])
782
+ masked_image = Image.fromarray(masked_array.astype('uint8'))
783
+ mask_and_phrase.append((masked_image, pred_phrases[i]))
 
784
 
 
785
  for box, label in zip(boxes_filt, pred_phrases):
786
  phrase_to_box[label] = list(box.cpu().numpy())
787
  show_box(box.cpu().numpy(), plt.gca(), label)