Spec-Zone.ru › TensorFlow 2.9

tf.image.crop_to_bounding_box

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

Вырезает прямоугольную область изображения по заданной ограничивающей рамке.

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

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

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

tf.compat.v1.image.crop_to_bounding_box

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

Данная операция вырезает прямоугольную ограничивающую рамку из image. Верхний левый угол ограничивающей рамки расположен по координатам offset_height, offset_width в image, а нижний правый угол - по координатам offset_height + target_height, offset_width + target_width.

Пример использования:

image = tf.constant(np.arange(1, 28, dtype=np.float32), shape=[3, 3, 3])
image[:,:,0] # print the first channel of the 3-D tensor
<tf.Tensor: shape=(3, 3), dtype=float32, numpy=
array([[ 1.,  4.,  7.],
       [10., 13., 16.],
       [19., 22., 25.]], dtype=float32)>
cropped_image = tf.image.crop_to_bounding_box(image, 0, 0, 2, 2)
cropped_image[:,:,0] # print the first channel of the cropped 3-D tensor
<tf.Tensor: shape=(2, 2), dtype=float32, numpy=
array([[ 1.,  4.],
       [10., 13.]], dtype=float32)>
Аргументы
image 4-мерный Tensor с формой [batch, height, width, channels] или 3-мерный Tensor с формой [height, width, channels].
offset_height Вертикальная координата верхнего левого угла ограничивающей рамки в image.
offset_width Горизонтальная координата верхнего левого угла ограничивающей рамки в image.
target_height Высота ограничивающей рамки.
target_width Ширина ограничивающей рамки.
Возвращаемое значение
Если image был 4-мерным, то 4-мерный Tensor с формой [batch, target_height, target_width, channels]. Если image был 3-мерным, то 3-мерный Tensor с формой [target_height, target_width, channels]. Он имеет тот же тип данных, что и image.
Исключения
ValueError image не является 3-мерным или 4-мерным Tensor.
ValueError offset_width < 0 или offset_height < 0.
ValueError target_width <= 0 или target_width <= 0.
ValueError width < offset_width + target_width или height < offset_height + target_height.

© 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/crop_to_bounding_box

Spec-Zone.ru

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