Before the rush

Before the rush
by evan-pak

Submit your Photo
Hall of Fame

Please participate in Meta
and help us grow.

Photography Stack Exchange is a question and answer site for professional, enthusiast and amateur photographers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Does an application exist where I can input an image and then the application indicates what parts of the image are in focus? I imagine it as a sort of post-process focus peaking.

share|improve this question
You could look for high frequency content, but that will only point out edges that are in focus. Detecting large flat areas that are in focus will be tough since they look the same whether in focus or not. – Olin Lathrop Jan 11 '13 at 14:12
@mattdm I don't understand why making a question more specific by including the desired OS is unwanted. I'm OK with it, but would like to know why for the future. – Saaru Lindestøkke Jan 12 '13 at 14:05
Because we end up with three of the same question (one for Mac, one for Windows, one for Linux) with virtually identical answers because the technique is the same across software (and the software often multi-platform anyway). – mattdm Jan 12 '13 at 14:54
up vote 14 down vote accepted

The simple recipe is to convolve with a Laplacian of Gaussian kernel (3x3, with 8 in the middle surrounded by -1 and take the abs(result)) . After this you get some artifacts if it is a jpeg image, and out of focus borders that have a high intensity difference will also "ping". The result you can threshold to detect the strongest edges and remove teh artifacts. Let the threshold be generous, letting a few fake specks through. Then median filter the image and you get a cleaner result.

For the example below I used Image View Plus More: 1. original 2. abs(LoG convolution ) 3. threshold 4. median filter

There are more advanced approaches using Gabor filters in fourier domain, and using the gaussian pyramid approach. Halcon (which is very expensive) has some examples with these methods.

simple focus

share|improve this answer

For example you can use Photoshop (or any other program which has a High Pass filter) for that. In Photoshop:

  1. Open the image
  2. Go to menu an choose Filter -> Other -> High Pass
  3. In the dialog which appears, perhaps is better to enter Radius to be 1 pixels (but you need to have good eyes later)
  4. Choose [ok]

You will see (if you have good eyes) the focused edges having a different gray tone than the background. At the step 3 you can play a little bit with the Radius to obtain different results.

The method works in common cases but there are some situations in which an out-of-focus object might appear as 'focused'. But these cases are usually rare.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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