mindspore.dataset.vision.py_transforms.CenterCrop

class mindspore.dataset.vision.py_transforms.CenterCrop(size)[source]

Crop the central region of the input PIL Image with the given size.

Parameters

size (Union[int, Sequence[int, int]]) – The size of the cropped image. If int is provided, a square of size (size, size) will be cropped with this value. If Sequence[int, int] is provided, its two elements will be taken as the cropped height and width.

Raises
  • TypeError – If size is not of type int or Sequence[int, int].

  • ValueError – If size is not positive.

Supported Platforms:

CPU

Examples

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