trw.transforms.deform
¶
Module Contents¶
Functions¶
|
Generate random deformation grid (one for each sample) |
|
Non linearly deform an image based on a grid of control points. |
- trw.transforms.deform.random_grid_using_control_points(shape: trw.basic_typing.ShapeNX, control_points: Union[int, Sequence[int]], max_displacement: Optional[Union[float, Sequence[float]]] = None, geometry_moving: Optional[trw.transforms.spatial_info.SpatialInfo] = None, tfm: Optional[torch.Tensor] = None, geometry_fixed: Optional[trw.transforms.spatial_info.SpatialInfo] = None, gaussian_filter_sigma: Optional[float] = None, align_corners: bool = False) torch.Tensor ¶
Generate random deformation grid (one for each sample) based on the number of control points and maximum displacement of the control points.
This is done by decomposing the affine (grid) and deformable components.
The gradient can be back-propagated through this transform.
Notes
The deformation field’s max_displacement will not rotate according to geometry_fixed but will be axis aligned.
- Parameters
control_points – the control points spread on the image at regularly spaced intervals with random max_displacement magnitude
max_displacement – specify the maximum displacement of a control point. Range [-1..1]
geometry_moving – defines the geometry of an image. In particular to handle non-isotropic spacing
align_corners – should be False. The (0, 0) is the center of a voxel
shape – the shape of the moving geometry. Must match the geometry_moving if specified
geometry_moving – geometry of the moving object. If None, default to a geometry of spacing 1 and origin 0
geometry_fixed – geometry output (dictate the final geometry). If None, use the same as the geometry_moving
tfm – the transformation to be applied to the geometry_moving
gaussian_filter_sigma – if not None, smooth the deformation field using a gaussian filter. The smoothing is done in the control point space
- Returns
N * X * dim displacement field
- trw.transforms.deform.deform_image_random(moving_volumes: List[trw.basic_typing.TorchTensorNCX], control_points: Union[int, Sequence[int]], max_displacement: Optional[Union[float, Sequence[float]]] = None, geometry: Optional[trw.transforms.spatial_info.SpatialInfo] = None, interpolation: typing_extensions.Literal[linear, nearest] = 'linear', padding_mode: typing_extensions.Literal[zeros, border, reflection] = 'zeros', gaussian_filter_sigma: Optional[float] = None, align_corners: bool = False) List[trw.basic_typing.TorchTensorNCX] ¶
Non linearly deform an image based on a grid of control points.
The grid of control points is first uniformly mapped to span the whole image, then the control point position will be randomized using max_displacement. To avoid artifacts at the image boundary, a control point is added with 0 max displacement all around the image.
The gradient can be back-propagated through this transform.
Notes
The deformation field’s max_displacement will not rotate according to geometry_fixed but instead is axis aligned.
- Parameters
moving_volumes – a list of moving volumes. All volumes will be deformed using the same deformation field
control_points – the control points spread on the image at regularly spaced intervals with random max_displacement magnitude
max_displacement – specify the maximum displacement of a control point. Range [-1..1]. If None, use the moving volume shape and number of control points to calculate appropriate small deformation field
geometry – defines the geometry of an image. In particular to handle non-isotropic spacing
interpolation – the interpolation of the image with displacement field
padding_mode – how to handle data outside the volume geometry
align_corners – should be False. The (0, 0) is the center of a voxel
gaussian_filter_sigma – if not None, smooth the deformation field using a gaussian filter. The smoothing is done in the control point space
- Returns
a deformed image