FastSAM icon indicating copy to clipboard operation
FastSAM copied to clipboard

Masks without the background image

Open DenisSebastian opened this issue 1 year ago • 5 comments

How to obtain as a result the masks without the background image?

DenisSebastian avatar Jul 25 '23 04:07 DenisSebastian

Some lines in prompt.py/plot_to_result should be modified

BWDforce avatar Jul 25 '23 06:07 BWDforce

I was also looking for a way to get the masks without the background image, similar to the format that the original SAM provides. The FastSAM code is not very clear about this.

giswqs avatar Aug 16 '23 19:08 giswqs

I also have this problem+

yejing0 avatar Nov 15 '23 12:11 yejing0

import sys import os from matplotlib import pyplot as plt import numpy as np import cv2 from PIL import Image

file_path = os.path.abspath(file) work_path = os.path.dirname(os.path.dirname(file_path)) sys.path.append(work_path) from fastsam import FastSAM, FastSAMPrompt

model = FastSAM(work_path+'/weights/FastSAM_X.pt') IMAGE_PATH = work_path+'/examples/home.jpg' DEVICE = 'cuda' #'cpu' everything_results = model(IMAGE_PATH, device=DEVICE, retina_masks=False, conf=0.4, iou=0.9,) conf=0.4, iou=0.9,imgsz=1024, prompt_process = FastSAMPrompt(IMAGE_PATH, everything_results, device=DEVICE)

ann = prompt_process.everything_prompt()

mask=everything_results[0].masks.data mask=(mask.cpu()*np.array(list(range(1,mask.size()[0]+1)))[:,np.newaxis,np.newaxis]).sum(axis=0)

image = Image.fromarray(mask.numpy().astype('uint8')) image.save(work_path+'/output/home.png')

plt.figure(figsize=(10, 10)) # 255 is the fill color in grayscale (white) plt.imshow(mask, cmap='gray') # Display the image in grayscale plt.axis('off') # Turn off axis numbers and ticks plt.show()

YukunZEX avatar Feb 20 '24 09:02 YukunZEX

How to obtain as a result the masks without the background image?

do you have any way to relize it?

TuuSiwei avatar May 23 '24 14:05 TuuSiwei