So here goes my attempt at quantifying and correcting lighting...
Still using the Daylight1A.JPG source file for testing, let's assume it's a plain white paper test image taken by whatever camera and lighting you have available. (I think it was, outdoors?) This command will convert that file into a grayscale image and dump out some useful numbers that can be hoovered up into automation later:
Code: Select all
convert Daylight1A.JPG -colorspace Gray -verbose info: | grep -E 'min|max|mean'
min: 110 (0.43209)
max: 148 (0.579721)
mean: 134.673 (0.528131)
So now I know that this test image has a brightness range from 43-58%. For now I'm not interested in evaluating the evenness quality of the lighting, so I'll skip generating the autolevel scaled contrast images for now. I just want to make a compositing mask that will even out the scanned image somehow, and after banging my head on the keyboard a while I came up with this command:
Code: Select all
convert Daylight1A.JPG -colorspace Gray -level 58%,43% +level 0%,15% correction-mask.jpg
If I understand correctly this will invert the range, re-scale the range, and shift things around magically to whatever they need to be. (Hey, now I know why they call it imagemagick...) We end up with a very dark image like this:
- correction-mask.jpg (16.49 KiB) Viewed 12752 times
If you run a similar grep command on this new dark image it tells you that the brightness ranges from 0-15%. That's the same brightness range we started with, so it looks promising. We want it shifted down to the dark side because the best way to do a composite brightness correction is by the "screen" method. (I think.) Black is transparent in this process and never darkens, only lighter areas lighten, your other image. In fact if your scanner had perfect lighting the correction mask would come out perfectly black and the scanned image wouldn't be changed by this process because it wouldn't need to be. (Sanity check - that sounds like circular logic, but it isn't... right?)
Ok, so now we assume we have this dark correction image, our optical junk is rock solid so the lighting doesn't really change much between scans, and we've now got a bunch of pages with darkness around the edges because we live in the real world and we don't have perfect lighting. Well now we do that "screen" compositing thingy...
Code: Select all
composite -compose Screen -gravity center correction-mask.jpg Daylight1A.JPG Daylight1A-corrected_brightness.jpg
And it spits out an image like this:
- Daylight1A-corrected_brightness.jpg (18.47 KiB) Viewed 12752 times
And the brightness profile comes out like:
Code: Select all
convert Daylight1A-corrected_brightness.jpg -colorspace Gray -verbose info: | grep -E 'min|max|mean'
min: 131 (0.513573)
max: 149 (0.583368)
mean: 141.149 (0.553527)
Honestly, it still looks like a flat gray box to my eyes. I can't tell the difference unless I load up an image viewer and swap them back and forth quickly.
So a little better but still kind of a failure. Good experiments always fail, don't they? I took it from about a 15% variation in brightness to about 7%, but at least I didn't change the maximum brightness level hardly at all. (less than 0.5%) Maybe a grayscale alpha correction on a color image isn't the best approach. Maybe my math is wrong somewhere or I fat-fingered a command. There's always more to learn and test. Anyway, I need to go try this on a bunch of real pages. I hope anybody following my mental bread crumbs can figure out what I'm trying to explain. I hope a bunch of you out there will show me what I did wrong, so I don't have to figure it out all on my own.
With more experimentation some better target values for max brightness, range, and correction limits should become apparent. How this affects visual contrast or clarity could be a deal breaker. Combined with further post-processing I have hope that this isn't all wasted effort.
Regarding work flow integration, theoretically you could do this lighting calibration process once on your scanner and just save the correction mask image to be applied as often as you want later. Or at least until something in the optical tool chain changes somehow. Maybe start a book session with a pair of blank white pages so that set of images can be calibrated to the particular age of the light bulbs, or whatever else might have an effect that day. Two extra images out of hundreds isn't that much trouble compared to the processing required of astro-photography image stacking.