When reading an image into openCV, they are stored as a color matrix using an RGB model. This is convenient, as it makes it possible to treat the image as a matrix of numbers to build a function that returns a numeric "color score". Our goal for this color score therefore is to calculate how “green” the bike lane image is. The hard part in this process is how to define this "bike lane green", since the bike lane green is a very specific color.
However, we should include a range of green colors in order to account for variations in the lighting of the images captured. In this step, we use image processing software (photoshop and gimp) to find the RGB components for the color of a sample bike lane and set lower and upper bound according to the RGB components. With lower and upper bounds in place, we can create a mask and perform a color filtering, leaving only the target green color behind. Which means that the resulting image's matrix after filtering will have non-green values set to 0, thus we can calculate the difference between original image and the resulting image. The more green kept, the more components kept and the higher the sum will be. The sum of the number of green pixels is our color score.
To summarize:
- Convert image to HSV color model matrix.
- Create color bound for "bike lane green".
- Filter out colors that are not in the range.
- Calculate color score based on total sum of green pixels after filtering