mindspore.dataset.vision.Perspective

View Source On Gitee
class mindspore.dataset.vision.Perspective(start_points, end_points, interpolation=Inter.BILINEAR)[source]

Apply perspective transformation on input image.

Parameters
  • start_points (Sequence[Sequence[int, int]]) – Sequence of the starting point coordinates, containing four two-element subsequences, corresponding to [top-left, top-right, bottom-right, bottom-left] of the quadrilateral in the original image.

  • end_points (Sequence[Sequence[int, int]]) – Sequence of the ending point coordinates, containing four two-element subsequences, corresponding to [top-left, top-right, bottom-right, bottom-left] of the quadrilateral in the target image.

  • interpolation (Inter, optional) – Image interpolation method defined by Inter . Default: Inter.BILINEAR.

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

  • TypeError – If end_points is not of type Sequence[Sequence[int, int]].

  • TypeError – If interpolation is not of type Inter .

  • RuntimeError – If shape of the input image is not <H, W> or <H, W, C>.

Supported Platforms:

CPU

Examples

>>> import numpy as np
>>> import mindspore.dataset as ds
>>> import mindspore.dataset.vision as vision
>>> from mindspore.dataset.vision import Inter
>>>
>>> # Use the transform in dataset pipeline mode
>>> start_points = [[0, 63], [63, 63], [63, 0], [0, 0]]
>>> end_points = [[0, 32], [32, 32], [32, 0], [0, 0]]
>>> transforms_list = [vision.Perspective(start_points, end_points, Inter.BILINEAR)]
>>> # apply the transform to dataset through map function
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
>>> 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
>>> start_points = [[0, 63], [63, 63], [63, 0], [0, 0]]
>>> end_points = [[0, 32], [32, 32], [32, 0], [0, 0]]
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
>>> output = vision.Perspective(start_points, end_points, Inter.BILINEAR)(data)
>>> print(output.shape, output.dtype)
(100, 100, 3) uint8
Tutorial Examples:
device(device_target='CPU')[source]

Set the device for the current operator execution.

  • When the device is Ascend, input shape should be limited from [6, 10] to [8192, 4096].

Parameters

device_target (str, optional) – The operator will be executed on this device. Currently supports CPU and Ascend . Default: CPU .

Raises
  • TypeError – If device_target is not of type str.

  • ValueError – If device_target is not within the valid set of [‘CPU’, ‘Ascend’].

Supported Platforms:

CPU Ascend

Examples

>>> import numpy as np
>>> import mindspore.dataset as ds
>>> import mindspore.dataset.vision as vision
>>> from mindspore.dataset.vision import Inter
>>>
>>> # 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"])
>>> start_points = [[0, 63], [63, 63], [63, 0], [0, 0]]
>>> end_points = [[0, 32], [32, 32], [32, 0], [0, 0]]
>>> perspective_op = vision.Perspective(start_points, end_points).device("Ascend")
>>> transforms_list = [perspective_op]
>>> 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
>>> start_points = [[0, 63], [63, 63], [63, 0], [0, 0]]
>>> end_points = [[0, 32], [32, 32], [32, 0], [0, 0]]
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
>>> output = vision.Perspective(start_points, end_points, Inter.BILINEAR).device("Ascend")(data)
>>> print(output.shape, output.dtype)
(100, 100, 3) uint8
Tutorial Examples: