Many DSLR users are familiar with the micro focus adjustments of modern cameras. This adjustment allows the user's calibration of the autofocus result to account for mechanical tolerances, lens behavior or even light conditions in order to achieve better autofocus. The micro adjustment is based on trial and error as the photographer shoots images of a test target with different offsets finding eventually the one that produces the best focus given the camera-lens combination. Some cameras can store lens specific offsets while others can only use one setting for all lenses. The following work has been performed on a Pentax K-7 that allows lens specific offsets for modern lens and one generic offset for all other less "modern" lenses (I won't go into the Pentax specific lingo here...). Everything though still applies to other camera manufactures as long as they support any flavor of micro focus adjustment.
The vast majority of micro focus adjustments are made in a qualitative way, where each test image of a test target is evaluated by "eye" usually using ruler placed in the test scene at 45 degrees with respect to the lens optixal axis. I have been looking for a more quantitative evaluation of the defocus in order to get rid of the ruler and using a 2D target scene as opposed to a 3D one. Each 2D test image is then evaluated by software (contrast, sharpness etc) and scored so that a "coefficient of focusness" can be associated to each test image making the quest for the optimal focus offset a quantitative and objective process. A 2D target can also be a far away object... like a window across the street etc.
Here is the outline of the process, I'll give the details and practical examples for some of my lenses on the K-7 further down. Note: the K-7 allows offsets in the range of -10 to +10 microns (integers only). In Debug mode you can change the master zero point if needed (more details below)
Process Outline:
1) Shoot 11 photos with focus offsets -10,-8,-6,-4,-2,0,2,4,6,8,10 microns (you can shoot more at closer offsets if you want). Also the range is probably different on different cameras.
2) Register (align) all images
3) Load them in software application for crunching
4) Obtain best focus offset.
Here is the detailed process:
Conditions:
- Camera on tripod
- Lens set to max aperture (Faster lenses should provide a more clear cut result). Use manual mode to avoid the camera picking something else than max aperture.
- I shot a scene at infinity (Window across the street in sunlight). However you can use a much closer target if you work indoor or you want to test artificial light. (Some recommends the target to be at a distance at least 10x the focal length in use).
- The target works as a 2D one, you need some contrast in it to be evaluated by the software, no 3D features (rulers, scales etc.). I haven't experimented indoor though so my data is all related to infinity scenes.
- Use mirror lock up (The K-7 has a multiple mirror lock up features, I just used the 2 sec option). This is useful especially with long lenses in order to avoid camera shake blur to be interpreted as out of focus. For very long heavy lenses use a good tripod and put some weight on it (if it has a hook at the bottom of the central column)
- I also used a cable shutter release, or you can use a PC to control the camera etc.
- I shoot raw ( this isn't critical)
- Use the central focus sensor. That's the one I care and unfortunately we can't adjust tilts as far as I know ;-). Obviously you could set up your camera based on any other AF sensor if your application demands it.
Taking the pictures:
- Put your micro adjust offset to -10um and take a shot. Chage the offset to -8 and take a shot and repeat all the way to +10 in steps of 2um. You can do this at a finer step of +1um or even less if your camera allows it. However I prefer doing a +2um step as first pass and if the needed I can do a denser sample around the best focus region as a second pass.
Before I take each shot, I defocus the system (I focus on something much closer than the target or manually move the focus ring). This will insure that the AF will do its job after the offset is changed.
I also rename all the files from let's say "_IGP5673.DNG" to "F300mm_4.5_IGP5673 -10.DNG" so I have the lens ID F300 f/4.5, the raw image name and also the focus offset -10. This is important in the following process so you can keep track of what is what. After shooting, I have a folder on my desktop with the following files:
F300mm_4.5_IGP5673 -10.DNG
F300mm_4.5_IGP5673 -8.DNG
F300mm_4.5_IGP5673 -6.DNG
F300mm_4.5_IGP5673 -4.DNG
F300mm_4.5_IGP5673 -2.DNG
F300mm_4.5_IGP5673 -0.DNG
F300mm_4.5_IGP5673 2.DNG
F300mm_4.5_IGP5673 4.DNG
F300mm_4.5_IGP5673 6.DNG
F300mm_4.5_IGP5673 8.DNG
F300mm_4.5_IGP5673 10.DNG
Note for Pentax K-7 and similar: In the examples below I used F or D or DA lenses so I used the lens specific offset leaving the overall offset at 0. Once all my F/FA/D/DA/A lenses are done I can take some of the older lenses ad adjust the overall focus just for them. This will not affect the single lens offset already created for the other lenses.
Note 2 for Pentax K-7 and similar: When I started calibrating my lenses I found I needed offsets very close to -10. This obviously gave me much less freedom as I was too close to the camera limit. So I entered DEBUG mode and adjusted the camera focus correction to -10um. All lenses now have calibrations in the +/-3um range.
Image processing part 1 (Photoshop workflow):
1) Develop raw images: the 11 raw images to TIF with no sharpening or any other enhancing. The workflow below is for Photoshop but there are plenty of other apps (including may free once) that can do the same.
- From Adobe Bridge, select the 11 images (or whatever number you have shot) and open them all in Camera Raw (Ctrl+R). In Camera raw you will put all the sharpening, color correction etc to 0. I also will crop all the image to just leave the feature I focused on, something in the order of 600x600 pixels (everything else in the image is of no use) (Fig. 2). You don't need to do this on each image one by one, just do on the first image and then synchronize them all in Adobe Camera Raw (Fig. 1). Once all the raw import settings and crop are defined hit the "done" button (don't open these images in PS just yet.
NOTE: I keep the images in 16 bits full resolution in Adobe Camera Raw. Any change will be left in the Photoshop edit.
Fig. 1 - Select all and Synchronize in Adobe Camera Raw
Fig. 2 - The 956x894 pixel crop I used for my Pentax F300mm 4.5 lens
2) Alignment:
The 11 images that I shot may not overlay perfectly especially if I bumped the tripod or if I'm using a long and heavy lens. Since the final analysis will be done automatically, we need all the images to overlap perfectly so that you will analyze the same portion of each picture. This will insure meaningful results. If your images are perfectly aligned then you can skip this alignment step.
In Adobe Bridge, select your 11 images (they should only show as cropped images by now) and go in Tools->Photoshop->Load Files into Photoshop Layers. This will open all the images in a single PS document with 11 layers, one for each raw file.
I would normally convert the document from 16 bits to 8 bits at this point to reduce footprint.
At this point we can register all the images. Select all layers and go to Edit->Auto-Align Layers you can also choose the alignment method and for that you should only pick one that does translation only i.e. X and Y shift only. You don't want to rotate or skew or scale the images as this will introduce interpolation that could in principle affect image quality and fool the out of focus calculation.. For PS CS5 I use "Reposition Only".
NOTE: There are free packages that can align the images for you too (Astrophoto techniques require this and so does panorama stitching so applications are out there)
3) Save the final images:
Once the image has all 11 layers aligned, you can crop further to eliminate areas at the edge where not all layers have data (because the layers have been moved around to overlap). This will be just a slight crop, not necessary but if you are a purist... ;-)
Now in Photoshop save the 11 layers as a single image TIFs. Just use File->Scripts->Export Layers to Files to save them automatically. I like TIFs because there is no quality loss as opposed to jpegs and in what we are doing jpeg artifatcs could be interpreted as out of focus.
Now you'll have something like:
Image processing part 2 (ImageJ workflow):
Now we are ready to analyze our 11 images and find out what's the best offset for this particular lens. To do this I use a nice little (and free) software called ImageJ. This is very used in the scientific community and was born for medical\biological image analysis but has evolved quite a bit and is being found uses in many fields now. This software runs in Java and has a plugin interface that allows people to develop functions as they need. In our case there is little plugin developed by the University of Catania (Italy) that does just what we need, it is called GM_Autofocus. You can find the details here: http://svg.dmi.unict.it/iplab/imagej/Plugins/Autofocus/gmautofocus.htm
The plugin is given is source code (Java) and needs to be compiled. I'm attaching here a compiled version to save you the trouble. Thanks again to his author and his research (Mr. Nicola Ciraulo). "GM_Autofocus.class" is the compiled version of the plugin. Just copy it into the ImageJ plugin folder (I added it to the Analize folder\menu): C:\Program Files (x86)\ImageJ\plugins\Analyze. Depending on your Windows version the ImageJ folder may be in a different place. After you copy the file you need to close and restart ImageJ if you had it open.
At this point you should have a folder with your 11 images and ImageJ and GM_Autofocus installed. To process the images do as follows:
From ImageJ import an image sequence (i.e. open the 11 TIF files):
Pick the first image of the list (in my case the one with an offset of -10 and open it up. ImageJ will come up with:
I like to deselect the "Sort Names numerically" so that my files are opened in the order of the focus offset i.e. from -10 to +10. I leave everything else as default. Once you click OK, ImageJ will open the 11 images into a single window with a scroll bar and a play button that allows you to quickly review all the images.
Now you can open the GM_Autofocus plugin as shown below. This assumes that you copied the plugin file into the Analyze sub-folder as described above.
The following window will come up:
This is the GM_Autofocus interface. In order to do the data crunching you need to select the area you want to analyze on the image sequence window. See below where I drag a yellow box around that particular window feature. You need to select a rectangular area (see the button below the file menu on the ImageJ inerface). Also GM_Autofocus can only deal with 8 bit images that's another reason we converted the raw files from 16 to 8 bits in PS.
Once the selection is done just push the "Load" button on the GM_Autofocus interface and a new window will come up with the results:
On the Y axis you have a "Coefficient of focusness" that is higher if focus is better (more contrast, more sharpness). On the X axis you have the sequence of pictures. If you flick through the data points using the horizontal slide bar you'll see each datapoint highlighted by a little box and at the same time the corresponding image will show in the image sequence window. If the file names were such to allow the import to sort them from -10 to +10 microns of focus offset this graph should show an inverted hyperbole with a max where the best focus offset is at. The focus offset used for the highest scoring picture should be the focus offset to use. In this case it is -2um.
You could narrow down the result by re-shooting fewer images spaced by 1um focus offset around the just found -2um result.
If the graph is too noisy or there is no clear max then something went wrong or the target has not enough contrast or the lens aperture is too slow... it could really be many things. It is always a good practice to flick through the image sequence to see if your eyes agree with the results and if not something needs to be fixed.
If the graph is trending in one direction consistently like a ramp up or down, then the +/-10um range used doesn't contain the best focus, so you may need to go into debug mode in the camera and add a fixed offset to the whole camera.
The images above were for a F300mm f/4.5 tele lens. Below I'm showing the results of a couple of other lenses I calibrated.
This is a DFA100mm macro at 2.8:
In this case best focus is around +2um
Now the DA16-50mm f/2.8 tested at 50mm. This is much closer to an ideal graph then the others, I'm very confident that thsi lens is very well calibrated now!
In this case -2um is the offset. It could be -1um so maybe another test at +/-5um range and 1um step could answer this question.
Another way could be to fit an hyperbole, however we are limited to integer offsets on the Pentax K-7 so I'm not too bothered by super precision results.
Conclusions:
I wanted to describe to the DSLR community an alternative method for AF calibration beside the usual ruler methods. If users will embrace this then there will be more data and an objective comparison of the two methods will be available. I'm not saying which method produces best results as I have no data to support any final decision, so I look forward to see more user results on this. In my specific case I can tell I fixed my front focus\back focus issues on my lenses ;-)
I'm sure more experiments can be done to find more and more suitable targets for this, but they will be simpler 2D ones as opposed to the 3D ruler ones.
One more issue is the focus calibration of very long lenses. For those lenses is very hard to use the ruler method effectively while with the workflow here proposed those lenses calibrated just as easily.
This is a rev. 1 description so I may add more details or comments if I have time.
Addendum
Questions have been raised regarding the AF repeatabilty, and the "exercise in futility" in trying to adjust AF offsets. Also There have been reports of liveview being so much more reliable than regular AF. So I did a quick test, I shot 10 identical images with AF (defocusing all the way before each shot), and did the same with Liveview contrast focus. I did this with two targets, one at infinity and one at 10ft using my 16-50 2.8 at 50mm.
My results from both sets are clear cut. My AF is much more repeatable than live view contrast focus. If you have a camera that doesn't autofocus properly and repeatably than obviously you have less chances to get proper calibration.
Here are the graphs, the first 10 shots are AF, the following 10 are contrast focus LV :
10ft target:
Infinity target:
The lens used above is the 16-50mm 2.8 (at 50mm) and it is an internal motor focus lens. I also wanted to test a lens that focus with the in camera motor like the F300mm 4.5.
The results are not too different. Again, the shots 1 to 10 are focused with regular AF, those 11-20 are focused with Live View contrast focus.
Vincenzo Miceli
12-Jan-2012
As usual you can contact me at:
vincenzomiceli at hotmail.com (preferred)
vincenzo.miceli at gmail.com
Visitors since Jan 2011: