Table of contents
1.
What is Image Augmentation?
2.
Need for Image Data Augmentation
3.
Image Augmentation Techniques
3.1.
Original Image
3.2.
Flipping the Image
3.3.
Adjusting Saturation in the Image
3.4.
Cropping the Image
3.5.
Rotating Image by 90 Degrees
3.6.
Brightening the Image
3.7.
Grayscaling the Image
3.8.
Random Image Constrast
3.9.
Random Image Brightness
4.
Frequently Asked Questions
5.
Key Takeaways
Last Updated: Mar 27, 2024

Image Data Augmentation

Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

What is Image Augmentation?

Image Augmentation is the process of making slight modifications to an image to form a new image. The new image formed will have the same properties as the original, with some small tweaks. 

Also Read, Resnet 50 Architecture

Need for Image Data Augmentation

Computer Vision or other Deep Learning projects require large datasets to make accurate predictions. Consider the task of image classification, to classify each image accurately; our model should be trained with as many images as possible.

It is not practical to gather large chunks of data from the internet which suit our needs. So a good alternative would be making slight changes in the available data to form new data.

Image Augmentation Techniques

Original Image

import tensorflow as tf
import matplotlib.pyplot as plt
You can also try this code with Online Python Compiler
Run Code
image = tf.io.read_file("sample_data/tf_CN.png")
image = tf.io.decode_jpeg(image)
plt.figure()
plt.imshow(image)
You can also try this code with Online Python Compiler
Run Code

Output

Flipping the Image

flip = tf.image.flip_left_right(image)
plt.imshow(flip)
You can also try this code with Online Python Compiler
Run Code

Output

Adjusting Saturation in the Image

saturate = tf.image.adjust_saturation(image, 10)
plt.imshow(saturate)
You can also try this code with Online Python Compiler
Run Code

Output

Cropping the Image

crop = tf.image.central_crop(image, central_fraction=0.5)
plt.imshow(crop)
You can also try this code with Online Python Compiler
Run Code

Output

Rotating Image by 90 Degrees

rotate = tf.image.rot90(image)
plt.imshow(rotate)
You can also try this code with Online Python Compiler
Run Code

Output

Brightening the Image

brighten = tf.image.adjust_brightness(image, delta=0.6)
plt.imshow(brighten)
You can also try this code with Online Python Compiler
Run Code

Output

Grayscaling the Image

gray = tf.image.rgb_to_grayscale(image)
plt.imshow(tf.squeeze(gray))
_ = plt.colorbar()
You can also try this code with Online Python Compiler
Run Code

Output

Random Image Constrast

seed = (5, 0)
rand_contrast = tf.image.stateless_random_contrast(image, lower=0.1, upper=0.9, seed=seed)
plt.imshow(rand_contrast)
You can also try this code with Online Python Compiler
Run Code

Output

Random Image Brightness

seed = (5, 0)
rand_brightness = tf.image.stateless_random_brightness(image, max_delta=0.95, seed=seed)
plt.imshow(rand_brightness)
You can also try this code with Online Python Compiler
Run Code

Output

Frequently Asked Questions

Q1. How can you create a Black Image with the same shape as the input image?

Ans. A Black image contains all zeros; hence we can use tf.zeros_like. The tf.zeros_like takes a tensor (input_image) as input & creates a tensor of zeros of the same shape and size.

tensor = tf.constant([[1, 2, 3], [7, 8, 9], [4, 5, 6])

tf.zeros_like(tensor) #[[0, 0, 0], [0, 0, 0], [0, 0, 0]]
You can also try this code with Online Python Compiler
Run Code

Q2. What is ImageDataGenerator?

Ans. ImageDataGenerator is one of the features of tensorflow.keras API. We use it to perform data augmentation, such that we can train our model with different new combinations of data. With ImageDataGenerator, we do not generate new images directly, but the dataset images are transformed dynamically.

Q3. What are image augmentation techniques available in TensorFlow?

Ans. We can augment the image by following ways in TensorFlow:

  • Flipping
  • Changing Saturation
  • Cropping
  • Brightening
  • Grayscaling

Key Takeaways

Congratulations on finishing the blog!! Below, I have some blog suggestions for you. Go ahead and take a look at these informative articles.

In today’s scenario, more & more industries are adapting to AutoML applications in their products; with this rise, it has become clear that AutoML can be the next boon in the technology. Check this article to learn more about AutoML applications.

Also Read - Image Sampling

If you are preparing for the upcoming Campus Placements, don't worry. Coding Ninjas has your back. Visit this link for a carefully crafted and designed course on-campus placements and interview preparation.

Live masterclass