Tuesday, September 11, 2018

Image Equalization and Normalization

Preprocessing data before training is a very important and critical part for machine Learning. In computer vision, Image Equalization and Normalization are confusing, but very different. I want to make clear out the difference.

In this article, I am going to normalize and equalize the pic below that Samurai visited Egypt in 1864. This image is really old and blurry. When you normalize and equalize, the image becomes clearer to see.

Base image


Normalized image


Equalized image


Let's look at the difference between base and normalized image. The figures below describes the distribution of pixel values and accumulation of those values. The base image shows the pixel values are in the span between 145 and 201 while the normalized image 0 and 255. The normalized distribution is transformed from the normal distribution by using linear normalization method that equally expands intensity values throughout the image. On the other hand, the equalized image shows the slope of accumulation of the pixel distribution values is linear. This means the base image is transformed so each intensity level is found equally in the range 0-255.

Base image

Normalized image

Equalized image


For normalization, I used a formula of linear normalization. The code below obtains both base image and normalized image.
For equalization, I used OpenCV function cv2.equalizeHist()