Данная операция вырезает прямоугольную ограничивающую рамку из 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.