cellmap_data.utils.roi#
Classes
|
A rectangular region of interest, defined by an offset and a shape. Special Cases: An infinite/unbounded ROI: offset = (None, None, ...) shape = (None, None, ...). |
- class cellmap_data.utils.roi.Roi(offset: Iterable[int | float | None], shape: Iterable[int | float | None])[source]#
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, int, or float) - shifts the offset elementwise (alias for shift)
Multiplication/division (Coordinate, int, or float) - 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 (array-like of
int
orfloat
) – The offset of the ROI. Entries can beNone
to indicate there is no offset (either unbounded or empty).shape (array-like of
int
orfloat
) – The shape of the ROI. Entries can beNone
to indicate unboundedness.
- property offset: Coordinate#
- get_offset() Coordinate [source]#
- Return type:
- set_offset(new_offset: Iterable[int | float | None]) None [source]#
- Parameters:
new_offset (Iterable[int | float | None])
- Return type:
None
- property shape: Coordinate#
- get_shape() Coordinate [source]#
- Return type:
- set_shape(new_shape: Iterable[int | float | None]) None [source]#
- Parameters:
new_shape (Iterable[int | float | None])
- Return type:
None
- property begin: Coordinate#
Smallest coordinate inside ROI.
- get_begin() Coordinate [source]#
- Return type:
- property end: Coordinate#
Smallest coordinate which is component-wise larger than any inside ROI.
- get_end() Coordinate [source]#
- Return type:
- property center: Coordinate#
Get the center of this ROI.
- get_center() Coordinate [source]#
- Return type:
- to_slices(grid_size: Coordinate | int | float | Iterable[int | float] = 1) Tuple[slice, ...] [source]#
Get a
tuple
ofslice
that represent this ROI and can be used to index arrays.- Parameters:
grid_size (
Coordinate
orint
orfloat
orNone
, optional)None (The size of the grid to divide coordinates by. If)
- Return type:
Tuple[slice, …]
:param : :param coordinates are simply rounded outward to ensure full ROI: :param coverage. If a number: :param it is used for all dimensions.:
- property dims: int#
The the number of dimensions of this ROI.
- property size: float | None#
Get the volume of this ROI. Returns
None
if the ROI is unbounded.
- property empty: bool#
Test if this ROI is empty.
- property unbounded: bool#
Test if this ROI is unbounded.
- contains(other: Roi | Iterable[int | float | None]) bool [source]#
Test if this ROI contains
other
, which can be anotherRoi
,Coordinate
, ortuple
.- Parameters:
other (Roi | Iterable[int | float | None])
- Return type:
bool
- intersects(other: Roi) bool [source]#
Test if this ROI intersects with another
Roi
.- Parameters:
other (Roi)
- Return type:
bool
- shift(by: Coordinate | int | float) Roi [source]#
Shift this ROI.
- Parameters:
by (Coordinate | int | float)
- Return type:
- snap_to_grid(voxel_size: Iterable[int | float | None], mode: str = 'grow') Roi [source]#
Align a ROI with a given voxel size.
- Parameters:
voxel_size (
Coordinate
ortuple
) – The voxel size of the grid to snap to.mode (string, optional) – 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: Iterable[int | float | None] | int | float = 0, amount_pos: Iterable[int | float | None] | int | float = 0) Roi [source]#
Grow a ROI by the given amounts in each direction:
- Parameters:
amount_neg (
Coordinate
orint
orfloat
) – 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 (
Coordinate
orint
orfloat
) – 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: