An implementation of color balancing as outlined in the Image Processing On Line Journal.
A comparison to GIMP's automatic image enhancements can be found here.