mindspore.dataset.vision.py_transforms.RandomRotation

class mindspore.dataset.vision.py_transforms.RandomRotation(degrees, resample=Inter.NEAREST, expand=False, center=None, fill_value=0)[source]

Rotate the input PIL Image by a random angle.

Parameters
  • degrees (Union[int, float, sequence]) – Range of random rotation degrees. If degrees is a number, the range will be converted to (-degrees, degrees). If degrees is a sequence of length 2, it should be in shape of (min, max).

  • resample (Inter, optional) –

    An optional resampling filter (default=Inter.NEAREST). If the image is in mode of “1” or “P”, it is set to Inter.NEAREST by default. It can be any of [Inter.NEAREST, Inter.ANTIALIAS, Inter.BILINEAR, Inter.BICUBIC].

    • Inter.NEAREST, nearest-neighbor interpolation.

    • Inter.ANTIALIAS, antialias interpolation.

    • Inter.BILINEAR, bilinear interpolation.

    • Inter.BICUBIC, bicubic interpolation.

  • expand (bool, optional) – Optional expansion flag (default=False). If set to True, expand the output image to make it large enough to hold the entire rotated image. If set to False, keep the output image the same size as the input. Note that the expand flag assumes rotation around the center and no translation.

  • center (tuple, optional) – Optional center of rotation, which must be a tuple of length 2 (default=None). Origin is the top left corner. Default None means to set the center of the image.

  • fill_value (int or tuple, optional) – Pixel fill value for the area outside the rotated image (default=0). If fill_value is a tuple of length 3, it is used to fill R, G, B channels respectively. If fill_value is an integer, it is used to fill all RGB channels.

Raises
  • TypeError – If degrees is not of type integer, float or sequence.

  • TypeError – If resample is not of type Inter.

  • TypeError – If expand is not of type boolean.

  • TypeError – If center is not of type tuple.

  • TypeError – If fill_value is not of type integer or tuple of integer.

  • ValueError – If fill_value is not in range [0, 255].

  • RuntimeError – If given tensor shape is not <H, W> or <H, W, C>.

Supported Platforms:

CPU

Examples

>>> from mindspore.dataset.transforms.py_transforms import Compose
>>> transforms_list = Compose([py_vision.Decode(),
...                            py_vision.RandomRotation(30),
...                            py_vision.ToTensor()])
>>> # apply the transform to dataset through map function
>>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list,
...                                                 input_columns="image")