Choose one of the images that has good levels. Use the imagemagick script histmatch to adjust the histograms of the other images to match that one's; or use bcmatch to adjust only brightness and contrast.
Call e.g. histmatch good_in.bmp ith_in.bmp ith_out.bmp
from within a loop, in whatever language you like: bash, perl, python, ruby, etc.