MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / apply_affine_to_points

Function apply_affine_to_points

monai/transforms/utils.py:2582–2600  ·  view source on GitHub ↗

apply affine transformation to a set of points. Args: data: input data to apply affine transformation, should be a tensor of shape (C, N, 2 or 3), where C represents the number of channels and N denotes the number of points. affine: affine matrix to be applied,

(data: torch.Tensor, affine: torch.Tensor, dtype: DtypeLike | torch.dtype | None = None)

Source from the content-addressed store, hash-verified

2580
2581
2582def apply_affine_to_points(data: torch.Tensor, affine: torch.Tensor, dtype: DtypeLike | torch.dtype | None = None):
2583 """
2584 apply affine transformation to a set of points.
2585
2586 Args:
2587 data: input data to apply affine transformation, should be a tensor of shape (C, N, 2 or 3),
2588 where C represents the number of channels and N denotes the number of points.
2589 affine: affine matrix to be applied, should be a tensor of shape (3, 3) or (4, 4).
2590 dtype: output data dtype.
2591 """
2592 data_: torch.Tensor = convert_to_tensor(data, track_meta=False, dtype=torch.float64)
2593 affine = to_affine_nd(data_.shape[-1], affine)
2594
2595 homogeneous: torch.Tensor = concatenate((data_, torch.ones((data_.shape[0], data_.shape[1], 1))), axis=2) # type: ignore
2596 transformed_homogeneous = torch.matmul(homogeneous, affine.T)
2597 transformed_coordinates = transformed_homogeneous[:, :, :-1]
2598 out, *_ = convert_to_dst_type(transformed_coordinates, data, dtype=dtype)
2599
2600 return out
2601
2602
2603if __name__ == "__main__":

Callers 1

transform_coordinatesMethod · 0.90

Calls 4

convert_to_tensorFunction · 0.90
to_affine_ndFunction · 0.90
concatenateFunction · 0.90
convert_to_dst_typeFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…