API#
Both classes are importable from funlib.geometry.
- class funlib.geometry.coordinate.Coordinate(*array_like)#
A
tupleof 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:
- 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:
- floor_division(other)#
- Return type:
- ceil_division(other)#
- Return type:
- __neg__()#
- Return type:
- __abs__()#
- Return type:
- __add__(other)#
Return self+value.
- Return type:
- __sub__(other)#
- Return type:
- __mul__(other)#
Return self*value.
- Return type:
- __truediv__(other)#
- Return type:
- __floordiv__(other)#
- Return type:
- __mod__(other)#
- Return type:
- __pow__(other)#
- Return type:
- 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 beNoneto indicate there is no offset (either unbounded or empty).shape (
Iterable[int|None]) – The shape of the ROI. Entries can beNoneto indicate unboundedness.
- property offset: Coordinate#
- Setter accepts:
Iterable[int|None]
- get_offset()#
- Return type:
- set_offset(new_offset)#
- Return type:
None
- property shape: Coordinate#
- Setter accepts:
Iterable[int|None] |None
- get_shape()#
- Return type:
- set_shape(new_shape)#
- Return type:
None
- property begin: Coordinate#
Smallest coordinate inside ROI.
- get_begin()#
- Return type:
- property end: Coordinate#
Smallest coordinate which is component-wise larger than any inside ROI.
- get_end()#
- Return type:
- property center: Coordinate#
Get the center of this ROI.
- get_center()#
- Return type:
- to_slices()#
Get a
tupleofslicethat 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
Noneif 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 anotherRoi,Coordinate, ortuple.- Return type:
bool
- 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:
- 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:
- __eq__(other)#
Return self==value.
- Return type:
bool