# Ascertaining the Ideality of Photometric Stereo Datasets under Unknown Lighting
## 4 Dealing with Nonideal Data  
When the light estimation techniques discussed in Sections 2 and 3 are applied to experimental datasets, usually computational problems emerge. This is due to the fact that in real applications some of the assumptions required by the model may be unmet. The most limiting assumption in the application of the Hayakawa procedure is the positive definiteness of matrix \(G\) in (7). For some datasets, the smallest eigenvalue of \(G\) turns out to be nonpositive, leading to a breakdown in the Cholesky algorithm. This is clearly due to \"nonideality\" of data. In applicative scenarios, it would be useful to predict if the available data satisfy the model assumptions by a numerical indicator of ideality. What is needed is a clear and effective strategy to check this at a reasonable computational cost. Our first attempt was to control the error produced by approximating the data matrix \(M\) by the matrix \(M_{3}\), obtained by truncating the factorization (5) to three terms. In this case, it is known that \(\|M-M_{3}\|=\sigma_{4}\), the fourth singular value of \(M\), and that such value is minimal among all matrices of Rank 3 [27]. We tried to vary the composition of the dataset, removing some images from it, aiming to minimize the value of the approximation error \(\sigma_{4}\). We also investigated the minimization of the ratio \(\rho=\sigma_{4}/\sigma_{3}\), which represents the distance of \(M\) from being a Rank-3 matrix. None of these attempts was successful, in the sense that the values of both \(\sigma_{4}\) and \(\rho\) appear to be unrelated to the positive definiteness of \(G\) and to a good 3D reconstruction of the observed object. Then, we focused on the matrix \(H\) defined in (8). This matrix determines the entries of the matrix \(G\) via the solution of the system \(H\mathbf{g}=\mathbf{1}\), and so is directly related to its spectral properties. From (8), it is immediate to observe that each row of \(H\) is obtained from one column of the matrix \(Z\), which is the first tentative approximation of the light matrix \(L\). So, each row of \(H\) is associated with a light direction, and consequently, it depends upon a single image in the dataset. Since the matrix \(H\) must have at least six rows to ensure a unique solution matrix \(G\), a redundant dataset allows one to investigate the effect of different image subsets by simply removing from \(H\) the rows corresponding to the neglected images. One important feature of this process is that the SVD factorization (5) is performed only once, and the solution of system (8) only requires the QR factorization of the relatively small matrix \(H\in\mathbb{R}^{q\times 6}\). We propose to validate a dataset using the value of the smallest eigenvalue \(\lambda_{3}(G)\) of the matrix \(G\) as a measure of data ideality. Indeed, a negative value of \(\lambda_{3}(G)\) is a clear indicator of an inappropriate shooting technique, and suggests that some images should be removed from the dataset. At the same time, to select one between two different reduced datasets, which are both admissible for the application of the Hayakawa procedure, one may choose the one which produces the largest eigenvalue \(\lambda_{3}(G)\). In fact, in our experiments, we observed that a small value of \(\lambda_{3}(G)\) may introduce distortions in the 3D reconstruction. This idea inspired the numerical method outlined in Algorithm 1. It stands on the assumption that in the given dataset of \(q\) images, there exists a subset of \(q-1\) images, which leads to a positive definite matrix \(G\). If this condition is not met, then some preprocessing is needed to exclude the worst images from the dataset.