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 according to padding parameters.

Parameters
  • padding (Union[int, sequence]) – The number of pixels to pad the image. If a single number is provided, pad all borders with this value. If a tuple or list of 2 values is provided, pad the left and top with the first value and the right and bottom with the second value. If 4 values are provided as a list or tuple, pad the left, top, right and bottom respectively.

  • fill_value (Union[int, tuple], optional) – The pixel intensity of the borders, only valid for padding_mode Border.CONSTANT (default=0). If it is an integer, it is used for all RGB channels. If it is a 3-tuple, it is used to fill R, G, B channels respectively.

  • padding_mode (Border mode, optional) –

    The method of padding (default=Border.CONSTANT). It can be any of [Border.CONSTANT, Border.EDGE, Border.REFLECT, Border.SYMMETRIC].

    • Border.CONSTANT, means it fills the border with constant values.

    • Border.EDGE, means it pads with the last value on the edge.

    • Border.REFLECT, means it reflects the values on the edge omitting the last value of edge.

    • Border.SYMMETRIC, means it reflects the values on the edge repeating the last value of edge.

Examples

>>> from mindspore.dataset.transforms.py_transforms import Compose
>>> transforms_list = Compose([py_vision.Decode(),
...                            # adds 10 pixels (default black) to each side of the 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")