mindspore.dataset.vision.TenCrop

class mindspore.dataset.vision.TenCrop(size, use_vertical_flip=False)[source]

Crop the given image into one central crop and four corners with the flipped version of these.

Parameters
  • size (Union[int, sequence]) – The size of the cropped image. If a single integer is provided, a square of size (size, size) will be cropped with this value. If a sequence of length 2 is provided, an image of size (height, width) will be cropped.

  • use_vertical_flip (bool, optional) – If True, flip the images vertically. Otherwise, flip them horizontally. Default: False.

Raises
  • TypeError – If size is not of type integer or sequence of integer.

  • TypeError – If use_vertical_flip is not of type boolean.

  • ValueError – If size is not positive.

Supported Platforms:

CPU

Examples

>>> import numpy
>>> from mindspore.dataset.transforms import Compose
>>>
>>> transforms_list = Compose([vision.Decode(to_pil=True)),
...                            vision.TenCrop(size=200),
...                            # 4D stack of 10 images
...                            lambda *images: numpy.stack([vision.ToTensor()(image) for image in images])])
>>> # apply the transform to dataset through map function
>>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list,
...                                                 input_columns="image")
execute_py(img)[source]

Execute method.

Parameters

img (PIL Image) – Image to be cropped.

Returns

tuple, a tuple of 10 PIL Image, in order of top_left, top_right, bottom_left, bottom_right, center

of the original image and top_left, top_right, bottom_left, bottom_right, center of the flipped image.