MCPcopy Index your code
hub / github.com/CASIA-LMC-Lab/FastSAM / crop_image

Function crop_image

utils/tools.py:342–363  ·  view source on GitHub ↗
(annotations, image_like)

Source from the content-addressed store, hash-verified

340
341
342def crop_image(annotations, image_like):
343 if isinstance(image_like, str):
344 image = Image.open(image_like)
345 else:
346 image = image_like
347 ori_w, ori_h = image.size
348 mask_h, mask_w = annotations[0]["segmentation"].shape
349 if ori_w != mask_w or ori_h != mask_h:
350 image = image.resize((mask_w, mask_h))
351 cropped_boxes = []
352 cropped_images = []
353 not_crop = []
354 origin_id = []
355 for _, mask in enumerate(annotations):
356 if np.sum(mask["segmentation"]) <= 100:
357 continue
358 origin_id.append(_)
359 bbox = get_bbox_from_mask(mask["segmentation"]) # mask 的 bbox
360 cropped_boxes.append(segment_image(image, bbox)) # 保存裁剪的图片
361 # cropped_boxes.append(segment_image(image,mask["segmentation"]))
362 cropped_images.append(bbox) # 保存裁剪的图片的bbox
363 return cropped_boxes, cropped_images, not_crop, origin_id, annotations
364
365
366def box_prompt(masks, bbox, target_height, target_width):

Callers 1

text_promptFunction · 0.85

Calls 2

get_bbox_from_maskFunction · 0.85
segment_imageFunction · 0.85

Tested by

no test coverage detected