## 2 Proposed Methods
### Path-Optimized Search with EWMA Control  
Unlike static focus scenarios [27; 28; 29], NMFP requires rapid execution within relatively ideal imaging conditions to mitigate the impact of low-quality fundus images. In this study, a high-performance autofocus search should have the following: (i) fast convergence; (ii) a strong ability to suppress local extrema. The hill-climbing method [20] converges immediately upon meeting termination conditions, yet the search path is susceptible to becoming trapped in a local optimum. Exponentially weighted moving average (EWMA) [34; 35], a data processing method for process control, provides a heuristic solution. Its core idea is to fuse the current measurement value and historical statistical values to overcome data disturbances. Based on this mechanism, a path-optimized search with EWMA control (POSE) was designed, whichskillfully directs the search path of hill-climbing towards the focal plane by dynamically rectifying the evaluation curve noise. Figure 3 illustrates the initial consideration of equal-step sampling, where the sharpness values of the image stack are stored in a vector \(\mathbf{F}=[F_{1},\,F_{2},\,\ldots,\,F_{t}]\), with \(t\) representing the current sampling point. Then, the EWMA vector \(\mathbf{E}=[E_{1},\,E_{2},\,\ldots,\,E_{t}]\) is calculated with the following recursive formula:  
\[E_{t}=\beta E_{t-1}+(1-\beta)F_{t} \tag{2}\]  
where \(\beta\) is the smoothing coefficient (0 < \(\beta\) < 1), and \(E_{t-1}\) represents historical statistical values of sharpness information before \(t\) (\(E_{0}\) = 0). Expanding \(E_{t-1}\) in (2) step-by-step, \(E_{t}\) can be written as follows:  
\[E_{t}=\sum_{n=1}^{t}\,(1-\beta)\beta^{t-n}F_{n} \tag{3}\]  
It is regarded as the inner product of vector \(\mathbf{F}\) and an index weight vector (\(1-\beta\)) [\(\beta^{t-1}\), \(\beta^{t-2}\), \(\ldots\), \(\beta^{1}\), \(\beta^{0}\)], and the weight away from \(t\) decreases exponentially. In theory, the curve described by vector \(\mathbf{E}\) can effectively smooth the local errors within the search path. Simultaneously, it also enables real-time tracking of the sharpness curve described by vector \(\mathbf{F}\) due to its capacity to disregard outdated data gradually. With the performance advantages of EWMA, the first stage of POSE is realized through the following steps:  
**STEP 1. ** Perform continuous axial scanning with a large step \(D\) (\(D<\Delta\), \(\Delta\) is the depth of field (DOF) of the imaging system) while utilizing the sampling interval to update vectors \(\mathbf{F}\) and \(\mathbf{E}\);  
**STEP 2. ** If vector \(\mathbf{E}\) decreases continuously for three steps, \(E_{t-2}>E_{t-1}>E_{t}\) (meaning the scanning starts to leave the curve's peak), then proceed to STEP 3; otherwise, go back to STEP 1. **STEP 3. ** Pause the scanning and calculate the coarse focus position, \(P_{coarse}=[\text{argmax}(\mathbf{F})]\cdot D\). \(\beta\) is an essential parameter to determine the performance of POSE. Assuming that the contribution of low-weight points (less than \(1/e\) times the weight of \(t\) position) is ignored, EWMA can effectively average about \(1/(1-\beta)\) sampling points. Increasing \(\beta\) means improving the smoothness of vector \(\mathbf{E}\) but weakening its sensitivity (leading to slow convergence). To balance the trade-off between search efficiency and noise immunity,  
Figure 3: Schematic diagram of the POSE search process at the first stage. The search path converges to the rough position of the sharpness evaluation peak with the control of the EWMA vector. smoothing sampling points within \(\Delta\) are considered sufficient to overcome most local extrema in the search path, and \(\beta\) that satisfies this constraint is given by the following:  
\[\beta=1-D/\Delta \tag{4}\]  
The second stage of POSE provides high focus accuracy by compressing the search interval and step size.