# tensorflow::ops::SampleDistortedBoundingBox

`#include <image_ops.h>`

Generate a single randomly distorted bounding box for an image.

## Summary

Bounding box annotations are often supplied in addition to ground-truth labels in image recognition or object localization tasks. A common technique for training such a system is to randomly distort an image while preserving its content, i.e. *data augmentation*. This Op outputs a randomly distorted localization of an object, i.e. bounding box, given an `image_size`, `bounding_boxes` and a series of constraints.

The output of this Op is a single bounding box that may be used to crop the original image. The output is returned as 3 tensors: `begin`, `size` and `bboxes`. The first 2 tensors can be fed directly into `tf.slice` to crop the image. The latter may be supplied to `tf.image.draw_bounding_boxes` to visualize what the bounding box looks like.

Bounding boxes are supplied and returned as `[y_min, x_min, y_max, x_max]`. The bounding box coordinates are floats in `[0.0, 1.0]` relative to the width and height of the underlying image.

For example,


```
    # Generate a single distorted bounding box.
    begin, size, bbox_for_draw = tf.image.sample_distorted_bounding_box(
        tf.shape(image),
        bounding_boxes=bounding_boxes)
```

<br />


```
    # Draw the bounding box in an image summary.
    image_with_box = tf.image.draw_bounding_boxes(tf.expand_dims(image, 0),
                                                  bbox_for_draw)
    tf.summary.image('images_with_box', image_with_box)
```

<br />


```
    # Employ the bounding box to distort the image.
    distorted_image = tf.slice(image, begin, size)
```

<br />

Note that if no bounding box information is available, setting `use_image_if_no_bounding_boxes = true` will assume there is a single implicit bounding box covering the whole image. If `use_image_if_no_bounding_boxes` is false and no bounding boxes are supplied, an error is raised.

Arguments:

- scope: A [Scope](https://www.tensorflow.org/versions/r1.15/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope) object
- image_size: 1-D, containing `[height, width, channels]`.
- bounding_boxes: 3-D with shape `[batch, N, 4]` describing the N bounding boxes associated with the image.

<br />

Optional attributes (see `https://www.tensorflow.org/versions/r1.15/api_docs/cc/struct/tensorflow/ops/sample-distorted-bounding-box/attrs#structtensorflow_1_1ops_1_1_sample_distorted_bounding_box_1_1_attrs`):

- seed: If either `seed` or `seed2` are set to non-zero, the random number generator is seeded by the given `seed`. Otherwise, it is seeded by a random seed.
- seed2: A second seed to avoid seed collision.
- min_object_covered: The cropped area of the image must contain at least this fraction of any bounding box supplied. The value of this parameter should be non-negative. In the case of 0, the cropped area does not need to overlap any of the bounding boxes supplied.
- aspect_ratio_range: The cropped area of the image must have an aspect ratio = width / height within this range.
- area_range: The cropped area of the image must contain a fraction of the supplied image within this range.
- max_attempts: Number of attempts at generating a cropped region of the image of the specified constraints. After `max_attempts` failures, return the entire image.
- use_image_if_no_bounding_boxes: Controls behavior if no bounding boxes supplied. If true, assume an implicit bounding box covering the whole input. If false, raise an error.

<br />

Returns:

- `https://www.tensorflow.org/versions/r1.15/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output` begin: 1-D, containing `[offset_height, offset_width, 0]`. Provide as input to `tf.slice`.
- `https://www.tensorflow.org/versions/r1.15/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output` size: 1-D, containing `[target_height, target_width, -1]`. Provide as input to `tf.slice`.
- `https://www.tensorflow.org/versions/r1.15/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output` bboxes: 3-D with shape `[1, 1, 4]` containing the distorted bounding box. Provide as input to `tf.image.draw_bounding_boxes`.

<br />

| ### Constructors and Destructors ||
|---|---|
| `https://www.tensorflow.org/versions/r1.15/api_docs/cc/class/tensorflow/ops/sample-distorted-bounding-box#classtensorflow_1_1ops_1_1_sample_distorted_bounding_box_1a021ed3a4ffa7ed0cbe3d98c088ce6e5c(const ::https://www.tensorflow.org/versions/r1.15/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope & scope, ::https://www.tensorflow.org/versions/r1.15/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input image_size, ::https://www.tensorflow.org/versions/r1.15/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input bounding_boxes)` ||
| `https://www.tensorflow.org/versions/r1.15/api_docs/cc/class/tensorflow/ops/sample-distorted-bounding-box#classtensorflow_1_1ops_1_1_sample_distorted_bounding_box_1af821be29f65e93ffc361ed8eaf0aec86(const ::https://www.tensorflow.org/versions/r1.15/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope & scope, ::https://www.tensorflow.org/versions/r1.15/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input image_size, ::https://www.tensorflow.org/versions/r1.15/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input bounding_boxes, const https://www.tensorflow.org/versions/r1.15/api_docs/cc/struct/tensorflow/ops/sample-distorted-bounding-box/attrs#structtensorflow_1_1ops_1_1_sample_distorted_bounding_box_1_1_attrs & attrs)` ||

| ### Public attributes ||
|---|---|
| `https://www.tensorflow.org/versions/r1.15/api_docs/cc/class/tensorflow/ops/sample-distorted-bounding-box#classtensorflow_1_1ops_1_1_sample_distorted_bounding_box_1aee2279ee4a03be14d869ebd6f8958a33` | `::https://www.tensorflow.org/versions/r1.15/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output` |
| `https://www.tensorflow.org/versions/r1.15/api_docs/cc/class/tensorflow/ops/sample-distorted-bounding-box#classtensorflow_1_1ops_1_1_sample_distorted_bounding_box_1ada2c6d0817a82a6dbec40ee9d5182f9b` | `::https://www.tensorflow.org/versions/r1.15/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output` |
| `https://www.tensorflow.org/versions/r1.15/api_docs/cc/class/tensorflow/ops/sample-distorted-bounding-box#classtensorflow_1_1ops_1_1_sample_distorted_bounding_box_1a26d9c8b5c6c30f43253edc3158381339` | `https://www.tensorflow.org/versions/r1.15/api_docs/cc/class/tensorflow/operation#classtensorflow_1_1_operation` |
| `https://www.tensorflow.org/versions/r1.15/api_docs/cc/class/tensorflow/ops/sample-distorted-bounding-box#classtensorflow_1_1ops_1_1_sample_distorted_bounding_box_1a500da32b33dc39f1287669192357709b` | `::https://www.tensorflow.org/versions/r1.15/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output` |

| ### Public static functions ||
|---|---|
| `https://www.tensorflow.org/versions/r1.15/api_docs/cc/class/tensorflow/ops/sample-distorted-bounding-box#classtensorflow_1_1ops_1_1_sample_distorted_bounding_box_1a4f0add4d91089befcaaeeaef7e8708aa(const gtl::ArraySlice< float > & x)` | `https://www.tensorflow.org/versions/r1.15/api_docs/cc/struct/tensorflow/ops/sample-distorted-bounding-box/attrs#structtensorflow_1_1ops_1_1_sample_distorted_bounding_box_1_1_attrs` |
| `https://www.tensorflow.org/versions/r1.15/api_docs/cc/class/tensorflow/ops/sample-distorted-bounding-box#classtensorflow_1_1ops_1_1_sample_distorted_bounding_box_1a6778b4e519eb66d91cfc8cf875a35516(const gtl::ArraySlice< float > & x)` | `https://www.tensorflow.org/versions/r1.15/api_docs/cc/struct/tensorflow/ops/sample-distorted-bounding-box/attrs#structtensorflow_1_1ops_1_1_sample_distorted_bounding_box_1_1_attrs` |
| `https://www.tensorflow.org/versions/r1.15/api_docs/cc/class/tensorflow/ops/sample-distorted-bounding-box#classtensorflow_1_1ops_1_1_sample_distorted_bounding_box_1abe98fbac41e9bb092f94c11111d4602c(int64 x)` | `https://www.tensorflow.org/versions/r1.15/api_docs/cc/struct/tensorflow/ops/sample-distorted-bounding-box/attrs#structtensorflow_1_1ops_1_1_sample_distorted_bounding_box_1_1_attrs` |
| `https://www.tensorflow.org/versions/r1.15/api_docs/cc/class/tensorflow/ops/sample-distorted-bounding-box#classtensorflow_1_1ops_1_1_sample_distorted_bounding_box_1a6516caf5b769f3defd633ad1521fa9ff(float x)` | `https://www.tensorflow.org/versions/r1.15/api_docs/cc/struct/tensorflow/ops/sample-distorted-bounding-box/attrs#structtensorflow_1_1ops_1_1_sample_distorted_bounding_box_1_1_attrs` |
| `https://www.tensorflow.org/versions/r1.15/api_docs/cc/class/tensorflow/ops/sample-distorted-bounding-box#classtensorflow_1_1ops_1_1_sample_distorted_bounding_box_1a2982f9362e414e1427443a0e21aad53c(int64 x)` | `https://www.tensorflow.org/versions/r1.15/api_docs/cc/struct/tensorflow/ops/sample-distorted-bounding-box/attrs#structtensorflow_1_1ops_1_1_sample_distorted_bounding_box_1_1_attrs` |
| `https://www.tensorflow.org/versions/r1.15/api_docs/cc/class/tensorflow/ops/sample-distorted-bounding-box#classtensorflow_1_1ops_1_1_sample_distorted_bounding_box_1ab86d2540a3733d65f994f86810bb85b4(int64 x)` | `https://www.tensorflow.org/versions/r1.15/api_docs/cc/struct/tensorflow/ops/sample-distorted-bounding-box/attrs#structtensorflow_1_1ops_1_1_sample_distorted_bounding_box_1_1_attrs` |
| `https://www.tensorflow.org/versions/r1.15/api_docs/cc/class/tensorflow/ops/sample-distorted-bounding-box#classtensorflow_1_1ops_1_1_sample_distorted_bounding_box_1ad3726dbe014117d519e0ce88aa37e644(bool x)` | `https://www.tensorflow.org/versions/r1.15/api_docs/cc/struct/tensorflow/ops/sample-distorted-bounding-box/attrs#structtensorflow_1_1ops_1_1_sample_distorted_bounding_box_1_1_attrs` |

| ### Structs ||
|---|---|
| [tensorflow::ops::SampleDistortedBoundingBox::Attrs](https://www.tensorflow.org/versions/r1.15/api_docs/cc/struct/tensorflow/ops/sample-distorted-bounding-box/attrs) | Optional attribute setters for [SampleDistortedBoundingBox](https://www.tensorflow.org/versions/r1.15/api_docs/cc/class/tensorflow/ops/sample-distorted-bounding-box#classtensorflow_1_1ops_1_1_sample_distorted_bounding_box). |

## Public attributes

### bboxes

```
::tensorflow::Output bboxes
```

### begin

```
::tensorflow::Output begin
```

### operation

```
Operation operation
```

### size

```
::tensorflow::Output size
```

## Public functions

### SampleDistortedBoundingBox

```
 SampleDistortedBoundingBox(
  const ::tensorflow::Scope & scope,
  ::tensorflow::Input image_size,
  ::tensorflow::Input bounding_boxes
)
```

### SampleDistortedBoundingBox

```
 SampleDistortedBoundingBox(
  const ::tensorflow::Scope & scope,
  ::tensorflow::Input image_size,
  ::tensorflow::Input bounding_boxes,
  const SampleDistortedBoundingBox::Attrs & attrs
)
```

## Public static functions

### AreaRange

```
Attrs AreaRange(
  const gtl::ArraySlice< float > & x
)
```

### AspectRatioRange

```
Attrs AspectRatioRange(
  const gtl::ArraySlice< float > & x
)
```

### MaxAttempts

```
Attrs MaxAttempts(
  int64 x
)
```

### MinObjectCovered

```
Attrs MinObjectCovered(
  float x
)
```

### Seed

```
Attrs Seed(
  int64 x
)
```

### Seed2

```
Attrs Seed2(
  int64 x
)
```

### UseImageIfNoBoundingBoxes

```
Attrs UseImageIfNoBoundingBoxes(
  bool x
)
```