Histogram equalization.

Optional histogram equalization, and refactoring.