Utilities for bounding box manipulation.
Project description
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 pointcorners(box)- Get four corner coordinatesside_midpoints(box)- Get midpoints of each sideinscribed_ellipse_points(box, n_angles, n_radii)- Sample points inside inscribed ellipsearea(box)- Calculate area
Transformations
shift(box, delta)- Translate box by offsetexpand(box, factor)- Scale box around its centerexpand_to_square(box)- Expand to square using max dimensioncrop_to_square(box)- Crop to square using min dimensionbox_around(center, size)- Create box from center point and size
Set Operations
intersection(box1, box2)- Intersection of two boxesbox_hull(box1, box2)- Smallest box containing bothcontains(box, points)- Check if points are inside box
Metrics
iou(box1, box2)- Intersection over Uniongiou(box1, box2)- Generalized IoU
Construction
bb_of_points(points)- Bounding box of point setbb_of_mask(mask)- Bounding box of binary maskfull(imshape=None, imsize=None)- Full image bounding boxempty()- Zero-size box at origin
Image Operations
crop_image(image, box, pad=True)- Crop image to box with optional padding
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
boxlib-0.3.3.tar.gz
(22.4 kB
view details)
File details
Details for the file boxlib-0.3.3.tar.gz.
File metadata
- Download URL: boxlib-0.3.3.tar.gz
- Upload date:
- Size: 22.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4d61a7d92fff06625561291210523c40284f14e89fa427b42c95c1224f09aeef
|
|
| MD5 |
4a44e59e6baa2c289f6d0dd1023eaa4d
|
|
| BLAKE2b-256 |
609af42f7ae470b07868bfcb617e8dcce352cf5a4ff3af6a37310e5149581a98
|
Provenance
The following attestation bundles were made for boxlib-0.3.3.tar.gz:
Publisher:
python-publish.yml on isarandi/boxlib
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
boxlib-0.3.3.tar.gz -
Subject digest:
4d61a7d92fff06625561291210523c40284f14e89fa427b42c95c1224f09aeef - Sigstore transparency entry: 814034436
- Sigstore integration time:
-
Permalink:
isarandi/boxlib@4574c8eeef2212f588fa6074ca2fb9813cbce0bd -
Branch / Tag:
refs/tags/v0.3.3 - Owner: https://github.com/isarandi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@4574c8eeef2212f588fa6074ca2fb9813cbce0bd -
Trigger Event:
release
-
Statement type: