tf.image.crop_to_bounding_box

Crops an image to a specified bounding box.

Used in the notebooks

Used in the tutorials

This op cuts a rectangular bounding box out of image. The top-left corner of the bounding box is at offset_height, offset_width in image, and the lower-right corner is at offset_height + target_height, offset_width + target_width.

Example Usage:

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)