# A Non-Contact Measurement of Animal Body Size Based on Structured Light
## 2 Materials and Methods
### Measurement of Animal Body Parameters
#### 2.3.2 Denoising and Matching of Gray Center Point  
Using Algorithm 1 can address the impact shown in Figure 6d, but it cannot resolve the light astigmatism caused by the animal fur in Figure 6e, which requires a denoising algorithm. The astigmatism of fur has characteristics such as uncertain distribution and small numbers of grayscale centers clustering in light streaks. We propose a denoising algorithm based on the central intensity of the grayscale within the deleted neighborhood for the characteristics of the distribution of these astigmatic points. The main idea of this algorithm is to traverse all the grayscale centers, calculate the concentration of grayscale centers within a certain range, and remove any point with a concentration less than a certain value as noise. We calculate the average stripe width from the left and right boundaries in Algorithm 2 and create a window in which columns and rows are equal to the average stripe width for each pixel. Then, we count the gray-center point in this window. If the number is less than the stripe width, we set this point as an outlier and discard it. After denoising, the grayscale centers must match the sequence number of the corresponding light planes. Therefore, this study proposes a new matching algorithm that considers the trend of optical stripes orientation. First, we traverse each row in the center of the grayscale image, finding the first row with the same columns as the number of light planes as the main row and using the abscissa of each point as the initial reference point. Then, we traverse upward and downward, respectively, and match the points with the slightest difference in the abscissa from the reference point in each row as the same light stripe. When traversing up and down, we record the offset between each row and the main row and update the coordinates of the reference points used for matching. This is because the distance between the light stripes is relatively close, and the shape is complex. If the reference point is not updated, it will result in the intersection of adjacent light stripes. Therefore, it is necessary to use the average offset value recorded earlier as a direction of the light stripes to update the reference point, thereby effectively avoiding the problem of matching light stripes that intersect. The pseudo-code of denoising and matching the gray-center is shown in Algorithm 3. ```
Input: gray center point matrix, average stripes width, the number of light planes. Initialize: main center line. 1 foreach points \(\in\) gray center point matrix do
2 Create the window which cols and rows = average stripes width;
3 Count the gray center point in the window;
4 ifcount < average stripes width then
5 delete the point from gray center point;
6 endif
7
8 endfor
9 forcol : gray center point matrix.cols, do
10 Ifcol_size() == number of light planes, then
11 main center line = col;
12 endif
13
14 endfor
15 fori = position of main center line \(-1\); i > 0; i -- perform do
16 forj = points: cols[i] perform do
17 Find the points most near to j in main center line;
18 Match the points as the same light stripe;
19 Update the main center line;
20 End for
21 endfor
22
23 Fori = position of main center line + 1; i < gray center point matrix.size(); i ++ do
24 Forforj = points: cols[i] do
25 Find the points most near to j in main center line;
26 Match the points as the same light stripe;
27 Update the main center line;
28 endfor
29 endfor
30 Output: gray center point. ```  
**Algorithm 3**Animal Surface Gray-Center Denoising and Matching Algorithm. 2.3.3. Calculating the Body Size Parameters  
When the gray scale centers and the light planes are matched, the improved segment-facet intersection method is used to obtain the 3D point cloud of the animal. Because the point clouds are grouped according to light stripes, the animal body height can be automatically calculated based on each group's highest and lowest points.