Histogram equalization algorithm