trw.transforms.spatial_info
¶
Module Contents¶
Classes¶
Represent a the geometric space of a n-dimensional (2D or 3D) volume. |
Functions¶
|
Make a patient scale transform from (origin, spacing, without rotation or shear component) |
|
Return the spacing (expansion factor) of the transformation per dimension ZYX |
|
Return the origin of the transformation per dimension ZYX |
- trw.transforms.spatial_info.make_aligned_patient_scale_transform(origin: trw.basic_typing.Length, spacing: trw.basic_typing.Length) torch.Tensor ¶
Make a patient scale transform from (origin, spacing, without rotation or shear component)
- Parameters
origin – (Z)YX origin of the geometric space (millimeter)
spacing – (Z)YX spacing of the geometric space (millimeter)
- Returns
a patient scale transform, mapping a (Z)YX voxel to a position in (Z)YX defined in millimeter
- trw.transforms.spatial_info.patient_scale_transform_get_spacing(pst: torch.Tensor) torch.Tensor ¶
Return the spacing (expansion factor) of the transformation per dimension ZYX
- Parameters
pst – a 3x3 or 4x4 transformation matrix
- Returns
[Z]YX spacing
- trw.transforms.spatial_info.patient_scale_transform_get_origin(pst: torch.Tensor) torch.Tensor ¶
Return the origin of the transformation per dimension ZYX
- Parameters
pst – a 3x3 or 4x4 transformation matrix
- Returns
[Z]YX spacing
- class trw.transforms.spatial_info.SpatialInfo(shape: trw.basic_typing.ShapeX, patient_scale_transform: Optional[torch.Tensor] = None, origin: Optional[trw.basic_typing.Length] = None, spacing: Optional[trw.basic_typing.Length] = None)¶
Represent a the geometric space of a n-dimensional (2D or 3D) volume.
- Concepts: patient scale transform
we often need to work with data in a given geometric space. This can be achieved by mapping voxel indices of a tensor to given geometric space by applying a linear transform on the location of the voxel to express.
This patient transform can be decomposed as multiple linear transforms such as translation, rotation, zoom and shearing. SpatialInfo will encode its geometric space as PST = Translation * (RotationZ *) RotationY * RotationZ * Spacing
The matrix is a homogeneous transformation matrix:
with (RX, RY, RZ) the basis of the geometric space. The spacing is defined as (||RX||^2, ||RY||^2, ||RZ||^2).
Notes
function will require calls argument names (*), since the xyz / zyx is cumbersome and probably both conventions will need to be supported in the future
We use arbitrary unit millimeter unit for all the attributes.
- set_patient_scale_transform(self, patient_scale_transform: torch.Tensor) None ¶
- property spacing(self) numpy.ndarray ¶
Calculate the spacing of the PST. Return the components as ZYX order.
- property origin(self) numpy.ndarray ¶
Return the origin expressed in world space (expressed as ZYX order).
- property center(self) numpy.ndarray ¶
Return the center in world space (expressed as ZYX order).
- index_to_position(self, *, index_zyx: torch.Tensor) torch.Tensor ¶
Map an index to world space
- Parameters
index_zyx – coordinate in index space
- Returns
position in world space (Z)YX
- position_to_index(self, *, position_zyx: torch.Tensor) torch.Tensor ¶
Map world space coordinate to an index
- Parameters
position_zyx – position in world space
- Returns
coordinate in index space (Z)YX
- sub_geometry(self, *, start_index_zyx: torch.Tensor, end_index_zyx_inclusive: torch.Tensor)¶
Create a sub-geometry from min and max indices
- Parameters
start_index_zyx – starting index
end_index_zyx_inclusive – ending index (inclusive)
- Returns
a new Spatial info representing this sub-geometry