A complete guide to automatic focus stacking with CHDK and a Canon A2400
Focus stacking is pretty awesome, and perfect to take your model photos to the next level. The only problem is that it's pretty slow and time consuming, or expensive, or both. Luckily there is a way to make it quick, easy, painless... and it's cheap. What follows is my approach to focus stacking, built around a bunch of open source/free software.
1: Get a compatible camera
First step is to acquire a compatible camera. Take a look at the Supported Hardware sidebar on the CHDK home page and select a camera. I chose a Canon a2400, which is a nice new, extra small point-and-shoot camera. It has optical image stabilisation which is nice, but most importantly it's small and has a good macro mode. I managed to pick one up brand new for under $NZ100, delivered to my door.
2: Set up CHDK
Using Stick, we can pretty quickly set up CHDK for your camera.
- Take a photo with your camera.
- Download Stick from its download page.
- Drop said photo onto Stick.
- Stick will download the right version of CHDK and set up your SD card for you.
3: Install my focus stacking script
To make things nice and quick, we'll use a script I developed to automate the process. Copy the following code to a file called dof.bas in the CHDK/SCRIPTS folder on your SD card.
@title DOF stackmaker rem Written by Michael Adams, released as public domain code. rem http://www.utrainia.com/87-a-complete-guide-to-automatic-focus-stacking-with-chdk-and-a-canon-a2400 @param a end dist (x1) @default a 0 @range a 0 10 @param b end dist (x10) @default b 0 @range b 0 10 @param c end dist (x100) @default c 2 @range c 0 10 @param d shoot 1x infinity @default d 0 @range d 0 1 get_zoom z if z>0 then gosub "nozoom" let s = get_focus let e = 100*c+10*b+a if e < s then gosub "bad_focus_dist" print "Starting from: ", s print "Ending at: ", e sleep 1000 gosub "countdown" rem start at 2mm steps, increase as focusing further back as DoF changes as we move focus point let i = 2 rem starting focus distance let f = s let n = 1 :mainloop print "Number: ", n print "Focus: ", f set_focus f shoot rem finished shooting if f > e then goto "exitloop" rem calculate the focus. take more shots at close end, step more at larger distances if f >= 500 then let i = 20 if f < 500 then let i = 18 if f < 400 then let i = 17 if f < 350 then let i = 16 if f < 300 then let i = 15 if f < 280 then let i = 14 if f < 260 then let i = 13 if f < 240 then let i = 12 if f < 220 then let i = 11 if f < 200 then let i = 10 if f < 180 then let i = 9 if f < 160 then let i = 8 if f < 140 then let i = 7 if f < 120 then let i = 6 if f < 100 then let i = 5 if f < 80 then let i = 3 if f < 60 then let i = 2 let f = f + i let n = n + 1 goto "mainloop" :exitloop rem shoot a shot at infinity? if d = 1 then gosub "take_inf_shot" end :take_inf_shot print "Taking photo at infinity" set_focus 65000 shoot return :countdown for n=1 to 4 print "starting in:", 6-n,"secs..." sleep 940 next n for n=1 to 4 print " " next n return :nozoom rem Focus nearer than 5cm requires widest zoom (7.3mm focal length) rem (I chose not to, but code could override using set_zoom 0) print "***TO USE THIS SCRIPT***" print "You MUST set camera" print "to widest zoom" print "then RESTART script." wait_click goto "theend" return :bad_focus_dist print "***BAD FOCUS***" print "End dist & end dist are wrong" print "Starting from: ", s print "Ending at: ", e
4: Take some photos
Time to take some photos!
- Make sure your SD card has the write-protect toggle set and turn on your camera.
- Mount your camera somewhere stable.
- Use the ALT button â€“ (?) or (â–¶) to enter CHDK mode
- In ALT mode, press menu and navigate down to Script, then load dof.bas.
- Scroll down and enter your end distance using the x1, x10, and x100 multipliers. I usually use 150-200 for a small scene, and 300-400 for a deep scene. If you're shooting outside and have a natural backdrop, enable the "shoot 1x infinity" option.
- Press menu again to exit.
- Use the up arrow to enable manual focus mode. Use the zoom toggle to change the step size (1, 10, 100 steps) and then use left and right to set your starting focus. I usually start at about 30.
- Finally, press the shutter button to start the script.
Now just stand back and wait. It'll take a few minutes to click off 50 or so shots.
5: Stack some photos
Time to make some magic.
- Download CombineZP. It's not the greatest looking bit of software, but it's free with lots of knobs to twiddle, and turns out good results.
- Back on your computer, place each photo set into a folder. This makes it a bit easier to pick files in the next step.
- Start CombineZP and click the New button. Select all the photos from one set and click open.
- It'll tick away for a minute and then show you a fuzzy picture. From the drop down menu, choose "All methods" and click GO.
- Now go off and do something else for half an hour. This is a pretty intensive process!
- When you come back there will be a bunch of files in the output folder. Examine each one and see which you like the best. Note from its filename what method was used. It'll be something like "pyramid max contast" etc.
- Go back to CombineZP and from the drop down choose the above method. Click GO and sit back for a few minutes.
- You'll notice once done that there are some strange reflections around the perimeters. I'm not really sure where these come from, but it's easily fixed. Click the crop button (next to the GO button) to automatically crop the image. You can adjust it by clicking and dragging if you want. Finally click the SAVE button to export your image. Bingo, one focus stacked photo! With practice you'll learn which methods you like the best and can cut out some of the intermediate steps.
It goes without saying that all the shots on this page are done using CHDK and my script. You'll see that some things work better than others; you need lots of light, and reflections/highlights can be difficult. But when it all comes together, the results are great! No go forth and stack some photos of your own...