Black and white image Reduces gray level display algorithm

xiaoxiao2021-03-06  40

Everyone knows that the black and white image is 0,1 binary, and when the display is displayed, the N points are converted into one point, which will cause the image local detail information to be lost, such as a width of a pixel, the thin line of a pixel is not Display, and use the gray level display is a problem that can solve this reduction display. The image processing provided by the Windows comes with the image processing of the Eastman Software can be displayed when you reduce the black and white picture. Let's take a deep study. How this algorithm is implemented.

Basic agreement: 1. The grayscale reduction shows only a black and white or grayscale image, and the algorithm transform can be used for color imaging 2. Only the grayscale display is only effective at the display <100%. The gray scale reduction algorithm is based on the original image to operate the specific algorithm: 1. The reduction algorithm generates 1 point in the original image NXN 1: N (N can be a floating point number), and the gray level transformation can be used in consideration of the efficiency, from 0-255 to take the intermediate point 127 greater than this value. Shows white less than the changed value display black.

2. The gray scale display algorithm combines the reduction algorithm NXN point to generate a point of principle, and multiply the weight and color of each point in the original map to obtain a color value of the generated point. For example: A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 | ----- | --- * - | ----- | - * --- | ----- | * ---- | ---- * ----- | ----- | ----- |

| --------- | --------- | -------------------- --- | --------- | - B1 B2 B3 B4 B5 B1 after transform B1 = (1.0 * a1 0.8 * a2) /1.8 b2 = (0.2 * a2 A3 0.6 * A3 ) /1.8 ...

This is a one-dimensional coordinate, which extends to the two-dimensional spatial algorithm. Specific implementation method: 1. The bitmap size (NXM) after the reduction is calculated, such as the original image 100X100, and 90% after zooming 90%. Cycle point array, the color assignment assignment method of each point takes the related point color multiplied by the corresponding weight, and

The original map is 66.6% to calculate each point value Delphi code as follows

VAR

I, J: Integer; TMPCOLORR, TMPCOLORG, TMPCOLORB: DWORD; X, Y: Integer; Scalerate, Scaleratex, Scaleratey: REAL; Begin

//comboBOX1.Text is zoom%

Scalerate: = 100 / STRTOFLOATDEF (ComboBoX1.Text, 100); // Cyclic Generate Image

For i: = 0 to trunc (image1.picture.width / scalerate) do for j: = 0 to trunc (image1.picture.height / scalerate) Do Begin

TMPCOLORR: = 0; tmpcolorg: = 0; TMPCOLORB: = 0; // For each point accumulated colors

For x: = trunc (i * scalerate) To CEIL ((i 1) * scalerate) -1) Do Begin

For Y: = trunc (j * scalerate) To CEIL (((J 1) * scalerate) -1) DO Begin

Scaleratex: = min (x 1, (i 1) * scalerate) - Max (x, i * scalerate); scaleratey: = min (y 1, (j 1) * scalerate) - max (y, j * Scalerate); // Take the RGB value of each point (if it is black or grayscale, only one need to get one) TMPCOLORR: = TmpColorr trunc (scaleragex * scaleratey * (image1.canvas.pixels [x, y ]))); tmpColorG: = tmpColorG trunc (ScaleRateX * ScaleRateY * (GetGValue (Image1.Canvas.Pixels [x, y]))); tmpColorB: = tmpColorB trunc (ScaleRateX * ScaleRateY * (GetBValue (Image1.Canvas .Pixels [x, y])); end; end; // For point assignment color image2.canvas.pixels [i, j]: = RGB (Trunc (TmpColorr / (Scalerate * Scalerate), Trunc (TMPCOLORG / (Scalerate * Scalerate)), Trunc (TMPCOLORB / (Scalerate * Scalerate)))

This algorithm is the first version I wrote, and there are many optimization rooms. For example, if it is black and white image, it does not need to calculate the RGB, because 256 grayscale is all the expression possible image speed in the same other for loop, and integers The operation will be fast than floating point, and so on.

转载请注明原文地址:https://www.9cbs.com/read-69403.html

New Post(0)