# An Efficient Neural Network for Shape from Focus with Weight Passing Method
## 3 Neural Network for SFF  
### Neural Network Model over FIS  
The neural network model over FIS (NN.FIS) proposed in [10] employs a three layers neural network model as shown in Figure 2. The input layer consists of three linear neurons and hidden layer  
Figure 1: Principle of image sequence acquisition in shape from focus (SFF). contains sigmoidal neurons with an additional linear neuron. Whereas the third layer is composed of one sigmoidal neuron and it provides output in the range \([0,1]\). At an iteration \((n)\), the local depth map \(z^{(n)}_{(x,y)}(j,k)\) for a small window of size \(M\times M\) centered at global index \((x,y)\) is described as:  
\[z^{(n)}_{(x,y)}(j,k)=\phi\left(\left(\mathbf{v}^{(n)}\right)^{T}\cdot\phi \left(\mathbf{U}^{(n)}\cdot\mathbf{i}\right)+w^{(n)}_{b}\right) \tag{1}\]  
where \((j,k)\) is spatial representation of the local index values in the window, \(\mathbf{U}^{(n)}\in\mathbb{R}^{H\times 3}\) and \(\mathbf{v}^{(n)}\in\mathbb{R}^{H}\) are the network weight matrices between the layers, \(H\) is the number of sigmoidal neurons, \(w^{(n)}_{b}\) represents the bias, \(\mathbf{i}=[j\;k\;1]^{T}\) is the input vector, \((\cdot)^{T}\) indicates transpose function of the matrix function, and \(\phi(\cdot)\) is the sigmoidal function. The focus measure \(F\) is calculated from \(z^{(n)}_{(x,y)}(j,k)\) by GLV as follows:  
\[F=\sum_{ \begin{subarray}{c}-m\leq j\leq m\\ -n\leq k\leq m\end{subarray} }\left[I\left(x+j,y+k,z^{(n)}_{(x,y)}(j,k)\right)- \mu\right]^{2} \tag{2}\]  
where \(I\left(x+j,y+k,z^{(n)}_{(x,y)}(j,k)\right)\) is the gray level at \((x+j,y+k)\) in the frame number \(z^{(n)}_{(x,y)}(j,k)\), \(m=(M-1)/2\) the local index bound, and \(\mu\) represents the average gray level of the pixels on the window surface defined by \(z^{(n)}_{(x,y)}(j,k)\) as:  
\[\mu=\frac{1}{M^{2}}\sum_{ \begin{subarray}{c}-m\leq j\leq m\\ -n\leq k\leq m\end{subarray} }I\left(x+j,y+k,z^{(n)}_{(x,y)}(j,k)\right) \tag{3}\]  
It is important to note that \(F\) and \(\mu\) are the functions of \(z^{(n)}_{(x,y)}(j,k)\). Accordingly, these functions not only depend on global index \((x,y)\) but also depend on local index \((j,k)\). It means, they can only be calculated during the network learning. Consequently, the complexity rises sharply. Generally, feedforward neural networks are utilized for learning an input-output relationship from the given example data set. In case of neural networks for SFF, there is no such an example data  
Figure 2: Multilayer feedforward neural network structure for shape recovery of neural network model over FIS and local depth map from the neural network model. **Left**: NN.FIS model; **Right**: local depth map from NN.FIS model. The local depth map consists of 9 neighboring pixels centered around \((x,y)\), when small window size is \(3\times 3\). In addition, each local depth is produced by network with changing the local index \(j\) and \(k\). set available. Therefore, it is a distinctive application of neural networks where a focus measure, which is role of a performance function, is to be optimized. The network weights are updated according to the gradient decent rule as follows:  
\[\Delta\textbf{W}^{(n)} = -\beta\left(\frac{\partial E}{\partial\textbf{W}^{(n)}}\right)\] \[= \beta\left(\frac{\partial F}{\partial\textbf{W}^{(n)}}\right)\]  
where \(\Delta\textbf{W}^{(n)}\) means the net change of the weight matrix \(\textbf{W}^{(n)}\), which includes \(\textbf{U}^{(n)}\), \(\textbf{v}^{(n)}\), and \(w_{b}^{(n)}\), whereas \(\beta\) is the learning rate. In addition, \(E=-F\) is the minimization criterion. At each iteration weights are updated and consequently \(z_{(x,y)}^{(n)}(j,k)\) are also updated.