## 3 Defocus Effect Calibration and Compensation
### Defocus Position Determination and Defocus Effect Compensation  
As mentioned above, both the incident angle calibration and ellipsometric parameter compensation rely on the accurate determination of defocus distance of a film. A defocus determination method based on actual BFP image characterization is introduced. The frequency domain analysis method, generally applied in autofocusing [34; 35], stems from the imaging resolution varying with defocus. The high-frequency signal in the image spectrum will be lost due to blurring when defocus occurs. In other words, the high-frequency components of a BFP image reduce when defocusing. This fact can establish the relationship between the frequency domain evaluation function of a defocused BFP image and its defocus position \(x_{i}\). The method begins with a discrete Fourier transform (DFT), and the formula of DFT for M \(\times\) N digital image is shown in Equation (8):  
\[f(k,l)=\sum_{\mu=0}^{M-1}\sum_{\
u=0}^{N-1}I(\mu,\
u)e^{-2\pi(\frac{ik}{M}+ \frac{l}{N})} \tag{8}\]  
where \(k\) and \(l\) are frequency domain pixel coordinates, and \(\mu\) and \(\
u\) are image pixel coordinates. The spectrum function \(P_{\rm s}\) denoting the pixel intensity of the image is shown in Equation (9) below:  
\[P_{s}(k,l)=|f(k,l)|^{2}. \tag{9}\]  
Thus, the frequency domain transform evaluation function \(F\) based on DFT is obtained as shown in Equation (10):  
\[F=\frac{1}{MN}\sum_{k=0}^{M-1}\sum_{l=0}^{N-1}\sqrt{k^{2}+l^{2}}P_{s}(k,l). \tag{10}\]  
The relationship between the evaluation function \(F\) and defocus position \(x_{i}\) is shown in Figure 4a. The negative values of \(x_{i}\) indicate a defocus direction away from the objective lens, while the positive values indicate towards the objective lens. The determination criterion from the \(F\)-\(x_{i}\) curve shows high resolution and sensitivity in the defocus position around [-35; 45]\(\mu\)m (bold solid red line), which is very suitable for calculating the defocus position of the defocus sample near the focal point. However, the resolution and sensitivity of the far focus position are significantly reduced, as shown by the dotted line in Figure 4a. Moreover, the curve is convex and cannot tell the defocus direction. Figure 4: Three different evaluation function were sampled from an experiment regarding defocus positions (curves represent a polynomial fit): (**a**) the frequency domain method using normalized DFT and the maximum radius method (the dashed lines corresponding to high sensitivity is used as the criteria for defocus determination); (**b**) the energy density method. Therefore, considering that the size of the imaging spot on the BFP changes with the defocus position, the maximum radius method and energy density method are introduced to overcome the limitation of the frequency domain method in calculating the defocus position \(x_{i}\). The maximum radius method extracts the \(R_{max}\) of the BFP image through edge detection, and the obtained \(R_{max}\)-\(x_{i}\) curve shows high resolution and sensitivity in the far-end focus positions (less than \(-35\)\(\upmu\)m and more than \(45\)\(\upmu\)m), as shown by the blue line in Figure 4a, where \(Fp\) is a threshold used to distinguish the high resolution and sensitivity of the defocus position curve from the low resolution and sensitivity. Further, a combination of the maximum radius method and frequency domain method shows significant improvement in calculating the defocus amount accurately, but the defocus direction remains to be determined. To address this problem, we introduced an energy density method. This method calculates the energy density within the \(R_{max}\) of a BFP image using \(NM=\sum{I_{ij}}/{S_{\max}}\), where \(S_{\max}\) is the pixel area of the circle with a radius of \(R_{max}\), and \(\sum{I_{ij}}\) is the sum of intensity values of image pixels within \(R_{max}\). An experimental variation curve of the energy density regarding defocus positions is shown in Figure 4b.