Skip to main content

Simple bounding box operations

Project description

Package bbx

Simple operations over bounding boxes. Bounding boxes are represented in XYWH format where (X,Y) is coordinate of top-left corner, and (W,H) its size. I.e. bb = [0,0,64,16] represents a rectangle of size 64x16 located at coordinate (0,0). The units are always abstract - the interpretation is left for the user (usually pixels are used).

The package defines several common operations - resize, aspect ratio changes, randomization.

import bbx

bb = (-5,-5,10,10)   # Center at (0,0)
bb = bbx.set_aspect_ratio(bb, 2, bbx.KEEP_WIDTH)
print(bb)  # Prints [[-5.0, -10.0, 10, 20]]


The package is in PyPI so just use pip

pip install bbx


Bounding boxes are defined in x,y,w,h format, but they can hold any additional information (e.g. ignore flag). All functions always work on first four elements.

bbx.set_aspect_ratio(bbs, ar, type)

Set aspecr ratio ar to all bounding boxes in bbs using type method. The type can be one of:

  • bbx.EXPAND
  • bbx.SHRINK
  • bbx.KEEP_WIDTH
  • bbx.KEEP_AREA

For unknown type, the function raises NotImplementedError

bbx.resize(bbs, scale)

Resize bbs by ratio without moving center. The ratio can be:

  • scalar - all boxes are resized by the same factor
  • tuple of two scalars - resize all boxes with different scale for width and height









  • Documentation
  • Tests


This code is published under MIT License

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for bbx, version 0.0.4
Filename, size File type Python version Upload date Hashes
Filename, size bbx-0.0.4-py3-none-any.whl (5.2 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size bbx-0.0.4.tar.gz (5.1 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page