mindspore.dataset.vision.Affine

View Source On Gitee
class mindspore.dataset.vision.Affine(degrees, translate, scale, shear, resample=Inter.NEAREST, fill_value=0)[source]

Apply Affine transformation to the input image, keeping the center of the image unchanged.

Parameters
  • degrees (float) – Rotation angle in degrees between -180 and 180, clockwise direction.

  • translate (Sequence[float, float]) – The horizontal and vertical translations, must be a sequence of size 2.

  • scale (float) – Scaling factor, which must be positive.

  • shear (Union[float, Sequence[float, float]]) – Shear angle value in degrees between -180 to 180. If float is provided, shear along the x axis with this value, without shearing along the y axis; If Sequence[float, float] is provided, shear along the x axis and y axis with these two values separately.

  • resample (Inter, optional) – Image interpolation method defined by Inter . Default: Inter.NEAREST.

  • fill_value (Union[int, tuple[int, int, int]], optional) – Optional fill_value to fill the area outside the transform in the output image. There must be three elements in tuple and the value of single element is [0, 255]. Default: 0.

Raises
  • TypeError – If degrees is not of type float.

  • TypeError – If translate is not of type Sequence[float, float].

  • TypeError – If scale is not of type float.

  • ValueError – If scale is non positive.

  • TypeError – If shear is not of float or Sequence[float, float].

  • TypeError – If resample is not of type Inter .

  • TypeError – If fill_value is not of type int or tuple[int, int, int].

  • RuntimeError – If shape of the input image is not <H, W> or <H, W, C>.

Supported Platforms:

CPU

Examples

>>> import mindspore.dataset as ds
>>> import mindspore.dataset.vision as vision
>>> from mindspore.dataset.vision import Inter
>>>
>>> decode_op = vision.Decode()
>>> affine_op = vision.Affine(degrees=15, translate=[0.2, 0.2], scale=1.1, shear=[1.0, 1.0],
...                           resample=Inter.BILINEAR)
>>> affine_list = [decode_op, affine_op]
>>>
>>> image_folder_dataset = ds.ImageFolderDataset("/path/to/image_folder_dataset_directory")
>>> image_folder_dataset = image_folder_dataset.map(operations=affine_list, input_columns=["image"])
Tutorial Examples: