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, ax=None)¶ 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) – An array of shape \((3, height, width)\).
This is in RGB format and the range of its value is
\([0, 255]\). If this is
None
, no image is displayed. - bbox (ndarray) – An array of shape \((R, 4)\), where \(R\) is the number of bounding boxes in the image. Each element is organized by \((y_{min}, x_{min}, y_{max}, x_{max})\) in the second axis.
- label (ndarray) – An integer array of shape \((R,)\).
The values correspond to id for label names stored in
label_names
. This is optional. - score (ndarray) – A float array of shape \((R,)\). Each value indicates how confident the prediction is. 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 thei
-th instance. Ifinstance_colors
isNone
, 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.
- ax (matplotlib.axes.Axis) – The visualization is displayed on this
axis. If this is
None
(default), a new axis is created.
Returns: Returns the Axes object with the plot for further tweaking.
Return type: Axes
- img (ndarray) – An array of shape \((3, height, width)\).
This is in RGB format and the range of its value is
\([0, 255]\). If this is
vis_image¶
-
chainercv.visualizations.
vis_image
(img, ax=None)¶ Visualize a color image.
Parameters: 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, ax=None)¶ 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) – An array of shape \((3, H, W)\).
This is in RGB format and the range of its value is
\([0, 255]\). If this is
None
, no image is displayed. - mask (ndarray) – A bool array of shape
:math`(R, H, W)`.
If there is an object, the value of the pixel is
True
, and otherwise, it isFalse
. - label (ndarray) – An integer array of shape \((R, )\).
The values correspond to id for label names stored in
label_names
. - score (ndarray) – A float array of shape \((R,)\). Each value indicates how confident the prediction is. 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 thei
-th instance. Ifinstance_colors
isNone
, 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 is0.7
. This option is useful for overlaying the label on the source image. - ax (matplotlib.axes.Axis) – The visualization is displayed on this
axis. If this is
None
(default), a new axis is created.
Returns: Returns
ax
.ax
is anmatploblib.axes.Axes
with the plot.Return type: matploblib.axes.Axes
- img (ndarray) – An array of shape \((3, H, W)\).
This is in RGB format and the range of its value is
\([0, 255]\). If this is
vis_point¶
-
chainercv.visualizations.
vis_point
(img, point, mask=None, ax=None)¶ Visualize points in an image.
Example
>>> import chainercv >>> import matplotlib.pyplot as plt >>> dataset = chainercv.datasets.CUBPointDataset() >>> img, point, mask = dataset[0] >>> chainercv.visualizations.vis_point(img, point, mask) >>> plt.show()
Parameters: - img (ndarray) – An image of shape \((3, height, width)\).
This is in RGB format and the range of its value is
\([0, 255]\). This should be visualizable using
matplotlib.pyplot.imshow(img)
- point (ndarray) – An array of point coordinates whose shape is \((P, 2)\), where \(P\) is the number of points. The second axis corresponds to \(y\) and \(x\) coordinates of the points.
- mask (ndarray) – A boolean array whose shape is
\((P,)\). If \(i\) th element is
True
, the \(i\) th point is not displayed. If not specified, all points inpoint
will be displayed. - ax (matplotlib.axes.Axes) – If provided, plot on this axis.
Returns: Returns the Axes object with the plot for further tweaking.
Return type: Axes
- img (ndarray) – An image of shape \((3, height, width)\).
This is in RGB format and the range of its value is
\([0, 255]\). This should be visualizable using
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)¶ 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) – An array of shape \((3, height, width)\).
This is in RGB format and the range of its value is
\([0, 255]\). If this is
None
, no image is displayed. - label (ndarray) – An integer array of shape
\((height, width)\).
The values correspond to id for label names stored in
label_names
. - 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
isNone
, 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 is1
. 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 inlabel
. The default value isFalse
. - ax (matplotlib.axes.Axis) – The visualization is displayed on this
axis. If this is
None
(default), a new axis is created.
Returns: Returns
ax
andlegend_handles
.ax
is anmatploblib.axes.Axes
with the plot. It can be used for further tweaking.legend_handles
is a list of legends. It can be passedmatploblib.pyplot.legend()
to show a legend.Return type: matploblib.axes.Axes and list of matplotlib.patches.Patch
- img (ndarray) – An array of shape \((3, height, width)\).
This is in RGB format and the range of its value is
\([0, 255]\). If this is