Skip to content

LimImageSource class

This class is mainly used for converting images of different formats to ND2 format. It serves as a locator for specific image frame (just filepath for most image formats, filepath + IDF for TIFF files).

This class is not a part of the base limnd2 namespace, but is instead accessible through the limnd2.tools namespace like this:

from limnd2.tools import LimImageSource

LimImageSource

LimImageSource(filename: str | Path)

Abstract class for reading images of different formats. Currently supported formats are:

  • TIFF and its subformats (.ome.tiff, .btf, .tif, .tiff)
  • LSM (.lsm)
  • CZI (.czi)
  • OIF/OIB (.oif, .oib)
  • PNG (.png)
  • JPEG (.jpg, .jpeg)
  • ND2 (.nd2)

This class provides a common interface for reading images and converting them to ND2 format, as well as for extracting additional information from the images.

Warning

This class is not intended to be used directly, but rather as a base class for specific image source classes. In order to correctly create object of this class, use the open() method, which will automatically detect the file type and create the appropriate LimImageSource object.

is_rgb abstractmethod property

is_rgb: bool

Check if the image is RGB.

get_file_dimensions

get_file_dimensions() -> dict[str, int]

Return dimensions inside just the file. In OME TIFF file, this will return OME dimensions within file. In multipage file, this will return unknown dimension in the file. In other file formats, this will return empty dictionary.

metadata_as_pattern_settings

metadata_as_pattern_settings() -> dict

Return metadata as a dictionary for internal usage in QML.

nd2_attributes abstractmethod

nd2_attributes(*, sequence_count=1) -> ImageAttributes

Get ND2 attributes from the image source.

Note

If you use those attributes when converting file sequence to ND2, you need to replace the sequence count with the number of files in the sequence. You must also set component count if you use convert multichannel ND2 image.

open staticmethod

open(filename: str | Path) -> LimImageSource

Create a LimImageSource object from a filename. This will automatically detect the file type and create the appropriate LimImageSource object (LimImageSourceTiff, LimImageSourcePng, ...).

read abstractmethod

read() -> ndarray

Read the image into numpy array writeable by limnd2 library.

merge_four_fields

merge_four_fields(a, b)

Merge only: time_step, z_step, channels, metadata. Rules: - Keep A as source of truth. - For numbers: fill A. from B only if A. is None. - For channels: if A.channels already has anything (non-empty), LEAVE IT AS-IS. Only if A.channels is None/empty, copy B.channels. - For metadata: if A.metadata is None, take B.metadata; otherwise fill unset pixel_calibration and append planes missing by name. Mutates and returns 'a'.