Histogram alignment — it is a method of processing the contrast of an image using an image histogram.
This method usually increases the overall contrast of many images, especially when the usable image data is represented by similar contrast values. By this setting, intensities can be better distributed over the histogram. This allows areas of lower local contrast to receive higher contrast. Histogram flattening does this by effectively distributing the most frequent intensity values. This method is useful for background and foreground images that are bright or dark.
OpenCV has a function for this, cv2.equalizeHist () . Its input is just a grayscale image, and the output is — histogram aligned image.
Below is the Python3 code that implements histogram alignment: