# Calibration and Image Reconstruction in a Spot Scanning Detection System for Surface Defects
## 3 System Calibration and Image Reconstruction Methods
### System Adjustment and Image Reconstruction Method  
Once the calibrated system parameter vector \(\hat{\psi}\) is obtained, the corresponding calibrated mapping relationship \(\mathbf{g}_{\hat{\psi}}\) can be established to reconstruct an image free of distortions. However, because of the position deviation between the initial illuminated spot and the origin, the undetected area is still present at the central part of the surface and the image. Thus, it is required to adjust the system to make them coincide. The adjustment method is to move the two-dimensional translation stage from its original position by distances of \(\Delta x\) and \(\Delta y\) along the X and the Y directions, respectively, and take this position as the starting point of scanning. The values of \(\Delta x\) and \(\Delta y\) are dependent on the thickness of the sample to be detected. Let \(\Delta h\) be the thickness difference between the sample and the calibration plate. When \(\Delta h\
eq 0\), the origin \(O_{s}\), which is the intersection of the rotation axis and the surface, will shift, leading to the changes of the coordinate of the initial illuminated spot. Assuming that the sample'surface is always on the focal plane of the ellipsoidal mirror, we can derive the expression of \(\Delta x\) and \(\Delta y\) using simple geometric relations as  
\[\Delta x =\hat{x}_{i}-\Delta t\tan\theta_{i}\cos\varphi_{i} \tag{15}\] \[\Delta y =\hat{y}_{i}-\Delta t\tan\theta_{i}\sin\varphi_{i}\]  
where \(\hat{x}_{i}\) and \(\hat{y}_{i}\) are the parameters that represent the coordinate of the initial illuminated spot in \(\hat{\psi}\). After adjustment, the SS-SDES can perform the scan for the whole optical surface in a normal way but without any missing area at the center. Let \(\hat{\psi}^{{}^{\prime}}\) be the system parameter vector of the adjusted system. Apparently, \(\hat{\psi}^{{}^{\prime}}\) is the same as \(\hat{\psi}\) except that the values of parameters \(x_{i}\) and \(y_{i}\) are equal to zero. The adjusted mapping relationship \(\mathbf{g}_{\hat{\psi}^{{}^{\prime}}}\) is then constructed to map the discrete intensity sequence acquired by the adjusted system to image coordinates. This is a mapping transformation from one dimension to two dimensions, and there still exist some problems to be addressed. First, the resulting coordinates are generally non-integral, failing to meet the regulation that requires the image coordinate of each pixel to be integral. Second, because the sampling frequency and the scanning velocity are fixed during scanning, the density of sampling points in the central area of the surface will be much higher than that in the edge. As a consequence, the pixel in the central part of the reconstructed image may correspond to more than one sequence number while some pixels in the edge correspond to zero. Aiming at these problems, this paper proposes an image reconstruction method based on weighted average as follows:  
1. Initialize an image matrix \(Ig(\mathbf{u})\) and a weight matrix \(Wt(\mathbf{u})\) with the same size determined by the actual scanning range and \(k_{0}\); initialize the sequence number \(n=0\);
2. Calculate the image coordinate corresponding to the sequence number by \(\mathbf{u}=\mathbf{g}_{\hat{\psi}^{{}^{\prime}}}(n)\), and round it to the integer coordinate \(\mathbf{u}_{int}\); define a weight value according to the distance between them as \(w=1-\|\mathbf{u}-\mathbf{u}_{\text{int}}\|\);
3. Update the image matrix by \(Ig(\mathbf{u}_{\text{int}})=Ig(\mathbf{u}_{\text{int}})+wl_{n}\) with \(I_{n}\), the corresponding intensity in the acquired discrete intensity sequence, and the weight matrix by \(Wt(\mathbf{u}_{\text{int}})=Wt(\mathbf{u}_{\text{int}})+w\);
4. Update the sequence number by \(n=n+1\); if the traversal has not been completed (i.e., \(n<N\)), go back to step 2;
5. Compute the element-wise quotient of the two matrices, i.e., \(Ig(\mathbf{u})=Ig(\mathbf{u})/Wt(\mathbf{u})\);
6.