5.7. Focus Methods¶
5.7.1. Procedure¶
The focus search procedure is shown in the Figure below.
Fig. 5.21 Autofocus process flowchart.¶
5.7.2. RMS Spot Size¶
Standard RMS
An analytical solution exists for the RMS spot size method. The following derivation closely follows [1]. For a ray section starting at \(x_i, y_i, z_0\), the position at an axial displacement \(t\) is given by:
We can define the RMS spot size relative to the center coordinates \(x_c^*, y_c^*\). This average position also propagates along the optical axis, originating from \(x_c, y_c\) and with direction vector \(s_c\). Next, the merit function is defined as:
Introducing the new relative coordinates \(\Delta x_i, \Delta y_i\) and the relative direction \(\Delta \theta_{x,i}, \Delta \theta_{y,i}\):
Applying variational calculus to minimize this function results in [1]:
Thus, the focal position is located at \(z_0 + t_\text{RMS}\).
Ray Weighted RMS
Additional weights \(w_i\) can be assigned to each ray. By choosing the ray power as weights, the power-weighted RMS spot size is obtained:
Assigning ray powers as weights \(w_i\) leads to the following weighted solution:
Position Weighted RMS
Utilizing other strictly monotonically increasing functions that depend on \(r^2 = \left(x_i^* - x_c^*\right)^2 + \left(y_i^* - y_c^*\right)^2\) does not yield any additional benefits. These functions all share the same minimum position. Optimizing the least-squares cost \(r^2\) should be preferred due to its simplicity and convexity.
5.7.3. Optimization Methods¶
The scipy.optimize.minimize() function, along with its optimization methods,
is utilized under the hood for various optimization tasks.
For the Irradiance Variance method, the Nelder-Mead solver is employed directly, without doing additional search iterations or refinements. This choice is motivated on the observation of a typically smooth merit function.
In contrast, for the methods Image Sharpness and Image Center Sharpness, the merit function tends to be much noisier and may include numerous local minima. To address this challenge, the search region is initially sampled at multiple points. Subsequently, minimization is initiated relative to the smallest found error position. The COBYLA solver yields satisfactory results in these cases.
5.7.4. Pixel Dimensions for Rendering Methods¶
Methods such as Irradiance Variance, Image Sharpness, and Image Center Sharpness render multiple images denoted as \(P_z\), each with a pixel count of \(N_\text{px} \, N_\text{px}\).
The side length in pixels, \(N_\text{px}\), is influenced by the number of rays used for focus search. When working with a small number of rays, it is advantageous to keep \(N_\text{px}\) low to minimize noise effects. Conversely, as the number of rays increases, \(N_\text{px}\) can be gradually increased to resolve finer details. Distributing \(N\) rays over a square area necessitates increasing \(N_\text{px}\) proportionally to \(\sqrt{N}\) to maintain a relatively consistent Signal-to-Noise Ratio (SNR). The implemented formula follows the form
For simplicity, both image dimensions share the same pixel dimensions.
References