Again, this was created from an assignment. I did it in GNU Octave. But, I want to try doing it in JavaScript.
There are two techniques described here: contrast stretching and histogram equalization. Each techniques has its own usage.
Histogram equalization makes objects easier to distinguish, but can make the image looks "unreal".