Open sarkadava opened 1 month ago
So you can use these masks that it outputs (Numpy array) and turn them into an image using PIL. Here is a quick example i made def save_mask_with_original_name(maskimage, original_filename, save_directory):
if maskimage.dtype != np.uint8:
maskimage = (maskimage * 255).astype(np.uint8) # Convert to 8-bit grayscale if necessary
# Convert maskimage to RGB
masksss = Image.fromarray(maskimage).convert('RGB')
masksss = masksss.resize(mask_size, Image.Resampling.LANCZOS)
# Extract the base filename without extension
base_filename = os.path.splitext(original_filename)[0]
# Save the mask image with the same base filename
save_path = os.path.join(save_directory, f"{base_filename}_mask.jpg")
masksss.save(save_path, format='JPEG')
@Dashenboy thanks for your reply. Sorry if I was not clear, I don't need an image of the mask. I need the mask to save in COCO formant, ie, with coordinates such that I am able to open it with Image Annotator, or further use in training an object/subject recognition model. I see that the output of SAM has vectors of True,False; and am not sure how to get rather the coordinates
Hey, sorry if I am missing something in the documentation, but I would like to know how can I convert the annotation results for images into json file with coordinates (something like coco file) so that I can work with the annotations further? Thanks a lot!