MCPcopy Create free account
hub / github.com/UVA-Computer-Vision-Lab/FrameINO / VisImage

Class VisImage

preprocess/oneformer_code/demo/visualizer.py:270–340  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

268
269
270class VisImage:
271 def __init__(self, img, scale=1.0):
272 """
273 Args:
274 img (ndarray): an RGB image of shape (H, W, 3) in range [0, 255].
275 scale (float): scale the input image
276 """
277 self.img = img
278 self.scale = scale
279 self.width, self.height = img.shape[1], img.shape[0]
280 self._setup_figure(img)
281
282 def _setup_figure(self, img):
283 """
284 Args:
285 Same as in :meth:`__init__()`.
286 Returns:
287 fig (matplotlib.pyplot.figure): top level container for all the image plot elements.
288 ax (matplotlib.pyplot.Axes): contains figure elements and sets the coordinate system.
289 """
290 fig = mplfigure.Figure(frameon=False)
291 self.dpi = fig.get_dpi()
292 # add a small 1e-2 to avoid precision lost due to matplotlib's truncation
293 # (https://github.com/matplotlib/matplotlib/issues/15363)
294 fig.set_size_inches(
295 (self.width * self.scale + 1e-2) / self.dpi,
296 (self.height * self.scale + 1e-2) / self.dpi,
297 )
298 self.canvas = FigureCanvasAgg(fig)
299 # self.canvas = mpl.backends.backend_cairo.FigureCanvasCairo(fig)
300 ax = fig.add_axes([0.0, 0.0, 1.0, 1.0])
301 ax.axis("off")
302 self.fig = fig
303 self.ax = ax
304 self.reset_image(img)
305
306 def reset_image(self, img):
307 """
308 Args:
309 img: same as in __init__
310 """
311 img = img.astype("uint8")
312 self.ax.imshow(img, extent=(0, self.width, self.height, 0), interpolation="nearest")
313
314 def save(self, filepath):
315 """
316 Args:
317 filepath (str): a string that contains the absolute path, including the file name, where
318 the visualized image will be saved.
319 """
320 self.fig.savefig(filepath)
321
322 def get_image(self):
323 """
324 Returns:
325 ndarray:
326 the visualized image of shape (H, W, 3) (RGB) in uint8 type.
327 The shape is scaled w.r.t the input image using the given `scale` argument.

Callers 2

__init__Method · 0.85
get_imageMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected