TF‘s Image Processing Module (Part 2)
Learn to apply color transformations and color space conversion using TF’s tf.image module.
We'll cover the following...
The TF framework provides us with the tf.image module to perform image processing. This module consists of numerous image processing functions for geometric and color transformations. Let’s explore the functions of the tf.image module for color transformations.
Color transformations
Color transformations change the pixel values of images without altering their geometry. Some of the color transformations are given below.
Brightness adjustment
The tf.image.adjust_brightness function adjusts image brightness according to the value of the delta argument. A delta=0.3 value adds 30% brightness to the image. 
The tf.image.random_brightness function adjusts the image brightness using a random factor max_delta. This function picks the delta in the interval [-max_delta, max_delta). 
import matplotlib.pyplot as pltimport numpy as npimport tensorflow as tfimport tensorflow_datasets as tfdsimage_path = '/usr/local/notebooks/datasets/baboon.png'image = plt.imread(image_path)adjusted_brightness = tf.image.adjust_brightness(image, delta = 0.1)random_brightness = tf.image.random_brightness(image, max_delta = 0.2)# Displaying imagesplt.subplot(1, 2, 1)plt.imshow(tf.clip_by_value(adjusted_brightness, 0, 1)) # Clipping values outside the (0, 1) rangeplt.title('Adjusted brightness')plt.axis('off')plt.subplot(1, 2, 2)plt.imshow(tf.clip_by_value(random_brightness, 0, 1))plt.title('Random brightness')plt.axis('off')plt.savefig('output/output_image.png', dpi = 300)
Contrast and gamma adjustment
The following are some of the functions of the tf.image module for contrast and gamma adjustment:
- The - tf.image.adjust_contrastfunction adjusts image contrast by computing the mean values of pixels in each image channel. It uses the- contrast_factorargument as- ...