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

Method segment_image_with_click

visual_chatgpt.py:924–945  ·  view source on GitHub ↗
(self, img, is_positive: bool,
                            evt: gr.SelectData)

Source from the content-addressed store, hash-verified

922
923
924 def segment_image_with_click(self, img, is_positive: bool,
925 evt: gr.SelectData):
926
927 self.sam_predictor.set_image(img)
928 self.saved_points.append([evt.index[0], evt.index[1]])
929 self.saved_labels.append(1 if is_positive else 0)
930 input_point = np.array(self.saved_points)
931 input_label = np.array(self.saved_labels)
932
933 # Predict the mask
934 with torch.cuda.amp.autocast():
935 masks, scores, logits = self.sam_predictor.predict(
936 point_coords=input_point,
937 point_labels=input_label,
938 multimask_output=False,
939 )
940
941 img = self.show_mask(masks[0], img, random_color=False, transparency=0.3)
942
943 img = self.show_points(input_point, input_label, img)
944
945 return img
946
947 def segment_image_with_coordinate(self, img, is_positive: bool,
948 coordinate: tuple):

Callers

nothing calls this directly

Calls 3

show_maskMethod · 0.95
show_pointsMethod · 0.95
set_imageMethod · 0.80

Tested by

no test coverage detected