Here is a script I wrote to make focus stacks based on depth-of-field (DOF) with my S5IS camera. I thought I would share it with you in case it could be useful to someone... The script was written for S5IS and should also work as is for S2IS and S3IS. Minor modifications would be required to make it work with other cameras (see below).
I know that many of similar scripts are available around but I could find none that works correctly for my camera. All of the DOF-based scripts I could find (i.e., scripts that use real DOF calculations to make the focus stack rather than proposing fixed focus steps) rely on CHDK calculations of DOF. The problem is that CHDK calculation of DOF is broken on S5IS (and probably other cameras) at focal lengths higher than ~50mm (e.g. DOF calculated is always “inf”).
The script first calculates and displays the optimal number of shots required to get every part of an object in good focus. The user needs only to input the desired nearest and furthest distance to be in focus. These can be determined easily by displaying the subject distance in the DOF calculator (CHDK menu - OSD param - DOF calculator). The script extracts the aperture and focal length and uses these values to make the DOF calculations (without using the commands “get_dof”, etc.). For each shot, the focus distance is increased by the calculated DOF. For the first shot, the distance is increased so that the edge of the region in focus corresponds to the initial position requested. For example, at focal length 6mm and F5.6 (with a coc of 5 um), the script takes 7 shots to get everything in focus from 0.1m to 10m. The shots are taken at 107mm, 127mm, 157mm, 204mm, 290mm, 507mm and 2000mm. You can verify that these shots are taken at the optimal positions to get everything in focus by looking at an
online DOF calculator.
The script is not directly compatible with all cameras because, as far as I know, there is no universal CHDK script function to get the focal length. There is a small section of the script that is clearly identified where changes must be made. Basically, the relation between the function get_zoom and the actual focal length must be known.
Notes:
• Camera must be in Av or M mode and Manual focus must be active. The script will try to set Manual focus automatically if it was not active (tested on S5IS).
• Make sure to disable the option -Safety MF- in Canon menu. It is also better to set continuous shooting mode off, review off, and flash off.
• The script works both with and without a close-up lens (e.g. DCR-250). I indeed use this script mostly for macro shots with a close-up lens where focus depth is very small (see the example in next post).
• A typical value for the circle of confusion is about 30um/(crop factor). Thus, for S5IS (crop factor = 6), a CoC of 5 um should give good results. Smaller CoC increases focus overlap and number of shots, while higher CoC decreases number of shots but can lead to regions not in perfect focus.
• A log file is saved to CHDK/LOGS/LOG_0179.txt.