Skip to main content

module  pixeltable.functions.vision

Pixeltable UDFs for Computer Vision. Example:
import pixeltable as pxt
from pixeltable.functions import vision as pxtv

t = pxt.get_table(...)
t.select(
    pxtv.bboxes_draw(t.img, boxes=t.boxes, labels=t.labels)
).collect()

udf  bboxes_convert()

Signature
@pxt.udf
bboxes_convert(
    bboxes: pxt.Json,
    *,
    src_format: pxt.String,
    dst_format: pxt.String
) -> pxt.Json
Convert a list of bounding boxes from src_format to dst_format. Parameters:
  • bboxes (pxt.Json): List of bounding boxes, each either specified with absolute pixel coordinates or relative coordinates in [0, 1].
  • src_format (pxt.String): Source format, one of ‘xyxy’, ‘xywh’, ‘cxcywh’.
  • dst_format (pxt.String): Destination format, one of ‘xyxy’, ‘xywh’, ‘cxcywh’.
Returns:
  • pxt.Json: List of bounding boxes in dst_format.

udf  bboxes_draw()

Signature
@pxt.udf
bboxes_draw(
    img: pxt.Image,
    boxes: pxt.Json,
    *,
    labels: pxt.Json | None = None,
    color: pxt.String | None = None,
    box_colors: pxt.Json | None = None,
    alpha: pxt.Float | None = None,
    fill: pxt.Bool = False,
    fill_alpha: pxt.Float | None = None,
    width: pxt.Int = 1,
    font: pxt.String | None = None,
    font_size: pxt.Int | None = None
) -> pxt.Image
Draws bounding boxes on the given image. Labels can be any type that supports str() and is hashable (e.g., strings, ints, etc.). Colors can be specified as common HTML color names (e.g., ‘red’) supported by PIL’s ImageColor module or as RGB/RGBA hex codes (e.g., ‘#FF0000’, ‘#FF0000FF’). If opacity isn’t specified in the color string and alpha/fill_alpha is None, defaults to 1.0 for box borders and 0.5 for filled boxes. If no colors are specified, this function randomly assigns each label a specific color based on a hash of the label. Parameters:
  • img (pxt.Image): The image on which to draw the bounding boxes.
  • boxes (pxt.Json): List of bounding boxes, each represented as [xmin, ymin, xmax, ymax].
  • labels (pxt.Json | None): List of labels for each bounding box.
  • color (pxt.String | None): Single color to be used for all bounding boxes and labels.
  • box_colors (pxt.Json | None): List of colors, one per bounding box.
  • alpha (pxt.Float | None): Opacity (0-1) of the bounding box borders and labels. If non-None, overrides any alpha in color/box_colors.
  • fill (pxt.Bool): Whether to fill the bounding boxes with color.
  • fill_alpha (pxt.Float | None): Opacity (0-1) of the bounding box fill. If non-None, overrides any alpha in color/box_colors.
  • width (pxt.Int): Width of the bounding box borders.
  • font (pxt.String | None): Name of a system font or path to a TrueType font file, as required by PIL.ImageFont.truetype(). If None, uses the default provided by PIL.ImageFont.load_default().
  • font_size (pxt.Int | None): Size of the font used for labels in points. Only used in conjunction with non-None font argument.
Returns:
  • pxt.Image: The image with bounding boxes drawn on it.

udf  bboxes_resize()

Signatures
# Signature 1:
@pxt.udf
bboxes_resize(
    bboxes: pxt.Json,
    format: pxt.String,
    width: pxt.Int | None,
    height: pxt.Int | None,
    aspect: pxt.String | None,
    aspect_mode: pxt.String | None
) -> pxt.Json

# Signature 2:
@pxt.udf
bboxes_resize(
    bboxes: pxt.Json,
    format: pxt.String,
    width: pxt.Float | None,
    height: pxt.Float | None,
    aspect: pxt.Float | None,
    aspect_mode: pxt.String | None
) -> pxt.Json
Resize a list of bounding boxes (center-anchored):
  • to a specified width or height (the other dimension is scaled to maintain the aspect ratio)
  • to a specified aspect ratio
Only one of width, height, or aspect can be specified. Parameters:
  • bboxes (Json): List of bounding boxes, each either specified with absolute pixel coordinates or relative coordinates in [0, 1].
  • format (String): Format of the bounding box coordinates, one of ‘xyxy’, ‘xywh’, ‘cxcywh’.
  • width (Int | None, default: Literal(None)): Target width. Pass an int for absolute pixels or a float for relative coordinates.
  • height (Int | None, default: Literal(None)): Target height. Pass an int for absolute pixels or a float for relative coordinates.
  • aspect (String | None, default: Literal(None)): Target aspect ratio. Pass a str like ‘16:9’ or a float like 1.78.
  • aspect (String | None, default: Literal(None)): Target aspect ratio as a string ‘W:H’ (e.g., ‘16:9’) or a float. Resizes either the width or height to match the specified aspect ratio, maintaining the other dimension. Requires aspect_mode.
  • aspect_mode (String | None, default: Literal(None)): Either ‘crop’ or ‘pad’. Required when aspect is specified. If crop, reduces the oversized dimension to match the aspect ratio. If pad, extends the undersized dimension to match the aspect ratio.
Returns:
  • pxt.Json: List of resized bounding boxes in the same format as the input.

udf  eval_detections()

Signature
@pxt.udf
eval_detections(
    pred_bboxes: pxt.Json,
    pred_labels: pxt.Json,
    pred_scores: pxt.Json,
    gt_bboxes: pxt.Json,
    gt_labels: pxt.Json,
    min_iou: pxt.Float = 0.5
) -> pxt.Json
Evaluates the performance of a set of predicted bounding boxes against a set of ground truth bounding boxes. Parameters:
  • pred_bboxes (pxt.Json): List of predicted bounding boxes, each represented as [xmin, ymin, xmax, ymax].
  • pred_labels (pxt.Json): List of predicted labels.
  • pred_scores (pxt.Json): List of predicted scores.
  • gt_bboxes (pxt.Json): List of ground truth bounding boxes, each represented as [xmin, ymin, xmax, ymax].
  • gt_labels (pxt.Json): List of ground truth labels.
  • min_iou (pxt.Float): Minimum intersection-over-union (IoU) threshold for a predicted bounding box to be considered a true positive.
Returns:
  • pxt.Json: A list of dictionaries, one per label class, with the following structure:
    {
        'min_iou': float,  # The value of `min_iou` used for the detections
        'class': int,  # The label class
        # List of 1's and 0's indicating true positives for each
        # predicted bounding box of this class
        'tp': list[int],
        # List of 1's and 0's indicating false positives for each
        # predicted bounding box of this class; `fp[n] == 1 - tp[n]`
        'fp': list[int],
        # List of predicted scores for each bounding box of this class
        'scores': list[float],
        'num_gts': int,  # Number of ground truth bounding boxes of this class
    }
    
Last modified on March 15, 2026