5.7. Focus Methods

5.7.1. Procedure

The focus search procedure is shown in the Figure below.

../_images/FocusPAP.svg

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:

(5.165)\[\begin{split}x_i^*&=x_i+\frac{s_{x, i}}{s_{z, i}} t \\ y_i^*&=y_i+\frac{s_{y, i}}{s_{z, i}} t\end{split}\]

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:

(5.166)\[\begin{split}R_v(d) &=\sqrt{\frac{1}{N} \sum_{i=1}^N\left(\left(x_i^*-x_c^*\right)^2+\left(y_i^*-y_c^*\right)^2\right)} \\ &=\sqrt{\frac{1}{N} \sum_{i=1}^N\left(\left(\Delta x_i+d \Delta \theta_{x, i}\right)^2 +\left(\Delta y_i+d \Delta \theta_{y, i}\right)^2\right)}\end{split}\]

Introducing the new relative coordinates \(\Delta x_i, \Delta y_i\) and the relative direction \(\Delta \theta_{x,i}, \Delta \theta_{y,i}\):

(5.167)\[\begin{split}\Delta x_i & =x_i-x_c \\ \Delta y_i & =y_i-y_c \\ \Delta \theta_{x, i} & =\frac{s_{x, i}}{s_{z, i}}-\frac{s_{x, c}}{s_{z, c}} \\ \Delta \theta_{y, i} & =\frac{s_{y, i}}{s_{z, i}}-\frac{s_{y, c}}{s_{z, c}}\end{split}\]

Applying variational calculus to minimize this function results in [1]:

(5.168)\[t_\text{RMS} = -\frac{\sum_{i=1}^N \left(\Delta \theta_{x, i} \Delta x_i+\Delta \theta_{y, i} \Delta y_i \right)} {\sum_{i=1}^N \left(\Delta \theta_{x, i}^2+\Delta \theta_{y, i}^2 \right)}\]

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:

(5.169)\[\begin{split}R_v(d) =\sqrt{\frac{1}{N} \sum_{i=1}^N\left(\left(w_i\left(x_i^*-x_c^*\right)\right)^2 +\left(w_i\left(y_i^*-y_c^*\right)\right)^2\right)} \\\end{split}\]

Assigning ray powers as weights \(w_i\) leads to the following weighted solution:

(5.170)\[t = -\frac{\sum_{i=1}^N w_i^2 \left(\Delta \theta_{x, i} \Delta x_i+\Delta \theta_{y, i} \Delta y_i \right)} {\sum_{i=1}^N w_i^2 \left(\Delta \theta_{x, i}^2 + \Delta \theta_{y, i}^2 \right)}\]

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

(5.171)\[N_\text{px} = \text{offset} + \text{factor} \, \sqrt{N}\]

For simplicity, both image dimensions share the same pixel dimensions.


References