Create your own professional image tool - Visual C ++ 2005 Image Programming Series [2]

xiaoxiao2021-04-05  251

Author: Lai Yiling

Return to the directory

1.2 Image processing preparation knowledge

During the image processing, there are many aspects of the squares that we need to master or pay attention. Here, I will briefly introduce some comparison, important knowledge.

1, image processing system framework

A basic image processing system contains four subsystems: image input system, image output system (display), image storage system, image processing and analysis system.

Figure 1-1

2, the composition of the image

Image gives us the first straight view feeling is some colorful points, in the computer language, these points are called pixels. It is these pixels to form a picture of a deputy beautiful picture. So how do you combine this intuitive understanding and our computer program? How to represent these colorful points in your computer? Understand these two issues have a lot of help to the image processing behind us. The image can be a matrix. In the computer program language, the best representation is the array, two-dimensional arrays. Save the image each pixel point in an element of an array. This process is also known as digital image sampling: digitizes the image representing the two-dimensional coordinate space.

3, speed of image processing

In the process of image processing, there is a large number of mathematical calculations and cycles. How to handle these processes a very important impact on the speed of image processing. The definition of the internal variable within the processing function also requires attention: For example, for a commonly used variable, it can be saved inside the function to save, speed up the speed. However, in large projects, too much static, local variables take up more memory while affecting the boot speed of the program. So this requires us to trade according to the actual situation.

There is floating point and integer when mathematical calculations, and the floating point operation is very accurate; however, the calculation speed is slightly slow, and the integer calculation does not have an error, and the speed is fast. Therefore, during the image processing, try to use an integer operation, the floating point operation will have a certain error because the computer's processor representation.

When traversing the pixel point of the image, there will be a large number of cyclic processes. During the cycle, minimize possible code such as variable definitions, multi-purpose processor support better addition and shift operation, and reduce multiplication. Even if possible, some common functions can be used in assembly language.

4, the efficiency of the map

Many beginner image programming friends have almost encountered a flashing problem. Our most common method is to have a double buffer map. Basic code snippet:

// PDC is the target window DC displayed by the last image, and Pmemdc is a temporary DC in memory.

CDC * Pmemdc = CREATECOMPATIBLEDC (PDC);

CBitmap Bitmap;

// width, height is the target window height and width of the image last display

Bitmap. CreateCompatibleBitmap (PDC, Width, Height);

Pmemdc-> SELECTOBJECT (& BITMAP);

Then we can make any needed drawing operations on the PMEMDC. After painting, apply to the target window DC.

PDC-> Bitblt (0, 0, Width, Height, Pmemdc, 0, 0, Srcopy);

Pmemdc-> deletedc ();

In some cases, we need a lot of maps. When you post a lot of different small pictures, you need to pay attention to the call of the SelectObject function, frequent calling this function is selected to reduce the speed of the program.

Avoid some unnecessary heavy draws, after completing your own drawing, the system's drawing process can be prohibited to avoid flashing: Returns True directly in the WM_ERASEBKGND message function, no longer continued to call the base class message processing function. Accurate updates are needed when needed, rather than blindness, all content will be swapped, such as calling InValidateRect instead of the transition INVALIDATE calling process. Because calculating the time of the RECT is much less than the time you don't need to redraw, you should be much less. In the image processing, there are many aspects that we need to pay special attention, I will discuss further in the following part.

5, color space, conversion

5.1, color space introduction

The color space is to map all components of the color to the two-dimensional or three-dimensional coordinate system of the Cartesian. Simple is how we use several color combinations to represent all colors in nature.

(1), RGB color space

Three color combinations of R (RED), G (Green), B (Blue) can represent all colors of nature, also known as a super color system. Because we add any color to the value of the RGB range. Assume that the image does not have other colors are black (RGB = 0), and then we add different RGB values ​​to the image, you can generate different colors, the following figure 1-2 shows how the RGB system adds a mixed color. of.

Figure 1-2 Figure 1-3

(2), CMY (CMYK) color space

CMY is a complementary color of RGB. The so-called complement is the color obtained after subtracting the RGB. White minus green is magenta, minus red is cyan (cyan), minus blue is yellow (Yellow).

The above figure 1-3 demonstrates how CMY is reduced to mix colors.

CMYK is the expansion of CMY, eliminating the theoretical and actual differences in the CMY representation. Since the CMY cannot be synthesized separately, the true black cannot be synthesized, so in order to avoid this problem, CMYK adds a black representation portion directly at CMY.

(2), HSV color space

There are three properties: color phase, color and brightness.

1) Hue is also known as hue, refers to the color of color, or the name or color of the color,

The color phase is not related to the brightness of the color.

2) The color of color (chroma) refers to the strength of the color, also known as the color saturation, color purity and incapable.

3) Value refers to the degree of brightness of the color, the highlight of the photomicity, and it is necessary to look close to the white or gray, the closer to the white brightness, the closer gray or black, the lower the brightness.

The HSV color space is to describe different colors with these three properties. When Saturation is 0, hue does not exist. The image is grayscale. The Value of Ming can also represent the brightness (Brightness). Hue is 0 when the color is red.

(4) HLS color space

The basic significance of HLS is the same, like the range of colors: Hue (0-360), L (0-1), S (0-1), V (0-1).

Just indicate the same color, Hue is 0 color is blue. The value of increasing L is equivalent to adding a white proportion to the Hue, and the reduction is to increase the proportion of black.

In real life, there are many other color spaces such as YiQ, YUV, YCRCB. We don't introduce it here, interested friends can refer to the relevant books.

5.2 Conversion of different color spaces

When image processing is adjusted in image processing, it is better to help we achieve different color values ​​in different color spaces. For example, adjust the image when adjusting tones and saturation

Turn into

HSV

Adjustment

HS

Value, then turn back

RGB

In the system. Specific conversion methods In subsequent image processing libraries, I will provide a complete class.

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

New Post(0)