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[float, Sequence[float, float]]) – Range of rotation degree to select from. If int is provided, the rotation degree will be randomly selected from (-degrees, degrees). If Sequence[float, float] is provided, it should be arranged in order of (min, max).

  • resample (Inter, optional) –

    Method of interpolation. It can be Inter.NEAREST, Inter.ANTIALIAS, Inter.BILINEAR or Inter.BICUBIC. If the input PIL Image is in mode of “1” or “P”, Inter.NEAREST will be used directly. Default: Inter.NEAREST.

    • Inter.NEAREST, nearest-neighbor interpolation.

    • Inter.ANTIALIAS, antialias interpolation.

    • Inter.BILINEAR, bilinear interpolation.

    • Inter.BICUBIC, bicubic interpolation.

  • expand (bool, optional) – If True, it will expand the image to make it large enough to hold the entire rotated image. If False, keep the image the same size as the input. Please note that the expansion assumes rotation around the center and no translation. Default: False.

  • center (Sequence[int, int], optional) – The position of the rotation center, taking the upper left corner as the origin. It should be arranged in order of (width, height). Default: None, means to set the center of the image.

  • fill_value (Union[int, tuple[int, int, int]], optional) – Pixel value for areas outside the rotated image. If int is provided, it will be used for all RGB channels. If tuple[int, int, int] is provided, it will be used for R, G, B channels respectively. Default: 0.

Raises
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")