<p>it is quite easy to measure the local max frequency in an image (at least as a low resolution mask, with some regularization).
Several papers of the MIT graphics group have been around detecting and processing from this kind of clue, with regular or coded aperture cameras.
e.g. <a href="http://people.csail.mit.edu/soonmin/dof/">Defocus Magnification</a> and <a href="http://groups.csail.mit.edu/graphics/CodedAperture/">Image and Depth from a Conventional Camera with a Coded Aperture</a>.</p>

CC BY-SA 3.0
2015-10-08T10:44:00.727Z
Many thanks Fabrice! If possible, can you elaborate *local max frequency*?
p2or
CC BY-SA 3.0
2015-10-08T12:58:38.223Z
I don't remember how these papers were estimating the native focus before refocusing. But I could think of various solutions: poor-man wavelets by calculating the FFT in a grid of subimages (i.e. a grid of windowed FFT), estimating local autocorrelation, poor-man FFT by convolving with a set of Differential of Gaussians (to detect ranges of focus), etc. But this is kind-of instant-hacking, the best is to read what the experts did for real :-)
Fabrice NEYRET
CC BY-SA 3.0
2015-10-19T15:08:50.363Z
Any work done on single image, not with Coded Aperture? Thank You.
Royi
CC BY-SA 3.0
2015-10-07T21:07:45.853Z
2015-10-07T21:07:45.853Z
Fabrice NEYRET
<p>Is there any strategy to detect the region of an image that is sharp and in-focus, in order to separate the out-of-focus background? I've tried using <a href="https://en.wikipedia.org/wiki/Edge_detection" rel="noreferrer">edge detection</a> methods but without any success. </p>

<p>In other words, is it possible to determine if an area of an image is blurred (out of focus) or not?</p>

CC BY-SA 3.0
2015-10-07T19:46:31.267Z
Do you mean that you want to detect areas of an image that are sharp and in-focus, versus blurred and out-of-focus?
Nathan Reed
CC BY-SA 3.0
2015-10-07T21:13:59.867Z
How did you used edge detection algorithms? Not sure it works and can't test now (so no answer for now :P), but just off the top of my head, you can divide your image in subregions and measure the value of gradients. Based on a threshold you can then decide whether that subregion is "in-focus" or not. Then you can re-use the edge info to refine your first approximation I described before. It makes sense to me know, but it may very well be a brain-fart being it late here :) I'll give it a try tomorrow if I have a minute to.
cifz
CC BY-SA 3.0
2015-10-08T10:24:07.547Z
@cifz - Thanks! Great idea to measure the gradiants, sounds like a simple and fast approach. But this will only work for a rough detection, right?
p2or
CC BY-SA 3.0
2015-10-08T10:28:27.593Z
@NathanReed Right. Sorry, not a native :) Do you think I should rephrase the question?
p2or
CC BY-SA 3.0
2015-10-08T17:10:30.513Z
@poor Yes, I think it would be helpful to rephrase and edit the title to make it more clear.
Nathan Reed
<algorithm><blur><image-processing>
Detect in-focus regions of an image
p2or
# Detect in-focus regions of an image

(Asked by: username_0 on 2015-10-07)

Is there any strategy to detect the region of an image that is sharp and in-focus, in order to separate the out-of-focus background? I've tried using [edge detection](https://en.wikipedia.org/wiki/Edge_detection) methods but without any success.

In other words, is it possible to determine if an area of an image is blurred (out of focus) or not?

**Tags:** algorithm, blur, image-processing

> **Comments:**
> **username_1**: Do you mean that you want to detect areas of an image that are sharp and in-focus, versus blurred and out-of-focus?  
> **username_2**: How did you used edge detection algorithms? Not sure it works and can't test now (so no answer for now :P), but just off the top of my head, you can divide your image in subregions and measure the value of gradients. Based on a threshold you can then decide whether that subregion is "in-focus" or not. Then you can re-use the edge info to refine your first approximation I described before. It makes sense to me know, but it may very well be a brain-fart being it late here :) I'll give it a try tomorrow if I have a minute to.  
> **username_0**: @username_2 - Thanks! Great idea to measure the gradiants, sounds like a simple and fast approach. But this will only work for a rough detection, right?  
> **username_0**: @username_1 Right. Sorry, not a native :) Do you think I should rephrase the question?  
> **username_1**: @poor Yes, I think it would be helpful to rephrase and edit the title to make it more clear.  

---

## 1 answers

### Answer by username_3 on 2015-10-07. Score: 11 | Accepted answer

it is quite easy to measure the local max frequency in an image (at least as a low resolution mask, with some regularization).
Several papers of the MIT graphics group have been around detecting and processing from this kind of clue, with regular or coded aperture cameras.
e.g. [Defocus Magnification](http://people.csail.mit.edu/soonmin/dof/) and [Image and Depth from a Conventional Camera with a Coded Aperture](http://groups.csail.mit.edu/graphics/CodedAperture/).

> **Comments:**
> **username_0**: Many thanks username_3! If possible, can you elaborate *local max frequency*?  
> **username_3**: I don't remember how these papers were estimating the native focus before refocusing. But I could think of various solutions: poor-man wavelets by calculating the FFT in a grid of subimages (i.e. a grid of windowed FFT), estimating local autocorrelation, poor-man FFT by convolving with a set of Differential of Gaussians (to detect ranges of focus), etc. But this is kind-of instant-hacking, the best is to read what the experts did for real :-)  
> **username_4**: Any work done on single image, not with Coded Aperture? Thank You.  

---

