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:
I load the image, in this case http://rlog.rgtti.com/wp-content/uploads/2013/01/10/macro-lenses-are-expensive-all-of-them/paseo_15sep_more_rosse.jpg
Now I copy the background layer, and I transform the new layer to grayscale.
I apply edge-detect by difference of gaussian:
playing with the parameters to have a nice area defined. Apply the filter
- Now you apply a threshold to the image:
...and this is a map of your sharp (how much sharp you decide in the previous step setting the parameters for the filters) are.
- You can now use the "select by color tools", click on the black, and then grow the selection a bit:
... 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
- manually edit the layer to fill the sharp areas with black:
...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
enfuse --exposure-weight=0 --saturation-weight=0 --contrast-weight=1 \ --hard-mask --save-masks --output=base.tif INPUTImage*.tif
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