MCPcopy Create free account
hub / github.com/SooLab/CGFormer / showRef

Method showRef

tools/refer.py:239–293  ·  view source on GitHub ↗
(self, ref, seg_box='seg')

Source from the content-addressed store, hash-verified

237 return ann['bbox'] # [x, y, w, h]
238
239 def showRef(self, ref, seg_box='seg'):
240 ax = plt.gca()
241 # show image
242 image = self.Imgs[ref['image_id']]
243 I = io.imread(osp.join(self.IMAGE_DIR, image['file_name']))
244 ax.imshow(I)
245 # show refer expression
246 for sid, sent in enumerate(ref['sentences']):
247 print('%s. %s' % (sid + 1, sent['sent']))
248 # show segmentations
249 if seg_box == 'seg':
250 ann_id = ref['ann_id']
251 ann = self.Anns[ann_id]
252 polygons = []
253 color = []
254 c = 'none'
255 if type(ann['segmentation'][0]) == list:
256 # polygon used for refcoco*
257 for seg in ann['segmentation']:
258 poly = np.array(seg).reshape((len(seg) / 2, 2))
259 polygons.append(Polygon(poly, True, alpha=0.4))
260 color.append(c)
261 p = PatchCollection(polygons,
262 facecolors=color,
263 edgecolors=(1, 1, 0, 0),
264 linewidths=3,
265 alpha=1)
266 ax.add_collection(p) # thick yellow polygon
267 p = PatchCollection(polygons,
268 facecolors=color,
269 edgecolors=(1, 0, 0, 0),
270 linewidths=1,
271 alpha=1)
272 ax.add_collection(p) # thin red polygon
273 else:
274 # mask used for refclef
275 rle = ann['segmentation']
276 m = mask.decode(rle)
277 img = np.ones((m.shape[0], m.shape[1], 3))
278 color_mask = np.array([2.0, 166.0, 101.0]) / 255
279 for i in range(3):
280 img[:, :, i] = color_mask[i]
281 ax.imshow(np.dstack((img, m * 0.5)))
282 # show bounding-box
283 elif seg_box == 'box':
284 ann_id = ref['ann_id']
285 ann = self.Anns[ann_id]
286 bbox = self.getRefBox(ref['ref_id'])
287 box_plot = Rectangle((bbox[0], bbox[1]),
288 bbox[2],
289 bbox[3],
290 fill=False,
291 edgecolor='green',
292 linewidth=3)
293 ax.add_patch(box_plot)
294
295 def getMask(self, ref):
296 # return mask, area and mask-center

Callers 1

refer.pyFile · 0.80

Calls 2

getRefBoxMethod · 0.95
decodeMethod · 0.45

Tested by

no test coverage detected