Serene Life

by garik

submit your photo


Hall of Fame
View past winners from this year

Please participate in Meta
and help us grow.

Take the 2-minute tour ×
Photography Stack Exchange is a question and answer site for professional, enthusiast and amateur photographers. It's 100% free, no registration required.

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?

share|improve this question
    
FYI, your use of "get" is very ambiguous here. What do you mean by "get only this part" of the image? Do you mean that's the only pixels you want remaining in the file? Or do you simply want to identify this area for some kind of analysis or what? "Select" would be a better term, or "mask" or even "identify" –  Jasmine Jun 13 at 20:12
    
If you have more than one image, (i.e. similar to focus stacking but without actual stacking), I'd have an answer that would give you in-focus masks. –  Unapiedra Jun 14 at 9:26
    
Good point @Jasmine. I have branches of a shrub in focus against an background trees/shrubs (putting up a blue-key isn't an option), so to reduce the error I want to limit the analysis to the branches. This can be done by masking, or by have an reduced file with only the in-focus pixels. –  LaurensP Jun 14 at 20:23
    
@Unapiedra, it's the first time hear about focus stacking. How would that method or derivative give me an in-focus mask? I'll have several pictures a day over a month, fixed frame and focal distance. –  LaurensP Jun 14 at 20:24
    
@LaurensP: It wouldn't help in this case. I strongly suspect that your question is wrong here: It is a programming question and should be moved to StackOverflow. You could also expand your question to say what you actually want to do/analyse/etc. So far you revealed that you want to analyse branches of a shrub, how and why you didn't say. Maybe clustering and segmentation is an option? Please upload a sample image, while you're at it. –  Unapiedra Jun 15 at 8:04

3 Answers 3

I normally use GIMP for that --- this probably needs to be refined for automatic procedures. My procedure is as follow:

  1. 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

  2. Now I copy the background layer, and I transform the new layer to grayscale.

  3. I apply edge-detect by difference of gaussian:

enter image description here

playing with the parameters to have a nice area defined. Apply the filter

  1. Now you apply a threshold to the image:

enter image description here

...and this is a map of your sharp (how much sharp you decide in the previous step setting the parameters for the filters) are.

  1. You can now use the "select by color tools", click on the black, and then grow the selection a bit:

enter image description here

... 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

  1. manually edit the layer to fill the sharp areas with black:

enter image description here

...and the repeat the select-by-color procedure to create a new mask.

share|improve this answer
    
This will give you textured areas (with edges). Your use of growing is clever but the result isn't perfect. Look at the inside of the leaf on the left hand side. It is in focus, but not completely black in the mask. I think this might actually be impossible to solve as one can't distinguish between out-of-focus and texture-less. –  Unapiedra Jun 14 at 8:55

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 --save-masks.

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.

share|improve this answer

Adobe Photoshop CC will do this after June 18th. Here's the link to the preview feature

share|improve this answer
5  
The question is specifically asking for options other than Photoshop :-) –  Philip Kendall Jun 13 at 16:00
    
It didn't initially –  R Hall Jun 13 at 21:13
1  
It's never been edited. –  John Cavan Jun 13 at 22:22
    
Oh well. Let's keep down voting I guess. we're at -4 now. Anyone else? –  R Hall Jun 14 at 5:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.