As I commented, it is hard do give you a Answer which is fitting your Needs, because we don't know your needs. Still on Stackoverflow is a quite common solution for a problem like this.
To prevent Link corruption I add the Answer here too:
You can convert your Image into a YUV Image and then perform a histogram equalization on the Y channel. After that convert it back to RGB (if needed). With this method, you can normalize the luminance of your Image.
Code in opencv c++ would be:
cv::cvtColor(img, img, CV_BGR2YUV);
std::vector<cv::Mat> channels;
cv::split(img, channels);
cv::equalizeHist(channels[0], channels[0]);
cv::merge(channels, img);
cv::cvtColor(img, img, CV_YUV2BGR);
For more details look at the Link and note: this is not a solution I came up with it was the solution of Aurelius from stackoverflow
It is too "wide" question to get the simple answer. What kind of bad conditions did you mean?
your question is broad, we can't really suggest you sth. if we don't know more details.