I did a lot of work on autofocusing when I built an automated metrology system. The focus measurement method I used could be extended and used for an application like this. It would locate the areas with the best focus and combine them from a series of images to create a single image completely in focus. It would also be possible to create a "depth map" image where it shows the depth at which each part of the image was best focused.
Bruce
Bruce Ammons
Ammons Engineering