Skip to content

Drawing

powerboxes.draw_boxes(image, boxes, colors=None, thickness=2, filled=False, opacity=1.0)

Draw bounding boxes on an image.

Parameters:

Name Type Description Default
image NDArray[uint8]

3d array of shape (3, H, W) in CHW format, uint8

required
boxes NDArray[float64]

2d array of boxes in xyxy format, float64

required
colors NDArray[uint8]

optional 2d array of shape (N, 3) with RGB colors per box, uint8

None
thickness int

line thickness in pixels (default 2)

2
filled bool

whether to fill box interiors before drawing outlines

False
opacity float

alpha blend strength in the range [0.0, 1.0]

1.0

Raises:

Type Description
TypeError

if image or boxes are not numpy arrays

Returns:

Type Description
NDArray[uint8]

np.ndarray: 3d array of shape (3, H, W) with boxes drawn

draw_boxes draws axis-aligned xyxy boxes on CHW uint8 images.

Axis-Aligned Example

import numpy as np
import powerboxes as pb

image = np.zeros((3, 100, 100), dtype=np.uint8)
boxes = np.array(
    [
        [10.0, 10.0, 50.0, 50.0],
        [20.0, 20.0, 80.0, 70.0],
    ]
)

outlined = pb.draw_boxes(image, boxes)
filled = pb.draw_boxes(image, boxes, filled=True, opacity=0.35)

Rotated Boxes

powerboxes.draw_rotated_boxes(image, boxes, colors=None, thickness=2, filled=False, opacity=1.0)

Draw rotated bounding boxes on an image.

Parameters:

Name Type Description Default
image NDArray[uint8]

3d array of shape (3, H, W) in CHW format, uint8

required
boxes NDArray[float64]

2d array of boxes in cxcywha format, float64

required
colors NDArray[uint8]

optional 2d array of shape (N, 3) with RGB colors per box, uint8

None
thickness int

line thickness in pixels (default 2)

2
filled bool

whether to fill box interiors before drawing outlines

False
opacity float

alpha blend strength in the range [0.0, 1.0]

1.0

Raises:

Type Description
TypeError

if image or boxes are not numpy arrays

Returns:

Type Description
NDArray[uint8]

np.ndarray: 3d array of shape (3, H, W) with boxes drawn

draw_rotated_boxes draws cxcywha boxes using general line rasterization, so non-axis-aligned edges render correctly.

import numpy as np
import powerboxes as pb

image = np.zeros((3, 100, 100), dtype=np.uint8)
rotated_boxes = np.array(
    [
        [50.0, 50.0, 30.0, 20.0, 30.0],
        [60.0, 35.0, 20.0, 10.0, -20.0],
    ]
)

result = pb.draw_rotated_boxes(image, rotated_boxes, filled=True, opacity=0.4)

Notes

  • Images use CHW layout: (3, H, W).
  • colors must have shape (N, 3) when provided.
  • opacity must be in the closed interval [0.0, 1.0].

drawing features example