facebookresearch / segment-anything

The repository provides code for running inference with the SegmentAnything Model (SAM), links for downloading the trained model checkpoints, and example notebooks that show how to use the model.
Apache License 2.0
47.12k stars 5.57k forks source link

How to crop and save segmented images #442

Open ki580 opened 1 year ago

ki580 commented 1 year ago

Hi, I am trying to get semantic segmentation working in practice and would like to cut out a color coded segmented area and save it individually. How can I do this after getting the masks information

cajdotxa71262 commented 1 year ago

that is what I want to ask

Bruce337f commented 1 year ago

me too,that is what I want to ask!

ki580 commented 1 year ago

I can save crop image this code

output_directory = 'your output file'

for i in range(len(mask)): x, y, width, height = mask[i]['bbox'] cropped_image = image[int(y):int(y+height), int(x):int(x+width)] filename = os.path.join(output_directory, str(i) + '.png') cv2.imwrite(filename, cropped_image)

skycitywing commented 1 year ago

我可以保存裁剪图像此代码

output_directory =“您的输出文件”

对于 i in range(len(mask)): x, y, width, height = mask[i]['bbox'] cropped_image = image[int(y):int(y+height), int(x):int(x+width)] 文件名 = os.path.join(output_directory, str(i) + '.png') cv2.imwrite(文件名, cropped_image)

I hope someone can provide an example on colab. After getting the mask file and the original image, but don't know how to use the information about the mask boundaries for cropping.

Github-Yilei commented 1 year ago

this might be useful: #221