# Use of Gradient-Based Shadow Detection for Estimating Environmental Illumination Distribution
## 2 Materials and Methods
### Line Fitting and Matching Score Computation  
Line fitting is performed using only the points that have passed the gradient direction matching, as described in Section 2.1. We use principal component analysis (PCA) to obtain the normal (direction) information of the fitted line [19]. If an insufficient number of points have passed the gradient direction matching, we determine that a reliable shadow boundary is not detected (under 20 pixels, experimentally). When the shadow cast by the \(i\)-th candidate light source has \(N\) line segments, we compute the matching score, \(L_{i\_k}\), on the \(k\)-th line segment, as shown in Equation (1):  
\[L_{i\_k}=1-e^{-\frac{r_{i\_k}}{\tau_{1}}},\qquad C_{i\_1}=\frac{1}{N}\sum_{k= 1}^{n}L_{i\_k}, \tag{1}\]  
where \(r_{i\_k}\) represents how many pixels in the image are matched with the \(i\)-th candidate's shadow boundary elements; \(r_{i\_k}\) is computed by dividing the number of the matched points by the total number of the sample points on \(k\)-th line segment. \(N\) is the total number of shadow boundary lines cast by the \(i\)-th candidate light source, \(\tau\_1\) is used to control the relative influence of the gradient direction matching (here it is set to 0.3, experimentally), and \(C_{i\_1}\) is the average score of the gradient-based matching of the \(i\)-th candidate light source. This measure represents the number of points that support the shadow boundary cast by the \(i\)-th candidate light source. We compute an angular difference between the candidate shadow boundary line and the fitted line using the matched points. Specifically, we compute a slope direction, \(\theta_{A\_ik}\), of the \(k\)-th boundary line of the \(i\)-th shadow, and a slope direction, (\(\theta_{B\_ik}\)), of the fitted line segment, respectively. We can then obtain the angular difference, \(D_{i\_k}\), using Equation (2) (\(\tau\_2\) is set to 3, experimentally). Here, \(C_{i\_2}\) is the average score of the angular difference of the \(i\)-th candidate light source in the image. \[ \begin{split} D_{i\_k}&=e^{-\frac{\Delta Angle(i _k})}{\tau_{2}},\qquad C_{i\_2}=\frac{1}{N}\sum\limits_{k=1}^{n}D_{i\_k}\quad, \\ \Delta Angle_{i\_k}&=\min(180^{\circ}-|\theta_{A\_ ik}- \theta_{B\_ik}|,|\theta_{A\_ik}-\theta_{B\_ik}|)\end{split}  \tag{2}\]  
When the AR marker occludes the \(i\)-th light source, we can compute the position of the upper corner of the AR marker on the shadow surface, which is a vertex of the shadow boundary. Our algorithm computes a distance score, \(E_{i\_k}\), between the intersection point of the fitted line and the projected corner point of the AR marker. The cubic marker is employed, meaning that the number of intersection points is one less than the total number of the shadow boundary lines. This measure represents how close the junction of the shadow boundary is to the projected upper corner of the 3-D marker on the shadow surface. \(E_{i\_k}\) is calculated as follows:  
\[E_{i\_k}=e^{-\frac{error_{i\_k}}{\tau_{3}}},\quad C_{i\_3}=\frac{1}{N}\sum \limits_{k=1}^{n}E_{i\_k},\quad error_{i\_k}=\|projPt_{ik}-fittingPt_{ik}\|, \tag{3}\]where _projPtij_ is the \(j\)-th projected corner position of the \(i\)-th candidate shadow, and _fittingPtij_ is the intersection between the \((j-1)\)-th shadow boundary and the \(j\)-th shadow boundary. Here, \(\tau\_3\) is set to 8, experimentally. Figure 4a shows one of the shadow boundaries of the candidate illumination source. The upper and lower corners are represented by red and yellow, respectively. Figure 4b shows the matched (red) points in the search region of the third shadow boundary line segment. A total of 100 points in the search region are sampled, along 10 line segments. Each of these sections has the same slope as the boundary line, in a vertically bi-directional direction with respect to the boundary line (Figure 4b). Figure 4c shows the fitted boundary lines (green) with the matched points and their intersection points (purple).