Source: https://web.stanford.edu/class/ee368/Handouts/Lectures/2014_Spring/4-Histograms/Histogram_Equalization_for_Discrete_Case.pdf