*3.1.1.3. Pixel extraction*

To identify traffic density, three categories of pixel colors are extracted: green, orange, and red (see Algorithm 3). The green, orange, and red pixels mean low, medium, and high amount of traffic, respectively. The pixel number of each category is obtained by getting the RGB component of the whole pixels in the image. After excluding the white pixels (line 6 of Algorithm 3), three rules are implemented to classify the remaining pixels in one or another category (lines 7 to 12 of Algorithm 3). Once the picture is entirely read, the percentage of each category is calculated by dividing the number of green, orange, and red pixels by the total number of colored pixels.

Algorithm 3. Generating the pixel color extraction.

1: for(int i = 0, i < allFrame, i++)

(lines 14 and 15 of Algorithm 2). On the contrary, if the brightness difference is higher than the threshold, the color of the pixel does not change (lines 16 and 17 of Algorithm 2). Thanks to this method, it is possible to extract only the color information of the traffic.

**Figure 1.** Description of the principle of background removal. The background image (b) is subtracted from the image

that includes the traffic (a). The result is a picture with the traffic information only (c).

20 Machine Learning - Advanced Techniques and Emerging Applications

2: float red = 0, orange = 0, green = 0

