Monday, August 18, 2008

Part 5: Putting It All Together

In previous posts, we've looked at the Canon G9 point-and-shoot camera's vignetting, geometric distortion, and chromatic aberration. We've also looked at strategies for addressing these issues, primarily using the fulla command from the hugin panorama photo stitcher package.

The fulla command doesn't have a nice friendly GUI interface but it does allow us to put together arbitrary corrections to be applied to large numbers of images without a great deal of effort. Each of the fulla corrections we've explored in previous posts can be combined into a single command addressing vignetting, geometric distortion, and chromatic aberration.

Your workflow sequence is very important. The corrections we've been discussing should be applied to the images before any cropping, resizing, etc. have been done. I always shoot raw so I use ACR or some other tool for "developing" the image to set the correct initial tonality, color temperature, etc. and then export the image in 16-bit TIFF format (lossless unlike JPEG). I apply the image corrections and then bring the corrected version into Photoshop for subsequent processing.

Let's start with a hypothetical file shot on the Canon G9 at 7.4 mm and f/4, and processed from the raw CR2 file into a 16-bit TIFF file called example.tif. To apply my standard corrections for vignetting, geometric distortion, and chromatic aberration, I would use the following command:

fulla -c 1.0398:-0.1155:0.1954:-0.1605 \
-g 0.028:-0.0871:0.0521:1.007 \
-r 0:0:0:1.00024 -b 0:0:0:1.00041 example.tif

(The '\' characters indicate arbitrary line breaks for formatting here. This is actually all one command line.)

The "-c" option gives the polynomial coefficients for correcting vignetting, the "-g" option gives the polynomial coefficients for geometric distortion correction, and the "-r" and "-b" options provided the polynomial coefficients for transverse chromatic aberration correction. (But you already knew that.)

When fulla is done crunching the numbers, it outputs a file with a "_corr" filename suffix. So our example correction would create a new file called example_corr.tif. It will look substantially better than the original with the corrections applied.

Naturally you don't want to have to type in that command every time you process a file so you can create a MSDos batch command file (on Windows) or a Bash script (on Unix systems) to generalize it. Let's say we want to correct arbitrary numbers of files with one command. We can create a batch file like this:


for %%f in (%1) do \
fulla -c 1.0398:-0.1155:0.1954:-0.1605 \
-g 0.028:-0.0871:0.0521:1.007 \
-r 0:0:0:1.00024 -b 0:0:0:1.00041 %%f

(Once again, this should be all on one line in the real batch file.) Assuming you named this something like G9_74_4.bat (because it's only useful for the G9's 7.4 mm f/4 images), you can process all the TIFF files in a directory with a single command:

g9_74_4 *.tif

Unix, Linux, Mac users can create analogous script files using for iterations to do precisely the same thing.

I must mention something about the fulla command here: it's flaky and not mature in some regards. One frustration is that, when it outputs a corrected image, that corrected image has its metadata stored in an unconventional way that is not visible to Photoshop and many other applications. If you're running any kind of responsible workflow, this is not good, but there is a way around the problem.

ExifTool by Phil Harvey is a superbly-done high-function image metadata management tool. It has an extraordinary number of capabilities and it handles them well. If you download the tool, you can use it to save your EXIF (and other metadata) from your image, apply your fulla corrections, and then restore the original metadata in standard format. For example, you can save the metadata for all TIFF files in a subdirectory with this command:

exiftool -o %f.mie -ext tif .

Process your files using the fulla corrections and then restore the metadata to the corrected files.

exiftool -overwrite_original -tagsfromfile %-.5f.mie \
-ext tif .

You can even skip the intial save to MIE file (Meta Information Encapsulation) and simply rewrite the original file's metadata over the fulla output file:

exiftool -overwrite_original -tagsfromfile %-.5f.%e \
example_corr.tif


Finally, if you're really ambitious and have Perl programming skills, you could use the Perl Image::ExifTool package to determine the focal length and f-stop for the image and then do a table lookup to determine which of the fulla option parameters to use. I've done a rudimentary job of this just for the subset of camera settings I almost always use for the Canon G9.

If all these seems like a lot of trouble to correct the occasional image, you're right. It's most worthwhile if you routinely have large numbers of images you wish to optimize; then the use of fulla in batch or script files makes more sense.

If you only do occasional corrections, want something a bit easier to deal with, or want a commercial solution, stay tuned. Next up we'll glance at a couple of alternatives for correcting images that don't require all the up-front work we've been slogging through here.

No comments: