Bitmap grayscale processing method

Abstract] Grayscale processing is an important step in image processing. Its result is the basis of subsequent processing. This paper first introduces the basic structure of the bitmap and the color system, and then focuses on the grayscale processing method of the 16-bit bitmap.

Keywords: grayscale bitmap image processing Abstract: Gray processing is a very important step in image processing, its result is the foundation of later image processing. This paper introduces primary structure of bitmap and color system, and then only mainly has gray processing Method of 16-bit bitmap.
Key words:Graying Bitmap Image Processing

1. Introduction Grayscale refers to an image that contains only luminance information and no color information. Grayscale processing is a process of converting a color image containing brightness and color into a grayscale image. Gray-scale processing is a very important step in many image processing and his results are the basis for subsequent processing. Therefore, it is particularly important to seek a correct and effective grayscale processing method.
2, device-independent bitmap (DIB)
DIB is Device_Independent Bitmap. Currently, Windows-processed DIBs usually exist as BMP files. The BMP file has the following four parts;
1) Bitmap header file: BITMAPFILEHEADER
It is defined as:
Type struct tag BITMAPFILEHEADER{
WORD bfType;
DWORD bfSize;
WORD bfReserved1;
WORD bfReserved2;
OWORD bfOffBits;
}BITMAPFILEHEADER;
2) Bitmap header: BITMAINFOHEADER
It is defined as:
Type struttagBITMAPINFOHEADER{
OWORD biSize:
DWORD biWidth;
DWORD biHeight;
WORD biPlanes:
WORD BiBitCount:
DWORD biCOmpression;
DWORD biSiZelmage;
DWORD biXPelsPerMeter:
DWORD biYPelsPerMeter:
DWORD biClrUsed;
DWORD biClrlmportant;
}BITMAPINFOHEADER;
Its length is fixed at 40 bytes.
3) Palette
It is used to store the color of the bitmap. If it is a true color image, it does not require a color palette. It is defined as:
Typedef tagRGBQUAD{
BYTE rgbBlue;
BYTE rgbGreen;
BYTE rgbRed;
BYTE rgbReserved;
}RGBQUAD;
4) Actual image data For the bitmap used in the palette, the image data is the index value of the pixel color in the palette. For the true color image, the image data is the actual red (R), green (G) ), the value of blue (B).
3, color system color system commonly used RGB, YIQ, YUV.
1) The YIQ color system belongs to the NTSC system. Y is the brightness, the gray value of the image, and I and Q are the tones. Its relationship with RGB is:

2) YUV belongs to the PAL system. Y is also brightness, and U and V are also hue. Its relationship with RGB is:


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 graph represented by BMP, red (R), green (G), and blue (B) The values ​​of the components are equal, that is, R=G=B (4) (4) Substituting (4) into (1), we get: I=Q=0, that is, the image has no color information. .
Similarly, the same applies to the YUV color system.
4, gray-scale processing from the above (3) can be seen: In order to convert the color image to a gray-scale image, we must first find out the color value of the color image: R, G, 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.

Facial Skin Spatula

Facial Skin Spatula,Skin Scrubber Spatula,Ultrasonic Skin Spatula,Ultrasound Skin Scrubber,Face Spatula

Zhongshan Seven Cool Electronics Technology Co.,Ltd , https://www.gdsevencool.com