Thanks, Sajah. This actually makes sense. I found a discussion (that gets a bit technical...and heated
) on the topic
here.
You're correct that a contrast-detect algorithm would probably work, and it would likely be pretty simple to implement. Some remaining variables:
1. The size of the region over which contrast is detected must be determined. It certainly cannot be global, but it probably has to be larger than a few pixels...akin to focusing regions in the camera.
2. The algorithm likely has to have some sort of cutoff, as well, to "decide" what is in focus.
3. Most importantly, the routine probably has to have some smart way of aiming its efforts on the "edge" regions between images. It cannot just eliminate out-of-focus portions, or it would delete the bokeh areas in the final photo.
4. The last step would involve the manner in which the stacked photos are blended together. I imagine some flexibility exists here, but a simple layer mask would probably work.