# An Efficient Neural Network for Shape from Focus with Weight Passing Method
## 4 Initial Weight Setting
### Proposed WP Method  
Figure 4 highlights the distribution of initial depth \(z_{i}\). From the figure, it can be observed that the initial depth values near the extremities may affect the procedure of choosing the proper initial weights. Particularly, the RS method may produce an erroneous initial depth values near the extremities as theses depth values may considerably deviate from the precise depth. This phenomena can also be understandable as there is high probability that \(G^{(1)}\) may be near to zero at these condition. Therefore, weights will become stagnant as this fact can be observed from Equations (17)-(19). It can be concluded that the initial depth needs to be close to the precise depth for avoiding local minimization problem. Therefore, WP method is proposed to relieve the local minimization regardless of a depth range of a reference depth map. The proposed WP method is described in Algorithm 2. In the proposed algorithm, in first step, a 2-dimensional reference depth map \(z_{r}(x,y)\) patch is converted into 1-dimensional reference depth vector \(z_{r}(s)\). In the second step, a new vector \(\hat{z}_{r}(t)\) is obtained by sorting \(z_{r}(s)\) with respect to depth in ascending order. In third step, an index vector \(\hat{s}(t)\) is acquired by rearranging the indices of \(z_{r}(s)\) corresponding to the depth at \(\hat{z}_{r}(t)\). In fourth step, 2-dimentional indices \((\hat{x}(t),\hat{y}(t))\) are acquired by rearranging the index of 2-dimentional patch \(z_{r}(x,y)\) corresponding to the depth at \(\hat{z}_{r}(t)\). In order to describe these four steps, an example is shown in Figure 5. In fifth step, the proper initial weights for the first pixel \(z_{r}(\hat{x}(1),\hat{y}(1))\) are obtained by comparing the initial depth with the reference depth. In sixth step, a depth for \((\hat{x}(t),\hat{y}(t))\) is estimated through the NN.Planar model as using Equations (7)-(21) with \(\mathbf{u}^{(1)},\mathbf{v}^{(1)}\), and \(\mathbf{w_{b}}^{(1)}\). In next step, initial weights for the next pixel are set by passing updated weights from the present pixel. In this way, the entire depth map is estimated by repeating the steps 6-7 for all pixel positions. Figure 4: Histogram of \(z^{(1)}_{(x,y)}\) values. It graphically represents the distribution of numerical data of \(z^{(1)}_{(x,y)}\). In addition, the bins are same size of 0.01 and the total frequency is \(10,000\). Note that it is similar to the Gaussian distribution, and thus the frequency number is very low at a range of \(z^{(1)}_{(x,y)}\leq 0.1\) or \(z^{(1)}_{(x,y)}\geq 0.9\). Consequently, in the range, it is hard to meet the requirements of \(|z^{(1)}_{(x,y)}-z_{r}(x,y)|\leq T_{1}\) within \(R\), and thus it fails to set the proper initial weights in RS method. ```
1:procedureWeightPassing
2:\(z_{r}(s)\gets z_{r}(x,y)\)\(\triangleright\) Change 2-dimensional \(z_{r}(x,y)\) into 1-dimensional vector form \(z_{r}(s)\)
3:\(\hat{z}_{r}(t)\leftarrow\) sorted \(z_{r}(s)\) into depth order
4:\(\hat{s}(t)\leftarrow\) rearranged the index of \(z_{r}(s)\) corresponding to the depth of \(\hat{z}_{r}(t)\)
5:\((\hat{x}(t),\hat{y}(t))\leftarrow\) rearranged the index of \(z_{r}(x,y)\) corresponding to the depth of \(\hat{z}_{r}(t)\)
6:for\(i=1\) to \(R\)do
7: Generate initial weights \(\mathbf{u},\mathbf{v},w_{b}\) randomly.