Open cristianohello opened 1 year ago
好玩
you may use the binary mask to extract the object pixels from the original image:
img_arr = cv2.imread(img_path)
img_arr = cv2.cvtColor(img_arr, cv2.COLOR_BGR2RGB)
mask_generator = SamAutomaticMaskGenerator(sam)
predictor = mask_generator.generate(img_arr)
# choose the first masks
mask = predictor[1]['segmentation']
# Remove background by turn it to white
img_arr[mask==False] = [255,255,255]
plt.imshow(img_arr)
plt.axis('off')
Hey, I don't want the background. I just want the cut out image of object as they have shown in demo.
Hey, I don't want the background. I just want the cut out image of object as they have shown in demo.
You can try on this repository: https://github.com/Nomination-NRB/SAM-webui
You can save the color mask, white mask and cut out image of object
I just choose the one with the largest area
img_arr = cv2.imread(img_path)
img_arr = cv2.cvtColor(img_arr, cv2.COLOR_BGR2RGB)
mask_generator = SamAutomaticMaskGenerator(sam)
masks = mask_generator.generate(img_arr)
# choose the biggest area
masks = sorted(masks, key=lambda x: x['area'], reverse=True)
mask = masks[0]['segmentation']
its like ?