Visualizations

vis_bbox

chainercv.visualizations.vis_bbox(img, bbox, label=None, score=None, label_names=None, instance_colors=None, alpha=1.0, linewidth=3.0, sort_by_score=True, ax=None)[source]

Visualize bounding boxes inside image.

Example

>>> from chainercv.datasets import VOCBboxDataset
>>> from chainercv.datasets import voc_bbox_label_names
>>> from chainercv.visualizations import vis_bbox
>>> import matplotlib.pyplot as plt
>>> dataset = VOCBboxDataset()
>>> img, bbox, label = dataset[60]
>>> vis_bbox(img, bbox, label,
...          label_names=voc_bbox_label_names)
>>> plt.show()

This example visualizes by displaying the same colors for bounding boxes assigned to the same labels.

>>> from chainercv.datasets import VOCBboxDataset
>>> from chainercv.datasets import voc_bbox_label_names
>>> from chainercv.visualizations import vis_bbox
>>> from chainercv.visualizations.colormap import voc_colormap
>>> import matplotlib.pyplot as plt
>>> dataset = VOCBboxDataset()
>>> img, bbox, label = dataset[61]
>>> colors = voc_colormap(label + 1)
>>> vis_bbox(img, bbox, label,
...          label_names=voc_bbox_label_names,
...          instance_colors=colors)
>>> plt.show()
Parameters
  • img (ndarray) – See the table below. If this is None, no image is displayed.

  • bbox (ndarray) – See the table below.

  • label (ndarray) – See the table below. This is optional.

  • score (ndarray) – See the table below. This is optional.

  • label_names (iterable of strings) – Name of labels ordered according to label ids. If this is None, labels will be skipped.

  • instance_colors (iterable of tuples) – List of colors. Each color is RGB format and the range of its values is \([0, 255]\). The i-th element is the color used to visualize the i-th instance. If instance_colors is None, the red is used for all boxes.

  • alpha (float) – The value which determines transparency of the bounding boxes. The range of this value is \([0, 1]\).

  • linewidth (float) – The thickness of the edges of the bounding boxes.

  • sort_by_score (bool) – When True, instances with high scores are always visualized in front of instances with low scores.

  • ax (matplotlib.axes.Axis) – The visualization is displayed on this axis. If this is None (default), a new axis is created.

name

shape

dtype

format

img

\((3, H, W)\)

float32

RGB, \([0, 255]\)

bbox

\((R, 4)\)

float32

\((y_{min}, x_{min}, y_{max}, x_{max})\)

label

\((R,)\)

int32

\([0, \#fg\_class - 1]\)

score

\((R,)\)

float32

Returns

Returns the Axes object with the plot for further tweaking.

Return type

Axes

vis_image

chainercv.visualizations.vis_image(img, ax=None)[source]

Visualize a color image.

Parameters
  • img (ndarray) – See the table below. If this is None, no image is displayed.

  • ax (matplotlib.axes.Axis) – The visualization is displayed on this axis. If this is None (default), a new axis is created.

name

shape

dtype

format

img

\((3, H, W)\)

float32

RGB, \([0, 255]\)

Returns

Returns the Axes object with the plot for further tweaking.

Return type

Axes

vis_instance_segmentation

chainercv.visualizations.vis_instance_segmentation(img, mask, label=None, score=None, label_names=None, instance_colors=None, alpha=0.7, sort_by_score=True, ax=None)[source]

Visualize instance segmentation.

Example

This example visualizes an image and an instance segmentation.

>>> from chainercv.datasets import SBDInstanceSegmentationDataset
>>> from chainercv.datasets         ...     import sbd_instance_segmentation_label_names
>>> from chainercv.visualizations import vis_instance_segmentation
>>> import matplotlib.pyplot as plt
>>> dataset = SBDInstanceSegmentationDataset()
>>> img, mask, label = dataset[0]
>>> vis_instance_segmentation(
...     img, mask, label,
...     label_names=sbd_instance_segmentation_label_names)
>>> plt.show()

This example visualizes an image, an instance segmentation and bounding boxes.

>>> from chainercv.datasets import SBDInstanceSegmentationDataset
>>> from chainercv.datasets         ...     import sbd_instance_segmentation_label_names
>>> from chainercv.visualizations import vis_bbox
>>> from chainercv.visualizations import vis_instance_segmentation
>>> from chainercv.visualizations.colormap import voc_colormap
>>> from chainercv.utils import mask_to_bbox
>>> import matplotlib.pyplot as plt
>>> dataset = SBDInstanceSegmentationDataset()
>>> img, mask, label = dataset[0]
>>> bbox = mask_to_bbox(mask)
>>> colors = voc_colormap(list(range(1, len(mask) + 1)))
>>> ax = vis_bbox(img, bbox, label,
...     label_names=sbd_instance_segmentation_label_names,
...     instance_colors=colors, alpha=0.7, linewidth=0.5)
>>> vis_instance_segmentation(
...     None, mask, instance_colors=colors, alpha=0.7, ax=ax)
>>> plt.show()
Parameters
  • img (ndarray) – See the table below. If this is None, no image is displayed.

  • mask (ndarray) – See the table below.

  • label (ndarray) – See the table below. This is optional.

  • score (ndarray) – See the table below. This is optional.

  • label_names (iterable of strings) – Name of labels ordered according to label ids.

  • instance_colors (iterable of tuple) – List of colors. Each color is RGB format and the range of its values is \([0, 255]\). The i-th element is the color used to visualize the i-th instance. If instance_colors is None, the default color map is used.

  • alpha (float) – The value which determines transparency of the figure. The range of this value is \([0, 1]\). If this value is 0, the figure will be completely transparent. The default value is 0.7. This option is useful for overlaying the label on the source image.

  • sort_by_score (bool) – When True, instances with high scores are always visualized in front of instances with low scores.

  • ax (matplotlib.axes.Axis) – The visualization is displayed on this axis. If this is None (default), a new axis is created.

name

shape

dtype

format

img

\((3, H, W)\)

float32

RGB, \([0, 255]\)

mask

\((R, H, W)\)

bool

label

\((R,)\)

int32

\([0, \#fg\_class - 1]\)

score

\((R,)\)

float32

Returns

Returns ax. ax is an matploblib.axes.Axes with the plot.

Return type

matploblib.axes.Axes

vis_point

chainercv.visualizations.vis_point(img, point, visible=None, ax=None)[source]

Visualize points in an image.

Example

>>> import chainercv
>>> import matplotlib.pyplot as plt
>>> dataset = chainercv.datasets.CUBKeypointDataset()
>>> img, point, visible = dataset[0]
>>> chainercv.visualizations.vis_point(img, point, visible)
>>> plt.show()
Parameters
  • img (ndarray) – See the table below. If this is None, no image is displayed.

  • point (ndarray or list of arrays) – See the table below.

  • visible (ndarray or list of arrays) – See the table below.

  • ax (matplotlib.axes.Axes) – If provided, plot on this axis.

name

shape

dtype

format

img

\((3, H, W)\)

float32

RGB, \([0, 255]\)

point

\((R, K, 2)\) or \([(K, 2)]\)

float32

\((y, x)\)

visible

\((R, K)\) or \([(K,)]\)

bool

Returns

Returns the Axes object with the plot for further tweaking.

Return type

Axes

vis_semantic_segmentation

chainercv.visualizations.vis_semantic_segmentation(img, label, label_names=None, label_colors=None, ignore_label_color=(0, 0, 0), alpha=1, all_label_names_in_legend=False, ax=None)[source]

Visualize a semantic segmentation.

Example

>>> from chainercv.datasets import VOCSemanticSegmentationDataset
>>> from chainercv.datasets         ...     import voc_semantic_segmentation_label_colors
>>> from chainercv.datasets         ...     import voc_semantic_segmentation_label_names
>>> from chainercv.visualizations import vis_semantic_segmentation
>>> import matplotlib.pyplot as plt
>>> dataset = VOCSemanticSegmentationDataset()
>>> img, label = dataset[60]
>>> ax, legend_handles = vis_semantic_segmentation(
...     img, label,
...     label_names=voc_semantic_segmentation_label_names,
...     label_colors=voc_semantic_segmentation_label_colors,
...     alpha=0.9)
>>> ax.legend(handles=legend_handles, bbox_to_anchor=(1, 1), loc=2)
>>> plt.show()
Parameters
  • img (ndarray) – See the table below. If this is None, no image is displayed.

  • label (ndarray) – See the table below.

  • label_names (iterable of strings) – Name of labels ordered according to label ids.

  • label_colors – (iterable of tuple): An iterable of colors for regular labels. Each color is RGB format and the range of its values is \([0, 255]\). If colors is None, the default color map is used.

  • ignore_label_color (tuple) – Color for ignored label. This is RGB format and the range of its values is \([0, 255]\). The default value is (0, 0, 0).

  • alpha (float) – The value which determines transparency of the figure. The range of this value is \([0, 1]\). If this value is 0, the figure will be completely transparent. The default value is 1. This option is useful for overlaying the label on the source image.

  • all_label_names_in_legend (bool) – Determines whether to include all label names in a legend. If this is False, the legend does not contain the names of unused labels. An unused label is defined as a label that does not appear in label. The default value is False.

  • ax (matplotlib.axes.Axis) – The visualization is displayed on this axis. If this is None (default), a new axis is created.

name

shape

dtype

format

img

\((3, H, W)\)

float32

RGB, \([0, 255]\)

label

\((H, W)\)

int32

\([-1, \#class - 1]\)

Returns

Returns ax and legend_handles. ax is an matploblib.axes.Axes with the plot. It can be used for further tweaking. legend_handles is a list of legends. It can be passed matploblib.pyplot.legend() to show a legend.

Return type

matploblib.axes.Axes and list of matplotlib.patches.Patch