# Sampling Based on Kalman Filter for Shape from Focus in the Presence of Noise
## 6 Results and Discussion
### Experimental Results  
Figure 8 presents the performance comparison of the filters in the 97 th frame of the simulated cone using various iterations in the presence of Gaussian jitter noise. Figure 9 provides performance comparison of the filters in the 100 th iteration using various frames of the simulated cone in the presence of Gaussian jitter noise. These Figures are intensively enlarged versions of the last iteration. \"Kalman output\" is the estimated position through Kalman filter, \"Bayesian output\" is the estimated position through Bayes filter, \"Particle output\" is the estimated position through particle filter, and \"True position\" is the position without the jitter noise. It is clear from these Figures that Kalman output converged better to True position than Bayesian output and Particle output. It means that Kalman filter outperformed the other filters compared for experiments. Figure 8: Performance of the filters: (**a**) Iteration—50, (**b**) Iteration—100, (**c**) Iteration—150, (**d**) Iteration—200. Figure 10 shows the Gaussian approximation of the focus curves using experimented objects in the presence of Gaussian jitter noise. \"Without Noise\" is the Gaussian approximation of the focus curve without the jitter noise, \"After Kalman Filtering\" is the Gaussian approximation of the focus curve after Kalman filtering, \"After Bayesian Filtering\" is the Gaussian approximation of the focus curve after Bayes filtering, and \"After Particle Filtering\" is the Gaussian approximation of the focus curve after particle filtering. It is clear from Figure 10 that the optimal position with the highest focus value in After Kalman Filtering is closer to the optimal position in Without Noise than the optimal positions in the focus curves obtained after using other filtering techniques. For performance evaluation of 3D shape recovery, three metrics were used in case of simulated cone, since the synthetic object had an actual depth map, as in Figure 11[47]. Figure 9: Performance of the filters: (**a**) Frame number—10, (**b**) Frame number—30, (**c**) Frame number—50, (**d**) Frame number—70. The first one is Root Mean Square Error (RMSE), which is a commonly used measure when dealing with the difference between estimated and actual value, as follows:  
\[RMSE=\sqrt{\frac{1}{XY}\sum_{x=0}^{X-1}\sum_{y}^{Y-1}\left(d(x,y)-\hat{d}(x,y) \right)^{2}} \tag{26}\]  
Figure 11: Actual depth map of simulated cone. Figure 10: Gaussian approximation of focus curves: (**a**) Simulated cone (60, 60), (**b**) Coin (120, 120), (**c**) LCD-TFT filter (180, 180), (**d**) Letter-I (240, 240). where, \(d(x,y)\) and \(\hat{d}(x,y)\) are the actual and estimated depth map, respectively, and \(X\) and \(Y\) are width and height of 2D images, which are used for SFF, respectively. The second one is correlation, which shows the linear relationship and strength between two variables as:  
\[\text{Correlation}=\frac{\sum_{x=0}^{X-1}\sum_{y=0}^{Y-1}\bigl{(}d(x,y)-\overline {d}(x,y)\bigr{)}\bigl{(}\hat{d}(x,y)-\overline{\hat{d}(x,y)}\bigr{)}}{\sqrt{ (\sum_{x=0}^{X-1}\sum_{y=0}^{Y-1}\bigl{(}d(x,y)-\overline{\hat{d}(x,y)}\bigr{)} ^{2})(\sum_{x=0}^{X-1}\sum_{y=0}^{Y-1}\bigl{(}\hat{d}(x,y)-\overline{\hat{d}(x, y)}\bigr{)}^{2})}} \tag{27}\]  
where, \(\overline{d(x,y)}\) and \(\overline{\hat{d}(x,y)}\) are the means of the actual and estimated depth map, respectively. The third one is Peak Signal-to-Noise Ratio (PSNR), which is the power of noise over the maximum power a signal can have. It is usually represented in terms of the logarithmic decibel scale as:  
\[PSNR=10 log_{10}(\frac{d_{max}^{2}}{MSE}) \tag{28}\]  
where, \(d_{max}\) is maximum depth value in the depth map and \(MSE\) is the Mean Square Error, which is the square of the RMSE. The lower the RMSE, the higher the correlation, and the higher the PSNR, the higher the accuracy of 3D shape reconstruction.