diff --git a/monai/transforms/spatial/array.py b/monai/transforms/spatial/array.py index 75a25459e8..f0cf047aa6 100644 --- a/monai/transforms/spatial/array.py +++ b/monai/transforms/spatial/array.py @@ -285,11 +285,16 @@ def __call__( class Flip(Transform): """ Reverses the order of elements along the given spatial axis. Preserves shape. - Uses ``np.flip`` in practice. See numpy.flip for additional details. - https://docs.scipy.org/doc/numpy/reference/generated/numpy.flip.html + Uses ``np.flip`` in practice. See numpy.flip for additional details: + https://docs.scipy.org/doc/numpy/reference/generated/numpy.flip.html. Args: spatial_axis: spatial axes along which to flip over. Default is None. + The default `axis=None` will flip over all of the axes of the input array. + If axis is negative it counts from the last to the first axis. + If axis is a tuple of ints, flipping is performed on all of the axes + specified in the tuple. + """ def __init__(self, spatial_axis: Optional[Union[Sequence[int], int]]) -> None: @@ -567,6 +572,9 @@ def __call__( class Rotate90(Transform): """ Rotate an array by 90 degrees in the plane specified by `axes`. + See np.rot90 for additional details: + https://numpy.org/doc/stable/reference/generated/numpy.rot90.html. + """ def __init__(self, k: int = 1, spatial_axes: Tuple[int, int] = (0, 1)) -> None: @@ -575,6 +583,7 @@ def __init__(self, k: int = 1, spatial_axes: Tuple[int, int] = (0, 1)) -> None: k: number of times to rotate by 90 degrees. spatial_axes: 2 int numbers, defines the plane to rotate with 2 spatial axes. Default: (0, 1), this is the first two axis in spatial dimensions. + If axis is negative it counts from the last to the first axis. """ self.k = k spatial_axes_ = ensure_tuple(spatial_axes) diff --git a/tests/test_rotate90.py b/tests/test_rotate90.py index a8b4e3f57c..4ab39d5cf6 100644 --- a/tests/test_rotate90.py +++ b/tests/test_rotate90.py @@ -37,11 +37,11 @@ def test_k(self): self.assertTrue(np.allclose(rotated, expected)) def test_spatial_axes(self): - rotate = Rotate90(spatial_axes=(0, 1)) + rotate = Rotate90(spatial_axes=(0, -1)) rotated = rotate(self.imt[0]) expected = [] for channel in self.imt[0]: - expected.append(np.rot90(channel, 1, (0, 1))) + expected.append(np.rot90(channel, 1, (0, -1))) expected = np.stack(expected) self.assertTrue(np.allclose(rotated, expected))