Detection of blurred vs. sharp image areas (in-focus/out-of-focus distinction)

Started by
4 comments, last by Meltac 7 years, 10 months ago

Hi all,

I'm looking for a way to distinguish sharp areas in an image from those that exceed a certain amount of blur / "unsharpness". In HLSL.

More specifically, I want to detect / mask / mark the entire out-of-focus part of a photograph, or, vice-versa, its in-focus part.

So far I've tested several approaches dealing either with edge detection, or the overall-sharpness of images, but they all fail in properly and robustly masking areas with certain blur or sharpness.

I couldn't imagine that this would be such a hard task since the human eye can distinguish in-focus (sharp) from out-of-focus (blurred) areas of a photo quite easily.

Any ideas or hints?

Advertisement

I couldn't imagine that this would be such a hard task since the human eye can distinguish in-focus (sharp) from out-of-focus (blurred) areas of a photo quite easily.

Just because something is trivial for people to do, does not mean it is easy for a computer.

You could run a type-2 discrete cosine transform over the luminance values on a small area, 4x4 for example. Then, the ratio of the blurred vs the sharp transitions on that area could be determined by observing the highest frequency coefficient (the last one). The lower it is, the less effective sharpness you have.

Niko Suni

Also note that if you have, for example, a flat-colored surface, neither the human eye nor any algorithm can distinguish whether or not it is in focus :)

The DCT approach would determine the image to be fully blurred in this case, since the low-frequency coefficients would get the most contribution.

Niko Suni

I think what you might be looking for is a "Shape From Focus" algorithm.

Generating accurate data from a static image instead of a live one where you can change the focus isn't easy though, because you don't know how blurry the real object looks.

Focus systems in cameras tend to change the focus, and search for a local maximum contrast. https://graphics.stanford.edu/courses/cs178/applets/autofocusCD.html

Thanks so far guys.

I've read that some guys used derivatives (e.g. the third derivative) to detect blur / sharpness.

Anyone knows how to implement a derivative / derivation in HLSL?

This topic is closed to new replies.

Advertisement