I was wondering if there was any photo management software out there that could auto detect and "rate" images on how in focus they are. This comes up for me quite commonly when i am looking through a large series of macro images of the same subject.
In a perfect world, Light Room (or whatever program) could highlight in focus and out of focus areas the same way that it detects burned out areas of an image. Also the algorithm I am hoping exists would be smart and would not be distracted by blurred backgrounds and only seeks that some sufficient area is in enough focus.
Anything like that out there?

As another thought for people talking about pictures being in focus on the wrong spot, and that camera focus models already look into this. Another large factor for a lack of clarity in a macro image is blur from camera movement. This damages all points on an image, and is not something the camera accounted for when focusing.

  • Which camera are you using? Some cameras include the focus point information in their RAW files and EXIF data, with a little effort, it wouldn't be too difficult to use that information to gauge the sharpness and contrast to determine a rating of focus. I don't know anything that does this though... Jan 20, 2011 at 22:45
  • 2
    @Benjamin Anderson - this is only a partial solution. Usually you focus then recompose, so the focus point indication will actually be misleading in this case and will rate many perfect images as out-of-focus
    – ysap
    Jan 20, 2011 at 22:47
  • @ysap - True, especially when it comes to macro shots. Jan 20, 2011 at 22:50
  • It would be even better if you could more clearly see what is in focus before taking a picture. For example, live view could use colour coding to clearly highlight in-focus and out-of-focus areas. I wonder if there are any cameras that can do that... Jan 20, 2011 at 23:38
  • 1
    @Jukka what you're asking for is called colour peaking and it's found on high end digital video cameras (which are often manually focussed). I believe you can get it on the Canon 5D mkII via the Magic Lantern firmware hack.
    – Matt Grum
    Jan 21, 2011 at 12:11

7 Answers 7


It's an interesting question. It's certainly possible for software to detect the parts of an image that is in focus, as it's the basis for focus-stacking software like Helicon Focus.

Focus stacking is a technique used by macro photographers. The depth of field in many macro shots is very shallow, so to extend this it's possible to take a set of photos of the subject, modifying the focal point in each one. Helicon Focus takes the stack of photos and detects the most in-focus parts of each image, and blends them together to produce a result where the entire subject is in focus. It's also possible to do this with some of the technology behind Hugin, but it's a bit more tricky to set up.

I think the difficulty in extending this for a general "in focus" check would be determining whether the subject is in focus - how do we automatically determine what the subject is? How much depth of field was required by the photographer?

  • 1
    I think the need for control over the camera's autofocus system demonstrates that it's impossible to know, without the photographer's input, what the intent is. There's also a sort of Godel problem, where I can take an out-of-focus picture on the wall, and take a picture of it, that is itself correctly focused. It would be impossible to identify the latter as being correct. Apr 11, 2012 at 13:58

What you are asking for is problematic in the sense that a software based focus detection will essentially use the same algorithm as a contrast based camera autofocus system uses. That means that you need to scan the image and look for the most contrasty place to determine the amount of "focusness". However, it is possible you were shooting a low-detail (low-contrast) subject, so even though your focus is spot-on your target, still the software algorithm will determine a low focus or out-of-focus image.

Additionally, how will the software know what was your actual intended focus point? If you're shooting a portrait, and the eyes are mis-focused, the software will detect perfect focus on the ear, but this really is a low-quality or unusable image.

  • 1
    I'm starting to see how it's possible to design such a program. For faces, well, do a facial recognition type program, look at the eyes and see if they are in focus. Something should be possible for this, although it might be somewhat difficult... Jan 20, 2011 at 22:55
  • Well, the proposed technique (highlighting areas that seemed to be in focus) would not have the problem of ear vs. eye. I'd guess that seeing which areas are relatively contrasty vs. not contrasty would be similarly interpretable - and if you're concerned with a series of similar images, then comparing them to each other rather than an absolute "focusness" quality seems like the right way to do it.
    – Reid
    Jan 21, 2011 at 14:12
  • @Reid - I assume the intent of the OP is to have an automated process for removing bad pictures. My answer addresses this requirement by pointing out why this feature will be hard to accomplish, and I also gave examples in comments to other answers. If there is a human in the loop, then everything is possible...
    – ysap
    Jan 21, 2011 at 16:52
  • My reading of the question is that the OP does seem to be pretty clearly describing a mixed initiative process, not a fully automated one (e.g., "highlight in focus and out of focus ares").
    – Reid
    Jan 22, 2011 at 23:16

As a human, I would rather rate them myself with my subjective observation, seeing as I know where the focus should or shouldn't have been, but I suppose there could be a rough way to determine the focus quality of a shot based on the aperture, focal length, subject distance and focus/unfocused areas of the image.

For example, long focal length, small aperture, close subject means there is likely to be a small point of focus with a lot of bokeh (for common applications of this recipe).

On the other hand, short focal length with a longer subject distance means there's likely to be more in focus areas than out of focus areas (think landscape or group shot).

I guess the most important thing in any photo is, wherever the most focused area of a photo is, it's in focus. This simple "is the most focused point in focus" check would be one I could possibly use as there's most commonly no point in using an out of focus or back-focused shot unless you think it will work.

  • your last point is only partially true, as most of the time you will focus and then recompose. Like the example I gave in other comment, it can be that the ear will be in perfect focus (and as such your image will have great most focus point) but the eye will be OOF.
    – ysap
    Jan 21, 2011 at 0:23
  • I didn't even think of that, and yes, I very often focus and recompose, so there could be a slight shift in the focus plane. Jan 21, 2011 at 3:22

In a perfect world, light room (or whatever program) could highlight in focus and out of focus ares the same way that it detects burned out areas of an image.

So, to start with, the Darktable manual includes:

ctrl-z fully zoom into the image and show areas in focus

And that looks like this on an image in partial focus:

enter image description here

More specifically I think that you can get what you are looking for by quantizing the amount of high-frequency information in the fourier transform of the image. (the high frequencies are the sharply focused bits we care about).

Helpfully another SE answer (which I've upvoted for the privilege of the copy paste) gives code for pulling out the frequencies. If it's interesting to people I might come back to this answer and see if I can write the code that orders a set of images by how much sharp(rather than total) focus they have.


I've just come across this (now almost) 9 year-old question. There is some good information in these answers, but many are quite old now, and none really answer the OP's original question: Can software auto-detect image focus?

After reviewing the posts here, I found an application called Fast Raw Viewer that has at least a partial solution.


A really cheap expedient for images taken with the same quality settings of the camera and the same scene and light setup is to look at the file size of the JPEG. The more material is in focus, the more visibly discernible information is considered by the lossy JPEG compression algorithm worth preserving, increasing the file size.

Of course this makes only sense if the bulk of the image content is what you want to be in focus. It doesn't help against smaller defocused subjects against an in-focus background, for example.

But it can be useful as a quick tie breaker.


Capture 1 maybe what you need!

  • 2
    Could you expand this answer to explain what "Capture 1" is and why it might help?
    – Philip Kendall
    Jan 26, 2016 at 15:57
  • 1
    Most unhelpful answer I have ever seen in SE
    – Trect
    Nov 28, 2019 at 11:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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