# tf.image.crop_to_bounding_box

<br />

|---|---|
| [![](https://www.tensorflow.org/images/tf_logo_32px.png) TensorFlow 2 version](https://www.tensorflow.org/api_docs/python/tf/image/crop_to_bounding_box) | [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/ops/image_ops_impl.py#L809-L886) |

Crops an image to a specified bounding box.

#### View aliases


**Compat aliases for migration**

See
[Migration guide](https://www.tensorflow.org/guide/migrate) for
more details.

[`tf.compat.v1.image.crop_to_bounding_box`](https://www.tensorflow.org/api_docs/python/tf/image/crop_to_bounding_box), \`tf.compat.v2.image.crop_to_bounding_box\`

<br />

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

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

<br />

<br />

<br />

| ## Args ||
|---|---|
| `image` | 4-D Tensor of shape `[batch, height, width, channels]` or 3-D Tensor of shape `[height, width, channels]`. |
| `offset_height` | Vertical coordinate of the top-left corner of the result in the input. |
| `offset_width` | Horizontal coordinate of the top-left corner of the result in the input. |
| `target_height` | Height of the result. |
| `target_width` | Width of the result. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| If `image` was 4-D, a 4-D float Tensor of shape `[batch, target_height, target_width, channels]` If `image` was 3-D, a 3-D float Tensor of shape `[target_height, target_width, channels]` ||

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `ValueError` | If the shape of `image` is incompatible with the `offset_*` or `target_*` arguments, or either `offset_height` or `offset_width` is negative, or either `target_height` or `target_width` is not positive. |

<br />