Jump to content
  • Advertisement
Sign in to follow this  
Meltac

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

This topic is 845 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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. Edited by Nik02

Share this post


Link to post
Share on other sites

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

Edited by Adam_42

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!