Lets import an image from the Wikipedia page about Focus Stacking. Note that the first and second image parts are out-of-focus: the head or tail of the fly. The goal is to get a result comparable to the 3rd image part below where all in-focus areas are merged in single crispy image.
i = Import["http://goo.gl/xMThiZ"]
Because it is one large image, we start by grabbing first 2 images to process further.
images = {i1, i22} = Most@Flatten@ImagePartition[i, {{Scaled[1/3]}, Scaled[1]}]
Next we need to align images perfectly so no artifacts will appear during merging
i2 = RemoveAlphaChannel@ImageAlign[i1, i22];
Now if we blur images and find difference with original we can find sharper domains
list = ImageAdjust@ImageDifference[Blur[#, 5], #] & /@ {i1, i2}
Having that we make masks covering those domains
masks = FillingTransform@Dilation[Binarize[#], 1] & /@ list
And use those masks to set an alpha (transparency) channel in the images
list2 = MapThread[SetAlphaChannel, {{i1, i2}, masks}]
And now we can compose these with original to get complete-in-focus image. And after slight sharpening, voila, as crispy as we can get it. Note how in this image both head and tail of the fly are sharp.
ImageCompose[i1, ImageCompose @@ list2] // Sharpen