Notebooks Utils¶
supervision.utils.notebook.plot_image(image: ImageType, size: tuple[int, int] = (12, 12), cmap: str | None = 'gray') -> None
¶
Plots image using matplotlib.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
ImageType
|
The frame to be displayed ImageType
is a flexible type, accepting either |
required |
|
tuple[int, int]
|
The size of the plot in inches. |
(12, 12)
|
|
str | None
|
the colormap to use for single channel images. |
'gray'
|
Examples:
>>> import cv2
>>> import numpy as np
>>> import matplotlib
>>> matplotlib.use('Agg') # Prevents the GUI window from popping up
>>> import supervision as sv
>>> image = np.zeros((100, 100, 3), dtype=np.uint8)
>>> sv.plot_image(image=image, size=(16, 16))
...
Source code in src/supervision/utils/notebook.py
supervision.utils.notebook.plot_images_grid(images: list[ImageType], grid_size: tuple[int, int], titles: list[str] | None = None, size: tuple[int, int] = (12, 12), cmap: str | None = 'gray') -> None
¶
Plots images in a grid using matplotlib.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
list[ImageType]
|
A list of images as ImageType
is a flexible type, accepting either |
required |
|
tuple[int, int]
|
A tuple specifying the number of rows and columns for the grid. |
required |
|
list[str] | None
|
A list of titles for each image. Defaults to None. |
None
|
|
tuple[int, int]
|
A tuple specifying the width and height of the entire plot in inches. |
(12, 12)
|
|
str | None
|
the colormap to use for single channel images. |
'gray'
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the number of images exceeds the grid size. |
Examples:
>>> import cv2
>>> import numpy as np
>>> import matplotlib
>>> matplotlib.use('Agg') # Prevents the GUI window from popping up
>>> import supervision as sv
>>> from PIL import Image
>>> image1 = np.zeros((100, 100, 3), dtype=np.uint8)
>>> image2 = Image.new('RGB', (100, 100))
>>> image3 = np.zeros((100, 100, 3), dtype=np.uint8)
>>> images = [image1, image2, image3]
>>> titles = ["Image 1", "Image 2", "Image 3"]
>>> sv.plot_images_grid(images, grid_size=(2, 2), titles=titles, size=(16, 16))
...