scarlet.bbox

class scarlet.bbox.Box(shape, origin=None)[source]

Bases: object

Bounding Box for an object

A Bounding box describes the location of a data unit in the global/model coordinate system. It is used to identify spatial and channel overlap and to map from model to observed frames and back.

The BBox code is agnostic about the meaning of the dimensions. We generally use this convention:

  • 2D shapes denote (Height, Width)

  • 3D shapes denote (Channels, Height, Width)

Parameters
shape: tuple

Size of the box

origin: tuple

Minimum corner coordinate of the box

Attributes
D

Dimensionality of this BBox

bounds

Bounds of the box

center

Tuple of center coordinates

slices

Bounds of the box as slices

start

Tuple of start coordinates

stop

Tuple of stop coordinates

Methods

contains(p)

Whether the box contains a given coordinate p

copy()

Copy of the box

extract_from(image[, sub])

Extract sub-image described by this bbox from image

from_bounds(*bounds)

Initialize a box from its bounds

from_data(X[, min_value])

Define range of X above min_value

insert_into(image, sub)

Insert sub into image according to this bbox

property D

Dimensionality of this BBox

property bounds

Bounds of the box

property center

Tuple of center coordinates

contains(p)[source]

Whether the box contains a given coordinate p

copy()[source]

Copy of the box

extract_from(image, sub=None)[source]

Extract sub-image described by this bbox from image

Parameters
image: array

Full image

sub: array

Extracted image

Returns
sub: array
static from_bounds(*bounds)[source]

Initialize a box from its bounds

Parameters
bounds: tuple of (min,max) pairs

Min/Max coordinate for every dimension

Returns
bbox: scarlet.bbox.Box

A new box bounded by the input bounds.

static from_data(X, min_value=0)[source]

Define range of X above min_value

Parameters
X: array-like

Data to threshold

min_value: float

Minimum value of the result.

Returns
bbox: scarlet.bbox.Box

Bounding box for the thresholded X

insert_into(image, sub)[source]

Insert sub into image according to this bbox

Inverse operation to extract_from().

Parameters
image: array

Full image

sub: array

Extracted sub-image

Returns
image: array
property slices

Bounds of the box as slices

property start

Tuple of start coordinates

property stop

Tuple of stop coordinates

scarlet.bbox.overlapped_slices(bbox1, bbox2)[source]

Slices of bbox1 and bbox2 that overlap

Parameters
bbox1: `~scarlet.bbox.Box`
bbox2: `~scarlet.bbox.Box`
Returns
slices: tuple of slices

The slice of an array bounded by bbox1 and the slice of an array bounded by bbox in the overlapping region.