Data Pre-Processing: AI End-to-End Series (Part — 2)

Accredian Publication
4 min readDec 6, 2021

--

By Hiren Rupchandani, Abhinav Jangir, and Ashish Lepcha

In our previous article, we successfully extracted our image data using two different techniques. Now it is time to pre-process these images before they are ready for the model building phase. So, let’s get started:

Data Augmentation

  • It is the technique of introducing diversity in the training data, without collecting any actual new data, by performing simple operations.
  • The most common use case of data augmentation is image augmentation.
  • We can create many new images from a single image using various techniques such as rotation, flipping, shifting/translation, brightness adjustment, scaling, sharpening, etc.
Variations of the same image
  • Modern deep learning algorithms, such as the convolutional neural network, or CNN, can learn features that are invariant to their location in the image.
  • Nevertheless, augmentation can further aid in this transform invariant approach to learning and can aid the model in learning features that are also invariant to transforms such as left-to-right to top-to-bottom ordering, light levels in photographs, and more.
  • Let’ see some of these transformations one by one on the following input image:
Input Image

Translation

An image can be shifted horizontally or vertically by shifting all the pixels of the said image in a particular direction, without causing any changes to the image’s dimensions. This transformation uses causes some part of the image to be clipped out and some new predefined pixels will have to be specified for the opposite region of the clipped part.

For example:

Image shifted by 224 pixels horizontally and vertically

Rotation

This transformation rotates an image in a clockwise direction by an angle between 0 to 360. It also can cause some pixels to be clipped out and create a new region that has to be filled.

For example:

Image Rotated by 90 degrees clockwise

Flipping

We can also flip an image horizontally or vertically by reversing the columns or rows of an image respectively. This doesn’t cause any loss of pixels or the addition of new pixels as we are just reversing either the rows or the columns of an image. Horizontal flips can be useful in our dataset as it causes a perspective shift of where a person is looking at, resulting in entirely new data.

For example:

Horizontally Flipped Image

Zoom

A zoom augmentation randomly zooms the image in and either adds new pixel values around the image or interpolates pixel values.

For example:

Zoomed Image

Brightness Adjustment

The brightness of the image can be augmented by either randomly darkening images, brightening images, or both. The intent is to allow a model to generalize across images trained on different lighting levels.

For example:

Brightened and Darkened Image

RGB to Grayscale

Sometimes there is a need to convert the images into a uniform channel so that it is easier to work with them, so we convert them into grayscale images. This is generally done by taking the mean value of all the channels for a particular pixel and using that new pixel value to represent the image.

RGB to Grayscale conversion

Other Important Processing Steps

Pixel Normalization

Image data is generally in the range of 0–255. But we can scale this to fit between pixel values of the range 0–1, which is generally preferred by neural networks. To do so, we can simply divide each pixel value in an image by 255.

Pixel Centering

It is done to scale pixel values to have a zero mean across all the images in the training set.

Pixel Standardization

It is performed to scale pixel values to have a zero mean and unit variance. Also known as standard Gaussian Distribution, it is beneficial for a neural network to have standardized pixel values for all the images in the dataset.

Resizing

Our network expects an input image with 224x224 pixels, so we need to resize all the images to the mentioned dimension before preparing them for model building.

For example:

Resized Image

So these were the various image augmentation and pre-processing techniques that we can perform before using them as an input for the model.

What’s Next?

In the next article of this series, we will develop a model with the help of our preprocessed data.

Follow us for more upcoming future articles related to Data Science, Machine Learning, and Artificial Intelligence.

Also, Do give us a Clap👏 if you find this article useful as your encouragement catalyzes inspiration for and helps to create more cool stuff like this.

Visit us on https://www.insaid.co/

--

--

Accredian Publication
Accredian Publication

Written by Accredian Publication

One of India’s leading institutions providing world-class Data Science & AI programs for working professionals with a mission to groom Data leaders of tomorrow!

No responses yet