## 4 An Improved Focusing Window Selection Method  
In Section 3, we applied different IEFs to a whole-picture focusing window which contained lots of information. For telescope systems, it will take a long time to calculate the IEF values during digital image processing, resulting in the loss of the high-frequency part of the distinct edge and poor real-time performance of the system [32]. Further, in Scene h of Figure 3, because the image is sparse, all IEF values show smooth features, which will affect the accuracy of auto-focusing. In order to speed up the process and increase the accuracy of auto-focusing, a dynamic adaptive focusing window selection (DAFWS) method is presented. In the DAFWS, the number of pixels is greatly reduced during sharpness estimation, and the time consumed by the calculation can be significantly shortened [33]. In the meantime, the application of a focusing window will also improve the quality, accuracy, and sensitivity of image estimation [34]. The traditional methods of sampling focusing windows [35; 36], such as center window, multiple spots window, and inverted T window, only sample the pixels in the selected window uniformly, and information outside the window is completely lost. Besides, for these traditional approaches, the position of the target in the image must be determined before applying the auto-focus process, which will lead to an additional cost of calculation time [37]. Another drawback of these conventional methods is that the sharpness scores significantly depend on whether the target is in the selected focus window. Once the actual imaging target is not in the window or in the central position of the selected window, there will be a greater discrepancy between the IEF value and the actual situation. In order to resolve this inadequacy, an efficient and accurate method is proposed. Firstly, instead of sampling inside a certain window, the whole image is sampled evenly, and the whole gray distribution feature of the image is retained. There is no need to locate the target in advance. Second, rather than setting the focus window before starting the auto-focus process, an adaptive method is applied to provide a dynamic focusing window. The pixels are divided into two categories: ROI (region of interest) pixels and background pixels. Experiments determined that the IEF values of the ROI pixels change greatly compared to the ones of the background pixels during the focusing process. Therefore, the ROI region can be selected out of the background region and extracted as the focus window. For example, the texture and boundary on the railing of Figure 3h have a greater impact on the estimation function, and they are the ROI. The sky part, belonging to the background region, is of no concern during the focusing process. The specific process of this even sampling-DAFW (ES-DAFW) method is given as follows. An M \(\times\) N image is divided into several \(m\times n\) sub-blocks. Then, the IEF value of each sub-block can be given by the following formula:  
\[E=\sum_{x=0}^{m-1}\sum_{y=0}^{n-1}Tenengrad(x,y) \tag{11}\]  
where \((x,y)\) is the pixel coordinate in the sub-block, and \(E\) represents the Tenengrad IEF value of the image sub-block. The IEF value of each sub-block is recalculated as \(E^{\prime}\) after each rotation of the stepper motor. Then, the IEF value of each sub-block is normalized as  
\[\Delta=\frac{|E^{\prime}-E|}{E^{\prime}} \tag{12}\]The threshold is set to \(u\), then the sub-blocks with normalized IEF value larger than \(u\) (i.e., \(\Delta>u\)) are ROI sub-blocks, while the remaining ones are considered as background blocks. For example, in Figure 5, a blurred picture with severe defocus of the scene in Figure 3h is divided into \(8\times 8\) blocks.