# A Non-Contact Measurement of Animal Body Size Based on Structured Light
## 2 Materials and Methods
### Measurement of Animal Body Parameters  
#### 2.3.1 Gray-Center Detection  
As shown in Figure 5, after the calibration of the light plane, structured light is projected onto the surface of animals to obtain the distortion or fracture information of light stripes. When finding the gray centers, the RGB images are translated to grayscale images. Figure 6a is the original image in which we project the structured light onto a fox specimen, and the grayscale value of the 900 th pixel row in this image is shown in Figure 6b. The grayscale distribution of light stripes in the image should be in accord with Figure 6c, and the task is to find out the position of the peak value (redpoint). However, as shown in Figure 6d, some scattered points appear in the grayscale distribution. The reason is that there might be some loss or fracture on light stripes because of the irregular shape of the animal body, and meanwhile, the scattering of light may also occur on animal fur. In addition, the reflectivity is not identical in different areas due to the complex colors of animal fur, which leads to an abnormal distribution, such as that seen in Figure 6e. Figure 5: Project the structured light to the surface of animal. To avoid the impact of light scattering while retrieving gray centers, this study proposes a method based on the average grayscale in the sliding window and between-group variance. First of all, to get rid of the interference of environmental light, the image is  
Figure 6: (**a**) Original image; (**b**) the gray scale distribution chart; (**c**) the gray scale distribution under ideal condition; (**d**) the gray scale distribution influenced by light scattering; (**e**) the gray scale distribution influenced by animal fur. binarized, and then we initialize the left window and the right window for pixels and calculate the mean value of each window as well as the between-group variance between these two windows. For convenience's sake, it is necessary to set a signal to record the boundary of stripes. Second, we traverse each line in the image. Along with the traversal, for each line, the two windows slide on the image. If the mean value of the left window is smaller than that of the right window, and the between-groups variance is greater than a certain value, it can be determined that this pixel point is the starting point of a light stripe. This pixel is recorded as the left boundary, and the signal is then changed. We continue to traverse until it finds a pixel, which means the value of the left window is larger than the right window, and the between-groups variance is greater than a certain value. This pixel is recorded as the right boundary of the light stripe. However, due to the use of binarization to remove the influence of environmental light, the left boundary will have a significant deviation when searching the light stripes boundary, so we mirror the image and re-traverse it. Because the image has been mirrored, it is necessary to find the right boundary of the light stripe on the reversed image and locate the left boundary by obtaining the coordinates of the original image. Eventually, the gray center of the light stripe is obtained by taking an average of the left and right boundaries. For the pseudo-code, see Algorithm 2. ```
Input: image, slide window size, threshold value of binarization, inter group variance_ ratio threshold Initialize: left window, right window, flag, left boundary, right boundary, temp boundary, gray center
1. Turn image to gray scale;
2. Binarize image;
3. for i = 1: image.rows do
4. for j = 1: image.cols do
5. Calculate average of gray value in left window and right window;
6. Calculate inter group variance radio between two window;
7. if flag == false and left average < right average and inter group variance ratio > inter group variance_ ratio threshold then
8. Flag = true;
9. endif
10. If if flag == true and left average > right average and inter group variance ratio > inter group variance ratio threshold then
11. Right boundary:push_back(pixel\({}_{\#}\));
12.