The grayscale transform in Photoshop can make R, G, B 3 colors to enhance re-mixing, principle and below. Black and white picture of black and white transformation called grayscale transformation, color picture of color picture is also called grayscale transform, Photoshop is called color step transformation
Each pixel in a color image is mixed by RGB 3 colors in a certain ratio, such as black, RGB (0, 0), pure red is RGB (0, 1) , 0) .... When processing a photo, sometimes because the ambient source is too dark, the value of RGB color is small, it will make the graphic too dark, if the ambient light source is too light, but also makes the image pan, pass the grayscale transformation, The RGB value is adjusted to the appropriate degree, making the photo beautiful.
The principle of the transformation is this: first extract a pixel of an image, consist of 8-bit red brightness value, 8-bit green brightness value, and 8-bit blue brightness values in the BMP format, as long as the transformation function is composed of 8-bit red brightness value, 8-bit green brightness value, and 8-bit blue brightness values Transform
This three types of color of the three colors can function as a grayscale transformation.
For example, linear transformations can be used in a linear function F (x, y) = a ' (B'-a') / (ba) × (f (x, y) -a) f (x, y) represents a pixel [A, B] is the gray range of the original image, [A ', B'] is the grayscale range of the new image after the transformation, the linear function is used to transform the R, G and B components, respectively, can play a monochrome enhancement The purpose, then mix the output. If b'-a '> B-A, the image grayscale range is increased, that is, the contrast is increased, and the image becomes clear if B'-A' The segment linear transformation and linear transformation are almost almost almost use the segment function for single one R or G or B components. Such as F (x, y) = a ' (b'-a') / (ba) × (f (x, y) -a) When F (x, y) is in [A, B], f ( x, y) = 0 When F (x, y) Nonlinear transformations can be made to make a nonlinear function to transform the gradation as needed, typically have logarithmic transmissions f (x, y) = a ln [f (x, y) 1] / (b × LNC) here A, B, c is the parameter rather than the grayscale range, logarithmic variation for extending the low gray zone index transform f (x, y) = b ^ (C * [f (x, y)] - a]), A , B, C are also parameters, index transformations are used to compress low grayscale area The grayscale transformation of 256-color non-compressed BMP images will be implemented in BCB. // --------------------------------------- BCB6 program ----- ----------------------- # include #pragma pack (1) // ---- Force structure with 1 byte aligned Struct BitmapfileHeader_ {Short Type; Int bfsize; short re1, re2; int offbits; Struct Bitmapinfo_ {Long Size; Long Width, Height; Short Planes, Bitcount; Long Comp, SizeImg; Long Xpels, Ypels; Long Used, Important;}; // ------------- Bring BMP The data of the color table is corrected to the data of BCB TColor. Void SwitchColor (long & c) {long blue = C & 0x000000FF; Long Green = C & 0x0000FF00; Long Red = C & 0x00FF0000; C = (Blue << 16) | Green | (Red >> 16);} // -------- linear grayscale transform, RR, GG, BB is enhanced coefficient void Strengen (Long & C, Double Rr, Double GG, Double BB) {UNSIGNED CHAR R = (C & 0x00FF0000)> > 16; unsigned char g = (C & 0x0000FF00) >> 8; Unsigned char b = (C & 0x000000FF); Unsigned char ng; unsigned char nb; IF (rr * r> 255) NR = 255; ELSE NR = rr * r; IF (GG * G> 255) Ng = 255; ELSE NG = GG * G; IF (BB * B> 255) NB = 255; ELSE NB = BB * B; C = (NR << 16) | (Ng << 8) | (NB);} void xxx () {file * f = fopen ("f: //fx3.bmp", "rb"); if (f " == NULL) / * Judgment the file is open success * / {showMessage ("file open error"); return;} FSeek (f, 0, 0); // move to the beginning // ---------- Read BMP file head BitmapFileHeader_ * bmph = new bitmapfileHeader_ (); if (FREAD ((Char *) BMPH, SIZEOF (BitmapFileHeader_), 1, f) == null) {showMessage ("File Read Error"); RETURN;} // ----------- Read BMP information head bitmapinfo_ * bmpi = new bitmapinfo_ (); if (FREAD ((char *) BMPI, SIZEOF (BitmapInfo_), 1, f) == null) { ShowMessage ("File Read Error2"); Return;} // -------------- Read Color Table Long * C = New Long [BMPH-> Offbits-Sizeof (BitmapFileHeader_) - Sizeof (BitmapInfo_)]; FREAD ((char *) C, BMPH-> Offbits-Sizeof (BitmapFileHeader_) - Sizeof (BitmapInfo_), 1, F); // ---------- Display Some Information Form1-> Edit1-> Text = INTOSTOSTR (BMPH-> bfsize) Form1-> edit2-> text = INTOSTR (bmpi-> width); form1-> edit3-> text = INTTOSTR (bmpi-> height); form1-> edit4-> text = INTOSTR (BMPI-> comp); Form1 -> edit5-> text = INTOSTR (BMPI-> Used); // ------------ Show graphics unsigned char * p = new unsigned char [4]; int i = 0, j = 0, k = 0, wc = 0; tcolor * Tc; IF (bmpi-> width% 4 == 0) // ----------- Because BMP images 4 byte align WC = BMPI- > width / 4; else wc = BMPI-> Width / 4 1; For (i = 0; i