Grayscale processing and images (below)

From the formulas (1) and (2), knowing the R, G, and B values ​​of a certain point of the image and obtaining the luminance information, it can be calculated by the following equation:
Y=0.299*R+0.587*G+0.114*B
In the actual calculation, the following formula can be used:
Y=0.30*R+0.59*G+0.11*B (3)
In the grayscale image represented by the BMP, the red (R), green (G), and blue (B) components have the same value.
R=G=B (4)
Substituting (4) into (1), we can get: I = Q = 0, that is, the image has no color information.
Similarly, the same applies to the YUV color system.
4, gray processing
From the above equation (3), we can see that in order to convert a color image into a grayscale image, we first need to find out the color values ​​of the color image: R, G, and B. Then, by the formula (3) calculation, the luminance value Y can be obtained. Again: R = G = B = Y, then the new image is gray image.
For 24-bit or 32-bit true color images, finding the RGB value for each point is relatively easy. As explained earlier, 24-bit or 32-bit true color does not require a palette. Its image data is the actual RGB value. Each of the three RGB components occupies one byte, which is the value of RGB.
For a 16-bit bitmap, its one point is represented by two bytes. It also does not use palettes. To get RGB values, you need to understand R,
G, B position in these two bytes. Their position is this:

R accounted for 5, B accounted for 5, and G accounted for 6 in the middle.
After the corresponding RGB value is fetched, it is converted to eight bits (low 0). Therefore, to take out a RGB value of a point, the following algorithm can be used to obtain the values ​​of the three components of R, G, and B:
Typedef unio tagRGBDATA{
Unsigned int rgb16;
Stuct{
Unsigned B:5;//<<3
Unsigned G:6;//<<2
Unsigned R:5;//<<3
}Bits16;
}RGBDATA;
#define RR16(a)((unsigned char)
((((a).Bits 16.R)<<3)&Oxf8))
#define RG16(a)((unsigned char)
((((a).Bits 16.G)<<2)&Oxfc))
#define RB16(a)((unsigned char)
((((a).Bits 16.B)<<3)&Oxf8))
Obviously, by the above three macro definitions, it is easy to obtain the values ​​of R, G, and B components of a certain point. By using formula (3), the luminance value Y of this point can be obtained. Then, when writing back a new 256-color bitmap, let R = G = B = Y. Thus, a 256-level grayscale image is obtained.
Figure 2 is the effect of the transformation of Figure 1 through the above method:


Figure 1 before graying


Figure 2 after graying

5. Concluding remarks This article introduced the grayscale processing of 16-bit bitmaps when introducing the grayscale processing of color images. This method has good graying effect and high speed, and it has practical value in image processing.

Flooring For Basketball

Basketball PVC Flooring,Flooring For Basketball,Roll Indoor PVC Sports Floor

Landscape Grass Co., Ltd. , http://www.nsbcflooring.com

Posted on