ngff_zarr.ngff_transform_to_itk_transformΒΆ
Bridge RFC-5 coordinate transformations to ITK transforms.
RFC-5 and ITK describe the same affine geometry with two different conventions, and the differences are silent rather than loud: getting one wrong yields a plausible transform that is simply in the wrong place.
Axis order
RFC-5 orders transformation parameters the same way the Zarr array is
ordered β parameter i belongs to coordinate-system axis i, so a
zyx image has z first. ITK orders points fastest-axis-first by
name: x, then y, then z. Writing P for the permutation sending an
ITK-order vector to the dims-order vector, an RFC-5 affine
q = M p + b becomes A = P^T M P and t = P^T b in ITK. For
the canonical zyx order P is the axis reversal.
Composition order
An RFC-5 sequence applies its first entry first. An ITK transform
list applies its last entry first. Rather than emit a list and rely on
that inversion, this module composes the chain into a single matrix here,
where the order is explicit and testable.
Both conventions place the pixel center at the integer index, so no half-pixel correction is involved.
Module ContentsΒΆ
FunctionsΒΆ
Collapse one RFC-5 transformation into an |
|
Assemble a byDimension transformation into one homogeneous matrix. |
|
One byDimension item as a matrix and offset over its own axes. |
|
Convert an RFC-5 transformation to an ITK matrix and offset. |
|
Convert an RFC-5 transformation to an ITK-Wasm transform list. |
DataΒΆ
APIΒΆ
- ngff_zarr.ngff_transform_to_itk_transform._SPATIAL_DIMSΒΆ
(βxβ, βyβ, βzβ)
- ngff_zarr.ngff_transform_to_itk_transform._homogeneous_from_transform(
- transform: ngff_zarr.v06.zarr_metadata.Transform,
- ndim: int,
Collapse one RFC-5 transformation into an
(ndim+1, ndim+1)matrix.The matrix is in RFC-5 (Zarr) axis order and acts on column vectors in homogeneous coordinates.
- ngff_zarr.ngff_transform_to_itk_transform._homogeneous_from_by_dimension(
- transform: ngff_zarr.v06.zarr_metadata.ByDimension,
- ndim: int,
Assemble a byDimension transformation into one homogeneous matrix.
Each item is a lower-dimensional transformation between two subsets of axes, so its own matrix is written into the rows its
outputAxesname and the columns itsinputAxesname. Axes no item produces would leave a zero row, which collapses the image rather than transforming it, so a gap is refused here rather than resampled.
- ngff_zarr.ngff_transform_to_itk_transform._by_dimension_item_block(
- item: ngff_zarr.v06.zarr_metadata.ByDimensionItem,
- ndim: int,
One byDimension item as a matrix and offset over its own axes.
- ngff_zarr.ngff_transform_to_itk_transform._as_matrix(values, path: str | None, field: str) numpy.ndarrayΒΆ
- ngff_zarr.ngff_transform_to_itk_transform._ngff_transform_to_itk_matrix(
- transform: ngff_zarr.v06.zarr_metadata.Transform,
- dims: collections.abc.Sequence[str],
Convert an RFC-5 transformation to an ITK matrix and offset.
Internal. :func:
ngff_transform_to_itk_transformis the public entry point; nothing outside this package needs the raw numbers, since ITK is what the caller wants to hand them to. The tests use it as a fine probe on the axis and composition conventions.- Parameters:
transform (Transform) β An RFC-5 (OME-Zarr v0.6) coordinate transformation. It must describe a linear mapping β
identity,scale,translation,rotation,affine,mapAxis,byDimension,bijection, or asequenceof those.dims (Sequence[str]) β The axis names of the coordinate system the transformation is defined on, in RFC-5 (Zarr) order, e.g.
("z", "y", "x").
- Returns:
(matrix, offset)for the spatial axes only, in ITK (fastest-axis-first) order. ITK has no notion of a non-spatial axis, so a component acting purely ontorcβ a frame interval, say β is projected away. That is lossless for the spatial mapping, which is all an ITK transform describes, but the returned transform is not a faithful copy of the input. A component that couples the two kinds of axis is refused instead, because dropping it would move the image.- Return type:
tuple[numpy.ndarray, numpy.ndarray]
- Raises:
NotImplementedError β If the transformation is not linear.
ValueError β If the transformation couples spatial and non-spatial axes, or its parameters do not match
dims.
- ngff_zarr.ngff_transform_to_itk_transform.ngff_transform_to_itk_transform(
- transform: ngff_zarr.v06.zarr_metadata.Transform,
- dims: collections.abc.Sequence[str],
- *,
- fields: collections.abc.Mapping[str, object] | None = None,
- fixed=None,
- moving=None,
Convert an RFC-5 transformation to an ITK-Wasm transform list.
A linear transformation is collapsed into a single
Affineentry, so the result is independent of ITKβs own list-composition order. Adisplacementsorcoordinatestransformation becomes a singleDisplacementFieldentry built from the field passed infields.- Parameters:
transform (Transform) β An RFC-5 (OME-Zarr v0.6) coordinate transformation: a linear mapping β
identity,scale,translation,rotation,affine,mapAxis,byDimension,bijection, or asequenceof them β or adisplacementsorcoordinatestransformation.dims (Sequence[str]) β The axis names of the coordinate system the transformation is defined on, in RFC-5 (Zarr) order. Only the spatial axes take part.
fields (Mapping[str, NgffImage | NgffMultiscales], optional) β The field images a
displacementsorcoordinatestransformation points at, keyed by itspath: anNgffImage, or theNgffMultiscalesread fromf"{store}/{transform.path}". Required for those two, ignored otherwise.fixed (NgffImage, optional) β The fixed and moving images the transform relates. Passing both lets the conversion re-express the intrinsic-space mapping on ITK physical space, including the direction matrix derived from RFC-4 anatomical orientation. Omitting them is exact only when neither image carries an anatomical orientation.
moving (NgffImage, optional) β See
fixed. Pass both or neither.
- Returns:
A single-entry ITK-Wasm
TransformList.- Return type:
list[itkwasm.Transform]