In this project, you're going to modify CHDK to do focus stacking. The full source code for CHDK is here, and that's what you need to be playing with.
Focus stacking works by capturing multiple images at different focus distances and then, for each pixel, taking the pixel value from the sharpest image. That's it.
Ok, it's actually a tad complicated in that you need to write two separate things. One is a Lua script a lot like what you wrote for Automatically Heuristically Detail Revealing, but changing focus distance rather than exposure. The other is a change to the C code for the raw averaging module; you'll need to add code that instead of adding or averaging, combines based on maximizing contrast.
Obviously, you need to shoot raw and vary focus between shots. How many shots you take and how much you vary focus between them is entirely up to you (and your Lua script). Some appropriate parameters to your script would be nice... and should be documented.
How do you detect contrast to grab the "most in-focus" version of each pixel? That's up to you. The raw merge facility basically reads-in a row of pixels at a time, so the easiest would be detecting maximum contrast within a row.... Note that you can do that by simply measuring contrast between the current pixel and the pixels at X coordinates +/-2 from here -- those are the nearest pixels in the same color channel. Is that a good way?
You will be submitting source code (for your Lua script, allin.lua, and for your modified CHDK), and a very short implementor's notes document, formatted roughly as described here, that discusses how your script works, how you decided to do the contrast detection, and explains any issues in implementation or problems with functionality.
For full consideration, your project should be submitted no later than before class November 28, 2017. Submit your .tar or .tgz file here: