omni

OMNI file format.

This module implements support for reading and writing of OMNI image files.

class omni.Calibration(metadata: dict = None, *, type: str = None, unit_type: str = None, unit_name: str = None, slope: float = None, intercept: float = None, indirect_base_unit_type: str = None)

OMNI pixel calibration

calibrated_to_raw(calibrated: float) float

Convert a calibrated value to a raw value.

property indirect_base_unit_type: str | None

The base unit_type for slope_intercept_indirect calibrations.

property intercept: float

The intercept value of the slope / intercept calibration.

raw_stddev_to_calibrated_stddev(raw_stddev: float) float

Convert a raw standard deviation value to a calibrated standard deviation value.

raw_to_calibrated(raw: float) float

Convert a raw value to a calibrated value.

raw_variance_to_calibrated_variance(raw_variance: float) float

Convert a raw variance value to a calibrated variance value.

property slope: float

The slope value of the slope / intercept calibration.

property type: str

The type of calibration.

property unit_name: str | None

Optional: The name of the physical unit.

property unit_type: str

The type of physical unit.

class omni.Image(metadata_path: Path, metadata: dict)

OMNI Image or Segments

property additional_pixels_filenames: List[str]

Additional filenames of files containing pixel bulk data. E.g. for compressed multi-file formats like DRAINv1_DRY.

property axes: str

The types of axes (dimensions). XYZ (spatial) C (RGB color channel) W (wavelength spectra) F (frequency spectra) T (time for animation frames)

property default_pixel_calibration_unit_type: str | None

The unit_type of the pixel calibration that should be used by default.

derive_image(derived_omni_path: Path, derived_raw_path: Path, override_metadata: dict = {}) Image

Create a derived OMNI image, that inherits (and optionally overrides) metadata.

derive_segments(derived_omni_path: Path, derived_raw_path: Path, override_metadata: dict = {}) Image

Create a derived OMNI segments Image(), defaulting to metadata for a single binary object uint8 mask.

property dimensions: int

The number of dimensions.

ensure_pixels_loaded() ndarray

Ensure the pixels are loaded. May trigger lazy-loading from file.

property format: str

The format of this file: OMNI-1.0

static from_numpy_array(pixels: ndarray, metadata_path: Path, metadata: dict = None) Image

Initialize from a numpy array

get_relative_voi_pos_of_target_image(target_image: Image) List[int]

Get the relative VOI position of the target image in the coordinate system of this (source) image.

property image_relations: List[ImageRelation]

Image relations.

inherit_metadata(**kwargs) dict

Copy the inheritable metadata properties of this image for a derived image.

Unknown and the following non-inheritable metadata properties are ommitted by default:

pixels_filename additional_pixels_filenames pixels_file_data_offset pixels_file_data_offsets_per_slice pixels_compression pixel_calibrations default_pixel_calibration_unit_type invalid_pixels pixel_value_objects

DROP_INHERITED_METADATA can be used to drop individual inheritable metadata properties. INHERIT_METADATA can be used to force inheriting individual unknown or non-inheritable metadata properties.

property invalid_pixels: List[InvalidPixels]

Invalid pixels.

isotropic_pixel_size_mm(max_relative_stdev: float | None = 0.0002, axes: slice | None = None) float

Get the isotropic size of one pixel in millimeters.

By default allow a non-isotropic pixel size of at most 0.0002 relative standard deviations.

static load(metadata_path: Path) Image

Load metadata from file.

property pixel_calibrations: List[Calibration]

Pixel calibrations.

pixel_calibrations_of_unit_type(unit_type: str) List[Calibration]

Pixel calibrations of the given type.

property pixel_max_value: int | float | None

The maximum pixel value that occurs in the image.

property pixel_min_value: int | float | None

The minimum pixel value that occurs in the image.

property pixel_size_mm: List[float]

The physical size of one pixel in millimeters.

property pixel_size_mm_3d: List[float]

The physical size of one pixel in millimeters in 3D.

property pixel_type: str

The type of one pixel.

property pixel_value_objects: List[PixelValueObject]

E.g. for multi-segments different pixel values could be named objects.

property pixels: ndarray

The pixels NumPy array. May trigger lazy-loading from file.

property pixels_compression: str

The compression method.

property pixels_count: int

The total number of pixels.

property pixels_file_data_offset: int

The byte offset in the pixels file where the pixel data begins.

property pixels_filename: str

The filename of the file containing the pixel bulk data.

remove_image_relation(relation_type: str) None

Remove (if it exists) the image relation of the given type.

resave_all(override_metadata: dict = {})

Save the metadata and the raw pixels to files again, e.g. with compression.

resave_compressed(prefer_per_slice_compression: bool = False)

Save the metadata and the raw pixels to files again, with compression.

save_all()

Save the metadata and the raw pixels to files.

save_derived_image(derived_omni_path: Path, derived_raw_path: Path, override_metadata: dict = {}) Image

Save metadata of a derived OMNI image.

save_derived_segments(derived_omni_path: Path, derived_raw_path: Path, override_metadata: dict = {}) Image

Save metadata of a derived OMNI segments Image().

save_metadata()

Save the metadata to a file.

save_pixels()

Save the raw pixels as specified in the metadata.

Can modify the metadata! Only supports saving at offset 0.

save_pixels_as(pixels_path: Path, pixels_compression: str)

Save the raw pixels to the specified file with the specified compression.

Can modify the metadata!

property segments_type: str | None

The type of segments: Object, Millimeter or Component

set_default_image_relation(relation_type: str) ImageRelation

Set (if missing) and get a default image relation of the given type.

set_image_relation(relation: ImageRelation) None

Set (or replace) the image relation of the given type.

property size: List[int]

The number of pixels per dimension.

property size_3d: List[int]

The number of pixels in 3D.

property size_3d_tuple: Tuple[int, int, int]

The number of pixels in 3D as a tuple.

property type: str

The type of object: Image or Segments

verify_pixel_type()

Raise an exception if the pixel type metadata does not match the pixels numpy array dtype.

class omni.ImageRelation(metadata: dict = None, *, voi_pixel_position: List[int] = None)

OMNI image relation description

set_or_add_voi_pixel_position(pos: List[int]) None

Set (if missing) or add to the VOI position.

property type: str

The type of image relation description.

property voi_pixel_position: List[int]

The position (in pixels) of this image in the parent image.

class omni.InvalidPixels(metadata: dict = None, *, border_size: List[int] = None)

OMNI invalid pixels description

property border_size: List[int]

The size (in pixels) of the border.

property type: str

The type of invalid pixels description.

class omni.PixelValueObject(metadata: dict = None, *, pixel_value: int | float = None, name: str = None)

OMNI pixel value object description

property name: str

The name of that object.

property pixel_value: int | float

The pixel value of that object.

omni.Segments(metadata_path: Path, metadata: dict, segments_type: str) Image

Create an Image(), but set type metadata to Image.TYPE_SEGMENTS.

omni.import_from_aim(aim_path: Path, load_pixels: bool = True) Image

Create OMNI metadata for an AIM file.

omni.import_from_isq(isq_path: Path, load_pixels: bool = True) Image

Create OMNI metadata for an ISQ file.

omni.import_from_mlsd(mlsd_path: Path, sd_paths: List[Path], load_pixels: bool = True) Image

Create OMNI metadata for an MLSD file.