API#

Both classes are importable from funlib.geometry.

class funlib.geometry.coordinate.Coordinate(*array_like)#

A tuple of integers.

Allows the following element-wise operators: addition, subtraction, multiplication, division, absolute value, and negation. All operations are applied element wise and support both Coordinates and Numbers. This allows to perform simple arithmetics with coordinates, e.g.:

shape = Coordinate(2, 3, 4)
voxel_size = Coordinate(10, 5, 1)
size = shape*voxel_size # == Coordinate(20, 15, 4)
size * 2 + 1 # == Coordinate(41, 31, 9)

Coordinates can be initialized with any iterable of ints, e.g.:

Coordinate((1,2,3))
Coordinate([1,2,3])
Coordinate(np.array([1,2,3]))

Coordinates can also pack multiple args into an iterable, e.g.:

Coordinate(1,2,3)
property dims: int#
squeeze(dim=0)#
Return type:

Coordinate

is_multiple_of(coordinate)#

Test if this coordinate is a multiple of the given coordinate.

Return type:

bool

round_division(other)#

Will always round down if self % other == other / 2.

Return type:

Coordinate

floor_division(other)#
Return type:

Coordinate

ceil_division(other)#
Return type:

Coordinate

__neg__()#
Return type:

Coordinate

__abs__()#
Return type:

Coordinate

__add__(other)#

Return self+value.

Return type:

Coordinate

__sub__(other)#
Return type:

Coordinate

__mul__(other)#

Return self*value.

Return type:

Coordinate

__truediv__(other)#
Return type:

Coordinate

__floordiv__(other)#
Return type:

Coordinate

__mod__(other)#
Return type:

Coordinate

__pow__(other)#
Return type:

Coordinate

class funlib.geometry.roi.Roi(offset, shape)#

A rectangular region of interest, defined by an offset and a shape.

Special Cases:
An infinite/unbounded ROI:

offset = (None, None, …) shape = (None, None, …)

An empty ROI (e.g. output of intersecting two non overlapping Rois):

offset = (None, None, …) shape = (0, 0, …)

A ROI that only specifies a shape is not supported (just use Coordinate).

There is no guessing size of offset or shape (expanding to number of dims of the other).

Basic Operations:

Addition/subtraction (Coordinate or int) - shifts the offset elementwise (alias for shift)

Multiplication/division (Coordiante or int) - multiplies/divides the offset and the shape, elementwise

Roi Operations:

Intersect, union

Similar to Coordinate, supports simple arithmetics, e.g.:

roi = Roi((1, 1, 1), (10, 10, 10))
voxel_size = Coordinate((10, 5, 1))
roi * voxel_size = Roi((10, 5, 1), (100, 50, 10))
scale_shift = roi*voxel_size + 1 # == Roi((11, 6, 2), (101, 51, 11))
Parameters:
  • offset (Iterable[int | None]) – The offset of the ROI. Entries can be None to indicate there is no offset (either unbounded or empty).

  • shape (Iterable[int | None]) – The shape of the ROI. Entries can be None to indicate unboundedness.

squeeze(dim=0)#
Return type:

Roi

property offset: Coordinate#
Setter accepts:

Iterable[int | None]

get_offset()#
Return type:

Coordinate

set_offset(new_offset)#
Return type:

None

property shape: Coordinate#
Setter accepts:

Iterable[int | None] | None

get_shape()#
Return type:

Coordinate

set_shape(new_shape)#
Return type:

None

property begin: Coordinate#

Smallest coordinate inside ROI.

get_begin()#
Return type:

Coordinate

property end: Coordinate#

Smallest coordinate which is component-wise larger than any inside ROI.

get_end()#
Return type:

Coordinate

property center: Coordinate#

Get the center of this ROI.

get_center()#
Return type:

Coordinate

to_slices()#

Get a tuple of slice that represent this ROI and can be used to index arrays.

Return type:

tuple[slice, ...]

get_bounding_box()#

Alias for to_slices().

Return type:

tuple[slice, ...]

property dims: int#

The the number of dimensions of this ROI.

property size: int | None#

Get the volume of this ROI. Returns None if the ROI is unbounded.

get_size()#
Return type:

int | None

property empty: bool#

Test if this ROI is empty.

property unbounded: bool#

Test if this ROI is unbounded.

contains(other)#

Test if this ROI contains other, which can be another Roi, Coordinate, or tuple.

Return type:

bool

intersects(other)#

Test if this ROI intersects with another Roi.

Return type:

bool

intersect(other)#

Get the intersection of this ROI with another Roi.

Return type:

Roi

union(other)#

Get the union of this ROI with another Roi.

Return type:

Roi

shift(by)#

Shift this ROI.

Return type:

Roi

snap_to_grid(voxel_size, mode='grow')#

Align a ROI with a given voxel size.

Parameters:
  • voxel_size (Iterable[int | None]) – The voxel size of the grid to snap to.

  • mode (str) – How to align the ROI if it is not a multiple of the voxel size. Available modes are ‘grow’, ‘shrink’, and ‘closest’. Defaults to ‘grow’.

Return type:

Roi

grow(amount_neg=0, amount_pos=0)#

Grow a ROI by the given amounts in each direction:

Parameters:
  • amount_neg (Iterable[int | None] | int) – Amount (per dimension) to grow into the negative direction. Passing in a single integer grows that amount in all dimensions. Defaults to zero.

  • amount_pos (Iterable[int | None] | int) – Amount (per dimension) to grow into the positive direction. Passing in a single integer grows that amount in all dimensions. Defaults to zero.

Return type:

Roi

copy()#

Create a copy of this ROI.

Return type:

Roi

__add__(other)#
Return type:

Roi

__sub__(other)#
Return type:

Roi

__mul__(other)#
Return type:

Roi

__truediv__(other)#
Return type:

Roi

__floordiv__(other)#
Return type:

Roi

__eq__(other)#

Return self==value.

Return type:

bool