Focus peaking is a relatively new feature that is currently making its way into the newer digital cameras that are coming out. Peta Pixel reported on this feature appearing on the latest Sony cameras here:
One of the interesting technologies Sony introduced into its line of NEX mirrorless cameras last year (starting with the NEX-C3) was “focus peaking”, a feature from the video recording world that highlights in-focus areas of an image to aid in manual focusing. You know those colorful pixels that image editing programs use to indicate blown out or underexposed areas of photos? It’s like that, except for focus. What’s awesome is that you can adjust things like focus, focal length, and aperture, and then see the depth of field adjust on your screen in real time.
You can see a video below of how this works:
Basically the areas of the image that are in focus are being highlighted by the camera so that you can easily see what will be in focus when you take the shot. It enables you to fine tune the focus precisely the way you want.
It’s a very nice feature to have on the camera. But this got me thinking. When editing pictures in Photoshop, I often find myself wanting to edit only the parts of a picture that are in focus, or sometimes just the parts of a picture that are out of focus. For example, when applying noise reduction to images, I usually want to do this mostly for the out of focus areas (bokeh) of an image, and leave the detail inside the in focus areas intact. Wouldn’t it be awesome if we had a selection feature in Adobe Photoshop or Lightroom where we could easily select only the areas of an image that are in focus? The way this would work is exactly like the “Color Range” selection process in Photoshop, but only instead of a range of colors, it would select a range of focus. It would start by selecting the areas that are sharply in focus, and you could then increase the range/radius to include more of the picture in your selection extending more to the out of focus areas.
To my knowledge there’s no such feature in Photoshop or in any plugins that I know of. So I decided to try and see if I could use the functionality that is currently in Photoshop to build a selection in an image of only the areas that are in focus. It turns out that it’s possible to do this, although it’s not quite perfect, and you can even create an action to automate the process. It should be relatively easy for Adobe to include such a focus selection option in Photoshop, but until they do, we’ll have to use a different way.
The way I’ve tried to do this is by trying to detect the edges and details inside an image that are sharply in focus mostly by using a High Pass filter. Once you have the edges that are in focus selected, you can expand the selection around those edges and get a rough, sometimes even pretty accurate, selection of the areas in an image that are in focus. This method is by no means perfect, but it can help if you want to quickly and automatically select the areas of an image that are in focus. You can then refine the mask/selection afterwards if needed.
Some issues with this method:
Obviously trying to create this functionality in an action is limiting and won’t always give the best results. Only the Photoshop guys at Adobe or a plugin developer has the kind of low level access and flexibility to be able to make this better.
Below are some examples to show that it does work:
In the examples below I used sample images from the Canon EOS 1DX from Canon Inc’s website.
You can download actions that automate the steps shown in the below tutorial by clicking on this link. There’s a .atn file in the zip file which you can open in Adobe Photoshop. There are 3 actions inside this file:
PLEASE NOTE: Run these actions on the background layer after opening the image in Photoshop. These actions are optimized for images that are between 10-21 megapixels in size. For smaller images you may need to adjust certain settings as explained in the tutorial below. These actions only work for 8-Bits/Channel and 16-Bits/Channel images (the Color Range selection option is not available for 32-Bits/Channel images in Photoshop).
I’ve created a step by step tutorial below to show how to simulate focus peaking in Photoshop. You end up with a mask containing a rough selection of the areas in an image that are in focus. I’ll be using the image below in this tutorial. You can download a high resolution version here.
I will be posting updates here when there are bug fixes and/or improvements to the actions. If you run into any issues let me know. If you have suggestions for improvements also let me know. The latest update can be downloaded here.