# How can I "focus peak" a photograph?

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.

• 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. Jan 11, 2013 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. Jan 12, 2013 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). Jan 12, 2013 at 14:54

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.

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.