Utility functions for ez_zarr
Utility functions for ez_zarr
.
convert_coordinates(coords_from, scale_from, scale_to)
Convert coordinates between scales.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
coords_from |
tuple
|
The coordinates to be converted. |
required |
scale_from |
list[float]
|
The scale that the coordinates refer to.
Needs to be parallel to |
required |
scale_to |
list[float]
|
The scale that the coordinates should be converted to. |
required |
Returns:
Type | Description |
---|---|
Union[int, float]
|
A tuple of the same length as |
...
|
the new scale. |
Examples:
Convert a point (10, 30) from [1, 1] to [2, 3]:
>>> from ez_zarr.utils import convert_coordinates
>>> y, x = convert_coordinates((10,30), [1, 1], [2, 3])
Source code in src/ez_zarr/utils.py
rescale_image(im, scale_from, scale_to, im_type='intensity', number_nonspatial_axes=0)
Rescale an image (2 to 5-dimensional arrays, possibly with non-spatial axes).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
im |
ndarray
|
The image to be rescaled. |
required |
scale_from |
list[float]
|
The scale that the image refers to.
Needs to be parallel to |
required |
scale_to |
list[float]
|
The scale that the image should be
converted to. Needs to be of the same length as |
required |
im_type |
str
|
The type of the image. Can be 'intensity' (default) or 'label'. An intensity image is rescaled with anti-aliasing, while a label image is rescaled without, so that the resulting image only contains values (labels) also contained in the input. |
'intensity'
|
number_nonspatial_axes |
int
|
Number of first axes that refer to non-spatial dimensions, such as time or channel. Rescaling is performed only on the spatial axes, separately for each value or combination of values of the non-spatial axes. |
0
|
Returns:
Type | Description |
---|---|
ndarray
|
The rescaled image as a |
Examples:
Rescale a 4D image (channels, z, y, x):
>>> im_large = np.random.rand(4, 100, 100)
>>> im_small = rescale_image(im_large, [1, 0.3, 0.3], [1, 0.6, 0.6], number_nonspatial_axes=1)
>>> im_small.shape # returns (4, 50, 50)
Source code in src/ez_zarr/utils.py
resize_image(im, output_shape, im_type='intensity', number_nonspatial_axes=0)
Resize an image (2 to 5-dimensional arrays, possibly with non-spatial axes).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
im |
ndarray
|
The image to be rescaled. |
required |
output_shape |
tuple[int]
|
The shape of the output image. This must be parallel to the shape of the input image. |
required |
im_type |
str
|
The type of the image. Can be 'intensity' (default) or 'label'. An intensity image is rescaled with anti-aliasing, while a label image is rescaled without, so that the resulting image only contains values (labels) also contained in the input. |
'intensity'
|
number_nonspatial_axes |
int
|
Number of first axes that refer to non-spatial dimensions, such as time or channel. Rescaling is performed only on the spatial axes, separately for each value or combination of values of the non-spatial axes. |
0
|
Returns:
Type | Description |
---|---|
ndarray
|
The rescaled image as a |
Examples:
Resize a 4D image (channels, z, y, x):
>>> im_large = np.random.rand(4, 100, 100)
>>> im_small = resize_image(im_large, (4, 50, 50), number_nonspatial_axes=1)
>>> im_small.shape # returns (4, 50, 50)