# Auto-focus estimation?

What kind of analysis might be used on sets of 2D monochrome image matrices or bitmaps to estimate or compare their relative quality of being "in focus"? Is there an efficient way of computing a scalar metric on something like overall contrast, luminance sparsity, or other artifacts produced from out-of-focus blurring?

• Are the two images of the same thing, or are they of different things? May 6 '12 at 20:10
• Assume "similar" content, as in the camera is not on a tripod (and the cat may likely be doing the opposite of what you want). May 6 '12 at 21:12

Images in focus have sharper edges, so applying an edge detector and measuring the energy of the output puts you on the right track.

A simple technique is to compute the sum of the laplacian over the images, possibly center-weighted if you deal with everyday photographs (people tend to put the object of interest in the center, so it's better to have the center in focus than the borders)

This criterion is for example what is used in many "Stack focusing" applications for macro photography.

There are other approaches used in de-hazing or tone-mapping... Search for "Local contrast measures".

In general a lens can be modelled as a low pass filter. When an object is out of focus, the smoothing effect of the low pass filter is more intense.

Therefore, you could use a simple metric such as Standard Deviation either applied globally (over the full image) or applied locally through a suitable size moving window over the image to preserve the spatial information if in addition you would also be interested in which areas are in or out of focus.

In either case and assuming that the scene has not changed much between takes, the Standard Deviation of the image IN focus will be higher than the Standard Deviation of the image OUT of focus.

For an application of the Standard Deviation as a "focus estimator" you could have a look at this publication, while a review of a number of measures (including Standard Deviation) is available from this one.