LogoLogo
AI HubCommunityWebsite
  • Start Here
  • AI Hub
    • Overview
    • Quickstart
    • Teams
    • Device Farm
    • Browser Inference
    • Model Zoo
      • Hailo
      • Intel
      • MemryX
      • BrainChip
      • Google
      • DeGirum
      • Rockchip
    • View and Create Model Zoos
    • Compiler
    • PySDK Integration
  • PySDK
    • Overview
    • Quickstart
    • Installation
    • Runtimes and Drivers
      • Hailo
      • OpenVINO
      • MemryX
      • BrainChip
      • Rockchip
      • ONNX
    • PySDK User Guide
      • Core Concepts
      • Organizing Models
      • Setting Up an AI Server
      • Loading an AI Model
      • Running AI Model Inference
      • Model JSON Structure
      • Command Line Interface
      • API Reference Guide
        • PySDK Package
        • Model Module
        • Zoo Manager Module
        • Postprocessor Module
        • AI Server Module
        • Miscellaneous Modules
      • Older PySDK User Guides
        • PySDK 0.16.1
        • PySDK 0.16.0
        • PySDK 0.15.2
        • PySDK 0.15.1
        • PySDK 0.15.0
        • PySDK 0.14.3
        • PySDK 0.14.2
        • PySDK 0.14.1
        • PySDK 0.14.0
        • PySDK 0.13.4
        • PySDK 0.13.3
        • PySDK 0.13.2
        • PySDK 0.13.1
        • PySDK 0.13.0
    • Release Notes
      • Retired Versions
    • EULA
  • DeGirum Tools
    • Overview
      • Streams
        • Streams Base
        • Streams Gizmos
      • Compound Models
      • Analyzers
        • Clip Saver
        • Event Detector
        • Line Count
        • Notifier
        • Object Selector
        • Object Tracker
        • Zone Count
      • Inference Support
      • Support Modules
        • Audio Support
        • Model Evaluation Support
        • Math Support
        • Object Storage Support
        • UI Support
        • Video Support
  • DeGirumJS
    • Overview
    • Get Started
    • Understanding Results
    • Release Notes
    • API Reference Guides
      • DeGirumJS 0.1.3
      • DeGirumJS 0.1.2
      • DeGirumJS 0.1.1
      • DeGirumJS 0.1.0
      • DeGirumJS 0.0.9
      • DeGirumJS 0.0.8
      • DeGirumJS 0.0.7
      • DeGirumJS 0.0.6
      • DeGirumJS 0.0.5
      • DeGirumJS 0.0.4
      • DeGirumJS 0.0.3
      • DeGirumJS 0.0.2
      • DeGirumJS 0.0.1
  • Orca
    • Overview
    • Benchmarks
    • Unboxing and Installation
    • M.2 Setup
    • USB Setup
    • Thermal Management
    • Tools
  • Resources
    • External Links
Powered by GitBook

Get Started

  • AI Hub Quickstart
  • PySDK Quickstart
  • PySDK in Colab

Resources

  • AI Hub
  • Community
  • DeGirum Website

Social

  • LinkedIn
  • YouTube

Legal

  • PySDK EULA
  • Terms of Service
  • Privacy Policy

© 2025 DeGirum Corp.

On this page
  • Math Support Module Overview
  • Classes
  • NmsBoxSelectionPolicy
  • AnchorPoint
  • FIRFilterLP
  • Functions
  • __call__(sample)
  • __init__(normalized_cutoff, ...)
  • update(sample)
  • Functions
  • area(box)
  • intersection(boxA, ...)
  • xyxy2xywh(x)
  • tlbr2allcorners(x)
  • xywh2xyxy(x)
  • box_iou_batch(boxes_true, ...)
  • nms(detections, ...)
  • edge_box_fusion(detections, ...)
  • get_anchor_coordinates(xyxy, ...)
  • get_image_anchor_point(w, ...)
  • intersect(a, ...)
  • generate_tiles_fixed_size(tile_size, ...)
  • generate_tiles_fixed_ratio(tile_aspect_ratio, ...)

Was this helpful?

  1. DeGirum Tools
  2. Overview
  3. Support Modules

Math Support

This API Reference is based on DeGirum Tools version 0.16.7.

Math Support Module Overview

This module provides mathematical utilities for geometric operations and signal processing. It includes functions for bounding box manipulation, non-maximum suppression, image tiling, and a lightweight FIR low-pass filter implementation.

Key Features

  • Bounding Box Operations: Area calculation, IoU computation, coordinate conversions

  • Non-maximum Suppression: Multiple selection policies for detection filtering

  • Edge Box Fusion: Handling overlapping detections with configurable thresholds

  • Image Tiling: Utilities for fixed size or aspect ratio tiling

  • FIR Filter: Lightweight low-pass filter implementation for signal smoothing

Typical Usage

  1. Import required functions from the module

  2. Use bounding box operations for detection processing

  3. Apply NMS or box fusion for post-processing detections

  4. Generate image tiles for processing large images

  5. Use FIRFilterLP for smoothing numeric sequences

Integration Notes

  • Built on NumPy for efficient array operations

  • Compatible with various bounding box formats (xyxy, xywh)

  • Provides consistent results across platforms

  • Includes comprehensive error handling

Key Functions

  • area(): Calculate bounding box areas

  • intersection(): Compute intersection area of bounding boxes

  • nms(): Apply non-maximum suppression

  • edge_box_fusion(): Fuse overlapping edge detections

  • generate_tiles_fixed_size(): Generate overlapping image tiles

Configuration Options

  • NMS selection policies

  • Box fusion thresholds

  • Tile overlap parameters

  • Filter coefficients

Classes

NmsBoxSelectionPolicy

NmsBoxSelectionPolicy

Bases: Enum

Bounding box selection policy for non-maximum suppression.

This enum defines different strategies for selecting which bounding box to keep when multiple overlapping boxes are detected. Each policy has different use cases and trade-offs.

Attributes:

Name
Type
Description

MOST_PROBABLE

int

Traditional NMS approach that keeps the box with highest confidence score. Best for high-confidence detections where false positives are costly.

LARGEST_AREA

int

Keeps the box with the largest area. Useful when larger detections are more likely to be correct or when object size is important.

AVERAGE

int

Averages the coordinates of all overlapping boxes. Good for reducing jitter in tracking applications.

MERGE

int

Merges all overlapping boxes into a single box. Useful when multiple detections of the same object are expected.

AnchorPoint

AnchorPoint

Bases: Enum

Position of a point of interest within the bounding box.

FIRFilterLP

FIRFilterLP

Low-pass Finite Impulse Response (FIR) filter implementation.

This class implements a low-pass FIR filter for smoothing signals. It uses convolution with designed filter coefficients (FIR kernel) with configurable cutoff frequency and number of taps.

Attributes:

Name
Type
Description

normalized_cutoff

float

Normalized cutoff frequency (0 to 1).

taps_cnt

int

Number of filter taps (order of the filter).

dimension

int

Number of dimensions in the input signal.

Functions

__call__(sample)

__call__(sample)

Update the filter with a new sample and return the filtered value.

This is a convenience method that calls update().

Parameters:

Name
Type
Description
Default

sample

Union[float, ndarray]

New input sample. Can be a scalar or an array of length equal to the filter's dimension.

required

Returns:

Type
Description

ndarray

Filtered output value with the same shape as the input sample.

__init__(normalized_cutoff, ...)

__init__(normalized_cutoff, taps_cnt, dimension=1)

Initialize the FIR filter with specified parameters.

Parameters:

Name
Type
Description
Default

normalized_cutoff

float

Normalized cutoff frequency between 0 and 1. A value of 1 corresponds to the Nyquist frequency.

required

taps_cnt

int

Number of filter taps (order of the filter). Higher values provide better frequency response but increase computational cost and delay.

required

dimension

int

Number of dimensions in the input signal. Defaults to 1 for scalar signals.

1

Raises:

Type
Description

ValueError

If normalized_cutoff is not between 0 and 1.

ValueError

If taps_cnt is less than 1.

ValueError

If dimension is less than 1.

update(sample)

update(sample)

Update the filter with a new sample and return the filtered value.

This method adds a new sample to the filter's buffer and computes the filtered output by convolving the input samples with the FIR filter coefficients.

Parameters:

Name
Type
Description
Default

sample

Union[float, ndarray]

New input sample. Can be a scalar or an array of length equal to the filter's dimension.

required

Returns:

Type
Description

ndarray

Filtered output value with the same shape as the input sample.

Raises:

Type
Description

ValueError

If the input sample's shape doesn't match the filter's dimension.

Functions

area(box)

area(box)

Compute bounding box areas.

Parameters:

Name
Type
Description
Default

box

ndarray

Single box (x1, y1, x2, y2) or an array of such boxes with shape (N, 4).

required

Returns:

Type
Description

ndarray

Area of each input box.

intersection(boxA, ...)

intersection(boxA, boxB)

Compute intersection area of bounding boxes.

Parameters:

Name
Type
Description
Default

boxA

ndarray

First set of boxes (x1, y1, x2, y2).

required

boxB

ndarray

Second set of boxes (x1, y1, x2, y2).

required

Returns:

Type
Description

Union[float, ndarray]

Intersection area for each pair of boxes.

xyxy2xywh(x)

xyxy2xywh(x)

Convert (x1, y1, x2, y2) boxes to (x, y, w, h) format.

tlbr2allcorners(x)

tlbr2allcorners(x)

Convert (x1, y1, x2, y2) boxes to all four corner points.

xywh2xyxy(x)

xywh2xyxy(x)

Convert (x, y, w, h) boxes to (x1, y1, x2, y2) format.

box_iou_batch(boxes_true, ...)

box_iou_batch(boxes_true, boxes_detection)

Compute pairwise IoU between two sets of boxes.

Parameters:

Name
Type
Description
Default

boxes_true

ndarray

Ground-truth boxes (N, 4).

required

boxes_detection

ndarray

Detection boxes (M, 4).

required

Returns:

Type
Description

ndarray

IoU matrix of shape (N, M).

nms(detections, ...)

nms(detections, iou_threshold=0.3, use_iou=True, box_select=NmsBoxSelectionPolicy.MOST_PROBABLE, max_wh=10000, agnostic=False)

Apply non-maximum suppression to detection results.

Parameters:

Name
Type
Description
Default

detections

Iterable of detection dictionaries containing bbox, score and class fields.

required

iou_threshold

float

IoU/IoS threshold. Defaults to 0.3.

0.3

use_iou

bool

If True use IoU, otherwise IoS.

True

box_select

Box selection strategy.

MOST_PROBABLE

max_wh

int

Maximum image dimension for class separation.

10000

agnostic

bool

If True perform class-agnostic NMS.

False

Returns:

Type
Description

None

detections is modified in place with the filtered results.

edge_box_fusion(detections, ...)

edge_box_fusion(detections, iou_threshold=0.55, skip_threshold=0.0, destructive=True)

Perform box fusion on a set of edge detections. Edge detections are detections within a certain threshold of an edge.

Parameters:

Name
Type
Description
Default

detections

results

A list of dictionaries that contain detection results as defined in PySDK.

required

iou_threshold

float

1D-IoU threshold used for selecting boxes for fusion.

0.55

skip_threshold

float

Score threshold for which boxes to fuse.

0.0

destructive

bool

Keep skipped boxes (underneath the score_threshold) in the results.

True

Returns:

Type
Description

results

A list of dictionaries that contain detection results as defined in PySDK. Boxes that are not fused are kept if destructive is False, otherwise they are discarded.

get_anchor_coordinates(xyxy, ...)

get_anchor_coordinates(xyxy, anchor)

Get coordinates of an anchor point inside bounding boxes.

Parameters:

Name
Type
Description
Default

xyxy

ndarray

Array of boxes (N, 4).

required

anchor

Desired anchor location.

required

Returns:

Type
Description

ndarray

Array (N, 2) with [x, y] coordinates.

Raises:

Type
Description

ValueError

If anchor is unsupported.

get_image_anchor_point(w, ...)

get_image_anchor_point(w, h, anchor)

Return coordinates of an anchor point inside an image.

intersect(a, ...)

intersect(a, b, c, d)

Return True if two line segments intersect.

generate_tiles_fixed_size(tile_size, ...)

generate_tiles_fixed_size(tile_size, image_size, min_overlap_percent)

Generate overlapping tiles with fixed size.

Parameters:

Name
Type
Description
Default

tile_size

Union[ndarray, Sequence]

Tile size (w, h).

required

image_size

Union[ndarray, Sequence]

Image size (w, h).

required

min_overlap_percent

Union[ndarray, Sequence]

Minimum overlap in percent.

required

Returns:

Type
Description

ndarray

Array of shape (N, M, 4) containing tile coordinates, where N is the number of rows in the tile grid, M is the number of columns in the tile grid, and 4 represents the coordinates (x1, y1, x2, y2) for each tile.

generate_tiles_fixed_ratio(tile_aspect_ratio, ...)

generate_tiles_fixed_ratio(tile_aspect_ratio, grid_size, image_size, min_overlap_percent)

Generate overlapping tiles with fixed aspect ratio.

Parameters:

Name
Type
Description
Default

tile_aspect_ratio

Union[float, ndarray, Sequence]

Desired aspect ratio.

required

grid_size

Union[ndarray, Sequence]

Grid size (x, y).

required

image_size

Union[ndarray, Sequence]

Image size (w, h).

required

min_overlap_percent

Union[ndarray, Sequence, float]

Minimum overlap percent.

required

Returns:

Type
Description

ndarray

Array of shape (N, M, 4) containing tile coordinates, where N is the number of rows in the tile grid, M is the number of columns in the tile grid, and 4 represents the coordinates (x1, y1, x2, y2) for each tile.

PreviousModel Evaluation SupportNextObject Storage Support

Last updated 2 days ago

Was this helpful?

NmsBoxSelectionPolicy
AnchorPoint
InferenceResults