Module: tf.image

Image ops.

The tf.image module contains various functions for image processing and decoding-encoding Ops.

Many of the encoding/decoding functions are also available in the core tf.io module.

Image processing

Resizing

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

The convenience function tf.image.resize 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.

Resized images will be distorted if their original aspect ratio is not the same as size. To avoid distortions see tf.image.resize_with_pad.

The Class tf.image.ResizeMethod provides various resize methods like bilinear, nearest_neighbor.

Converting Between Colorspaces

Image ops work either on individual images or on batches of images, depending on the shape of their input Tensor.

If 3-D, the shape is [height, width, channels], and the Tensor represents one image. If 4-D, the shape is [batch_size, height, width, channels], and the Tensor represents batch_size images.

Currently, channels can usefully be 1, 2, 3, or 4. Single-channel images are grayscale, images with 3 channels are encoded as either RGB or HSV. Images with 2 or 4 channels include an alpha channel, which has to be stripped from the image before passing the image to most image processing functions (and can be re-attached later).

Internally, images are either stored in as one float32 per channel per pixel (implicitly, values are assumed to lie in [0,1)) or one uint8 per channel per pixel (values are assumed to lie in [0,255]).

TensorFlow can convert between images in RGB or HSV or YIQ.

Image Adjustments

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.

If several adjustments are chained it is advisable to minimize the number of redundant conversions by first converting the images to the most natural data type and representation.

Working with Bounding Boxes