MCPcopy Index your code
hub / github.com/chenfei-wu/TaskMatrix / segment_image_with_boxes

Method segment_image_with_boxes

visual_chatgpt.py:876–894  ·  view source on GitHub ↗
(self, image_pil, image_path, boxes_filt, pred_phrases)

Source from the content-addressed store, hash-verified

874 return masks
875
876 def segment_image_with_boxes(self, image_pil, image_path, boxes_filt, pred_phrases):
877
878 image = cv2.imread(image_path)
879 image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
880 self.sam_predictor.set_image(image)
881
882 masks = self.get_mask_with_boxes(image_pil, image, boxes_filt)
883
884 # draw output image
885
886 for mask in masks:
887 image = self.show_mask(mask[0].cpu().numpy(), image, random_color=True, transparency=0.3)
888
889 updated_image_path = get_new_image_name(image_path, func_name="segmentation")
890
891 new_image = Image.fromarray(image)
892 new_image.save(updated_image_path)
893
894 return updated_image_path
895
896 def set_image(self, img) -> None:
897 """Set the image for the predictor."""

Callers 1

inferenceMethod · 0.80

Calls 4

get_mask_with_boxesMethod · 0.95
show_maskMethod · 0.95
get_new_image_nameFunction · 0.85
set_imageMethod · 0.80

Tested by

no test coverage detected