image.md 31.6 KB
Newer Older
1 2
<!-- This file is machine generated: DO NOT EDIT! -->

3
# Images <a class="md-anchor" id="AUTOGENERATED-images"></a>
4

5 6
Note: Functions taking `Tensor` arguments can also take anything accepted by
[`tf.convert_to_tensor`](../../api_docs/python/framework.md#convert_to_tensor).
7

8 9
<!-- TOC-BEGIN This section is generated by neural network: DO NOT EDIT! -->
## Contents
10
### [Images](#AUTOGENERATED-images)
11
* [Encoding and Decoding](#AUTOGENERATED-encoding-and-decoding)
12 13 14 15
  * [`tf.image.decode_jpeg(contents, channels=None, ratio=None, fancy_upscaling=None, try_recover_truncated=None, acceptable_fraction=None, name=None)`](#decode_jpeg)
  * [`tf.image.encode_jpeg(image, format=None, quality=None, progressive=None, optimize_size=None, chroma_downsampling=None, density_unit=None, x_density=None, y_density=None, xmp_metadata=None, name=None)`](#encode_jpeg)
  * [`tf.image.decode_png(contents, channels=None, name=None)`](#decode_png)
  * [`tf.image.encode_png(image, compression=None, name=None)`](#encode_png)
16
* [Resizing](#AUTOGENERATED-resizing)
17 18 19 20 21
  * [`tf.image.resize_images(images, new_height, new_width, method=0)`](#resize_images)
  * [`tf.image.resize_area(images, size, name=None)`](#resize_area)
  * [`tf.image.resize_bicubic(images, size, name=None)`](#resize_bicubic)
  * [`tf.image.resize_bilinear(images, size, name=None)`](#resize_bilinear)
  * [`tf.image.resize_nearest_neighbor(images, size, name=None)`](#resize_nearest_neighbor)
22
* [Cropping](#AUTOGENERATED-cropping)
23 24 25 26 27
  * [`tf.image.resize_image_with_crop_or_pad(image, target_height, target_width)`](#resize_image_with_crop_or_pad)
  * [`tf.image.pad_to_bounding_box(image, offset_height, offset_width, target_height, target_width)`](#pad_to_bounding_box)
  * [`tf.image.crop_to_bounding_box(image, offset_height, offset_width, target_height, target_width)`](#crop_to_bounding_box)
  * [`tf.image.random_crop(image, size, seed=None, name=None)`](#random_crop)
  * [`tf.image.extract_glimpse(input, size, offsets, centered=None, normalized=None, uniform_noise=None, name=None)`](#extract_glimpse)
28
* [Flipping and Transposing](#AUTOGENERATED-flipping-and-transposing)
29 30 31 32 33
  * [`tf.image.flip_up_down(image)`](#flip_up_down)
  * [`tf.image.random_flip_up_down(image, seed=None)`](#random_flip_up_down)
  * [`tf.image.flip_left_right(image)`](#flip_left_right)
  * [`tf.image.random_flip_left_right(image, seed=None)`](#random_flip_left_right)
  * [`tf.image.transpose_image(image)`](#transpose_image)
34
* [Image Adjustments](#AUTOGENERATED-image-adjustments)
35 36 37 38 39
  * [`tf.image.adjust_brightness(image, delta, min_value=None, max_value=None)`](#adjust_brightness)
  * [`tf.image.random_brightness(image, max_delta, seed=None)`](#random_brightness)
  * [`tf.image.adjust_contrast(images, contrast_factor, min_value=None, max_value=None)`](#adjust_contrast)
  * [`tf.image.random_contrast(image, lower, upper, seed=None)`](#random_contrast)
  * [`tf.image.per_image_whitening(image)`](#per_image_whitening)
40 41 42 43


<!-- TOC-END This section was generated by neural network, THANKS FOR READING! -->

44
## Encoding and Decoding <a class="md-anchor" id="AUTOGENERATED-encoding-and-decoding"></a>
45 46 47 48 49 50 51 52 53 54 55 56 57 58

TensorFlow provides Ops to decode and encode JPEG and PNG formats.  Encoded
images are represented by scalar string Tensors, decoded images by 3-D uint8
tensors of shape `[height, width, channels]`.

The encode and decode Ops apply to one image at a time.  Their input and output
are all of variable size.  If you need fixed size images, pass the output of
the decode Ops to one of the cropping and resizing Ops.

Note: The PNG encode and decode Ops support RGBA, but the conversions Ops
presently only support RGB, HSV, and GrayScale.

- - -

59
### `tf.image.decode_jpeg(contents, channels=None, ratio=None, fancy_upscaling=None, try_recover_truncated=None, acceptable_fraction=None, name=None)` <a class="md-anchor" id="decode_jpeg"></a>
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78

Decode a JPEG-encoded image to a uint8 tensor.

The attr `channels` indicates the desired number of color channels for the
decoded image.

Accepted values are:

*   0: Use the number of channels in the JPEG-encoded image.
*   1: output a grayscale image.
*   3: output an RGB image.

If needed, the JPEG-encoded image is transformed to match the requested number
of color channels.

The attr `ratio` allows downscaling the image by an integer factor during
decoding.  Allowed values are: 1, 2, 4, and 8.  This is much faster than
downscaling the image later.

79
##### Args: <a class="md-anchor" id="AUTOGENERATED-args-"></a>
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95


*  <b>contents</b>: A `Tensor` of type `string`. 0-D.  The JPEG-encoded image.
*  <b>channels</b>: An optional `int`. Defaults to `0`.
    Number of color channels for the decoded image.
*  <b>ratio</b>: An optional `int`. Defaults to `1`. Downscaling ratio.
*  <b>fancy_upscaling</b>: An optional `bool`. Defaults to `True`.
    If true use a slower but nicer upscaling of the
    chroma planes (yuv420/422 only).
*  <b>try_recover_truncated</b>: An optional `bool`. Defaults to `False`.
    If true try to recover an image from truncated input.
*  <b>acceptable_fraction</b>: An optional `float`. Defaults to `1`.
    The minimum required fraction of lines before a truncated
    input is accepted.
*  <b>name</b>: A name for the operation (optional).

96
##### Returns: <a class="md-anchor" id="AUTOGENERATED-returns-"></a>
97 98 99 100 101 102

  A `Tensor` of type `uint8`. 3-D with shape `[height, width, channels]`..


- - -

103
### `tf.image.encode_jpeg(image, format=None, quality=None, progressive=None, optimize_size=None, chroma_downsampling=None, density_unit=None, x_density=None, y_density=None, xmp_metadata=None, name=None)` <a class="md-anchor" id="encode_jpeg"></a>
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123

JPEG-encode an image.

`image` is a 3-D uint8 Tensor of shape `[height, width, channels]`.

The attr `format` can be used to override the color format of the encoded
output.  Values can be:

*   `''`: Use a default format based on the number of channels in the image.
*   `grayscale`: Output a grayscale JPEG image.  The `channels` dimension
    of `image` must be 1.
*   `rgb`: Output an RGB JPEG image. The `channels` dimension
    of `image` must be 3.

If `format` is not specified or is the empty string, a default format is picked
in function of the number of channels in `image`:

*   1: Output a grayscale image.
*   3: Output an RGB image.

124
##### Args: <a class="md-anchor" id="AUTOGENERATED-args-"></a>
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149


*  <b>image</b>: A `Tensor` of type `uint8`.
    3-D with shape `[height, width, channels]`.
*  <b>format</b>: An optional `string` from: `"", "grayscale", "rgb"`. Defaults to `""`.
    Per pixel image format.
*  <b>quality</b>: An optional `int`. Defaults to `95`.
    Quality of the compression from 0 to 100 (higher is better and slower).
*  <b>progressive</b>: An optional `bool`. Defaults to `False`.
    If True, create a JPEG that loads progressively (coarse to fine).
*  <b>optimize_size</b>: An optional `bool`. Defaults to `False`.
    If True, spend CPU/RAM to reduce size with no quality change.
*  <b>chroma_downsampling</b>: An optional `bool`. Defaults to `True`.
    See http://en.wikipedia.org/wiki/Chroma_subsampling.
*  <b>density_unit</b>: An optional `string` from: `"in", "cm"`. Defaults to `"in"`.
    Unit used to specify `x_density` and `y_density`:
    pixels per inch (`'in'`) or centimeter (`'cm'`).
*  <b>x_density</b>: An optional `int`. Defaults to `300`.
    Horizontal pixels per density unit.
*  <b>y_density</b>: An optional `int`. Defaults to `300`.
    Vertical pixels per density unit.
*  <b>xmp_metadata</b>: An optional `string`. Defaults to `""`.
    If not empty, embed this XMP metadata in the image header.
*  <b>name</b>: A name for the operation (optional).

150
##### Returns: <a class="md-anchor" id="AUTOGENERATED-returns-"></a>
151 152 153 154 155 156 157

  A `Tensor` of type `string`. 0-D. JPEG-encoded image.



- - -

158
### `tf.image.decode_png(contents, channels=None, name=None)` <a class="md-anchor" id="decode_png"></a>
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174

Decode a PNG-encoded image to a uint8 tensor.

The attr `channels` indicates the desired number of color channels for the
decoded image.

Accepted values are:

*   0: Use the number of channels in the PNG-encoded image.
*   1: output a grayscale image.
*   3: output an RGB image.
*   4: output an RGBA image.

If needed, the PNG-encoded image is transformed to match the requested number
of color channels.

175
##### Args: <a class="md-anchor" id="AUTOGENERATED-args-"></a>
176 177 178 179 180 181 182


*  <b>contents</b>: A `Tensor` of type `string`. 0-D.  The PNG-encoded image.
*  <b>channels</b>: An optional `int`. Defaults to `0`.
    Number of color channels for the decoded image.
*  <b>name</b>: A name for the operation (optional).

183
##### Returns: <a class="md-anchor" id="AUTOGENERATED-returns-"></a>
184 185 186 187 188 189

  A `Tensor` of type `uint8`. 3-D with shape `[height, width, channels]`.


- - -

190
### `tf.image.encode_png(image, compression=None, name=None)` <a class="md-anchor" id="encode_png"></a>
191 192 193 194 195 196 197 198 199 200 201 202 203 204

PNG-encode an image.

`image` is a 3-D uint8 Tensor of shape `[height, width, channels]` where
`channels` is:

*   1: for grayscale.
*   3: for RGB.
*   4: for RGBA.

The ZLIB compression level, `compression`, can be -1 for the PNG-encoder
default or a value from 0 to 9.  9 is the highest compression level, generating
the smallest output, but is slower.

205
##### Args: <a class="md-anchor" id="AUTOGENERATED-args-"></a>
206 207 208 209 210 211 212


*  <b>image</b>: A `Tensor` of type `uint8`.
    3-D with shape `[height, width, channels]`.
*  <b>compression</b>: An optional `int`. Defaults to `-1`. Compression level.
*  <b>name</b>: A name for the operation (optional).

213
##### Returns: <a class="md-anchor" id="AUTOGENERATED-returns-"></a>
214 215 216 217 218

  A `Tensor` of type `string`. 0-D. PNG-encoded image.



219
## Resizing <a class="md-anchor" id="AUTOGENERATED-resizing"></a>
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246

The resizing Ops accept input images as tensors of several types.  They always
output resized images as float32 tensors.

The convenience function [resize_images()](#resize_images) supports both 4-D
and 3-D tensors as input and output.  4-D tensors are for batches of images,
3-D tensors for individual images.

Other resizing Ops only support 3-D individual images as input:
[resize_area](#resize_area), [resize_bicubic](#resize_bicubic),
[resize_bilinear](#resize_bilinear),
[resize_nearest_neighbor](#resize_nearest_neighbor).

Example:

```python
# Decode a JPG image and resize it to 299 by 299.
image = tf.image.decode_jpeg(...)
resized_image = tf.image.resize_bilinear(image, [299, 299])
```

<i>Maybe refer to the Queue examples that show how to add images to a Queue
after resizing them to a fixed size, and how to dequeue batches of resized
images from the Queue.</i>

- - -

247
### `tf.image.resize_images(images, new_height, new_width, method=0)` <a class="md-anchor" id="resize_images"></a>
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264

Resize `images` to `new_width`, `new_height` using the specified `method`.

Resized images will be distorted if their original aspect ratio is not
the same as `new_width`, `new_height`.  To avoid distortions see
[resize_image_with_crop_or_pad](#resize_image_with_crop_or_pad).

`method` can be one of:

*   <b>ResizeMethod.BILINEAR</b>: [Bilinear interpolation.]
    (https://en.wikipedia.org/wiki/Bilinear_interpolation)
*   <b>ResizeMethod.NEAREST_NEIGHBOR</b>: [Nearest neighbor interpolation.]
    (https://en.wikipedia.org/wiki/Nearest-neighbor_interpolation)
*   <b>ResizeMethod.BICUBIC</b>: [Bicubic interpolation.]
    (https://en.wikipedia.org/wiki/Bicubic_interpolation)
*   <b>ResizeMethod.AREA</b>: Area interpolation.

265
##### Args: <a class="md-anchor" id="AUTOGENERATED-args-"></a>
266 267 268 269 270 271 272 273


*  <b>images</b>: 4-D Tensor of shape `[batch, height, width, channels]` or
          3-D Tensor of shape `[height, width, channels]`.
*  <b>new_height</b>: integer.
*  <b>new_width</b>: integer.
*  <b>method</b>: ResizeMethod.  Defaults to `ResizeMethod.BILINEAR`.

274
##### Raises: <a class="md-anchor" id="AUTOGENERATED-raises-"></a>
275 276 277 278 279 280


*  <b>ValueError</b>: if the shape of `images` is incompatible with the
    shape arguments to this function
*  <b>ValueError</b>: if an unsupported resize method is specified.

281
##### Returns: <a class="md-anchor" id="AUTOGENERATED-returns-"></a>
282 283 284 285 286 287 288 289 290 291

  If `images` was 4-D, a 4-D float Tensor of shape
  `[batch, new_height, new_width, channels]`.
  If `images` was 3-D, a 3-D float Tensor of shape
  `[new_height, new_width, channels]`.



- - -

292
### `tf.image.resize_area(images, size, name=None)` <a class="md-anchor" id="resize_area"></a>
293 294 295 296 297

Resize `images` to `size` using area interpolation.

Input images can be of different types but output images are always float.

298
##### Args: <a class="md-anchor" id="AUTOGENERATED-args-"></a>
299 300 301 302 303 304 305 306


*  <b>images</b>: A `Tensor`. Must be one of the following types: `uint8`, `int8`, `int32`, `float32`, `float64`.
    4-D with shape `[batch, height, width, channels]`.
*  <b>size</b>: A 1-D int32 Tensor of 2 elements: `new_height, new_width`.  The
    new size for the images.
*  <b>name</b>: A name for the operation (optional).

307
##### Returns: <a class="md-anchor" id="AUTOGENERATED-returns-"></a>
308 309 310 311 312 313 314

  A `Tensor` of type `float32`. 4-D with shape
  `[batch, new_height, new_width, channels]`.


- - -

315
### `tf.image.resize_bicubic(images, size, name=None)` <a class="md-anchor" id="resize_bicubic"></a>
316 317 318 319 320

Resize `images` to `size` using bicubic interpolation.

Input images can be of different types but output images are always float.

321
##### Args: <a class="md-anchor" id="AUTOGENERATED-args-"></a>
322 323 324 325 326 327 328 329


*  <b>images</b>: A `Tensor`. Must be one of the following types: `uint8`, `int8`, `int32`, `float32`, `float64`.
    4-D with shape `[batch, height, width, channels]`.
*  <b>size</b>: A 1-D int32 Tensor of 2 elements: `new_height, new_width`.  The
    new size for the images.
*  <b>name</b>: A name for the operation (optional).

330
##### Returns: <a class="md-anchor" id="AUTOGENERATED-returns-"></a>
331 332 333 334 335 336 337

  A `Tensor` of type `float32`. 4-D with shape
  `[batch, new_height, new_width, channels]`.


- - -

338
### `tf.image.resize_bilinear(images, size, name=None)` <a class="md-anchor" id="resize_bilinear"></a>
339 340 341 342 343

Resize `images` to `size` using bilinear interpolation.

Input images can be of different types but output images are always float.

344
##### Args: <a class="md-anchor" id="AUTOGENERATED-args-"></a>
345 346 347 348 349 350 351 352


*  <b>images</b>: A `Tensor`. Must be one of the following types: `uint8`, `int8`, `int32`, `float32`, `float64`.
    4-D with shape `[batch, height, width, channels]`.
*  <b>size</b>: A 1-D int32 Tensor of 2 elements: `new_height, new_width`.  The
    new size for the images.
*  <b>name</b>: A name for the operation (optional).

353
##### Returns: <a class="md-anchor" id="AUTOGENERATED-returns-"></a>
354 355 356 357 358 359 360

  A `Tensor` of type `float32`. 4-D with shape
  `[batch, new_height, new_width, channels]`.


- - -

361
### `tf.image.resize_nearest_neighbor(images, size, name=None)` <a class="md-anchor" id="resize_nearest_neighbor"></a>
362 363 364 365 366

Resize `images` to `size` using nearest neighbor interpolation.

Input images can be of different types but output images are always float.

367
##### Args: <a class="md-anchor" id="AUTOGENERATED-args-"></a>
368 369 370 371 372 373 374 375


*  <b>images</b>: A `Tensor`. Must be one of the following types: `uint8`, `int8`, `int32`, `float32`, `float64`.
    4-D with shape `[batch, height, width, channels]`.
*  <b>size</b>: A 1-D int32 Tensor of 2 elements: `new_height, new_width`.  The
    new size for the images.
*  <b>name</b>: A name for the operation (optional).

376
##### Returns: <a class="md-anchor" id="AUTOGENERATED-returns-"></a>
377 378 379 380 381 382 383

  A `Tensor`. Has the same type as `images`. 4-D with shape
  `[batch, new_height, new_width, channels]`.




384
## Cropping <a class="md-anchor" id="AUTOGENERATED-cropping"></a>
385 386 387

- - -

388
### `tf.image.resize_image_with_crop_or_pad(image, target_height, target_width)` <a class="md-anchor" id="resize_image_with_crop_or_pad"></a>
389 390 391 392 393 394 395 396 397 398 399 400

Crops and/or pads an image to a target width and height.

Resizes an image to a target width and height by either centrally
cropping the image or padding it evenly with zeros.

If `width` or `height` is greater than the specified `target_width` or
`target_height` respectively, this op centrally crops along that dimension.
If `width` or `height` is smaller than the specified `target_width` or
`target_height` respectively, this op centrally pads with 0 along that
dimension.

401
##### Args: <a class="md-anchor" id="AUTOGENERATED-args-"></a>
402 403 404 405 406 407


*  <b>image</b>: 3-D tensor of shape [height, width, channels]
*  <b>target_height</b>: Target height.
*  <b>target_width</b>: Target width.

408
##### Raises: <a class="md-anchor" id="AUTOGENERATED-raises-"></a>
409 410 411 412


*  <b>ValueError</b>: if `target_height` or `target_width` are zero or negative.

413
##### Returns: <a class="md-anchor" id="AUTOGENERATED-returns-"></a>
414 415 416 417 418 419 420 421

  Cropped and/or padded image of shape
  `[target_height, target_width, channels]`



- - -

422
### `tf.image.pad_to_bounding_box(image, offset_height, offset_width, target_height, target_width)` <a class="md-anchor" id="pad_to_bounding_box"></a>
423 424 425 426 427 428 429 430 431 432

Pad `image` with zeros to the specified `height` and `width`.

Adds `offset_height` rows of zeros on top, `offset_width` columns of
zeros on the left, and then pads the image on the bottom and right
with zeros until it has dimensions `target_height`, `target_width`.

This op does nothing if `offset_*` is zero and the image already has size
`target_height` by `target_width`.

433
##### Args: <a class="md-anchor" id="AUTOGENERATED-args-"></a>
434 435 436 437 438 439 440 441


*  <b>image</b>: 3-D tensor with shape `[height, width, channels]`
*  <b>offset_height</b>: Number of rows of zeros to add on top.
*  <b>offset_width</b>: Number of columns of zeros to add on the left.
*  <b>target_height</b>: Height of output image.
*  <b>target_width</b>: Width of output image.

442
##### Returns: <a class="md-anchor" id="AUTOGENERATED-returns-"></a>
443 444 445

  3-D tensor of shape `[target_height, target_width, channels]`

446
##### Raises: <a class="md-anchor" id="AUTOGENERATED-raises-"></a>
447 448 449 450 451 452 453 454


*  <b>ValueError</b>: If the shape of `image` is incompatible with the `offset_*` or
    `target_*` arguments


- - -

455
### `tf.image.crop_to_bounding_box(image, offset_height, offset_width, target_height, target_width)` <a class="md-anchor" id="crop_to_bounding_box"></a>
456 457 458 459 460 461 462 463

Crops an image to a specified bounding box.

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'.

464
##### Args: <a class="md-anchor" id="AUTOGENERATED-args-"></a>
465 466 467 468 469 470 471 472 473 474


*  <b>image</b>: 3-D tensor with shape `[height, width, channels]`
*  <b>offset_height</b>: Vertical coordinate of the top-left corner of the result in
                 the input.
*  <b>offset_width</b>: Horizontal coordinate of the top-left corner of the result in
                the input.
*  <b>target_height</b>: Height of the result.
*  <b>target_width</b>: Width of the result.

475
##### Returns: <a class="md-anchor" id="AUTOGENERATED-returns-"></a>
476 477 478

  3-D tensor of image with shape `[target_height, target_width, channels]`

479
##### Raises: <a class="md-anchor" id="AUTOGENERATED-raises-"></a>
480 481 482 483 484 485 486 487


*  <b>ValueError</b>: If the shape of `image` is incompatible with the `offset_*` or
  `target_*` arguments


- - -

488
### `tf.image.random_crop(image, size, seed=None, name=None)` <a class="md-anchor" id="random_crop"></a>
489 490 491 492 493 494

Randomly crops `image` to size `[target_height, target_width]`.

The offset of the output within `image` is uniformly random. `image` always
fully contains the result.

495
##### Args: <a class="md-anchor" id="AUTOGENERATED-args-"></a>
496 497 498 499


*  <b>image</b>: 3-D tensor of shape `[height, width, channels]`
*  <b>size</b>: 1-D tensor with two elements, specifying target `[height, width]`
500 501 502
*  <b>seed</b>: A Python integer. Used to create a random seed. See
    [`set_random_seed`](../../api_docs/python/constant_op.md#set_random_seed)
    for behavior.
503 504
*  <b>name</b>: A name for this operation (optional).

505
##### Returns: <a class="md-anchor" id="AUTOGENERATED-returns-"></a>
506 507 508 509 510 511

  A cropped 3-D tensor of shape `[target_height, target_width, channels]`.


- - -

512
### `tf.image.extract_glimpse(input, size, offsets, centered=None, normalized=None, uniform_noise=None, name=None)` <a class="md-anchor" id="extract_glimpse"></a>
513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532

Extracts a glimpse from the input tensor.

Returns a set of windows called glimpses extracted at location `offsets`
from the input tensor. If the windows only partially overlaps the inputs, the
non overlapping areas will be filled with random noise.

The result is a 4-D tensor of shape `[batch_size, glimpse_height,
glimpse_width, channels]`. The channels and batch dimensions are the same as that
of the input tensor. The height and width of the output windows are
specified in the `size` parameter.

The argument `normalized` and `centered` controls how the windows are built:
* If the coordinates are normalized but not centered, 0.0 and 1.0
  correspond to the minimum and maximum of each height and width dimension.
* If the coordinates are both normalized and centered, they range from -1.0 to
  1.0. The coordinates (-1.0, -1.0) correspond to the upper left corner, the
  lower right corner is located at  (1.0, 1.0) and the center is at (0, 0).
* If the coordinates are not normalized they are interpreted as numbers of pixels.

533
##### Args: <a class="md-anchor" id="AUTOGENERATED-args-"></a>
534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555


*  <b>input</b>: A `Tensor` of type `float32`.
    A 4-D float tensor of shape `[batch_size, height, width, channels]`.
*  <b>size</b>: A `Tensor` of type `int32`.
    A 1-D tensor of 2 elements containing the size of the glimpses to extract.
    The glimpse height must be specified first, following by the glimpse width.
*  <b>offsets</b>: A `Tensor` of type `float32`.
    A 2-D integer tensor of shape `[batch_size, 2]` containing the x, y
    locations of the center of each window.
*  <b>centered</b>: An optional `bool`. Defaults to `True`.
    indicates if the offset coordinates are centered relative to
    the image, in which case the (0, 0) offset is relative to the center of the
    input images. If false, the (0,0) offset corresponds to the upper left corner
    of the input images.
*  <b>normalized</b>: An optional `bool`. Defaults to `True`.
    indicates if the offset coordinates are normalized.
*  <b>uniform_noise</b>: An optional `bool`. Defaults to `True`.
    indicates if the noise should be generated using a
    uniform distribution or a gaussian distribution.
*  <b>name</b>: A name for the operation (optional).

556
##### Returns: <a class="md-anchor" id="AUTOGENERATED-returns-"></a>
557 558 559 560 561 562 563

  A `Tensor` of type `float32`.
  A tensor representing the glimpses `[batch_size, glimpse_height,
  glimpse_width, channels]`.



564
## Flipping and Transposing <a class="md-anchor" id="AUTOGENERATED-flipping-and-transposing"></a>
565 566 567

- - -

568
### `tf.image.flip_up_down(image)` <a class="md-anchor" id="flip_up_down"></a>
569 570 571 572 573 574 575 576

Flip an image horizontally (upside down).

Outputs the contents of `image` flipped along the first dimension, which is
`height`.

See also `reverse()`.

577
##### Args: <a class="md-anchor" id="AUTOGENERATED-args-"></a>
578 579 580 581


*  <b>image</b>: A 3-D tensor of shape `[height, width, channels].`

582
##### Returns: <a class="md-anchor" id="AUTOGENERATED-returns-"></a>
583 584 585

  A 3-D tensor of the same type and shape as `image`.

586
##### Raises: <a class="md-anchor" id="AUTOGENERATED-raises-"></a>
587 588 589 590 591 592 593


*  <b>ValueError</b>: if the shape of `image` not supported.


- - -

594
### `tf.image.random_flip_up_down(image, seed=None)` <a class="md-anchor" id="random_flip_up_down"></a>
595 596 597 598 599 600

Randomly flips an image vertically (upside down).

With a 1 in 2 chance, outputs the contents of `image` flipped along the first
dimension, which is `height`.  Otherwise output the image as-is.

601
##### Args: <a class="md-anchor" id="AUTOGENERATED-args-"></a>
602 603 604


*  <b>image</b>: A 3-D tensor of shape `[height, width, channels].`
605 606 607
*  <b>seed</b>: A Python integer. Used to create a random seed. See
    [`set_random_seed`](../../api_docs/python/constant_op.md#set_random_seed)
    for behavior.
608

609
##### Returns: <a class="md-anchor" id="AUTOGENERATED-returns-"></a>
610 611 612

  A 3-D tensor of the same type and shape as `image`.

613
##### Raises: <a class="md-anchor" id="AUTOGENERATED-raises-"></a>
614 615 616 617 618 619 620 621


*  <b>ValueError</b>: if the shape of `image` not supported.



- - -

622
### `tf.image.flip_left_right(image)` <a class="md-anchor" id="flip_left_right"></a>
623 624 625 626 627 628 629 630

Flip an image horizontally (left to right).

Outputs the contents of `image` flipped along the second dimension, which is
`width`.

See also `reverse()`.

631
##### Args: <a class="md-anchor" id="AUTOGENERATED-args-"></a>
632 633 634 635


*  <b>image</b>: A 3-D tensor of shape `[height, width, channels].`

636
##### Returns: <a class="md-anchor" id="AUTOGENERATED-returns-"></a>
637 638 639

  A 3-D tensor of the same type and shape as `image`.

640
##### Raises: <a class="md-anchor" id="AUTOGENERATED-raises-"></a>
641 642 643 644 645 646 647


*  <b>ValueError</b>: if the shape of `image` not supported.


- - -

648
### `tf.image.random_flip_left_right(image, seed=None)` <a class="md-anchor" id="random_flip_left_right"></a>
649 650 651 652 653 654

Randomly flip an image horizontally (left to right).

With a 1 in 2 chance, outputs the contents of `image` flipped along the
second dimension, which is `width`.  Otherwise output the image as-is.

655
##### Args: <a class="md-anchor" id="AUTOGENERATED-args-"></a>
656 657 658


*  <b>image</b>: A 3-D tensor of shape `[height, width, channels].`
659 660 661
*  <b>seed</b>: A Python integer. Used to create a random seed. See
    [`set_random_seed`](../../api_docs/python/constant_op.md#set_random_seed)
    for behavior.
662

663
##### Returns: <a class="md-anchor" id="AUTOGENERATED-returns-"></a>
664 665 666

  A 3-D tensor of the same type and shape as `image`.

667
##### Raises: <a class="md-anchor" id="AUTOGENERATED-raises-"></a>
668 669 670 671 672 673 674 675


*  <b>ValueError</b>: if the shape of `image` not supported.



- - -

676
### `tf.image.transpose_image(image)` <a class="md-anchor" id="transpose_image"></a>
677 678 679 680 681

Transpose an image by swapping the first and second dimension.

See also `transpose()`.

682
##### Args: <a class="md-anchor" id="AUTOGENERATED-args-"></a>
683 684 685 686


*  <b>image</b>: 3-D tensor of shape `[height, width, channels]`

687
##### Returns: <a class="md-anchor" id="AUTOGENERATED-returns-"></a>
688 689 690

  A 3-D tensor of shape `[width, height, channels]`

691
##### Raises: <a class="md-anchor" id="AUTOGENERATED-raises-"></a>
692 693 694 695 696 697


*  <b>ValueError</b>: if the shape of `image` not supported.



698
## Image Adjustments <a class="md-anchor" id="AUTOGENERATED-image-adjustments"></a>
699 700 701 702 703 704 705 706

TensorFlow provides functions to adjust images in various ways: brightness,
contrast, hue, and saturation.  Each adjustment can be done with predefined
parameters or with random parameters picked from predefined intervals.  Random
adjustments are often useful to expand a training set and reduce overfitting.

- - -

707
### `tf.image.adjust_brightness(image, delta, min_value=None, max_value=None)` <a class="md-anchor" id="adjust_brightness"></a>
708 709 710 711 712 713 714 715 716 717 718

Adjust the brightness of RGB or Grayscale images.

The value `delta` is added to all components of the tensor `image`. `image`
and `delta` are cast to `float` before adding, and the resulting values are
clamped to `[min_value, max_value]`. Finally, the result is cast back to
`images.dtype`.

If `min_value` or `max_value` are not given, they are set to the minimum and
maximum allowed values for `image.dtype` respectively.

719
##### Args: <a class="md-anchor" id="AUTOGENERATED-args-"></a>
720 721 722 723 724 725 726


*  <b>image</b>: A tensor.
*  <b>delta</b>: A scalar. Amount to add to the pixel values.
*  <b>min_value</b>: Minimum value for output.
*  <b>max_value</b>: Maximum value for output.

727
##### Returns: <a class="md-anchor" id="AUTOGENERATED-returns-"></a>
728 729 730 731 732 733

  A tensor of the same shape and type as `image`.


- - -

734
### `tf.image.random_brightness(image, max_delta, seed=None)` <a class="md-anchor" id="random_brightness"></a>
735 736 737 738 739 740 741 742 743 744

Adjust the brightness of images by a random factor.

Equivalent to `adjust_brightness()` using a `delta` randomly picked in the
interval `[-max_delta, max_delta)`.

Note that `delta` is picked as a float. Because for integer type images,
the brightness adjusted result is rounded before casting, integer images may
have modifications in the range `[-max_delta,max_delta]`.

745
##### Args: <a class="md-anchor" id="AUTOGENERATED-args-"></a>
746 747 748 749


*  <b>image</b>: 3-D tensor of shape `[height, width, channels]`.
*  <b>max_delta</b>: float, must be non-negative.
750 751 752
*  <b>seed</b>: A Python integer. Used to create a random seed. See
    [`set_random_seed`](../../api_docs/python/constant_op.md#set_random_seed)
    for behavior.
753

754
##### Returns: <a class="md-anchor" id="AUTOGENERATED-returns-"></a>
755 756 757

  3-D tensor of images of shape `[height, width, channels]`

758
##### Raises: <a class="md-anchor" id="AUTOGENERATED-raises-"></a>
759 760 761 762 763 764 765 766


*  <b>ValueError</b>: if max_delta is negative.



- - -

767
### `tf.image.adjust_contrast(images, contrast_factor, min_value=None, max_value=None)` <a class="md-anchor" id="adjust_contrast"></a>
768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787

Adjust contrast of RGB or grayscale images.

`images` is a tensor of at least 3 dimensions.  The last 3 dimensions are
interpreted as `[height, width, channels]`.  The other dimensions only
represent a collection of images, such as `[batch, height, width, channels].`

Contrast is adjusted independently for each channel of each image.

For each channel, this Op first computes the mean of the image pixels in the
channel and then adjusts each component `x` of each pixel to
`(x - mean) * contrast_factor + mean`.

The adjusted values are then clipped to fit in the `[min_value, max_value]`
interval. If `min_value` or `max_value` is not given, it is replaced with the
minimum and maximum values for the data type of `images` respectively.

The contrast-adjusted image is always computed as `float`, and it is
cast back to its original type after clipping.

788
##### Args: <a class="md-anchor" id="AUTOGENERATED-args-"></a>
789 790 791 792 793 794 795


*  <b>images</b>: Images to adjust.  At least 3-D.
*  <b>contrast_factor</b>: A float multiplier for adjusting contrast.
*  <b>min_value</b>: Minimum value for clipping the adjusted pixels.
*  <b>max_value</b>: Maximum value for clipping the adjusted pixels.

796
##### Returns: <a class="md-anchor" id="AUTOGENERATED-returns-"></a>
797 798 799

  The constrast-adjusted image or images.

800
##### Raises: <a class="md-anchor" id="AUTOGENERATED-raises-"></a>
801 802 803 804 805 806 807


*  <b>ValueError</b>: if the arguments are invalid.


- - -

808
### `tf.image.random_contrast(image, lower, upper, seed=None)` <a class="md-anchor" id="random_contrast"></a>
809 810 811 812 813 814

Adjust the contrase of an image by a random factor.

Equivalent to `adjust_constrast()` but uses a `contrast_factor` randomly
picked in the interval `[lower, upper]`.

815
##### Args: <a class="md-anchor" id="AUTOGENERATED-args-"></a>
816 817 818 819 820


*  <b>image</b>: 3-D tensor of shape `[height, width, channels]`.
*  <b>lower</b>: float.  Lower bound for the random contrast factor.
*  <b>upper</b>: float.  Upper bound for the random contrast factor.
821 822 823
*  <b>seed</b>: A Python integer. Used to create a random seed. See
    [`set_random_seed`](../../api_docs/python/constant_op.md#set_random_seed)
    for behavior.
824

825
##### Returns: <a class="md-anchor" id="AUTOGENERATED-returns-"></a>
826 827 828

  3-D tensor of shape `[height, width, channels]`.

829
##### Raises: <a class="md-anchor" id="AUTOGENERATED-raises-"></a>
830 831 832 833 834 835 836 837


*  <b>ValueError</b>: if `upper <= lower` or if `lower < 0`.



- - -

838
### `tf.image.per_image_whitening(image)` <a class="md-anchor" id="per_image_whitening"></a>
839 840 841 842 843 844 845 846 847 848 849 850 851 852

Linearly scales `image` to have zero mean and unit norm.

This op computes `(x - mean) / adjusted_stddev`, where `mean` is the average
of all values in image, and
`adjusted_stddev = max(stddev, 1.0/srqt(image.NumElements()))`.

`stddev` is the standard deviation of all values in `image`. It is capped
away from zero to protect against division by 0 when handling uniform images.

Note that this implementation is limited:
*  It only whitens based on the statistics of an individual image.
*  It does not take into account the covariance structure.

853
##### Args: <a class="md-anchor" id="AUTOGENERATED-args-"></a>
854 855 856 857


*  <b>image</b>: 3-D tensor of shape `[height, width, channels]`.

858
##### Returns: <a class="md-anchor" id="AUTOGENERATED-returns-"></a>
859 860 861

  The whitened image with same shape as `image`.

862
##### Raises: <a class="md-anchor" id="AUTOGENERATED-raises-"></a>
863 864 865 866 867


*  <b>ValueError</b>: if the shape of 'image' is incompatible with this function.