比较与tf.image.crop_to_bounding_box的功能差异

查看源文件

tf.image.crop_to_bounding_box

tf.image.crop_to_bounding_box(
    image,
    offset_height,
    offset_width,
    target_height,
    target_width
)

更多内容详见tf.image.crop_to_bounding_box

mindspore.dataset.vision.Crop

class mindspore.dataset.vision.Crop(
    coordinates,
    size
)

更多内容详见mindspore.dataset.vision.Crop

使用方式

TensorFlow:在图像指定位置进行裁剪,入参为裁剪位置的高、宽坐标和裁剪子图的高、宽。

MindSpore:在图像指定位置进行裁剪,入参为裁剪位置的坐标和裁剪子图的大小。

代码示例

# The following implements Crop with MindSpore.
import numpy as np
import mindspore.dataset as ds

image = np.random.random((28, 28, 3))
result = ds.vision.Crop((0, 0), (14, 14))(image)
print(result.shape)
# (14, 14, 3)

# The following implements crop_to_bounding_box with TensorFlow.
import tensorflow as tf

image = tf.random.normal((28, 28, 3))
result = tf.image.crop_to_bounding_box(image, 0, 0, 14, 14)
print(result.shape)
# (14, 14, 3)