ngff_zarr.nibabel_image_to_ngff_image¶
Module Contents¶
Functions¶
Decompose affine transformation matrix into translation, scale, shear, and orientation. |
|
Extract translation, scale, and orientation from NIfTI spatial metadata. |
|
Convert a nibabel image to an NgffImage, preserving spatial metadata. |
|
Extract OMERO windowing metadata from a nibabel image’s cal_min/cal_max headers. |
API¶
- ngff_zarr.nibabel_image_to_ngff_image.decompose_affine_with_shear(affine)¶
Decompose affine transformation matrix into translation, scale, shear, and orientation.
- ngff_zarr.nibabel_image_to_ngff_image.extract_spatial_metadata(
- img,
Extract translation, scale, and orientation from NIfTI spatial metadata.
- ngff_zarr.nibabel_image_to_ngff_image.nibabel_image_to_ngff_image(
- nibabel_image,
- add_anatomical_orientation: bool = True,
Convert a nibabel image to an NgffImage, preserving spatial metadata.
This function optimizes memory usage by checking the NIfTI scaling parameters:
If scl_slope=1.0 and scl_inter=0.0 (identity scaling), uses the raw dataobj to preserve the original data type and minimize memory usage
If scaling is required, uses get_fdata(dtype=np.float32) to balance memory usage and precision
Args: nibabel_image: A nibabel image object add_anatomical_orientation: Whether to add anatomical orientation metadata. Only added if orientation matrix is identity (no rotation/shear).
Returns: NgffImage with spatial metadata from the NIfTI file
Note: The data is returned as a numpy array (not Dask) to maintain compatibility with the original implementation requirements.
- ngff_zarr.nibabel_image_to_ngff_image.extract_omero_metadata_from_nibabel(nibabel_image)¶
Extract OMERO windowing metadata from a nibabel image’s cal_min/cal_max headers.
Args: nibabel_image: A nibabel image object
Returns: Omero metadata if cal_min and cal_max are available and valid, None otherwise
Note: This function creates OMERO windowing metadata from NIfTI cal_min and cal_max header values when both are not 0.0 and neither is NaN. The windowing applies to all channels in the image.