Skip to main content

boxlib

A lightweight Python library for bounding box manipulation, designed for computer vision tasks.

Installation

pip install boxlib

Box Convention

All bounding boxes are NumPy arrays with format [x, y, width, height], where (x, y) is the top-left corner.

import numpy as np
import boxlib

box = np.array([10, 20, 100, 50])  # x=10, y=20, width=100, height=50

Quick Examples

import numpy as np
import boxlib

box = np.array([10, 20, 100, 50])

# Get center point
boxlib.center(box)  # array([60., 45.])

# Expand box by 2x around its center
boxlib.expand(box, 2)  # array([-40., -5., 200., 100.])

# Make box square (using max dimension)
boxlib.expand_to_square(box)  # array([10., -5., 100., 100.])

# Intersection of two boxes
box2 = np.array([50, 40, 100, 50])
boxlib.intersection(box, box2)  # array([50., 40., 60., 30.])

# IoU (Intersection over Union)
boxlib.iou(box, box2)  # 0.189...

# Crop image to bounding box
image = np.zeros((200, 200, 3))
cropped = boxlib.crop_image(image, box)  # shape: (50, 100, 3)

Functions

Geometry

  • center(box) - Get center point
  • corners(box) - Get four corner coordinates
  • side_midpoints(box) - Get midpoints of each side
  • inscribed_ellipse_points(box, n_angles, n_radii) - Sample points inside inscribed ellipse
  • area(box) - Calculate area

Transformations

  • shift(box, delta) - Translate box by offset
  • expand(box, factor) - Scale box around its center
  • expand_to_square(box) - Expand to square using max dimension
  • crop_to_square(box) - Crop to square using min dimension
  • box_around(center, size) - Create box from center point and size

Set Operations

  • intersection(box1, box2) - Intersection of two boxes
  • box_hull(box1, box2) - Smallest box containing both
  • contains(box, points) - Check if points are inside box

Metrics

  • iou(box1, box2) - Intersection over Union
  • giou(box1, box2) - Generalized IoU

Construction

  • bb_of_points(points) - Bounding box of point set
  • bb_of_mask(mask) - Bounding box of binary mask
  • full(imshape=None, imsize=None) - Full image bounding box
  • empty() - Zero-size box at origin

Image Operations

  • crop_image(image, box, pad=True) - Crop image to box with optional padding

License

MIT

Metadata

Release files for boxlib 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for boxlib 0.4.0
File Size Uploaded Provenance Actions
boxlib-0.4.0.tar.gz 23.9 kB With provenance Details for boxlib-0.4.0.tar.gz

Release files / boxlib-0.4.0.tar.gz

Download URL boxlib-0.4.0.tar.gz
Size 23.9 kB
Tags Source
SHA-256 checksum
How to use checksums
d55a04e4b7276393059fd7ea0b465654ece34ef7d4a9488a64ec908fc686caae
BLAKE2b-256 checksum
How to use checksums
c22e7eb5c2e17ece42fdbfe4a026ef67d64fc4f85c8546cec0943dc61960c8dc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 21, 2026.

Transparency log

Security for boxlib 0.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 1 file in this release has been uploaded with provenance metadata.

Attestation for boxlib-0.4.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 21, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page