locan.data.images.Image

class locan.data.images.Image(image=None, data=None, is_rgb=False, meta=None)[source]

Bases: ImageBase

Adapter class for Image objects.

The original image object is referenced via self._image. An array object that complies with the array API standard is referenced in self.data

All attribute requests are looked up in the following order: self, self.data, self._image

For initiation use the appropriate constructor method.

Parameters:
  • image (Any | None) – Image class to be adapted.

  • is_rgb (bool) – Whether the image is RGB or RGBA. If False the image is interpreted as a luminance image.

  • meta (Metadata | None) – Metadata about the current dataset.

Variables:
  • data (ArrayApiObject | npt.NDArray | None) – Image data as array object following the array API standard. If no such array can be provided a numpy.NDArray is returned. Can be N dimensional. If the last dimension has length 3 or 4 it can be interpreted as RGB or RGBA if is_rgb is True.

  • is_rgb (bool) – Whether the image data in self.data will be interpreted as RGB or RGBA. If False the image is interpreted as a luminance image.

  • bins (Bins | None) – Bins instance carrying pixel coordinates

  • meta (locan.data.metadata_pb2.Metadata) – Metadata about the current dataset.

Methods

__init__([image, data, is_rgb, meta])

from_array(array[, is_rgb, meta])

Constructor method for any image given as array.

from_bins(bins[, value, is_rgb, meta])

Constructor method for an image with constant values and a size that corresponds to the given bin specifications.

from_napari(cls, image[, meta])

Constructor method for an image derived from a napari.Image instance.

from_numpy(array[, is_rgb, meta])

Constructor method for any image given as numpy array.

from_pillow(image[, meta])

Constructor method for an image derived from a pillow.Image instance.

Attributes

property bins: Bins | None
property data: ArrayApiObject | ndarray[tuple[int, ...], dtype[Any]] | None
classmethod from_array(array, is_rgb=False, meta=None)[source]

Constructor method for any image given as array.

Parameters:
  • array (Any) – The image data

  • is_rgb (bool) – Whether the image is RGB or RGBA. If False the image is interpreted as a luminance image.

  • meta (Metadata | None) – Metadata about the current dataset.

Return type:

Image

classmethod from_bins(bins, value=1, is_rgb=False, meta=None)[source]

Constructor method for an image with constant values and a size that corresponds to the given bin specifications.

Parameters:
  • bins (Bins) – Bin specifications

  • value (float | int) – A single value as default for the new image.

  • is_rgb (bool) – Whether the image is RGB or RGBA. If False the image is interpreted as a luminance image.

  • meta (Metadata | None) – Metadata about the current dataset.

Return type:

Image

classmethod from_napari(cls, image, meta=None)[source]

Constructor method for an image derived from a napari.Image instance.

Parameters:
  • image (Union[Image, NewType(ImageData, ndarray)]) – The napari image or image data. Image can be of type LayerData for Image, i.e., Union[Tuple[DataType], Tuple[DataType, LayerProps], FullLayerData]

  • meta (Metadata | None) – Metadata about the current dataset.

Return type:

Image

classmethod from_numpy(array, is_rgb=False, meta=None)[source]

Constructor method for any image given as numpy array.

Parameters:
  • array (Union[_Buffer, _SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[dtype[Any]]], bool, int, float, complex, str, bytes, _NestedSequence[bool | int | float | complex | str | bytes]]) – The image data

  • is_rgb (bool) – Whether the image is RGB or RGBA. If False the image is interpreted as a luminance image.

  • meta (Metadata | None) – Metadata about the current dataset.

Return type:

Image

classmethod from_pillow(image, meta=None)[source]

Constructor method for an image derived from a pillow.Image instance.

Parameters:
  • image (PillowImage) – The pillow image.

  • meta (Metadata | None) – Metadata about the current dataset.

Return type:

Image

property is_rgb: bool