Search code examples
opencvfocusdetection

Focus Detection using OpenCV


I am trying to identify which parts of a picture are in focus and which are blurred, something like this: Focus Detection

But HOW to do that? Any ideas on how to mesure this? I've read something about finding the high frequencies but how could it produce a picture like those?

Cheers,


Solution

  • Any image will be the sharpest at its optimum focus. Take advantage of that - run the Sobel operator or the Laplace operator, any kind of difference(derivative) filter. Sum the results pixel by pixel, the image with the highest sum is the best focused one.

    Edit: There will be additional constraints depending on how much additional information you have, e.g. multiple samples, similarity of objects in the image, etc.