# A Stray Light Detection Model for VR Head-Mounted Display Based on Visual Perception
## 4 Modeling  
The stray light evaluation model is a calculation mechanism that further connects the stray light threshold obtained from psychophysical experiments with the image data  
Figure 7: Stray light threshold of three VR HMDs. taken by the camera to generate a corresponding relationship. It is the final critical step in establishing a stray light detection method based on human perception. This section describes the feature selection and extraction of the image, training, and performance in detail to establish the stray light evaluation model. The approach of feature extraction in image processing is shown in Figure 8.  
Figure 8: Flow chart of image processing algorithm. By applying an image processing algorithm, the outside radius and gray level of circular stimuli, gray level, and standard deviation of the stray light image were extracted as the machine learning model's inputs to conduct the learning procedure. The outside radius and the gray level of stimuli were selected because they are the independent variables of the psychophysical experiment. The gray level and standard deviation of stray light were selected because there may be stray light outside the area presented by the image pattern, but the human eye may be unable to detect it. In addition, using the standard deviation of stray light concerns the concept of stray light contrast. The following steps obtained the features of the stray light image. First, we resized the input images to 419 \(\times\) 368 pixels with cubic interpolation and selected a region of interest (ROI) in which half the width and height was 184 pixels from the central point, respectively, to avoid the impacts of lens distortion. After selecting the ROI, the following procedures focused on acquiring the masks of the stimuli and stray light region, which are complementary in relation, and then multiplying the masks with the original image to separate the stimulus image and the stray light image. Second, we converted the original images to YObCr color space and obtained the grayscale image (Y channel). After applying histogram equalization for image enhancement to increase the global contrast, the image was processed by edge detection and binary thresholding. A Canny edge detector found the edges with thresholds of 250 and 100 for the upper and lower limits to exclude the non-edge pixels. Since the edge detected by the Canny algorithm is discontinuous, it would obviously influence subsequent contour retrieval. Therefore, morphological image processing was adopted to extend the range for connecting. The dilation with a small elliptical structuring element (3 \(\times\) 3) was beneficial for repairing the stimulus image's edges. Third, we adopted contour retrieval to find the contour from the dilated images, and binarized the pixel enclosed by each contour to acquire the mask for the part of stimuli and stray light, and then calculated the outside radius of the circular stimuli. Then, the masks could be multiplied by the captured image to extract the information of stimuli and stray light. Finally, the gray level of stimuli, gray level, and standard deviation of stray light could be calculated according to these valid data and inputted into the classification algorithm for training a stray light evaluation model. The obtained features could be visualized using the t-Distributed Stochastic Neighbor Embedding (t-SNE) technique, which can explore the feature distribution of the dataset and visualize the feature representation of the samples in two dimensions. Figure 9 illustrates the result of the t-SNE projection. The initial step for building a machine learning model was to determine the inputs. The outside radius and gray level of circular stimuli, gray level, and standard deviation of the stray light image were utilized to describe the relationship between the input parameters  
Figure 9: t-SNE visualization of the obtained features. and the visual response. The four features were selected as the inputs for the training procedure.