Histogram
equalization can be used to improve the visual appearance of an image. Peaks in
the image histogram (indicating commonly used grey levels) are widened, while
the valleys are compressed.
Figure:
original image, with corresponding histogram
Figure:
same image, after equalization
Source code available at
http://www.pythonware.com/products/pil/articles/histogram-equalization.htm