In order to accelerate the processing speed in the image processing algorithm, color images often need to be converted into gray images. 24 represents each pixel of a color image in three bytes. Each byte corresponds to the brightness of the RGB component.
When the RGB component value is different, it is displayed as a color image. When the RGB component is the same, it is converted into a gray image:
Generally, there are three conversion formulas.
(1) Gray (I, j) = [R (I, j) + g (I, j) + B (I, j)]/3;
(2) Gray (I, j) = 0.299 * R (I, j) + 0.587 * g (I, j) + 0.144 * B (I, j );
(3) Gray (I, j) = g (I, j); // from 2, we can see that G has a large component, so we can directly use it instead.
The following code is used:
1 # include <cv. h> 2 # include
Original Image:
Grayscale image generated by algorithm 1:
Grayscale image generated by algorithm 2:
Grayscale image generated by algorithm 3: