(self, image_pil, image_path, boxes_filt, pred_phrases)
| 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.""" |
no test coverage detected