# Use of Gradient-Based Shadow Detection for Estimating Environmental Illumination Distribution
## 2 Materials and Methods
### Gradient-Based Shadow Boundary Detection  
After converting a given RGB input image to a YUV image, we apply a Sobel mask to the Y image, and then compute the gradient information (i.e., the magnitude and direction). Our method examines whether the gradient direction of each pixel in the image is the same as the normal direction of the shadow boundary line of the candidate light source. Only pixels with the same direction as the candidate shadow boundary are classified as matched points, within eight gradient direction ranges. Since the 3-D AR marker is a cubic object, the shadow map generated by the candidate light source consists of four or five shadow line segments. This examination is therefore repeated for every line segment making up the candidate shadow.  
At points where the gradient direction check passes, the non-maximum suppression, based on the gradient direction, is employed to remove spurious matching pixels. The gradient magnitude value of the anchor (center) pixel in a local mask (3 by 3) is compared with the gradient magnitudes of the two neighbor pixels along the same gradient direction. In other words, we check whether or not three consecutive pixels, including the center pixel of the mask, have the same gradient direction. Then, if the center pixel has a higher gradient magnitude value than the neighboring pixels on both sides, we determine the center pixel to have passed the non-maximum suppression.  
To confirm that the candidate shadows are actually present in the image, we then perform gradient-based matching along the candidate shadow boundary. Along the boundary line segment of the candidate shadow, 10 pixels are sampled at regular intervals, considering the length of the line segment.  
The distance between the upper corner point of the 3-D marker and the cast point on the shadow surface changes according to the incline angle of the candidate light source. This means that the shadow boundary corresponding to the edge of the upper plane of the 3-D marker may be blurred in  
Figure 3: Results of the Canny edge detector with double threshold values of **(a)** 10 and 20 and **(b)** 20 and 40, and results of the Sobel operator with threshold values of **(c)** 10 and **(d)** 20. The inset in (d) shows the eight directions in which the gradient direction is coded.  
Figure 2: **(a)** Geometric elements of the three-dimensional (3-D) marker; **(b)** candidate shadow boundaries at 30\({}^{\circ}\) intervals of longitude and latitude; **(c)** corners of the top plane of the augmented reality (AR) marker, consisting of the candidate shadow and cast points; **(d)** boundary of the cast shadow.  
the image. Therefore, in our method we examine more neighboring pixels along the gradient direction (perpendicular to the boundary line) to detect the soft-edged shadow. The distance from the corner of the 3-D AR marker to the corresponding vertex of the shadow boundary can then be calculated. For the soft edge connecting the two upper corners, we compute the average distance of the two upper corners, and one tenth of this distance is used as the width of the region of interest. Here, we sample 10 points in a vertically bi-directional direction, with respect to the boundary line, for gradient-based matching. In general, vertical shadow boundaries originate from the bottom corners of the AR cube marker. In this case, as the bottom corner is attached to the shadow surface, and the distance from this vertex is zero. We therefore compute the distance from the other vertex that constitutes the vertical boundary (the upper corner), to its projection point on the shadow surface. Our algorithm divides this distance by two, and uses this as the width of the sampling region.