File size: 427 Bytes
26932f6
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
import os
from PIL import Image

def save_segmented_objects(image, masks, boxes, output_dir):
    os.makedirs(output_dir, exist_ok=True)
    objects = []
    for i, (mask, box) in enumerate(zip(masks, boxes)):
        obj_image = image.crop(box)
        file_path = os.path.join(output_dir, f"object_{i}.png")
        obj_image.save(file_path)
        objects.append((f"object_{i}", file_path, box.tolist()))
    return objects