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

Function fast_process

utils/tools.py:95–191  ·  view source on GitHub ↗
(
    annotations, args, mask_random_color, bbox=None, points=None, edges=False
)

Source from the content-addressed store, hash-verified

93
94
95def fast_process(
96 annotations, args, mask_random_color, bbox=None, points=None, edges=False
97):
98 if isinstance(annotations[0], dict):
99 annotations = [annotation["segmentation"] for annotation in annotations]
100 result_name = os.path.basename(args.img_path)
101 image = cv2.imread(args.img_path)
102 image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
103 original_h = image.shape[0]
104 original_w = image.shape[1]
105 if sys.platform == "darwin":
106 plt.switch_backend("TkAgg")
107 plt.figure(figsize=(original_w/100, original_h/100))
108 # Add subplot with no margin.
109 plt.subplots_adjust(top=1, bottom=0, right=1, left=0, hspace=0, wspace=0)
110 plt.margins(0, 0)
111 plt.gca().xaxis.set_major_locator(plt.NullLocator())
112 plt.gca().yaxis.set_major_locator(plt.NullLocator())
113 plt.imshow(image)
114 if args.better_quality == True:
115 if isinstance(annotations[0], torch.Tensor):
116 annotations = np.array(annotations.cpu())
117 for i, mask in enumerate(annotations):
118 mask = cv2.morphologyEx(
119 mask.astype(np.uint8), cv2.MORPH_CLOSE, np.ones((3, 3), np.uint8)
120 )
121 annotations[i] = cv2.morphologyEx(
122 mask.astype(np.uint8), cv2.MORPH_OPEN, np.ones((8, 8), np.uint8)
123 )
124 if args.device == "cpu":
125 annotations = np.array(annotations)
126 fast_show_mask(
127 annotations,
128 plt.gca(),
129 random_color=mask_random_color,
130 bbox=bbox,
131 points=points,
132 point_label=args.point_label,
133 retinamask=args.retina,
134 target_height=original_h,
135 target_width=original_w,
136 )
137 else:
138 if isinstance(annotations[0], np.ndarray):
139 annotations = torch.from_numpy(annotations)
140 fast_show_mask_gpu(
141 annotations,
142 plt.gca(),
143 random_color=args.randomcolor,
144 bbox=bbox,
145 points=points,
146 point_label=args.point_label,
147 retinamask=args.retina,
148 target_height=original_h,
149 target_width=original_w,
150 )
151 if isinstance(annotations, torch.Tensor):
152 annotations = annotations.cpu().numpy()

Callers 1

predictMethod · 0.50

Calls 2

fast_show_maskFunction · 0.70
fast_show_mask_gpuFunction · 0.70

Tested by

no test coverage detected