vis4d.vis.image.seg_mask_visualizer

Segmentation mask visualizer.

Classes

ImageWithSegMask(image, image_name, masks)

Dataclass storing a data sample that can be visualized.

SegMask2D(mask, color)

Dataclass storing mask information.

SegMaskVisualizer(*args[, n_colors, ...])

Segmentation mask visualizer class.

class ImageWithSegMask(image, image_name, masks)[source]

Dataclass storing a data sample that can be visualized.

class SegMask2D(mask, color)[source]

Dataclass storing mask information.

class SegMaskVisualizer(*args, n_colors=50, class_id_mapping=None, file_type='png', color_palette=None, canvas=<vis4d.vis.image.canvas.pillow_backend.PillowCanvasBackend object>, viewer=<vis4d.vis.image.viewer.matplotlib_viewer.MatplotlibImageViewer object>, **kwargs)[source]

Segmentation mask visualizer class.

Creates a new Visualizer for Image and Bounding Boxes.

Parameters:
  • n_colors (int) – How many colors should be used for the color map.

  • class_id_mapping (dict[int, str]) – Mapping from class id to human readable name.

  • file_type (str) – Desired file type

  • color_palette (list[tuple[int, int, int]]) – Color palette for each class, in RGB format (0-255). If None, a random color palette with n_colors is generated automatically. Defaults to None.

  • canvas (CanvasBackend) – Backend that is used to draw on images

  • viewer (ImageViewerBackend) – Backend that is used show images

process(cur_iter, images, image_names, masks, class_ids=None)[source]

Processes a batch of data.

Parameters:
  • cur_iter (int) – Current iteration.

  • images (list[ArrayLikeFloat]) – Images to show.

  • image_names (list[str]) – Image names.

  • masks (list[ArrayLikeUInt]) – Segmentation masks to show, each with shape [H, W] or [N, H, W]. If the shape is [H, W], the mask is assumed to be a semantic segmentation mask with each pixel being the class id. If the shape is [N, H, W], each mask is assumed to be a binary mask with each pixel being either 0 or 1.

  • class_ids (list[ArrayLikeInt], optional) – Class ids for each mask, with shape [N]. If set, the masks are assumed to be binary masks and the length of class_ids must match the amount of masks. Defaults to None.

Return type:

None

process_single_image(image, image_name, masks, class_ids=None)[source]

Processes a single image entry.

Parameters:
  • image (ArrayLikeFloat) – Images to show.

  • image_name (str) – Name of the image.

  • masks (ArrayLikeUInt) – Binary masks to show, each with shape [N, H, W] or [H, W].

  • class_ids (ArrayLikeInt, optional) – Class ids for each mask, with shape [N]. Defaults to None.

Return type:

None

reset()[source]

Reset visualizer for new round of evaluation.

Return type:

None

save_to_disk(cur_iter, output_folder)[source]

Saves the visualization to disk.

Writes all processes samples to the output folder naming each image <sample.image_name>.<filetype>.

Parameters:
  • cur_iter (int) – Current iteration.

  • output_folder (str) – Folder where the output should be written.

Return type:

None

show(cur_iter, blocking=True)[source]

Shows the processed images in a interactive window.

Parameters:
  • cur_iter (int) – Current iteration.

  • blocking (bool) – If the visualizer should be blocking i.e. wait for human input for each image

Return type:

None