cellmap_data.image#

Classes

CellMapImage(path, target_class, ...[, pad, ...])

Initializes a CellMapImage object.

EmptyImage(target_class, target_scale, ...)

Initializes an empty image object.

ImageWriter(path, label_class, scale, ...)

Initializes an ImageWriter object.

class cellmap_data.image.CellMapImage(path: str, target_class: str, target_scale: Sequence[float], target_voxel_shape: Sequence[int], pad: bool = False, pad_value: float | int = nan, interpolation: str = 'nearest', axis_order: str | Sequence[str] = 'zyx', value_transform: Callable | None = None, context: Context | None = None)[source]#

Initializes a CellMapImage object.

Parameters:
  • path (str) – The path to the image file.

  • target_class (str) – The label class of the image.

  • target_scale (Sequence[float]) – The scale of the image data to return in physical space.

  • target_voxel_shape (Sequence[int]) – The shape of the image data to return in voxels.

  • axis_order (str, optional) – The order of the axes in the image. Defaults to “zyx”.

  • value_transform (Optional[callable], optional) – A function to transform the image pixel data. Defaults to None.

  • context (Optional[tensorstore.Context], optional) – The context for the image data. Defaults to None.

  • pad (bool)

  • pad_value (float | int)

  • interpolation (str)

__getitem__(center: Mapping[str, float]) Tensor[source]#

Returns image data centered around the given point, based on the scale and shape of the target output image.

Parameters:

center (Mapping[str, float])

Return type:

Tensor

property shape: Mapping[str, int]#

Returns the shape of the image.

property center: Mapping[str, float]#

Returns the center of the image in world units.

property multiscale_attrs: MultiscaleMetadata#

Returns the multiscale metadata of the image.

property coordinateTransformations: tuple[VectorScale | PathScale] | tuple[VectorScale | PathScale, VectorTranslation | PathTranslation]#

Returns the coordinate transformations of the image, based on the multiscale metadata.

property full_coords: tuple[DataArray, ...]#

Returns the full coordinates of the image’s axes in world units.

property scale_level: str#

Returns the multiscale level of the image.

property group: Group#

Returns the zarr group object for the multiscale image.

property array_path: str#

Returns the path to the single-scale image array.

property array: DataArray#

Returns the image data as an xarray DataArray.

property translation: Mapping[str, float]#

Returns the translation of the image.

property bounding_box: Mapping[str, list[float]]#

Returns the bounding box of the dataset in world units.

property sampling_box: Mapping[str, list[float]]#

Returns the sampling box of the dataset (i.e. where centers can be drawn from and still have full samples drawn from within the bounding box), in world units.

property bg_count: float#

Returns the number of background pixels in the ground truth data, normalized by the resolution.

property class_counts: float#

Returns the number of pixels for the contained class in the ground truth data, normalized by the resolution.

to(device: str) None[source]#

Sets what device returned image data will be loaded onto.

Parameters:

device (str)

Return type:

None

find_level(target_scale: Mapping[str, float]) str[source]#

Finds the multiscale level that is closest to the target scale.

Parameters:

target_scale (Mapping[str, float])

Return type:

str

rotate_coords(coords: Mapping[str, Sequence[float]], angles: Mapping[str, float]) Mapping[str, tuple[Sequence[str], ndarray]] | Mapping[str, Sequence[float]][source]#

Rotates the given coordinates by the given angles.

Parameters:
  • coords (Mapping[str, Sequence[float]])

  • angles (Mapping[str, float])

Return type:

Mapping[str, tuple[Sequence[str], ndarray]] | Mapping[str, Sequence[float]]

set_spatial_transforms(transforms: Mapping[str, Any] | None) None[source]#

Sets spatial transformations for the image data, for setting global transforms at the ‘dataset’ level.

Parameters:

transforms (Mapping[str, Any] | None)

Return type:

None

apply_spatial_transforms(coords) Tensor[source]#

Applies spatial transformations to the given coordinates.

Return type:

Tensor

return_data(coords: Mapping[str, Sequence[float]] | Mapping[str, tuple[Sequence[str], ndarray]]) DataArray[source]#

Pulls data from the image based on the given coordinates, applying interpolation if necessary, and returns the data as an xarray DataArray.

Parameters:

coords (Mapping[str, Sequence[float]] | Mapping[str, tuple[Sequence[str], ndarray]])

Return type:

DataArray

class cellmap_data.image.EmptyImage(target_class: str, target_scale: Sequence[float], target_voxel_shape: Sequence[int], store: Tensor | None = None, axis_order: str = 'zyx', empty_value: float | int = -100)[source]#

Initializes an empty image object.

Parameters:
  • target_class (str) – The intended label class of the image.

  • target_scale (Sequence[float]) – The intended scale of the image in physical space.

  • target_voxel_shape (Sequence[int]) – The intended shape of the image in voxels.

  • store (Optional[torch.Tensor], optional) – The tensor to return. Defaults to None.

  • axis_order (str, optional) – The intended order of the axes in the image. Defaults to “zyx”.

  • empty_value (float | int, optional) – The value to fill the image with. Defaults to -100.

__getitem__(center: Mapping[str, float]) Tensor[source]#

Returns the empty image data.

Parameters:

center (Mapping[str, float])

Return type:

Tensor

property bounding_box: None#

Returns the bounding box of the dataset. Returns None for an EmptyImage object.

property sampling_box: None#

Returns the sampling box of the dataset (i.e. where centers can be drawn from and still have full samples drawn from within the bounding box). Returns None for an EmptyImage object.

property bg_count: float#

Returns the number of background pixels in the ground truth data, normalized by the resolution. Returns zero for an EmptyImage object.

property class_counts: float#

Returns the number of pixels for the contained class in the ground truth data, normalized by the resolution. Returns zero for an EmptyImage object.

to(device: str) None[source]#

Moves the image data to the given device.

Parameters:

device (str)

Return type:

None

set_spatial_transforms(transforms: Mapping[str, Any] | None) None[source]#

Imitates the method in CellMapImage, but does nothing for an EmptyImage object.

Parameters:

transforms (Mapping[str, Any] | None)

Return type:

None

class cellmap_data.image.ImageWriter(path: str | ~upath.core.UPath, label_class: str, scale: ~typing.Mapping[str, float] | ~typing.Sequence[float], bounding_box: ~typing.Mapping[str, list[float]], write_voxel_shape: ~typing.Mapping[str, int] | ~typing.Sequence[int], scale_level: int = 0, axis_order: str = 'zyx', context: ~tensorstore.Context | None = None, overwrite: bool = False, dtype: ~numpy.dtype = <class 'numpy.float32'>, fill_value: float | int = 0)[source]#

Initializes an ImageWriter object.

Parameters:
  • path (str) – The path to the base folder of the multiscale image file.

  • label_class (str) – The label class of the image.

  • scale_level (int) – The multiscale level of the image. Defaults to 0.

  • scale (Mapping[str, float]) – The scale of the image in physical space.

  • bounding_box (Mapping[str, list[float]]) – The total region of interest for the image in world units. Example: {“x”: [12.0, 102.0], “y”: [12.0, 102.0], “z”: [12.0, 102.0]}.

  • write_voxel_shape (Mapping[str, int]) – The shape of data written to the image in voxels.

  • axis_order (str, optional) – The order of the axes in the image. Defaults to “zyx”.

  • context (Optional[tensorstore.Context], optional) – The context for the TensorStore. Defaults to None.

  • overwrite (bool, optional) – Whether to overwrite the image if it already exists. Defaults to False.

  • dtype (np.dtype, optional) – The data type of the image. Defaults to np.float32.

  • fill_value (float | int, optional) – The value to fill the empty image with before values are written. Defaults to 0.

property array: DataArray#

Returns the image data as an xarray DataArray.

property chunk_shape: Sequence[int]#

Returns the shape of the chunks for the image.

property world_shape: Mapping[str, float]#

Returns the shape of the image in world units.

property shape: Mapping[str, int]#

Returns the shape of the image in voxels.

property center: Mapping[str, float]#

Returns the center of the image in world units.

property offset: Mapping[str, float]#

Returns the offset of the image in world units.

property full_coords: tuple[DataArray, ...]#

Returns the full coordinates of the image in world units.

align_coords(coords: Mapping[str, tuple[Sequence, ndarray]]) Mapping[str, tuple[Sequence, ndarray]][source]#

Aligns the given coordinates to the image’s coordinates.

Parameters:

coords (Mapping[str, tuple[Sequence, ndarray]])

Return type:

Mapping[str, tuple[Sequence, ndarray]]

aligned_coords_from_center(center: Mapping[str, float])[source]#

Returns the aligned coordinates for the given center with linear sequential coordinates aligned to the image’s reference frame.

Parameters:

center (Mapping[str, float])