@@ -255,7 +255,7 @@ class VisImage:
255255 def __init__ (self , img , scale = 1.0 ):
256256 """
257257 Args:
258- img (ndarray): an RGB image of shape (H, W, 3).
258+ img (ndarray): an RGB image of shape (H, W, 3) in range [0, 255] .
259259 scale (float): scale the input image
260260 """
261261 self .img = img
@@ -284,11 +284,17 @@ def _setup_figure(self, img):
284284 # self.canvas = mpl.backends.backend_cairo.FigureCanvasCairo(fig)
285285 ax = fig .add_axes ([0.0 , 0.0 , 1.0 , 1.0 ])
286286 ax .axis ("off" )
287- # Need to imshow this first so that other patches can be drawn on top
288- ax .imshow (img , extent = (0 , self .width , self .height , 0 ), interpolation = "nearest" )
289-
290287 self .fig = fig
291288 self .ax = ax
289+ self .reset_image (img )
290+
291+ def reset_image (self , img ):
292+ """
293+ Args:
294+ img: same as in __init__
295+ """
296+ img = img .astype ("uint8" )
297+ self .ax .imshow (img , extent = (0 , self .width , self .height , 0 ), interpolation = "nearest" )
292298
293299 def save (self , filepath ):
294300 """
@@ -404,10 +410,12 @@ def draw_instance_predictions(self, predictions):
404410 alpha = 0.5
405411
406412 if self ._instance_mode == ColorMode .IMAGE_BW :
407- self .output .img = self ._create_grayscale_image (
408- (predictions .pred_masks .any (dim = 0 ) > 0 ).numpy ()
409- if predictions .has ("pred_masks" )
410- else None
413+ self .output .reset_image (
414+ self ._create_grayscale_image (
415+ (predictions .pred_masks .any (dim = 0 ) > 0 ).numpy ()
416+ if predictions .has ("pred_masks" )
417+ else None
418+ )
411419 )
412420 alpha = 0.3
413421
@@ -476,7 +484,7 @@ def draw_panoptic_seg(self, panoptic_seg, segments_info, area_threshold=None, al
476484 pred = _PanopticPrediction (panoptic_seg , segments_info , self .metadata )
477485
478486 if self ._instance_mode == ColorMode .IMAGE_BW :
479- self .output .img = self ._create_grayscale_image (pred .non_empty_mask ())
487+ self .output .reset_image ( self ._create_grayscale_image (pred .non_empty_mask () ))
480488
481489 # draw mask for all semantic segments first i.e. "stuff"
482490 for mask , sinfo in pred .semantic_masks ():
0 commit comments