# Ascertaining the Ideality of Photometric Stereo Datasets under Unknown Lighting
## 3 A Nonlinear Approach to Identify the Light Position  
Here, we propose an alternative new method for dealing with Problem (6), based on a nonlinear approach. By employing, as in the previous section, the QR factorization \(B=QR\), where the matrix \(Q\) is orthogonal, and \(R\) is upper triangular, we rewrite (6) as  
\[\|R\mathbf{z}_{t}\|^{2}=1,\qquad t=1,\dots,q. \tag{9}\]  
In these equations, the unknowns are the nonzero entries \(r_{ij}\) of \(R\), with \(i\leq j\), which we collect in the vector \(\mathbf{r}=[r_{11},r_{12},r_{13},r_{22},r_{23},r_{33}]^{T}\). Formula (9) can be seen as a nonlinear equation \(F(\mathbf{r})=\mathbf{0}\), for the vector-valued function, with values in \(\mathbb{R}^{q}\), defined by  
\[F(\mathbf{r})=[f_{1}(\mathbf{r}),\dots,f_{q}(\mathbf{r})]^{T},\qquad f_{1}( \mathbf{r})=\mathbf{z}_{t}^{T}R^{T}R\mathbf{z}_{t}-1,\qquad t=1,\dots,q.\]  
To determine the solution vector \(\mathbf{r}\), we apply the Gauss-Newton method to the solution of the nonlinear least-squares problem  
\[\min_{\mathbf{r}\in\mathbb{R}^{6}}\|F(\mathbf{r})\|^{2}, \tag{10}\]  
To ensure the uniqueness of the solution we set \(q\geq 6\), the same assumption of the Hayakawa procedure discussed in the previous section. We recall that the Gauss-Newton method [27] is an iterative algorithm that replaces the nonlinear problem (10) by a sequence of linear approximations  
\[\min_{\mathbf{s}\in\mathbb{R}^{6}}\|f(\mathbf{r}^{(k)})\mathbf{s}+F(\mathbf{r }^{(k)})\|,\qquad k=0,1,2,\dots,\]  
where \(J(\mathbf{r})\) is the Jacobian matrix of \(F(\mathbf{r})\). At each iteration, the step \(\mathbf{s}^{(k)}\) is computed by solving the above linear least-squares problem. Then, the approximated solution is of the form  
\[\mathbf{r}^{(k+1)}=\mathbf{r}^{(k)}+\mathbf{s}^{(k)}=\mathbf{r}^{(k)}-J^{ \dagger}(\mathbf{r}^{(k)})F(\mathbf{r}^{(k)}),\]  
where \(J^{\dagger}(\mathbf{r})\) is the Moore-Penrose pseudoinverse of \(J(\mathbf{r})\)[27]. A straightforward computation leads to the expression of the components \(f_{t}\) of \(F\)  
\[ \begin{split} f_{t}(\mathbf{r})=\mathbf{z}_{t}^{T}R^{T}R \mathbf{z}_{t}-1=& z_{1t}^{2}r_{11}^{2}+2z_{1t}z_{2t}r_{11}r_{12} +2z_{2t}r_{3t}r_{11}r_{13}+z_{2t}^{2}(r_{12}^{2}+r_{22}^{2})\\ &+2z_{2t}z_{3t}(r_{12}r_{13}+r_{22}r_{23})+z_{3t}^{2}(r_{13}^{2}+ r_{23}^{2}+r_{33}^{2})-1,\end{split} \]  
and, therefore, to the partial derivatives \(\partial f_{t}/\partial r_{ij}\). Consequently, the \(t\)th row of \(J\) is  
\[ \begin{split} J_{t,z}(\mathbf{r})&=\begin{bmatrix} \frac{\partial f_{t}}{\partial r_{11}}&\frac{\partial f_{t}}{\partial r _{12}}&\frac{\partial f_{t}}{\partial r_{13}}&\frac{\partial f_{t}}{ \partial r_{22}}&\frac{\partial f_{t}}{\partial r_{23}}&\frac{ \partial f_{t}}{\partial r_{33}}\end{bmatrix}\\ &=2\bigg{[}\begin{matrix}r_{11}&r_{12}&r_{13}\end{matrix} \mathbf{z}_{t}\mathbf{z}_{t}^{T}&\begin{bmatrix}r_{22}&r_{23}\end{bmatrix} \begin{bmatrix}z_{2t}&z_{3t}\end{bmatrix}&r_{33}z_{3t}^{2}\bigg{]}.\end{split}  \tag{11}\]  
To solve the nonlinear problem (10), we used the MATLAB function mmgn2 discussed in [31], which implements a relaxed version of the Gauss-Newton method and which is available on the web page [[https://bugs.unica.it/cana/software/](https://bugs.unica.it/cana/software/)]([https://bugs.unica.it/cana/software/](https://bugs.unica.it/cana/software/)) (accessed on 28 July 2023). The algorithm is especially suited for underdetermined nonlinear least-squares problems, but works nicely also for overdetermined ones. Formulating the solution of the PS problem with unknown lighting by a nonlinear model may appear as impractical, when there exists a linear formulation, e.g., the Hayakawa procedure. It has a principal advantage: the positive definiteness of the matrix \(G=R^{T}R\) is not an essential assumption for the application of the method. On the contrary, if the algorithm is successful in determining \(R\), then the matrix \(G\) is positive definite. This might help in introducing an ideality test for the dataset under scrutiny, as it will be shown in the following.