Skip to content

Normalization

DominikKwiatkowski edited this page Apr 12, 2021 · 1 revision

Normalization

Motivation

In our project, normalization is key part of it. All images must be normalized before being used in neural network or by OpenCV. There is many reasons for this, the most important one is to achieve better results in machine learning. In many projects you can achieve better impact on results by data normalization rather than finding better model

Methods

In our project we have multiple image norms, which can be applied by using normalize() function. If you want to use any norm, you should apply proper name parameters, for instance: image = normalization.normalization(image,minmax=True, clahe=True) This is the sample image on which I will show results:

Here I will describe briefly all currently applied norms.

  • min_max_norm and zero_one_norm. They are the simplest and most efficient norms in image processing. They change and evaluate pixel values to be in range 0-255(integer) or 0-1(floating point). As a result images have better quality. Zero_one norm should be used when we want to pass the image as neural network input to ensure better learning process and results. So use min_max if you want to process image with openCV and zero_one in case of neural networks.
  • gray_norm. It converts image to single channel one often called grayscale. Is is very efficient to change image to grayscale when we want to use it with neural networks.
  • histogram_equalization. It is probably most difficult norm I applied. In order to ensure it will work on both grayscale and color images, I made 3 different functions. If image is in grayscale it will only equalize one and only channel. In case of RGB image, it will make histogram equalization in every channel and additionally, it will convert image to YCrCb and equalize Y channel(luminance) to achieve better results. Here I'll show the effect of it on the sample. This equalization makes colors more vivid.
  • centralization. It is a typiccal machine learning operation which should be used after minmax or zero_one norm. In general it calculates mean pixel value and subtrack it from image.
  • clahe. It is a adaptive histogram equalization method that computes multiple histograms of different image areas and uses them to redistribute lightness of whole image. Please follow wikipedia to get more information.

How to add new norm

  1. Write your function in normalization.py. It must take 1 argument(image) and return process one name_norm(image: np.ndarray) -> np.ndarray
  2. Add this norm to normalization arguemtns like this: name: bool = False,
  3. Add this norm to norm_function_dict like this: norm_function_dict[name_norm] = name
  4. Test if it works.
  5. Add it to wiki page.

Clone this wiki locally