mindspore.dataset.vision.CenterCrop
- class mindspore.dataset.vision.CenterCrop(size)[source]
Crop the input image at the center to the given size. If input image size is smaller than output size, input image will be padded with 0 before cropping.
- Parameters
size (Union[int, sequence]) – The output size of the cropped image. If size is an integer, a square crop of size (size, size) is returned. If size is a sequence of length 2, it should be (height, width). The size value(s) must be larger than 0.
- Raises
TypeError – If size is not of type integer or sequence.
ValueError – If size is less than or equal to 0.
RuntimeError – If given tensor shape is not <H, W> or <H, W, C>.
- Supported Platforms:
CPU
Examples
>>> # crop image to a square >>> transforms_list1 = [vision.Decode(), vision.CenterCrop(50)] >>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list1, ... input_columns=["image"]) >>> # crop image to portrait style >>> transforms_list2 = [vision.Decode(), vision.CenterCrop((60, 40))] >>> image_folder_dataset_1 = image_folder_dataset_1.map(operations=transforms_list2, ... input_columns=["image"])