konfai.utils package#
Submodules#
konfai.utils.ITK module#
SimpleITK-based helpers for geometric transforms, resampling, and masking.
- konfai.utils.ITK.compose_transform(transform_files, image=None)[source]#
- Return type:
sitk.CompositeTransform
- konfai.utils.ITK.apply_to_image_rigid_transform(image, transform_files)[source]#
- Return type:
sitk.Image
- konfai.utils.ITK.resample_itk(image_reference, image, transform_files, mask=False, default_pixel_value=None, torch_resample=False)[source]#
- Return type:
sitk.Image
konfai.utils.config module#
Configuration helpers that map YAML trees to KonfAI Python objects.
- class konfai.utils.config.Range(min, max)[source]#
Bases:
objectUI hint attached to a parameter’s type — its inclusive numeric bounds.
Use
Annotated[int, Range(0, 100)](orfloat) in a config-bound signature: the binder ignores the metadata and validates the base type, while a UI reads the bounds to size a spinbox. Introspection-only.
- class konfai.utils.config.Choices(values)[source]#
Bases:
objectUI hint attached to a parameter’s type — its allowed values.
Use
Annotated[str, Choices([...])]for a fixed list, orAnnotated[str, Choices(resolver)]whereresolveris a zero-arg callable the app owns (e.g. one that lists a model registry it already fetches).resolve()returns the list — a reader calls it lazily, so the app resolves its own values and no tool re-fetches. Introspection-only; the binder ignores it (a value outside the list is still accepted, e.g. a local path). For a small FIXED, binder-validated set, preferLiteral[...].
- class konfai.utils.config.Config(key)[source]#
Bases:
objectContext manager for reading and updating a subtree of the active YAML config.
- Parameters:
key (
str) – Dot-separated path pointing to the configuration subtree to inspect or materialize.
- konfai.utils.config.config(key=None)[source]#
Attach a KonfAI configuration key to a class or callable.
konfai.utils.dataset module#
Dataset file abstractions and image conversion utilities for KonfAI.
- class konfai.utils.dataset.Attribute(attributes=None)[source]#
-
Metadata container storing repeated values with a stack-like naming scheme.
- konfai.utils.dataset.is_an_image(attributes)[source]#
Return whether the given attribute set contains image geometry metadata.
- Return type:
- konfai.utils.dataset.data_to_image(data, attributes)[source]#
Convert a NumPy array and KonfAI attributes into a SimpleITK image.
- Return type:
Image
- konfai.utils.dataset.image_to_data(image)[source]#
Convert a SimpleITK image into a channel-first NumPy array and attributes.
- konfai.utils.dataset.get_infos(filename)[source]#
Read shape and metadata from an image file without loading its full pixel data.
- konfai.utils.dataset.read_landmarks(filename)[source]#
Read Slicer-style fiducial landmarks from disk.
- Return type:
ndarray|None
- konfai.utils.dataset.write_landmarks(data, filename)[source]#
Write landmarks to the Slicer Markups fiducial CSV-like format.
- Return type:
- class konfai.utils.dataset.Dataset(filename, file_format)[source]#
Bases:
objectFilesystem or HDF5-backed dataset abstraction used across KonfAI.
- class AbstractFile[source]#
Bases:
ABC
- class H5File(filename, read)[source]#
Bases:
AbstractFile
- class SitkFile(filename, read, file_format)[source]#
Bases:
AbstractFile
- class OmeZarrFile(filename, read, level=0)[source]#
Bases:
AbstractFileOME-NGFF backend using chunked Zarr reads for KonfAI patches.
levelselects the multiscale pyramid resolution to read (0 = full resolution, higher = coarser); it comes from theomezarr@<level>dataset-spec suffix.
- class DicomFile(filename, read)[source]#
Bases:
AbstractFileDICOM series backend with header-only metadata and slice-level reads.
konfai.utils.utils module#
Compatibility facade for KonfAI utility helpers and lightweight array utilities.
- konfai.utils.utils.get_module(classpath, default_classpath)[source]#
Import the module a classpath names and return it with the name to take from it.
A
:separates the module from the name: everything before the last one is the module, sotorch:nn:L1Lossandtorch.nn:L1Lossname the same class. Without one, the name is taken from the kind’s own package, and the dots between them lead there:Diceis that package’s own,segmentation.UNet.UNetis under two of its subpackages.- Return type:
- konfai.utils.utils.get_patch_slices_from_nb_patch_per_dim(patch_size_tmp, nb_patch_per_dim, overlap)[source]#
- konfai.utils.utils.is_windows_absolute_path(path)[source]#
Return whether path looks like a Windows absolute path.
- Return type:
- konfai.utils.utils.split_format_level(file_format)[source]#
Split an optional pyramid-level suffix from a format token.
Used by the OME-Zarr backend to pick a multiscale resolution directly in the dataset spec, e.g.
omezarr@2selects pyramid level 2 (coarser), independently of any transform. Returns(base_format, level)and defaults to level 0 (full resolution) when no@<int>suffix is present.
- konfai.utils.utils.split_path_spec(value, *, default_format='mha', allowed_flags=None, supported_extensions=None)[source]#
Split a KonfAI
path[:flag]:formatspec without breaking Windows paths.KonfAI accepts dataset-like strings such as:
./Dataset./Dataset:mha./Dataset:a:mhaC:\Data\Dataset:mhaC:\Data\Dataset:a:mha
Parsing is performed from the right so the drive separator in Windows paths is preserved.
Module contents#
Utility modules supporting configuration, datasets, ITK, DICOM, OME-Zarr, and runtime helpers.