landingai.visualize
The landingai.visualize module contains functions to visualize the prediction results.
overlay_bboxes(predictions, image, options=None)
Draw bounding boxes on the input image and return the image with bounding boxes drawn. The bounding boxes are drawn using the bbox-visualizer package.
Parameters
predictions
A list of ObjectDetectionPrediction, each of which contains the bounding box and the predicted class.
image
The source image to draw the bounding boxes on.
options
Options to customize the drawing. Currently, it supports the following options:
1. bbox_style
: str, the style of the bounding box.
- "default": draw a rectangle with the label right on top of the rectangle. (default option)
- "flag": draw a vertical line connects the detected object and the label. No rectangle is drawn.
- "t-label": draw a rectangle with a vertical line on top of the rectangle, which points to the label.
For more information, see https://github.com/shoumikchow/bbox-visualizer
2. draw_label
: bool, default True. If False, the label won't be drawn. This option is only valid when bbox_style is "default". This option is ignored otherwise.
Returns
Image.Image The image with bounding boxes drawn.
Raises
ValueError When the value of bbox_style is not supported.
Source code in landingai/visualize.py
overlay_colored_masks(predictions, image, options=None)
Draw colored masks on the input image and return the image with colored masks drawn.
NOTE: - The image is converted to grayscale first, and then the colored masks are drawn on top of it. - The colored masks are drawn using the segmentation-mask-overlay package.
Parameters
predictions
A list of SegmentationPrediction, each of which contains the segmentation mask and the predicted class.
image
The source image to draw the colored masks on.
options
Options to customize the drawing. Currently, it supports the following options:
1. color_map
: dict, default empty. A map of label names to colors. For any labels that don't have a color, a color will be assigned to it.
The color is any value acceptable by PIL. The label name are case insensitive.
Example:
mask_alpha
: float, default 0.5. The alpha value of the colored masks. The value should be between 0 and 1.
Returns
Image.Image The image with segmented masks drawn.
Source code in landingai/visualize.py
overlay_ocr_predictions(predictions, image, options=None)
Draw the predicted texts and boxes on the input image with a side-by-side view.
Parameters
predictions A list of OcrPrediction, each of which contains the polygon and the predicted text and score. image The source image to draw the polygon on. options Options to customize the drawing. Currently, no options are supported.
Returns
Image The image with the polygon and text drawn.
Source code in landingai/visualize.py
overlay_predicted_class(predictions, image, options=None)
Draw the predicted class on the input image and return the image with the predicted class drawn.
Parameters
predictions
A list of ClassificationPrediction, each of which contains the predicted class and the score.
image
The source image to draw the colored masks on.
options
Options to customize the drawing. Currently, it supports the following options:
1. text_position
: tuple[int, int]. The position of the text relative to the left bottom of the image. The default value is (10, 25).
Returns
Image.Image the image with segmented masks drawn.
Source code in landingai/visualize.py
overlay_predictions(predictions, image, options=None)
Overlay the prediction results on the input image and return the image with the overlay.