Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions monai/transforms/spatial/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_rotate90.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down