Spec-Zone.ru › TensorFlow 2.9

tf.image.resize_with_crop_or_pad

Просмотреть исходный код на GitHub

Обрезает и/или заполняет изображение до целевой ширины и высоты.

Просмотр псевдонимов

Псевдонимы совместимости для миграции

См. Руководство по миграции для получения дополнительной информации.

tf.compat.v1.image.resize_image_with_crop_or_pad, tf.compat.v1.image.resize_with_crop_or_pad

tf.image.resize_with_crop_or_pad(
    image, target_height, target_width
)

Изменяет размер изображения до целевой ширины и высоты, либо центрированно обрезая изображение, либо равномерно заполняя его нулями.

Если width или height больше указанной target_width или target_height соответственно, этот оператор центрированно обрезает по этому измерению.

Например:

image = np.arange(75).reshape(5, 5, 3)  # create 3-D image input
image[:,:,0]  # print first channel just for demo purposes
array([[ 0,  3,  6,  9, 12],
       [15, 18, 21, 24, 27],
       [30, 33, 36, 39, 42],
       [45, 48, 51, 54, 57],
       [60, 63, 66, 69, 72]])
image = tf.image.resize_with_crop_or_pad(image, 3, 3)  # crop
# print first channel for demo purposes; centrally cropped output
image[:,:,0]
<tf.Tensor: shape=(3, 3), dtype=int64, numpy=
array([[18, 21, 24],
       [33, 36, 39],
       [48, 51, 54]])>

Если width или height меньше указанной target_width или target_height соответственно, этот оператор центрированно заполняет нулями по этому измерению.

Например:

image = np.arange(1, 28).reshape(3, 3, 3)  # create 3-D image input
image[:,:,0]  # print first channel just for demo purposes
array([[ 1,  4,  7],
       [10, 13, 16],
       [19, 22, 25]])
image = tf.image.resize_with_crop_or_pad(image, 5, 5)  # pad
# print first channel for demo purposes; we should see 0 paddings
image[:,:,0]
<tf.Tensor: shape=(5, 5), dtype=int64, numpy=
array([[ 0,  0,  0,  0,  0],
       [ 0,  1,  4,  7,  0],
       [ 0, 10, 13, 16,  0],
       [ 0, 19, 22, 25,  0],
       [ 0,  0,  0,  0,  0]])>
Аргументы
image 4-мерный тензор формы [batch, height, width, channels] или 3-мерный тензор формы [height, width, channels].
target_height Целевая высота.
target_width Целевая ширина.
Исключения
ValueError если target_height или target_width равны нулю или отрицательны.
Возвращаемые значения
Обрезанное и/или заполненное изображение. Если images было 4-мерным, 4-мерный плавающий тензор формы [batch, new_height, new_width, channels]. Если images было 3-мерным, 3-мерный плавающий тензор формы [new_height, new_width, channels].

© 2022 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 4.0.
Code samples licensed under the Apache 2.0 License.
https://www.tensorflow.org/versions/r2.9/api_docs/python/tf/image/resize_with_crop_or_pad

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API