# Auto-focus parabolic fit

There is a really interesting post on auto-focusing at CN here, involving a parabolic fit to the FWHM or HFD data. This seems like a natural way to do it and more robust and accurate than the V line intersection SGP uses now.

Gerrit

Actually, only the bottom curved portion of a good focus curve lends itself to a parabolic fit. Higher up on both the left and right side, the fit is to a straight line.

Isn’t the entire curve actually a hyperbola? That tends to a straight line when away from the centre.

Chris,
we discussed this topic already. It is NOT important whether the whole curve is hyperbolic or parabolic. I gave a lot of experimental data and showed that a quadratic fit (parabola) excellently works for fitting the data in the narrow region that is used by a auto focus run (see Proposal of a "Quadratic Fit" Auto Focus evaluation method ). One important point is: the coefficient of determination, R², would serve as a very good quality judgement of the AF run.

Bernd

This site https://openspim.org/SPIM_Optics_101/Theoretical_basics gives some interesting information about the shape of the light cone, the section on Gaussian Beam Optics has a diagram that looks like a hyperbola and the function that generates it is a hyperbola.

I’m sure that it can all be approximated by a couple of straight lines and a parabobla but woudn’t it be better to fit the whole V curve to what seems to be the correct function?

The straight-line V fit seems like a kluge. The fit should be to a function which matches the physical theory. If a hyperbola is what the theory indicates happens to FWHM outside focus, then that’s what ought to be used.

Also, fitting straight lines to the “wings” of the function doesn’t make use of the data near focus, which is probably the most important. Fitting to a proper function would make use of all the data. The CN post above also uses error bars in its fit, which would help even more.

Once again: By evaluating a fit of the whole curve and calculating the coefficient of determination, R², one has an excellent meassure of the quality of the focus run. If the quality is judged only from the 3 best points right and 3 best points left of best focus, the significance is much worse.

I presented a lot of data with R² from parabolic fits (link given above) - these data speak for themselves: parabolic fit is a very simple (to calculate) and efficient fit. If a hyperbolic fit can be used - OK, I don’t argue against it if it only will be realized.

Bernd

The main benefit of the approach I describe in the CN thread is that it weights the points on the curve based on standard deviation of the star measurements (which currently isn’t available in the sgp plot) and it provides an error estimate of the final focus in terms of focus steps. If you have a view of the focus curve and you also have an error estimate (along the x-axis) then you have a direct indication of how good your focus is.

As for hyperbola vs. parabola - there is no benefit in looking at what the underlying curve “really” is - because the measurements of hfd have their own biases. As long as you stay very close to the minimum, anything will be parabolic - and it will avoid complexities such as donuts that appear far from focus.

The approach I describe can take just a few points near focus and provide an assessment of how accurate the final focus is. If people feel that things would work better based on hyperbolic fit far from focus - then please include an estimate of how accurate the result is - based on error propagation from the original uncertain measurements.

The basic idea of fitting the curve to parabola is straightforward - but mapping the uncertain measurements to the uncertainty of the result has some tricks involved - which I have explained in detail so that I hope other software can make use of it.

Frank

@bulrichl, I think your work on this is exceptional. Just finished reading in detail your Proposal of a “Quadratic Fit” Auto Focus evaluation method (Proposal of a "Quadratic Fit" Auto Focus evaluation method). I think your method is the perfect solution for fixing the current problems with the SGP focus routine.
I predict that it will work exceptionally well for practically every rig using SGP, and definitely a big improvement over the current focus routine.

Concerns some folks have expressed about whether or not the true focus curve is parabolic or hyperbolic or straight lines or not symmetric are probably not really relevant, if the “Quadratic Fit” Auto Focus evaluation method presented by bulrichl is implemented. The only case where this might not be strictly true is where the left and right sides of the curve are not reasonably symmetric. Mine in general are somewhat asymmetric. This should be easy to demonstrate that the method even works well for the asymmetric case if we send bulrichl some examples to run through his routine.

As bulrichl has mentioned, his method has 3 key advantages:

1. Distinct identification of poor AF runs (automatable),
2. Robustness against a single outlier of a HFR value and
3. Better Correlation of fr values with temperature

Another big advantage: bulrichl has already done the work of programming this. All the developers have to do is plug it in.

Does anyone have anything remotely comparable. If not, lets all get behind this approach and do it.