dosma.core.orientation.to_affine
- dosma.core.orientation.to_affine(orientation, spacing: Optional[Sequence[Union[int, float]]] = None, origin: Optional[Sequence[Union[int, float]]] = None)[source]
Convert orientation, spacing, and origin data into affine matrix.
- Parameters:
orientation (Sequence[str]) – Image orientation in the standard orientation format (e.g.
("LR", "AP", "SI")).spacing (int(s) | float(s)) – Number(s) corresponding to pixel spacing of each direction. If a single value, same pixel spacing is used for all directions. If sequence is less than length of
orientation, remaining direction have unit spacing (i.e.1). Defaults to unit spacing(1, 1, 1)origin (int(s) | float(s)) – The
(x0, y0, z0)origin for the scan. If a single value, same origin is used for all directions. If sequence is less than length oforientation, remaining direction have standard origin (i.e.0). Defaults to(0, 0, 0)
- Returns:
A 4x4 ndarray representing the affine matrix.
- Return type:
ndarray
Examples
>>> to_affine(("SI", "AP", "RL"), spacing=(0.5, 0.5, 1.5), origin=(10, 20, 0)) array([[-0. , -0. , -1.5, 10. ], [-0. , -0.5, -0. , 20. ], [-0.5, -0. , -0. , 30. ], [ 0. , 0. , 0. , 1. ]])
Note
This method assumes all direction follow the standard principal directions in the normative patient orientation. Moving along one direction of the array only moves along one fo the normative directions.