For a research project it would be handy to get only the in focus part of an image. Does anyone know some software that can do this? I know that the next version (in a few weeks) of Photoshop CC will have something like it, but are there other options?
I normally use GIMP for that --- this probably needs to be refined for automatic procedures. My procedure is as follow:
playing with the parameters to have a nice area defined. Apply the filter
...and this is a map of your sharp (how much sharp you decide in the previous step setting the parameters for the filters) are.
... once you are satisfied, you can save the selection to a channel.
Notice that the selection do not include the sharp areas which are uniformly colored, without edges. I do not know any way of doing this automatically (is it possible?); but you can copy the channel to a new layer and
...and the repeat the select-by-color procedure to create a new mask.
In Hugin you can use a tool that does it. It is called enfuse.
Problem: It only works on multiple images.
Here you can find a tutorial on using enfuse for focus-stacking. You can get the masks (which is what you want) by using
However, note that while this is automated, the basic approach is the same as Rmano's answer: Detect large local contrast. For much more in-detail explanation have a look at Local Contrast Detection and Advanced Focus Stacking in the Enfuse documentation.
Adobe Photoshop CC will do this after June 18th. Here's the link to the preview feature