# Sampling Based on Kalman Filter for Shape from Focus in the Presence of Noise
## 1 Introduction  
Inferring three-dimensional (3D) shape of an object from two-dimensional (2D) images is a fundamental problem in computer vision applications. Many 3D shape recovery techniques have been proposed in literature [1; 2; 3; 4; 5]. The methods can be categorized into two categories based on the optical reflective model. The first one includes active techniques which use projected light rays. The second category consists of passive techniques which utilize reflected light rays without projection. The passive methods can further be classified into Shape from \(X\), where \(X\) denotes the cue used to reconstruct the 3D shape as _Stereo_[6], _Texture_[7], _Motion_[8], _Defocus_[9], and _Focus_[10]. Shape from Focus (SFF) is a passive optical method that utilizes a series of 2D images with different focus levels for estimating 3D information of an object [11]. For SFF, a focus measure is applied to each pixel of the image sequence, to evaluate the focus quantity at every point. The best focused position is acquired by maximizing the focus measure values along the optical axis. Many focus measures have been reported in literature [12; 13; 14; 15; 16]. Initial depth map, obtained through any of the focus measure operators, has the problem of information loss between consecutive framesdue to the discreteness of predetermined sampling step size. To solve this problem, refined depth map is acquired using approximation techniques, as reported in literature [17; 18; 19; 20; 21; 22]. As an important issue of SFF, when images are obtained by translating the object plane with constant step size, mechanical vibration, referred to as jitter noise, occurs in each step, as shown in Figure 1[21]. Since this noise changes the focus values of images by oscillating along the optical axis, accuracy of 3D shape recovery is considerably degraded. Unlike any image noise [23; 24], this noise is not detectable by simply observing images. Many filtering methods for removing the jitter noise have been reported [25; 26; 27]. In [25; 26], Kalman and Bayes filtering methods for removing Gaussian jitter noise have been proposed, respectively. In [27], a modified Kalman filtering method for removing Levy noise has been presented. In this paper, a new filtering method for removing the jitter noise is proposed as an extended version of [25]. First, jitter noise is modeled as Gaussian or speckle function to reflect more types of noise that can occur in SFF. At the second stage, the focus curves acquired by one of the focus measure operators are modeled as Gaussian function for application of the filter and a clearer performance comparison of various filters. Finally, Kalman filter as the proposed method is designed and applied. Kalman filter is a recursive filter that tracks the state of a linear dynamic system containing noise, and is used in many fields such as computer vision, robotics, radar, etc. [28; 29; 30; 31; 32; 33]. In many cases, this algorithm is based on measurements made over time. More precise results can be expected than from using only measurements at that moment. As the filter recursively processes input data, including noise, optimal statistical prediction for the current state can be performed. The proposed method is experimented by using image sequences of synthetic and real objects. The performance of the proposed method is analyzed through various metrics to show its effectiveness in terms of reconstruction accuracy and computational complexity. Root Mean Square Error (RMSE), correlation, Peak Signal-to-Noise Ratio (PSNR), and computational time of the proposed method are improved by an average of about 48%, 11%, 15%, and 5691%, respectively, compared with conventional filtering methods. In the remainder of this paper, Section 2 presents the concept of SFF and a summary of previously proposed focus measures as background. Sections 3 and 4 provide the modeling of jitter noise and focus curves, respectively. Section 5 explains the Kalman filter as the proposed method in detail.