mindspore.dataset.vision.Invert

class mindspore.dataset.vision.Invert[源代码]

对输入的RGB图像进行色彩反转。

对于图像中的每个像素,若原像素值为 pixel ,则反转后的像素值为 255 - pixel

异常:
  • RuntimeError - 如果输入图像的shape不是 <H, W, C>。

支持平台:

CPU

样例:

>>> import numpy as np
>>> import mindspore.dataset as ds
>>> import mindspore.dataset.vision as vision
>>>
>>> # Use the transform in dataset pipeline mode
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
>>> transforms_list = [vision.Invert()]
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
...     print(item["image"].shape, item["image"].dtype)
...     break
(100, 100, 3) uint8
>>>
>>> # Use the transform in eager mode
>>> data = np.array([[0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5]], dtype=np.uint8).reshape((2, 2, 3))
>>> output = vision.Invert()(data)
>>> print(output.shape, output.dtype)
(2, 2, 3) uint8
教程样例: