Box#

class scarlet2.Box(shape, origin=None)[source]#

Bases: Module

Bounding Box for data array

A Bounding box describes the location of a data array in the 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 array

  • origin (tuple, optional) – Start coordinate (in 2D: lower-left corner) of the array in model frame

property D#

Dimensionality of this BBox

__and__(other)[source]#

Intersection of two bounding boxes

If there is no intersection between the two bounding boxes then an empty bounding box is returned.

Parameters:

other (Box) – The other bounding box in the intersection

Returns:

result – The rectangular box that is in the overlap region of both boxes.

Return type:

Box

__or__(other)[source]#

Union of two bounding boxes

Parameters:

other (Box) – The other bounding box in the union

Returns:

result – The smallest rectangular box that contains both boxes.

Return type:

Box

property bounds#

Bounds of the box

property center#

Tuple of center coordinates

contains(p)[source]#

Whether the box contains a given coordinate p

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 – A new box bounded by the input bounds.

Return type:

Box

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

Define box where X is above min_value

Parameters:
  • X (jnp.ndarray) – Data to threshold

  • min_value (float) – Minimum value of the result.

Returns:

bbox – Bounding box for the thresholded X

Return type:

scarlet2.bbox.Box

get_extent()[source]#

Return the start and end coordinates.

grow(delta)[source]#

Grow the Box by the given delta in each direction

origin: tuple#

lower-left corner) of the array in model frame

Type:

Start coordinate (in 2D

set_center(pos)[source]#

Center box at given position

shape: tuple#

Size of the array

shrink(delta)[source]#

Shrink the Box by the given delta in each direction

property slices#

Bounds of the box as slices

property spatial#

Spatial component of higher-dimensional box

property start#

Tuple of start coordinates

property stop#

Tuple of stop coordinates