The standard way of handling this variation is by performing a normalization of the lightning.
- The easiest way is to use cv::equalizeHist / cvEqualizeHist. This will equilize the contrast over the input images.
- Gamma correction can be done using cv::pow / cvPow
- Difference of Gaussian approach can be done with cv::gaussianBlur / cvSmooth to get two different images then use cv::sub / cvSub to get the Difference of Gaussian.
But there are many other ways (including a Contrast Stretch, a Log filter, CLAHE, or even White Color Balancing or Retinex), that can work better or worse depending on your opinion and your project.
Some guidance: