# A Multi-Loop Vehicle-Counting Method under Gray Mode and RGB Mode
## 3 Methods
### Vehicle Detection under Gray and RGB Modes
#### 3.1.1 Preliminary Detection under Gray Mode
To analyze the unsuccessful detection more clearly, the result of background subtraction under gray mode (\(\delta^{gray}_{k}\)) was studied by mapping it to another color pattern to make it more intuitive. The constructed color pattern is a smooth transition from black to red, orange to yellow, and finally to white, as shown in Figure 4. The darker the color, the lower the background subtraction value. By comparing with Figure 2a, it can be seen that the background subtraction values at the position of the red vehicle were generally low, which directly led to the holes in Figure 3b. Therefore, the main reason for this result is that the detection fails when the gray-mode values of foreground and background are close to each other, as could be clearly reflected by comparing Figure 3a with Figure 2b. Figure 4: Mapped gray-mode result of background subtraction. Figure 3: Detection under gray mode. (**a**) Established gray-mode background (\(B^{gray}\)). (**b**) Detection result under gray mode (\(l^{binary_{gray}}_{539}\)). Figure 2: Current frame under (**a**) RGB mode (\(l^{RGB}_{539}\)) and (**b**) gray mode (\(l^{RGB}_{539}\)). Similarly, the result of subtracting the background from current frame under red mode, green mode, and blue mode could be expressed as follows:  
\[\delta_{k}^{red}=|I_{k}^{red}-B^{red}| \tag{8}\]  
\[I_{1_{(i,j)}}^{gray}(i,j)\leq\cdots\leq I_{n_{(i,j)}}^{gray}(i,j)\leq\cdots \leq I_{N_{(i,j)}}^{gray}(i,j) \tag{1}\]0  
\[I_{1_{(i,j)}}^{gray}(i,j)\leq\cdots\leq I_{n_{(i,j)}}^{gray}(i,j)\leq\cdots \leq I_{N_{(i,j)}}^{gray}(i,j) \tag{1}\]1  
where \(I_{k}^{red}\), \(I_{k}^{green}\), and \(I_{k}^{blue}\) are the current frame \(k\) under red mode, green mode, and blue mode. The mapped results of the background subtraction under red mode, green mode, and blue mode are shown in \[I_{1_{(i,j)}}^{gray}(i,j)\leq\cdots\leq I_{n_{(i,j)}}^{gray}(i,j)\leq\cdots \leq I_{N_{(i,j)}}^{gray}(i,j) \tag{1}\]2 By comparing Figure 4, Figure 7a, Figure 7b, and Figure 7c, it could be found that the results of background subtraction under gray mode, red mode, green mode, and blue mode were very different. Under gray mode and blue mode, the background subtraction values of the red vehicle were generally low, while under red mode and green mode, the background subtraction values were much higher, especially under red mode. In contrast, for the black vehicle on the left, the results of background subtraction under gray mode were higher. The vehicle segmentation is obtained by binarizing the subtracting result, as mentioned in Section 3.1.1. In this case, based on subtraction results with different properties, the detection under gray mode, red mode, green mode, and blue mode also has different characteristics, as shown in Figures 3b and 8a-c.  
\[I_{1_{(i,j)}}^{gray}(i,j)\leq\cdots\leq I_{n_{(i,j)}}^{gray}(i,j)\leq\cdots \leq I_{N_{(i,j)}}^{gray}(i,j) \tag{1}\]3 Background under (**a**) red mode (\(B^{red}\)), (**b**) green mode (\(B^{green}\)), and (**c**) blue mode (\(B^{blue}\)) and (**d**) the reconstructed RGB-mode background (\(B^{RGB}\)). \[I_{1_{(i,j)}}^{gray}(i,j)\leq\cdots\leq I_{n_{(i,j)}}^{gray}(i,j)\leq\cdots \leq I_{N_{(i,j)}}^{gray}(i,j) \tag{1}\]4 The mapped result of background subtraction under (**a**) red mode, (**b**) green mode, and (**c**) blue mode.