VC + + Digital Image processing Yang Shuxiang
This article to the teacher's code summary, code small white by the way to add their own more confused knowledge points, convenient follow-up review.
- The image structure for BMP format is divided into the following four parts:
Bitmap File Header structure Bitmapfileheader |
Bitmap Information Header Structure Bitmapinfoheader |
Bitmap Color Table Rgbquad |
Bit image Prime Data part |
- The image for the bitmap is divided into four categories:
- Monochrome Image: There are two values: 0,255 where 0 means black, 255 is white (also can be normalized to 0 and 1).
- Grayscale Image: With a color table, equivalent to an index table. RGB has the same component value.
- Pseudo-color Image: RGB components are not exactly the same, with a color table, equivalent to the index, the entire image of 256 colors.
- 24-bit True color Image: No color table, RGB three components accounted for 8 bits.
- For a description of struct structure in C + +:
In C + + if a typedef is used:
struct Student
{
int A;
}stu1;//STU1 is a variable
typedef struct STUDENT2
{
int A;
}STU2; STU2 is a struct type =struct Student
That is, using a typedef in C + + is equivalent to renaming an operation, which is equivalent to renaming a variable behind a struct.
- For type aliasing problems in variables-Introduce the header file "WindowsX.h"
windef.h--basic form definition
Winbase.h--kernel function
wingdi.h--Graphics Device Interface functions
winuser.h--User Interface functions
Here the main use is the first application: the basic shape definition, which defines the macro, convenient for later use.
1 Long 2 int BOOL; 3 Char 4 short WORD; 5 float FLOAT;
So the format of BMP image can be displayed in code way
Bitmap File Header:
1typedefstructTagbitmapfileheader2 {3WORD Bftype;//represents a 2-byte, 16-bit short integer that is used to determine whether the bitmap file type4DWORD bfsize;//represents the size of a 4-byte bitmap file. 5WORD bfReaserved1;//the reserved word for the bitmap file must be 0.6WORD BfReaserved2;//reserved word for bitmap file, must be 07DWORD bfoffbits;//represents the starting position of the data8} Bitmapfileheader;
Bitmap Information Header:
typedefstructTagbitmapinfoheader{dword bisize;//number of bytes occupied by this structureLONG Biwidth;//the width of the bitmap, in pixelsLONG Biheight;//the height of the bitmap, in pixelsWORD biplanes;//the level of the target device must be 1WORD biBitCount;//number of bits required per pixel, 1, 4, 8,DWORD bicompression;/*bitmap compression type, must be one of 0 (uncompressed), 1 (bi_rle8 compression type), 2 (bi_rle4 compression type)*/DWORD biSizeImage;//the size of the bitmap, in bytesLONG Bixpelspermeter;//Bitmap Horizontal resolution, pixels per metreLONG Biypelspermeter;//Bitmap vertical resolution, pixels per metreDWORD biclrused;//The number of colors that the bitmap actually uses for the color tableDWORD biclrimportant;//number of important colors during bitmap display}bitmapinfoheader;
Color table:
struct tagrgbquad{byte Rgbblue; // Blue Brightness (0~255) BYTE Rgbgreen; // Green BYTE rgbred; // Red BYTE rgbreserved; // reserved, must be 0} Rgbquad;
After the construction of the structure is finished, the class of BMP file is constructed:
Digital Image Processing-Learning summary