mindspore.dataset.vision.FiveCrop

View Source On Gitee
class mindspore.dataset.vision.FiveCrop(size)[source]

Crop the given image into one central crop and four corners.

Parameters

size (Union[int, Sequence[int, int]]) – 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.

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

  • ValueError – If size is not positive.

Supported Platforms:

CPU

Examples

>>> import mindspore.dataset as ds
>>> import mindspore.dataset.vision as vision
>>> import numpy
>>> from mindspore.dataset.transforms import Compose
>>>
>>> transforms_list = Compose([vision.Decode(to_pil=True),
...                            vision.FiveCrop(size=200),
...                            # 4D stack of 5 images
...                            lambda *images: numpy.stack([vision.ToTensor()(image) for image in images])])
>>> # apply the transform to dataset through map function
>>> image_folder_dataset = ds.ImageFolderDataset("/path/to/image_folder_dataset_directory")
>>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list,
...                                                 input_columns="image")
Tutorial Examples: