A color adjustment method, device and storage medium based on hardware implementation
By directly adjusting the grayscale value and saturation of each color phase area in RGB image data, the problems of high complexity of color adjustment calculation and high resource consumption in the prior art are solved, and efficient and accurate color adjustment is achieved, suitable for hardware accomplish.
Patent Information
- Application Number
- CN202411014320.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-26
- Publication Date
- 2024-12-10
- Estimated Expiration
- 2044-07-26
AI Technical Summary
The prior art has problems in color adjustment with high computational complexity, large resource consumption and low hue adjustment accuracy, especially in the conversion and matrix operation between RGB color space and HSV color space.
Using the hardware-based color adjustment method, by obtaining the original image data, selecting the hue adjustment model and saturation adjustment model, calculate the hue offset grayscale value and saturation correction value of each channel, and directly adjust the grayscale value and saturation correction value of each color phase area. Saturation avoids spatial conversion and matrix calculations, and improves the accuracy and efficiency of color adjustment.
It realizes efficient and accurate hue and saturation adjustment in RGB image data, avoiding the problems of image distortion and resource consumption, and is suitable for hardware implementation and is suitable for high-demand application scenarios.
Smart Images

Figure CN118537276B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data processing technology, and in particular to a color adjustment method, device and storage medium based on hardware implementation. Background Art
[0002] An image is composed of pixels of different colors. The visual experience of the human eye when viewing an image is affected by many factors. Hue and saturation, the most important attributes of color, usually affect the comfort of the human eye when viewing the image.
[0003] Affected by factors such as imaging equipment, imaging lighting conditions or the dark color of the scene itself, the color saturation of the image is low, the image is not bright and transparent, and the visual perception effect of the human eye is poor. Therefore, the hue and / or saturation of a certain color in the image is changed to process the original image in order to achieve a better display effect.
[0004] Color images are usually encoded with three original color channels, namely the Red-Green-Blue (RGB) color space. However, the human visual system is more sensitive to hue (H), saturation (S), intensity (I) or value (V). Therefore, the common image color adjustment algorithm is to convert the image from the RGB color space to the common HSI or HSV color space, adjust the hue / saturation, and then convert it back to the RGB space. For example, patents CN112599093B, CN115358935A, TW200808072A, etc., the color space conversion process involves complex operations such as square root and trigonometric operations, which increases the consumption of hardware resources.
[0005] In order to simplify the color space conversion calculation, such as patents CN105706434B and CN115088253A, a lookup table or comparison table is pre-built for color space conversion calculation. In the simplified calculation of image saturation adjustment, patent CN109741279B uses a color gamut mapping lookup table to adjust the saturation of each pixel in the RGB image, and directly adjusts the saturation of the RGB image to avoid the conversion between the RGB color space and the HSV color space. However, the process of pre-building a lookup table, comparison table, etc. is relatively cumbersome and time-consuming, which is not conducive to the rapid realization of hue adjustment.
[0006] In order to avoid the operation of space conversion, the prior art proposes to adopt the calculation method of matrix operation. However, matrix calculation is still a calculation method with large amount of calculation, and in the process of matrix calculation, it still needs to occupy more hardware resources.
[0007] In hue adjustment technology, patent CN117201950A provides a hue adjustment method, device and readable storage medium. By using a target correction matrix to process the original RGB data of the image, the processing logic of the hue adjustment operation is simplified, and the computational complexity and cost of the hue adjustment device are reduced.
[0008] Chinese patent CN110933386B proposes a color adjustment method for industrial cameras, which includes: step 1, obtaining the original RGB image data in the image to be processed in the industrial camera, calculating the product of the original RGB image data and the saturation adjustment matrix, and generating an overall saturation adjustment image, wherein the saturation adjustment matrix is determined by the saturation parameter and the image color conversion matrix; step 2, selecting at least three reference colors in the hue circle, determining the hue adjustment step and the saturation adjustment step according to the reference color and the adjustment direction in the user preference setting, and sequentially adjusting the color dimensions of different dimensions of the overall saturation adjustment image to generate a color adjustment image. This patent uses a matrix to calculate the saturation adjustment matrix, and based on the hue adjustment result, realizes color adjustment of the overall saturation adjustment image, and its saturation adjustment needs to be based on the hue adjustment; and in the hue adjustment content, based on the selection of the reference color or the coordinated color, the hue adjustment step of different color components is inconsistent, and the accuracy of its hue adjustment is low.
[0009] In addition, in the saturation adjustment method, the complex calculation of the color space is avoided by gradient adjustment. For example, patent CN 108932706 A provides a method for enhancing the contrast and saturation of a color image. By using a gradient adjustment-based method, the image contrast and saturation are improved at the same time, which significantly improves the visual effect of the image. In the image processing process of this patent, the gradient calculation formula uses matrix operations, which cannot solve the problem that matrix operations require more resource consumption. Summary of the invention
[0010] The present invention provides a color adjustment method, device and storage medium based on hardware implementation, which can solve at least one of the above technical problems.
[0011] To achieve the above object, the present invention proposes a color adjustment method based on hardware implementation, comprising:
[0012] Get the original image data (r, g, b);
[0013] Selecting a hue adjustment model and / or a saturation adjustment model to respectively calculate a hue shift grayscale value and / or a saturation correction value of each channel;
[0014] Based on the hue shift grayscale value and / or the saturation correction value, the original image data is processed to obtain the target image data (r', g', b');
[0015] The hue adjustment model includes an adjacent hue adjustment model and a complementary hue adjustment model. The adjacent hue adjustment model is a hue adjustment algorithm for the R hue region, the G hue region, and the B hue region. The complementary hue adjustment model is a hue adjustment algorithm for the C hue region, the Y hue region, and the M hue region.
[0016] The saturation adjustment model is a saturation adjustment algorithm for the RY hue region, the RM hue region, the GY hue region, the GC hue region, the BC hue region, and the BM hue region.
[0017] Furthermore, it also includes:
[0018] Before selecting a hue adjustment model and / or a saturation adjustment model, compare the sizes of r, g, and b in the original image data (r, g, b), determine the hue region to which the original image data belongs, and select the corresponding hue adjustment model and / or saturation adjustment model.
[0019] Furthermore, the hue shift grayscale value includes:
[0020] Based on the current hue region, a corresponding hue adjustment model is selected to determine the hue shift grayscale value of the first channel;
[0021] Calculate the moving step of the current hue area, select the correction coefficient of the current hue area, and calculate the hue shift grayscale value of the second channel and the hue shift grayscale value of the third channel of the current hue area based on the moving step and the correction coefficient.
[0022] Further, determining the hue shift grayscale value of the first channel includes:
[0023] In any hue region of the adjacent hue adjustment model, the first channel is the hue channel with the largest grayscale value, and its hue offset grayscale value is zero;
[0024] In any hue region of the complementary hue adjustment model, the first channel is the hue channel with the smallest grayscale value, and its hue shift grayscale value is zero.
[0025] Furthermore, the step of calculating the moving step of the current hue region includes:
[0026] In the current hue region, a first difference between the grayscale value of the first channel and the grayscale value of the second channel, and a second difference between the grayscale value of the first channel and the grayscale value of the third channel are calculated respectively;
[0027] The minimum value between the first difference and the second difference is selected; and the moving step length of the current hue area is calculated based on the coefficient and the minimum value of the hue adjustment model.
[0028] Furthermore, the saturation correction value includes:
[0029] Based on the current hue region, a corresponding saturation adjustment model is selected, and the gray value of the first channel is used as the saturation correction value of the first channel;
[0030] Calculate the saturation correction value of the second channel using the gray value of the first channel and the gray value of the second channel;
[0031] Calculate the saturation correction value of the third channel according to the saturation correction value of the second channel;
[0032] Among them, the first channel is the channel with the largest grayscale value, the second channel is the channel with the middle grayscale value, and the third channel is the channel with the smallest grayscale value.
[0033] Further, the calculating the saturation correction value of the second channel includes:
[0034] The difference between the grayscale value of the first channel and the grayscale value of the second channel is calculated, and a first adjustment value is obtained based on the difference and a first saturation coefficient of the current hue region, and a saturation correction value of the second channel is obtained according to the grayscale value of the first channel.
[0035] Further, the calculating the saturation correction value of the third channel includes:
[0036] The difference between the grayscale value of the second channel and the grayscale value of the third channel is calculated, and the second adjustment value is obtained based on the difference and the second saturation coefficient of the current hue area, and the saturation correction value of the third channel is obtained according to the saturation correction value of the second channel.
[0037] Based on the same inventive concept, the present invention also proposes a color adjustment device based on hardware implementation, comprising:
[0038] Get the original image data (r, g, b);
[0039] Selecting a hue adjustment model and / or a saturation adjustment model to respectively calculate the hue offset grayscale value and / or the saturation correction value of each channel; wherein the hue adjustment model includes an adjacent hue adjustment model and a complementary hue adjustment model;
[0040] Based on the hue shift grayscale value and / or the saturation correction value, the original image data is processed to obtain the target image data (r', g', b').
[0041] Based on the same inventive concept, the present invention further proposes a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the color adjustment method based on hardware implementation as described above is implemented.
[0042] The beneficial effects of the present invention are:
[0043] The present invention starts from the composition principle of RGB color space and hue circle, and adjusts the hue / saturation of RGB image data based on the relationship between (r, g, b). The color adjustment method proposed in the present invention directly adjusts the grayscale value of each channel in any hue area when implementing the hue / saturation adjustment of the hue / saturation of the hue area, and does not cause the hue / saturation of other hue areas to change, thereby improving the accuracy of the hue / saturation adjustment method of RGB image data to meet the needs of high-demand application scenarios.
[0044] The present invention proposes two hue adjustment models, using the adjacent hue model to achieve hue adjustment of the R hue region, the G hue region, and the B hue region, and using the complementary hue model to achieve hue adjustment of the C hue region, the Y hue region, and the M hue region. Aiming at the characteristics of the grayscale values of each channel in different hue regions, the present invention adapts the corresponding hue regions with two hue models, uses the unique hue adjustment formula of each hue region, and then accurately controls the moving step length, so as to achieve one-to-one conversion between adjacent hue regions, so that the hue adjustment result finally obtained is more accurate.
[0045] The hue adjustment method of the present invention realizes the adjustment of one or more hue regions based on the original image data, and obtains the target image data by accumulating the hue offset grayscale values of each channel. The calculation method is more efficient and convenient for adjusting the target image data. At the same time, on the basis of the original image data, by adjusting the hue offset grayscale value of the RGB channel of any hue region, the color adjustment of the corresponding hue region is realized, which can effectively avoid the loss of the original image data and avoid the problems such as image distortion caused by the sequential adjustment of multiple hue regions.
[0046] The saturation adjustment method of the present invention sets a specific calculation formula for the grayscale value of each channel in different hue areas according to the characteristics of the grayscale value of each channel in the hue area to obtain an accurate saturation adjustment result. In the present invention, the saturation adjustment of any hue area is based on the original image data, which can effectively avoid the loss of the original image data.
[0047] The hue / saturation adjustment method of the present invention does not involve any space conversion related content, and does not have any complex operations such as matrix calculation. It has a fast adjustment speed, requires a small storage space, occupies few resources, and is suitable for hardware implementation. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] Figure 1 This is a schematic diagram of the principle of RGB color space;
[0049] Figure 2 This is a schematic diagram of the principle of HSI color space;
[0050] Figure 3 This is a schematic diagram of the principle of the color wheel;
[0051] Figure 4 is a flow chart of a color adjustment method based on hardware implementation in the present invention;
[0052] Figure 5 is a flow chart of the hue adjustment method of the present invention;
[0053] Figure 6 It is a schematic diagram of the process of the adjacent hue adjustment model in the present invention;
[0054] Figure 7 is a schematic diagram of the process of the complementary hue adjustment model in the present invention;
[0055] Figure 8 It is a flow chart of the saturation adjustment method in the present invention. DETAILED DESCRIPTION
[0056] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments.
[0057] First, several terms involved in the embodiments of the present application are briefly introduced:
[0058] RGB color space: a color standard that defines colors by obtaining the superposition of the brightness values of three color channels: red (Red, R), green (Green, G), and blue (Blue, B).
[0059] The three points R, G, and B represent three basic colors. The combination of red (R) and blue (B) constitutes magenta (Magenta, M), the combination of red (R) and green (G) constitutes yellow (Yellow, Y), and the combination of blue (B) and green (G) constitutes cyan (Cyan, C). The changes in these six colors constitute the basic hue changes.
[0060] Figure 1 The figure shows a schematic diagram of the RGB color space. The six vertices of red, yellow, green, cyan, blue, and magenta divide the six regions in the hue circle. This color space can describe all colors in (r, g, b).
[0061] The RGB color space is usually used to construct a spatial rectangular coordinate system XYZ, so that all colors that can be displayed in a computer can find corresponding points in this space.
[0062] Taking 8-bit images as an example, each color channel in the RGB color space includes 256 brightness values. The brightness is lowest when the brightness value is 0, and highest when the brightness value is 255; when the brightness value of the red channel is 0, the brightness value of the green channel is 0, and the brightness value of the blue channel is 0, the corresponding color is black; when the brightness value of the red channel is 255, the brightness value of the green channel is 255, and the brightness value of the blue channel is 255, the corresponding color is white; when the brightness value of the red channel is 255, the brightness value of the green channel is 0, and the brightness value of the blue channel is 0, the corresponding color is red.
[0063] like Figure 1 In the diagram of the RGB color space shown in a, the grayscale value represented by the origin is (0,0,0), and the grayscale value of the brightest point is (255,255,255). Connect these two points (i.e., the spatial diagonal of the cube) and rotate the cube so that the connecting line is vertical. Figure 1 The schematic diagram of the RGB color space shown in b, where the brightness decreases from top to bottom (here the grayscale mean of the three channels is taken to represent the brightness), is the prototype of the HSI space cone model, and this axis is recorded as the brightness axis.
[0064] The HSI color space is based on the human visual system and uses hue (H), saturation (S) and intensity (I) to describe color. Figure 2 As shown, the HSI color space can be described by a cone space model. The upper vertex of the cone space model corresponds to I=1, that is, white; the lower vertex corresponds to I=0, that is, black. Hue is expressed as an angle, 0° represents red, and the complementary hue difference is 180°. The saturation value ranges from 0 to 1, 0 corresponds to the center line of the vertical axis (that is, there is no color on this line, only grayscale), and the saturation of red is 1 when I=0.5. The distance from a point in the color space to the I axis is its saturation.
[0065] Hue: It is the spectral color corresponding to light of different wavelengths. For example, hue can be defined by a hue wheel. Figure 3 As shown, the hue wheel is in degrees, with a value range of [0°, 360°]. Starting from red and going counterclockwise, red corresponds to 0°, yellow corresponds to 60°, green corresponds to 120°, cyan corresponds to 180°, blue corresponds to 240°, and magenta corresponds to 360°.
[0066] Saturation: Also known as chroma or purity, it is a parameter used to indicate the purity of a color relative to the spectral color. For example, the saturation range is [0, 1]. When the purity is the highest, the saturation is 1; when the purity is the lowest, the saturation is 0. A color with a saturation of 0 has no color.
[0067] like Figure 4 As shown, the present invention proposes a color adjustment method based on hardware implementation, comprising:
[0068] Get the original image data (r,g,b).
[0069] A hue adjustment model and / or a saturation adjustment model is selected to respectively calculate a hue offset grayscale value and / or a saturation correction value of each channel.
[0070] Based on the hue shift grayscale value and / or saturation correction value, the original image data is processed to obtain the target image data (r', g', b'). The target image data (r', g', b') includes the hue target image data (r', g', b') H , saturation target image data (r', g', b') S , Hue-saturation target image data (r', g', b') H-S .
[0071] Before selecting the hue adjustment model and / or the saturation adjustment model, the method further includes: comparing the sizes of r, g, and b in the original image data (r, g, b), determining the hue region to which the original image data belongs, and selecting the corresponding hue adjustment model and / or the saturation adjustment model.
[0072] Among them, the hue adjustment model includes an adjacent hue adjustment model and a complementary hue adjustment model. The adjacent hue adjustment model is a hue adjustment algorithm for the R hue area, G hue area, and B hue area. The complementary hue adjustment model is a hue adjustment algorithm for the C hue area, Y hue area, and M hue area; the saturation adjustment model is a saturation adjustment algorithm for the RY hue area, RM hue area, GY hue area, GC hue area, BC hue area, and BM hue area.
[0073] like Figure 5 As shown, the hue adjustment method proposed in this embodiment includes:
[0074] Get the original image data (r,g,b).
[0075] Select the hue adjustment model and calculate the hue shift grayscale values of the first channel, the second channel, and the third channel respectively.
[0076] According to the hue shift grayscale value, the original image data (r, g, b) is processed to obtain the hue target image data (r', g', b') H .
[0077] Before selecting the hue adjustment model, the method further includes: comparing the sizes of r, g, and b in the original image data (r, g, b), determining the hue region to which the original image data belongs, and selecting a corresponding hue adjustment model.
[0078] The hue adjustment model includes an adjacent hue adjustment model and a complementary hue adjustment model.
[0079] The adjacent hue adjustment model is a hue adjustment algorithm for the R hue region, the G hue region, and the B hue region. In the R hue region, r is the largest; in the G hue region, g is the largest; and in the B hue region, b is the largest.
[0080] The complementary hue adjustment model is a hue adjustment algorithm for the C hue region, the Y hue region, and the M hue region. In the C hue region, r is the smallest; in the M hue region, g is the smallest; and in the Y hue region, b is the smallest.
[0081] In this embodiment, the hue adjustment model is used to realize the conversion between adjacent hue regions in the hue circle to achieve hue adjustment. This embodiment describes a method for separately adjusting the R hue region, the G hue region, the B hue region, the C hue region, the Y hue region, and the M hue region in the hue circle for two hue adjustment models, namely, the adjacent hue adjustment model and the complementary hue adjustment model. In the adjustment process of this method, the color change of each channel in any hue region will not cause the color change of other hue regions.
[0082] In the present invention, the first channel, the second channel, and the third channel are used as different channels and do not represent a sequence relationship.
[0083] The calculation process of the hue adjustment model is as follows: based on the current hue area, select the corresponding hue adjustment model to determine the hue shift grayscale value of the first channel; calculate the moving step of the current hue area, select the correction coefficient of the current hue area, and based on the moving step and the correction coefficient, calculate the hue shift grayscale value of the second channel and the hue shift grayscale value of the third channel of the current hue area respectively.
[0084] Wherein, determining the hue shift grayscale value of the first channel includes:
[0085] In any hue area of the adjacent hue adjustment model, the first channel is the hue channel with the largest grayscale value, and its hue shift grayscale value is zero; in any hue area of the complementary hue adjustment model, the first channel is the hue channel with the smallest grayscale value, and its hue shift grayscale value is zero.
[0086] Calculate the moving step of the current hue area, including:
[0087] In the current hue area, the first difference between the grayscale value of the first channel and the grayscale value of the second channel, and the second difference between the grayscale value of the first channel and the grayscale value of the third channel are calculated respectively; the minimum value between the first difference and the second difference is selected; based on the coefficient and the minimum value of the hue adjustment model, the moving step length of the current hue area is calculated.
[0088] The following content will explain the hue adjustment process of the adjacent hue adjustment model to achieve the R hue area, the G hue area, and the B hue area.
[0089] The adjacent hue adjustment model is a hue adjustment algorithm for the R hue region, the G hue region, and the B hue region, and is used to realize the conversion of any hue region among the R hue region, the G hue region, and the B hue region to its corresponding adjacent hue region.
[0090] The adjacent hue regions of the R hue region include the Y hue region and the M hue region, the adjacent hue regions of the G hue region include the Y hue region and the C hue region, and the adjacent hue regions of the B hue region include the C hue region and the M hue region.
[0091] If the adjacent hue adjustment model is used, the R hue area can only be converted to the Y hue area or the M hue area; the G hue area can only be converted to the Y hue area or the C hue area; and the B hue area can only be converted to the C hue area or the M hue area.
[0092] The restriction condition of the adjacent hue adjustment model is that the conversion range of the adjacent hue adjustment model is [-A1, A1), the first coefficient A1∈(0,255), and A1 is a positive integer. On the basis of satisfying the use conditions of the adjacent hue adjustment model, the specific value of A1 is set according to user habits or needs, or is set according to actual application needs or environment. This embodiment does not limit the specific value.
[0093] like Figure 6 As shown, if the hue adjustment model is an adjacent hue adjustment model, the hue adjustment method is as follows:
[0094] In any hue region of the adjacent hue adjustment model, the first channel is the hue channel with the largest grayscale value, and its hue offset grayscale value is zero. That is, any hue region among the R hue region, the G hue region, and the B hue region is selected as the current hue region. Among them, in the R hue region, r is the largest, and the R channel is the first channel; in the G hue region, g is the largest, and the G channel is the first channel; in the B hue region, b is the largest, and the B channel is the first channel.
[0095] Obtain the original grayscale value of the first channel, the original grayscale value of the second channel, and the original grayscale value of the third channel of the current hue area; subtract the original grayscale value of the second channel from the original grayscale value of the first channel to obtain a first difference; subtract the original grayscale value of the third channel from the original grayscale value of the first channel to obtain a second difference; filter the minimum value between the first difference and the second difference; calculate the moving step of the current hue area based on the first coefficient and the minimum value of the adjacent hue adjustment model. In this embodiment, in the calculation of the first difference and the second difference, the grayscale value of the first channel is used as the minuend. Alternatively, the grayscale value of the first channel is used as the subtrahend, and its corresponding first coefficient is set.
[0096] In this embodiment, the first channel, the second channel, and the third channel are used as different channels, and do not represent a sequence relationship.
[0097] Taking the hue adjustment in the R hue area as an example, the calculation process of the adjacent hue adjustment model is explained:
[0098] If hue adjustment is implemented on the R hue region, based on the conditional restrictions of the adjacent hue adjustment model, the R hue region can only be converted to the Y hue region or the M hue region.
[0099] In the R hue area, r is the largest, so the R channel is used as the first channel; the grayscale value of the R channel remains unchanged, and the hue offset grayscale value of the first channel (R channel) is zero, that is, Here, the subscript R represents the R hue region.
[0100] Get the (original) grayscale value r of the R channel, the original grayscale value g of the G channel, and the original grayscale value b of the B channel in the R hue area. Here, the G channel is used as the second channel and the B channel is used as the third channel. The first difference (rg) and the second difference (rb) are calculated respectively, and the minimum value min(rg,rb) between the first difference and the second difference is selected; based on the first coefficient A1 and the minimum value min(rg,rb) of the adjacent hue adjustment model, the moving step step R is calculated. Similarly, the B channel can be used as the second channel and the G channel as the third channel to adaptively adjust the subsequent calculation process.
[0101] The calculation formula for the moving step length step R is: step R = min(rg, rb) / A1.
[0102] Select the correction factor k for the R hue area R , based on the moving step length step R and the correction coefficient, calculate the hue shift grayscale value of the G channel in the R hue area and the hue offset grayscale value of the B channel Here, the subscript R represents the R hue region. The calculation formula is as follows:
[0103] ; .
[0104] Similarly, the relevant calculation formula for the G hue area can be obtained as follows:
[0105] In the G hue area, g is the largest, then the G channel is the first channel; the grayscale value of the first channel remains unchanged, that is, the grayscale value of the G channel remains unchanged, and the hue shift grayscale value of the first channel (G channel) is zero, that is Here, the subscript G represents the G hue region.
[0106] Moving step length step G=min(gr, gb) / A1;
[0107] Select the correction factor k for the G hue area G , then the hue shift gray value of the R channel in the G hue area ; The hue shift grayscale value of the B channel in the G hue area .
[0108] Similarly, the relevant calculation formula for the B hue area can be obtained as follows:
[0109] In the B hue area, b is the largest, and the B channel is the first channel; the grayscale value of the first channel remains unchanged, that is, the grayscale value of the B channel remains unchanged, and the hue shift grayscale value of the first channel (B channel) is zero, that is Here, the subscript B indicates the B hue region.
[0110] Moving step length step B = min(br, bg) / A1;
[0111] Select the correction factor k for the B hue area B , then the hue shift gray value of the R channel in the B hue area ; The hue shift grayscale value of the G channel in the B hue area .
[0112] The following content will explain the hue adjustment process of the C hue area, the Y hue area, and the M hue area implemented by the complementary hue adjustment model.
[0113] The complementary hue adjustment model is a hue adjustment algorithm for the C hue region, the M hue region, and the Y hue region, and is used to realize the conversion of any hue region among the C hue region, the M hue region, and the Y hue region to its corresponding adjacent hue region.
[0114] The adjacent hue areas of the C hue area include the G hue area and the B hue area, the adjacent hue areas of the M hue area include the R hue area and the B hue area, and the adjacent hue areas of the Y hue area include the R hue area and the G hue area.
[0115] If the complementary hue adjustment model is used, the C hue area can only be converted to the G hue area or the B hue area; the M hue area can only be converted to the R hue area or the B hue area; and the Y hue area can only be converted to the R hue area or the G hue area.
[0116] The above-mentioned restriction condition is that the conversion range of the complementary hue adjustment model is [-A2, A2), the first coefficient A2∈(0,255), and A2 is a positive integer. On the basis of satisfying the use conditions of the complementary hue adjustment model, the specific value of A2 is set according to user habits or needs, or is set according to actual application needs or environment. This embodiment does not limit the specific value.
[0117] like Figure 7 As shown, if the hue adjustment model is a complementary hue adjustment model, the hue adjustment method is as follows:
[0118] In any hue region of the complementary hue adjustment model, the first channel is the hue channel with the smallest grayscale value, and its hue offset grayscale value is zero. Select any hue region among the C hue region, the Y hue region, and the M hue region as the current hue region. Among them, in the C hue region, r is the smallest, so the R channel is the first channel; in the M hue region, g is the smallest, so the G channel is the first channel; in the Y hue region, b is the smallest, so the B channel is the first channel.
[0119] In any hue area of the complementary hue adjustment model, the original grayscale value of the first channel, the original grayscale value of the second channel, and the original grayscale value of the third channel of the current hue area are obtained; the original grayscale value of the second channel is subtracted from the original grayscale value of the first channel to obtain a first difference, and the original grayscale value of the third channel is subtracted from the original grayscale value of the first channel to obtain a second difference; the minimum value between the first difference and the second difference is selected; based on the second coefficient and the minimum value of the complementary hue adjustment model, the moving step is calculated. In this embodiment, in the calculation of the first difference and the second difference, the grayscale value of the first channel is used as the subtrahend. Or the grayscale value of the first channel is used as the minuend, and its corresponding first coefficient is set.
[0120] In this embodiment, the first channel, the second channel, and the third channel are used as different channels, and do not represent a sequence relationship.
[0121] Taking the M hue area to achieve hue adjustment as an example, the calculation process of the complementary hue adjustment model is explained:
[0122] If hue adjustment is performed on the M hue region, based on the conditional restrictions of the complementary hue adjustment model, the M hue region can only be converted to the R hue region or the B hue region.
[0123] In the M hue area, g is the smallest, so the G channel is used as the first channel; the grayscale value of the G channel remains unchanged, and the hue offset grayscale value of the first channel is zero, that is, Here, the subscript M represents the M hue region.
[0124] Get the original grayscale value r of the R channel, the (original) grayscale value g of the G channel, and the original grayscale value b of the B channel corresponding to the M hue area. Here, the R channel is taken as the second channel and the B channel is taken as the third channel. The first difference (rg) and the second difference (bg) are calculated respectively, and the minimum value min(rg,bg) between the first difference and the second difference is selected; based on the second coefficient A2 and the minimum value of the complementary hue adjustment model, the moving step step M is calculated. Similarly, the B channel can also be taken as the second channel and the R channel as the third channel to adaptively adjust the subsequent calculation process.
[0125] The calculation formula is: step M = min(rg, bg) / A2.
[0126] Select the correction factor k for the M hue area M , based on the moving step size step M and the correction coefficient, calculate the hue shift grayscale value of the R channel of the M hue area respectively and the hue offset grayscale value of the B channel Here, the subscript M represents the M hue region.
[0127] The calculation formula is as follows:
[0128] ; .
[0129] Similarly, the relevant calculation formula for the C hue area can be obtained as follows:
[0130] In the C hue area, r is the smallest, so the R channel is used as the first channel; the grayscale value of the R channel remains unchanged, and the hue shift grayscale value of the first channel (R channel) is zero, that is, Here, the subscript C represents the C hue region.
[0131] Moving step length step C = min(gr, br) / A2;
[0132] Select the correction factor k for the C hue area C , then the hue shift gray value of the G channel in the C hue area ; Hue shift gray value of the B channel in the C hue area .
[0133] Similarly, the relevant calculation formula for the Y hue area can be obtained as follows:
[0134] In the Y hue region, b is the smallest, so the B channel is used as the first channel; the grayscale value of the B channel remains unchanged, and the hue offset grayscale value of the B channel is zero, that is, Here, the subscript Y indicates the Y hue region.
[0135] Moving step length step Y=min(rb, gb) / A2;
[0136] Select the correction factor k for the Y hue area Y , then the hue shift gray value of the R channel in the Y hue area ; Hue shift gray value of G channel in Y hue area .
[0137] Through calculation of the adjacent hue adjustment model or the complementary hue adjustment model, the hue shift grayscale value of each channel in any hue region can be obtained.
[0138] If only the hue adjustment is performed on the original image data, the hue shift grayscale value of each channel in any hue area is obtained through calculation of the hue adjustment model; based on the hue shift grayscale value, the original image data (r, g, b) is processed to obtain the hue target image data (r', g', b') H , H represents hue, and the calculation formula is as follows:
[0139] ;
[0140] ;
[0141] .
[0142] Here, subscript R is used to indicate the R hue region, subscript G is used to indicate the G hue region, subscript B is used to indicate the B hue region, subscript C is used to indicate the C hue region, subscript Y is used to indicate the Y hue region, and subscript M is used to indicate the M hue region.
[0143] In this embodiment, the number of hue regions to be adjusted is not limited, and one or more hue regions can be selected for hue adjustment to obtain the corresponding hue offset grayscale value, and then obtain the hue target image data (r', g', b'). H .
[0144] As an example, if the hue adjustment is performed only on the R hue area, the hue target image data (r', g', b') H , the calculation formula is: ; ; .
[0145] As an example, if the hue adjustment is performed on the B hue area and the C hue area, the hue target image data (r', g', b') H , the calculation formula is: ; ; .
[0146] The hue adjustment method of the present invention realizes the adjustment of one or more hue regions based on the original image data, and obtains the target image data by accumulating the hue offset grayscale values of each channel. The calculation method is more efficient and convenient for adjusting the target image data. At the same time, on the basis of the original image data, by adjusting the hue offset grayscale value of the RGB channel of any hue region, the color adjustment of the corresponding hue region is realized, which can effectively avoid the loss of the original image data and avoid the problems such as image distortion caused by the sequential adjustment of multiple hue regions.
[0147] like Figure 8 As shown, the saturation adjustment method proposed in this embodiment includes:
[0148] Get the original image data (r,g,b).
[0149] A saturation adjustment model is selected to calculate the saturation correction values of the first channel, the second channel, and the third channel respectively.
[0150] According to the saturation correction value, the original image data is processed to obtain the saturation target image data (r', g', b') S .
[0151] Before selecting the saturation adjustment model, the method further includes: comparing the sizes of r, g, and b in the original image data (r, g, b), determining the hue region to which the original image data belongs, and selecting a corresponding saturation adjustment model.
[0152] The saturation adjustment model is a saturation adjustment algorithm for the RY hue region, the RM hue region, the GY hue region, the GC hue region, the BC hue region, and the BM hue region.
[0153] Among them, in the RY hue area, r≥g≥b; in the RM hue area, r≥b≥g; in the GY hue area, g≥r≥b; in the GC hue area, g≥b≥r, in the BC hue area, b≥g≥r; in the BM hue area, b≥r≥g.
[0154] The saturation adjustment method of the present invention only changes the color of each channel of any hue region among the RY hue region, the RM hue region, the GY hue region, the GC hue region, the BC hue region and the BM hue region, and does not cause the saturation of other hue regions to change. In the present invention, the first channel, the second channel and the third channel are used as different channels, and do not represent a sequence relationship.
[0155] The calculation process of the saturation adjustment model is as follows: based on the current hue area, select the corresponding saturation adjustment model, and use the grayscale value of the first channel as the saturation correction value of the first channel; use the grayscale value of the first channel and the grayscale value of the second channel to calculate the saturation correction value of the second channel; use the grayscale value of the second channel, the grayscale value of the third channel, and the saturation correction value of the second channel to calculate the saturation correction value of the third channel; wherein the first channel is the hue channel with the maximum grayscale value, the second channel is the hue channel with the middle grayscale value, and the third channel is the hue channel with the minimum grayscale value.
[0156] The difference between the grayscale value of the first channel and the grayscale value of the second channel is calculated, and the first adjustment value is obtained based on the difference and the first saturation coefficient of the current hue region, and the saturation correction value of the second channel is obtained according to the grayscale value of the first channel. Two hue regions with the same grayscale value of the first channel have the same first saturation coefficient. The specific value of the first saturation coefficient is set according to user habits or needs, or is set according to actual application needs or environment. This embodiment does not limit the specific value.
[0157] The difference between the gray value of the second channel and the gray value of the third channel is calculated, and the second adjustment value is obtained based on the difference and the second saturation coefficient of the current hue area, and the saturation correction value of the third channel is obtained according to the saturation correction value of the second channel. Two hue areas with the same gray value of the third channel have the same second saturation coefficient. The specific value of the second saturation coefficient is set according to user habits or needs, or is set according to actual application needs or environment. This embodiment does not limit the specific value.
[0158] Taking the saturation adjustment in the BM hue area as an example, the calculation process of the saturation adjustment model is explained:
[0159] In the BM hue area, b≥r≥g, then the B channel is the first channel, the R channel is the second channel, and the G channel is the third channel; that is, the grayscale value of the first channel is b, the grayscale value of the second channel is r, and the grayscale value of the third channel is g.
[0160] Saturation correction value b of the first channel BM =b. Here, the subscript BM represents the BM hue region.
[0161] Calculate the difference (br) between the gray value b of the first channel and the gray value r of the second channel, obtain the first adjustment value (br)×k1 based on the difference and the first saturation coefficient k1 of the current hue region, and obtain the saturation correction value r of the second channel according to the gray value of the first channel BM =b-(br)×k1.
[0162] Calculate the difference (rg) between the second channel grayscale value r and the third channel grayscale value g, and obtain the second adjustment value (rg)×k2 based on the difference and the second saturation coefficient k2 of the current hue area, and obtain the saturation correction value g of the third channel based on the saturation correction value of the second channel BM =r BM -(rg)×k2=b-(br)×k1-(rg)×k2.
[0163] Similarly, the relevant calculation formula for the BC hue area can be obtained as follows:
[0164] In the BC hue area, b≥g≥r, then the B channel is the first channel, the G channel is the second channel, and the R channel is the third channel; that is, the grayscale value of the first channel is b, the grayscale value of the second channel is g, and the grayscale value of the third channel is r.
[0165] Saturation correction value b of the first channel BC = b. Here, the subscript BC represents the BC hue region.
[0166] The first channel of the hue region and the BM hue region is the B channel, and the first saturation coefficient of the hue region is consistent with that of the BM hue region, which is k1.
[0167] Saturation correction value g for the second channel BC =b-(bg)×k1.
[0168] Saturation correction value r of the third channel BC =g BC -(gr)×k3=b-(bg)×k1-(gr)×k3. Wherein k3 is the second saturation coefficient of the BC hue region.
[0169] Similarly, the relevant calculation formula for the GC hue area can be obtained as follows:
[0170] In the GC hue area, g≥b≥r, then the G channel is the first channel, the B channel is the second channel, and the R channel is the third channel; that is, the grayscale value of the first channel is g, the grayscale value of the second channel is b, and the grayscale value of the third channel is r.
[0171] Saturation correction value g of the first channel GC =g. Here, the subscript GC represents the GC hue region.
[0172] Saturation correction value b of the second channel GC =g-(gr)×k4. Wherein k4 is the first saturation coefficient of the GC hue region.
[0173] The third channel of this hue region and the BC hue region is the R channel, so the second saturation coefficient of this hue region is consistent with the second saturation coefficient of the BC hue region, which is k3. Then the saturation correction value of the third channel of the GC hue region is r GC =b GC -(br)×k3=g-(br)×k4-(br)×k3.
[0174] Similarly, the relevant calculation formula for the GY hue region can be obtained as follows:
[0175] In the GY hue area, g≥r≥b, then the G channel is the first channel, the R channel is the second channel, and the B channel is the third channel; that is, the grayscale value of the first channel is g, the grayscale value of the second channel is r, and the grayscale value of the third channel is b.
[0176] Saturation correction value g of the first channel GY =g. Here, the subscript GY indicates the GY hue region.
[0177] The first channel of this hue region is the same as that of the GC hue region, which is the G channel. The first saturation coefficient of this hue region is consistent with the first saturation coefficient of the GC hue region, which is k4. Then the saturation correction value of the second channel in the GY hue region is r GY =g-(gr)×k4.
[0178] Saturation correction value b of the third channel GY =r GY -(rb)×k5=g-(gr)×k4-(rb)×k5. Wherein k5 is the second saturation coefficient of the GY hue region.
[0179] Similarly, the relevant calculation formula for the RY hue area can be obtained as follows:
[0180] In the RY hue area, r≥g≥b, then the R channel is the first channel, the G channel is the second channel, and the B channel is the third channel; that is, the grayscale value of the first channel is r, the grayscale value of the second channel is g, and the grayscale value of the third channel is b.
[0181] Saturation correction value r of the first channel RY =r. Here, the subscript RY represents the RY hue region.
[0182] Saturation correction value g of the second channel in the RY hue area RY =r-(rg)×k6. Wherein k6 is the first saturation coefficient of the RY hue region.
[0183] The third channels of the RY hue region and the GY hue region are the same, both are B channels, so the second saturation coefficient of this hue region is consistent with the second saturation coefficient of the GY hue region, both are k5.
[0184] Saturation correction value b of the third channel RY =g RY -(gb)×k5=r-(rg)×k6-(gb)×k5.
[0185] Similarly, the relevant calculation formula for the RM hue area can be obtained as follows:
[0186] In the RM hue area, r≥b≥g, then the R channel is the first channel, the B channel is the second channel, and the G channel is the third channel; that is, the grayscale value of the first channel is r, the grayscale value of the second channel is b, and the grayscale value of the third channel is g.
[0187] Saturation correction value r of the first channel RM =r. Here, the subscript RM represents the RM hue region.
[0188] The first channel of this hue area is the same as that of the RY hue area, which is the R channel. The first saturation coefficient of this hue area is the same as that of the RY hue area, which is k6. The saturation correction value of the second channel in the RM hue area is b RM =r-(rb)×k6.
[0189] The third channel of the RM hue region and the BM hue region is the same, which is the G channel. Then the second saturation coefficient of the hue region is consistent with the second saturation coefficient of the BM hue region, which is k2.
[0190] Saturation correction value g of the third channel RM =b RM -(bg)×k2=r-(rb)×k6-(bg)×k2.
[0191] After calculation of the above saturation adjustment model, the saturation correction value of each channel in any hue area can be obtained.
[0192] If only the saturation of the original image data is adjusted, the saturation correction value of each channel in any hue area is obtained through calculation of the saturation adjustment model; based on the saturation correction value, the original image data (r, g, b) is processed to obtain the saturation target image data (r', g', b') S , S stands for saturation.
[0193] As an example, if the saturation adjustment is performed only on the RM hue region, the saturation target image data (r', g', b') HThe calculation formula is as follows:
[0194] r'=r RM =r; b'=b RM =r-(rb)×k6; g'=g RM =b RM -(bg)×k2=r-(rb)×k6-(bg)×k2.
[0195] The saturation adjustment method of the present invention sets a specific calculation formula for the grayscale value of each channel in different hue areas according to the characteristics of the grayscale value of each channel in the hue area to obtain an accurate saturation adjustment result. In the present invention, the saturation adjustment of any hue area is based on the original image data, which can effectively avoid the loss of the original image data.
[0196] After calculation of the above hue and / or saturation adjustment model, the hue shift grayscale value and / or saturation correction value of each channel in any hue region can be obtained; and according to the hue shift grayscale value and / or saturation correction value, the above content has explained that only hue / saturation adjustment is achieved, and finally the hue target image data (r', g', b') is obtained. H , saturation target image data (r', g', b') S process.
[0197] If the hue and saturation are adjusted simultaneously for the original image data (r, g, b) to obtain the hue-saturation target image data (r', g', b') H-S , the specific process is as follows:
[0198] Based on the size relationship of r, g, and b in the original image data (r, g, b), determine the hue area to which (r, g, b) belongs, select the corresponding hue adjustment model, and calculate the hue shift grayscale values of the first channel, the second channel, and the third channel respectively; based on the hue shift grayscale value, process (r, g, b) to obtain the hue target image data (r', g', b') H .
[0199] At this time, (r',g',b') H The original image data used as the saturation adjustment model is (r', g', b') H The relationship between r', g', and b' is determined by (r', g', b') H The corresponding saturation adjustment model is selected for the hue area to which it belongs, and the saturation correction values of the first channel, the second channel, and the third channel are calculated respectively; based on the saturation correction values, (r', g', b') are processed. H , get the hue-saturation target image data (r', g', b') H-S .
[0200] In addition to the above calculation process, the following method can also be used to obtain the hue-saturation target image data (r', g', b'): H-S , the specific process is as follows:
[0201] Based on the size relationship of r, g, and b in the original image data (r, g, b), determine the hue area to which (r, g, b) belongs, select the corresponding saturation adjustment model, and calculate the saturation correction values of the first channel, the second channel, and the third channel respectively; based on the saturation correction value, process (r, g, b) to obtain the saturation target image data (r', g', b') S .
[0202] At this time, (r',g',b') S As the original image data of the hue adjustment model, that is, (r', g', b') S The relationship between r', g', and b' is determined by (r', g', b') S The hue area to which it belongs selects the corresponding hue adjustment model, and calculates the hue shift grayscale values of the first channel, the second channel, and the third channel respectively; based on the hue shift grayscale values, processes (r', g', b') S , get the hue-saturation target image data (r', g', b') H-S .
[0203] Based on the same inventive concept, the present invention also proposes a color adjustment device based on hardware implementation, which is applicable to the above method, and is specifically as follows:
[0204] Get the original image data (r, g, b);
[0205] Selecting a hue adjustment model and / or a saturation adjustment model to respectively calculate the hue offset grayscale value and / or saturation correction value of the first channel, the second channel, and the third channel; wherein the hue adjustment model includes an adjacent hue adjustment model and a complementary hue adjustment model;
[0206] Based on the hue shift grayscale value and / or the saturation correction value, the original image data is processed to obtain the target image data (r', g', b').
[0207] In yet another aspect, the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the hardware-based color adjustment method as described above is implemented.
[0208] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0209] The above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A color adjustment method based on hardware implementation, characterized in that: include: Get the original image data (r, g, b); Compare the sizes of r, g, and b in the original image data (r, g, b), determine the hue region to which the original image data belongs, and select a corresponding hue adjustment model and / or saturation adjustment model; Selecting a hue adjustment model and / or a saturation adjustment model to respectively calculate a hue shift grayscale value and / or a saturation correction value of each channel; Based on the hue shift grayscale value and / or the saturation correction value, the original image data is processed to obtain the target image data (r', g', b'); The hue adjustment model includes an adjacent hue adjustment model and a complementary hue adjustment model. The adjacent hue adjustment model is a hue adjustment algorithm for the R hue region, the G hue region, and the B hue region. The complementary hue adjustment model is a hue adjustment algorithm for the C hue region, the Y hue region, and the M hue region. The saturation adjustment model is a saturation adjustment algorithm for the RY hue region, the RM hue region, the GY hue region, the GC hue region, the BC hue region, and the BM hue region; The hue shift grayscale value includes: Based on the current hue region, a corresponding hue adjustment model is selected to determine the hue shift grayscale value of the first channel; Calculate the moving step of the current hue area, select the correction coefficient of the current hue area, and calculate the hue shift grayscale value of the second channel and the hue shift grayscale value of the third channel of the current hue area based on the moving step and the correction coefficient; Wherein, determining the hue shift grayscale value of the first channel includes: In any hue region of the adjacent hue adjustment model, the first channel is the hue channel with the largest grayscale value, and its hue offset grayscale value is zero; In any hue region of the complementary hue adjustment model, the first channel is the hue channel with the smallest grayscale value, and its hue shift grayscale value is zero.
2. The color adjustment method based on hardware implementation according to claim 1, characterized in that: The step of calculating the moving step of the current hue region includes: In the current hue region, a first difference between the grayscale value of the first channel and the grayscale value of the second channel, and a second difference between the grayscale value of the first channel and the grayscale value of the third channel are calculated respectively; The minimum value between the first difference and the second difference is selected; and the moving step length of the current hue area is calculated based on the coefficient and the minimum value of the hue adjustment model.
3. The color adjustment method based on hardware implementation according to claim 1, characterized in that: The saturation correction value includes: Based on the current hue region, a corresponding saturation adjustment model is selected, and the gray value of the first channel is used as the saturation correction value of the first channel; Calculate the saturation correction value of the second channel using the gray value of the first channel and the gray value of the second channel; Calculate the saturation correction value of the third channel according to the saturation correction value of the second channel; Among them, the first channel is the channel with the largest grayscale value, the second channel is the channel with the middle grayscale value, and the third channel is the channel with the smallest grayscale value.
4. The color adjustment method based on hardware implementation according to claim 3, characterized in that: The step of calculating the saturation correction value of the second channel includes: The difference between the grayscale value of the first channel and the grayscale value of the second channel is calculated, and a first adjustment value is obtained based on the difference and a first saturation coefficient of the current hue region, and a saturation correction value of the second channel is obtained according to the grayscale value of the first channel.
5. The color adjustment method based on hardware implementation according to claim 4, characterized in that: The step of calculating the saturation correction value of the third channel includes: The difference between the grayscale value of the second channel and the grayscale value of the third channel is calculated, and the second adjustment value is obtained based on the difference and the second saturation coefficient of the current hue area, and the saturation correction value of the third channel is obtained according to the saturation correction value of the second channel.
6. A color adjustment device based on hardware, characterized in that: include: Get the original image data (r, g, b); Compare the sizes of r, g, and b in the original image data (r, g, b), determine the hue region to which the original image data belongs, and select a corresponding hue adjustment model and / or saturation adjustment model; Selecting a hue adjustment model and / or a saturation adjustment model to respectively calculate the hue offset grayscale value and / or the saturation correction value of each channel; wherein the hue adjustment model includes an adjacent hue adjustment model and a complementary hue adjustment model; Based on the hue shift grayscale value and / or the saturation correction value, the original image data is processed to obtain the target image data (r', g', b'); The hue shift grayscale value includes: Based on the current hue region, a corresponding hue adjustment model is selected to determine the hue shift grayscale value of the first channel; Calculate the moving step of the current hue area, select the correction coefficient of the current hue area, and calculate the hue shift grayscale value of the second channel and the hue shift grayscale value of the third channel of the current hue area based on the moving step and the correction coefficient; Wherein, determining the hue shift grayscale value of the first channel includes: In any hue region of the adjacent hue adjustment model, the first channel is the hue channel with the largest grayscale value, and its hue offset grayscale value is zero; In any hue region of the complementary hue adjustment model, the first channel is the hue channel with the smallest grayscale value, and its hue shift grayscale value is zero.
7. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the hardware-based color adjustment method according to any one of claims 1 to 5 is implemented.
