mindspore.dataset.vision.py_transforms.Pad
- class mindspore.dataset.vision.py_transforms.Pad(padding, fill_value=0, padding_mode=Border.CONSTANT)[source]
Pad the input PIL Image on all sides.
- Parameters
padding (Union[int, Sequence[int, int], Sequence[int, int, int, int]]) – The number of pixels to pad on each border. If int is provided, pad all borders with this value. If Sequence[int, int] is provided, pad the left and top borders with the first value and the right and bottom borders with the second value. If Sequence[int, int, int, int] is provided, pad the left, top, right and bottom borders respectively.
fill_value (Union[int, tuple[int, int, int]], optional) – Pixel value used to pad the borders, only valid when padding_mode is Border.CONSTANT. If int is provided, it will be used for all RGB channels. If tuple[int, int, int] is provided, it will be used for R, G, B channels respectively. Default: 0.
padding_mode (Border, optional) –
Method of padding. It can be Border.CONSTANT, Border.EDGE, Border.REFLECT or Border.SYMMETRIC. Default: Border.CONSTANT. Default: Border.CONSTANT.
Border.CONSTANT, pads with a constant value.
Border.EDGE, pads with the last value at the edge of the image.
Border.REFLECT, pads with reflection of the image omitting the last value on the edge.
Border.SYMMETRIC, pads with reflection of the image repeating the last value on the edge.
- Raises
TypeError – If padding is not of type int or Sequence[int, int].
TypeError – If fill_value is not of type int or tuple[int, int, int].
TypeError – If padding_mode is not of type
mindspore.dataset.vision.Border
.ValueError – If padding is negative.
ValueError – If fill_value is not in range of [0, 255].
RuntimeError – If shape of the input image is not <H, W> or <H, W, C>.
- Supported Platforms:
CPU
Examples
>>> from mindspore.dataset.transforms.py_transforms import Compose >>> >>> transforms_list = Compose([py_vision.Decode(), ... # adds 10 pixels (default black) to each border of the image ... py_vision.Pad(padding=10), ... py_vision.ToTensor()]) >>> # apply the transform to dataset through map function >>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list, ... input_columns="image")