powerboxesrs/lib.rs
1#![crate_name = "powerboxesrs"]
2
3//! # Powerboxesrs
4//!
5//! Utility functions for transforming bounding boxes and computing metrics.
6//!
7//! ## Installation
8//!
9//! ```toml
10//! [dependencies]
11//! powerboxesrs = "0.3.0"
12//! ```
13//!
14//! ## Slice-based API (no ndarray dependency)
15//!
16//! All core functions have a `_slice` variant that operates on flat `&[N]` slices,
17//! avoiding coupling to a specific `ndarray` version.
18//! To opt out of ndarray entirely, disable default features:
19//!
20//! ```toml
21//! [dependencies]
22//! powerboxesrs = { version = "0.3", default-features = false }
23//! ```
24//!
25//! ```rust
26//! use powerboxesrs::iou::iou_distance_slice;
27//!
28//! // Flat slice: [x1, y1, x2, y2, ...] with num_boxes
29//! let boxes1 = vec![0.0, 0.0, 1.0, 1.0, 2.0, 2.0, 3.0, 3.0];
30//! let boxes2 = vec![0.5, 0.5, 1.5, 1.5, 2.5, 2.5, 3.5, 3.5];
31//! let iou = iou_distance_slice(&boxes1, &boxes2, 2, 2);
32//! assert_eq!(iou, vec![0.8571428571428572, 1., 1., 0.8571428571428572]);
33//! ```
34//!
35//! ## ndarray API (default feature)
36//!
37//! With the `ndarray` feature (enabled by default), wrappers accepting `ArrayView2` are available.
38//! The ndarray dependency is flexible (`>=0.15, <=0.16`) to minimize version conflicts.
39//!
40//! ### Functions available
41//! **Note:** all functions expect boxes in `xyxy` format (top left and bottom right corners), except box conversion and rotated box functions.
42//!
43//! #### Box Transformations and utilities
44//! - `box_areas`: Compute the area of list of boxes
45//! - `box_convert`: Convert a box from one format to another. Supported formats are `xyxy`, `xywh`, `cxcywh`
46//! - `remove_small_boxes`: Remove boxes with area smaller than a threshold
47//! - `masks_to_boxes`: Convert a mask to a list of boxes
48//!
49//! #### Box Metrics
50//! - `iou_distance`: Compute the intersection over union matrix of two sets of boxes
51//! - `parallel_iou_distance`: Compute the intersection over union matrix of two sets of boxes in parallel
52//! - `giou_distance`: Compute the generalized intersection over union matrix of two sets of boxes
53//! - `parallel_giou_distance`: Compute the generalized intersection over union matrix of two sets of boxes in parallel
54//! - `diou_distance`: Compute the distance intersection over union matrix of two sets of boxes
55//! - `tiou_distance`: Compute the tracking intersection over union matrix of two sets of boxes
56//!
57//! #### Rotated Box Metrics
58//! Rotated boxes use `(cx, cy, w, h, angle)` format where angle is in degrees.
59//! - `rotated_iou_distance`: Compute IoU distance for rotated boxes
60//! - `rotated_giou_distance`: Compute GIoU distance for rotated boxes
61//! - `rotated_tiou_distance`: Compute tracking IoU distance for rotated boxes
62//!
63//! #### Box NMS
64//! - `nms`: Non-maximum suppression, returns the indices of the boxes to keep
65//! - `rtree_nms`: Non-maximum suppression using an R-tree for sub-quadratic complexity
66//!
67//! #### Drawing
68//! - `draw_boxes`: Draw bounding boxes on a CHW image tensor
69//!
70pub mod boxes;
71pub mod diou;
72pub mod draw;
73pub mod giou;
74pub mod iou;
75pub mod nms;
76pub mod rotation;
77pub mod tiou;
78pub(crate) mod utils;