Andrea, thank you for the formulas and questions. I have seen some information about STACKSTEP in your Flickr stream, but it's very helpful to have this extra information about how STACKSTEP works.

I would like your opinion if I operated properly.

This is a deeper question than it might seem at first glance.

On the one hand, it looks to me like you have operated in accordance with standard analysis and your values will work fine for practical application. So for that much, my answer is

*"Yes."*
On the other hand, it turns out that there's a fundamental flaw in standard analysis that introduces significant error into the calculation. So on that basis, I'll say

*"No, but you're in good company, and anyway it works out OK in the end."*
The fundamental flaw is in that little formula at the top of your post:

CoC_tot = sqrt (CoC_diff ^ 2 + CoC_def ^ 2)

It turns out that diffraction blur and geometry blur simply do

not combine according to that formula. The formula is widely used, but it has no basis in physics and it's not a very accurate approximating function either. (Aside: the formula

*would* be correct

*if* the two blurs were independent and Gaussian, but they're not.)

For the benefit of other readers, let me switch notation a little bit to make more clear what the symbols mean. I will use these:

AiryDiameter: diameter of the Airy disk, measured to the first zero

CoC_defocusOnly: diameter of the classic ray optics blur circle, ignoring diffraction

CoC_total: diameter of the total blur circle, including both diffraction and defocus

In this notation, the formula that you're using for CoC_tot corresponds to this:

CoC_total = sqrt (AiryDiameter ^ 2 + CoC_defocusOnly ^ 2)

To illustrate how inaccurate that formula is, let me show you three curves of MTF50 as a function of focus. MTF50 is the spatial frequency at which MTF = 0.5 = 50%. As discussed by

Imatest, this is arguably the best single indicator of sharpness. So, these curves show how much sharpness is lost due to diffraction and increasing amounts of defocus.

The middle curve, shown in blue, comes from the wave optics computation. That's the one from Hopkins, which combines diffraction and defocus in a unified and accurate manner.

The upper curve, shown in red, comes from the classic ray optics blur circle calculation that completely ignores diffraction. It's quite accurate beyond about 0.4 lambda wavefront error. Below that, it becomes inaccurate, and in the limit approaching perfect focus it's just plain wrong. No surprise there.

The lower curve, shown in green, comes from using the standard formula which pretends that CoC_total = sqrt (AiryDiameter ^ 2 + CoC_defocusOnly ^ 2), and then doing a blur circle computation on CoC_total. I've labeled this "rsumsq", for "root of summed squares".

You can see in the graph that the green curve is too low everywhere. Worse, its greatest errors occur in the region close to perfect focus -- exactly where we want to be operating to get the best results from our lenses. Essentially, the standard rsumsq calculation overestimates the effect of diffraction. It produces a "total blur circle" that is consistently too large, resulting in an MTF50 estimate that is consistently too small when compared to an accurate calculation.

The problem is easily fixed. All we have to do is use some different method of computing a CoC_total value that gives a better approximation to the wave optics result.

We can get arbitrarily close to the wave optics result by using table lookups and interpolation, but there's a simpler method that both appeals to intuition and produces good accuracy.

That method is to compute as follows:

p = 3.14

k = 0.715

CoC_total = ((k*AiryDiameter) ^ p + CoC_defocusOnly ^ p) ^ (1/p)

I'll call this the "pkf" method. It's a generalization of rsumsq, with the addition of parameters p and k that can be used for curve-fitting. Choosing p=2 and k=1 would give rsumsq. In the values that I've given, k is chosen to match MTF50 at perfect focus, and then the value of p is chosen to give minimum relative error over the rest of the curve.

Using the pkf method, the curves look like this:

Asked to choose between the green rsumsq curve and the dashed black pkf curve, I think it's pretty clear that we should go with pkf. It's a much better fit to the wave optics MTF50, for almost no additional cost in complexity.

Now that we have a more accurate formula for CoC_total, we can repeat the classic analysis, concluding that the optimum aperture occurs when:

COC_defocusOnly = k*AiryDiameter

Using k=0.715, this means that the two methods rsumsq and pkf disagree by only about half an f-stop, with pkf recommending the smaller aperture.

In terms of wavefront error, the difference is 0.305 lambda for rsumsq and 0.217 lambda for pkf. That sounds like a pretty large difference, but if we use wave optics to compute the MTF curves and plot them together, a more nuanced picture appears:

Here we see that the curve with the larger aperture has a higher cutoff frequency, but it also sags more. For most of the curve, these competing effects almost exactly cancel each other, with the result that the defocused MTF curves are virtually identical for all frequencies where MTF is 25% or more.

As predicted, the MTF50 is slighter higher using pkf than using rsumsq, but that difference is too small to matter.

Instead, the major differences are that 1) the pkf-recommended optimum aperture gives much less variation in sharpness between points of perfect focus and maximum defocus, but 2) this is achieved by making the in-focus areas

*less* sharp.

So, between these two conditions that are essentially the same based on MTF50, we would prefer different apertures depending on how much we weight uniformity versus average sharpness. Mathematics can formalize this difference, but the preference is a matter of taste. Both rsumsq and pkf make completely reasonable recommendations.

Now let's think about accuracy of the DOF estimate.

As shown in the first graph, the MTF50 estimate provided by rsumsq is significantly low compared to the wave optics and pkf estimates. In the range of recommended apertures, the discrepancy is roughly a ratio of 3:4.

On the surface, this 3:4 discrepancy in MTF50 can produce arbitrarily large errors in the DOF estimate. For example, if we choose a COC corresponding to the "Required MTF50" as shown in the graph below, then using pkf would predict almost three times as much DOF as rsumsq.

Carrying this farther, if the required MTF50 were a little higher than shown, than rsumsq would say "

*No, sorry, you've reached the diffraction limit and you simply can't get that MTF50*," while wave optics and pkf would say "

*Sure, no problem.*"

But here's the catch: all you have to do is adjust the required MTF50 in proportion to the error provided by rsumsq, and then you're back to getting the same DOF estimate. Here's the graph showing that adjustment:

The reason I say "here's the catch" is that COC specifications and the MTF50s that go along with them are very subjective in practice. People generally have no idea what COC = 5 pixels should actually look like, and they don't need to. Their problem is easily worked in the other direction: experiment to determine what COC has to be specified in order to get predictions that match their preferences.

When we include the human user, the whole system becomes self-correcting in the sense that errors in the approximating function are compensated by adjustments in the threshold. Should COC for full frame be 0.030 mm or 0.022 mm? Who knows, who cares? Just pick the one that "looks good" in one case and it'll look good for other cases too, even if under the covers the approximating function isn't so great.

You mention that your curves "are very close to those estimated from Zerene". Well, sure. That's because they're both calibrated against similar criteria for what "looks good". That's where your 30 microns CoC comes from, and also it's how I decided which numbers to print in bold-face at

http://zerenesystems.com/cms/stacker/do ... romicrodof.

Bottom line: the standard approximation for combining diffraction and defocus is flawed, but the system as a whole works fine in practice. It's unclear how much practical improvement could be made by using more accurate math.

--Rik