draw_bounding_boxes functionkeras.visualization.draw_bounding_boxes(
images,
bounding_boxes,
bounding_box_format,
class_mapping=None,
color=(128, 128, 128),
line_thickness=2,
text_thickness=1,
font_scale=1.0,
data_format=None,
)
Draws bounding boxes on images.
This function draws bounding boxes on a batch of images. It supports different bounding box formats and can optionally display class labels and confidences.
Arguments
(batch_size, height, width, channels).boxes: A tensor or array of shape (batch_size, num_boxes, 4)
containing the bounding box coordinates in the specified format.labels: A tensor or array of shape (batch_size, num_boxes)
containing the class labels for each bounding box.confidences (Optional): A tensor or array of shape
(batch_size, num_boxes) containing the confidence scores for
each bounding box.(255, 0, 0) for red. Defaults to (128, 128, 128).2.1.1.0."channels_last" or "channels_first",
specifying the order of dimensions in the input images. Defaults to
the image_data_format value found in your Keras config file at
~/.keras/keras.json. If you never set it, then it will be
"channels_last".Returns
A NumPy array of the annotated images with the bounding boxes drawn.
The array will have the same shape as the input images.
Raises
images is not a 4D tensor/array, if bounding_boxes is
not a dictionary, or if bounding_boxes does not contain "boxes"
and "labels" keys.bounding_boxes is not a dictionary.cv2 (OpenCV) is not installed.draw_segmentation_masks functionkeras.visualization.draw_segmentation_masks(
images,
segmentation_masks,
num_classes=None,
color_mapping=None,
alpha=0.8,
blend=True,
ignore_index=-1,
data_format=None,
)
Draws segmentation masks on images.
The function overlays segmentation masks on the input images. The masks are blended with the images using the specified alpha value.
Arguments
num_classes. Class 0 is reserved for
the background and will be ignored if ignore_index is not 0.None, it is
inferred from the maximum value in segmentation_masks.None, a default color palette is generated. The keys should be
integers starting from 1 up to num_classes.[0, 1].alpha value. If False, the masks are drawn directly on the
images without blending. Defaults to True."channels_last" or
"channels_first". Defaults to the image_data_format value found
in your Keras config file at ~/.keras/keras.json. If you never
set it, then it will be "channels_last".Returns
A NumPy array of the images with the segmentation masks overlaid.
Raises
images is not a 4D tensor or NumPy array.segmentation_masks is not an integer type.plot_bounding_box_gallery functionkeras.visualization.plot_bounding_box_gallery(
images,
bounding_box_format,
y_true=None,
y_pred=None,
value_range=(0, 255),
true_color=(0, 188, 212),
pred_color=(255, 235, 59),
line_thickness=2,
font_scale=1.0,
text_thickness=None,
class_mapping=None,
ground_truth_mapping=None,
prediction_mapping=None,
legend=False,
legend_handles=None,
rows=None,
cols=None,
data_format=None,
**kwargs
)
Plots a gallery of images with bounding boxes.
This function can display both ground truth and predicted bounding boxes on a set of images. It supports various bounding box formats and can include class labels and a legend.
Arguments
(batch_size, height, width, channels).bounding_boxes
argument in keras.visualization.draw_bounding_boxes.
Defaults to None.y_true. Defaults to None.(0, 255) or (0, 1)). Defaults to (0, 255).(0, 188, 212).(255, 235, 59).line_thickness.ground_truth_mapping
and prediction_mapping are not provided. Defaults to None.class_mapping
for ground truth. Defaults to None.class_mapping for
predictions. Defaults to None.False.Patch objects to use for the
legend. If this is provided, the legend argument will be ignored.
Defaults to None.None.None."channels_last" or
"channels_first". Defaults to the Keras backend data format.keras.visualization.plot_image_gallery.Returns
The output of keras.visualization.plot_image_gallery.
Raises
images is not a 4D tensor/array or if both legend a
nd legend_handles are specified.plot_image_gallery functionkeras.visualization.plot_image_gallery(
images,
y_true=None,
y_pred=None,
label_map=None,
rows=None,
cols=None,
value_range=(0, 255),
scale=2,
path=None,
show=None,
transparent=True,
dpi=60,
legend_handles=None,
data_format=None,
)
Displays a gallery of images with optional labels and predictions.
Arguments
(batch_size, height, width, channels).None.None.y_true or y_pred are provided.
Defaults to None.(0, 255) or (0, 1)). Defaults to (0, 255).None, it's calculated
based on the number of images and cols. Defaults to None.None, it's calculated
based on the number of images and rows. Defaults to None.2.None, the
image is displayed using plt.show(). Defaults to None.plt.show(). If True, the
image is displayed. If False, the image is not displayed.
Ignored if path is not None. Defaults to True if path
is None, False otherwise.True.Patch objects to use as legend
handles. Defaults to None."channels_last" or
"channels_first". Defaults to the Keras backend data format.Raises
path and show are set to non-None values,
if images is not a 4D tensor or array, or if y_true or y_pred
are provided without a label_map.plot_segmentation_mask_gallery functionkeras.visualization.plot_segmentation_mask_gallery(
images,
num_classes,
value_range=(0, 255),
y_true=None,
y_pred=None,
color_mapping=None,
blend=True,
alpha=0.8,
ignore_index=-1,
data_format=None,
**kwargs
)
Plots a gallery of images with corresponding segmentation masks.
Arguments
(batch_size, height, width, channels).1. Class 0 will be treated as background and
ignored if ignore_index is not 0.(0, 255) or (0, 1)). Defaults to (0, 255).(batch_size, height, width) or
(batch_size, height, width, 1). Defaults to None.y_true.
Defaults to None.None, a default color palette is used. Class indices start
from 1. Defaults to None.alpha value. If False, the masks are drawn directly on the
images without blending. Defaults to True.0.8.-1."channels_last" or
"channels_first". Defaults to the Keras backend data format.keras.visualization.plot_image_gallery.Returns
The output of keras.visualization.plot_image_gallery.
Raises
images is not a 4D tensor/array.