I ran into a different issue while trying to make an app to scan color coded notes in college. The colors skewed from the top to the bottom of the page making it hard to reliably tell blue pens from green ones. At some point I should look at it again.
Assuming the white background skews in the same way a good trick is to make a copy of the image, blur it VERY widely, and divide the original image by the blurred version. This essentially removes any low frequency color/brightness shifts. I'll often use it to get rid of shadows etc on photographed paper, but it should work for a color gradient all the same.