Gamma correction method and system
Gamma correction is performed through two-level lookup tables, and the problem of multiple storage units and limited correction effects in the prior art is solved, and image brightness correction and contrast enhancement with higher accuracy are achieved.
Patent Information
- Application Number
- CN202111662058.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-31
- Publication Date
- 2024-11-22
- Estimated Expiration
- 2041-12-31
AI Technical Summary
In the prior art, when using a level 1 lut table for Gamma correction, there are many storage units and the correction effect is limited, so it is impossible to effectively improve the overall brightness of the image and the contrast at low grayscale.
Gamma correction is performed using a two-level lookup table. By quantizing the Gamma curve in two-level segments, the first and second-level lookup tables are formed, and the correction grayscale value is obtained through interpolation operations, which improves the correction accuracy and is close to the Gamma curve.
The usage of memory cells is reduced, the correction accuracy is improved, the overall brightness of the image is closer to the perception of the human eye, and the contrast at low grayscale is enhanced.
Smart Images

Figure CN114390157B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image processing technology, and in particular to a gamma correction method and system. Background Art
[0002] The human eye's perception of brightness is not proportional to physical power, but rather presents a power function relationship. The exponent of the power function is usually 2.2, which is called the Gamma value. In order to meet the human eye's perception of image brightness, the image is Gamma corrected before it is displayed, thereby increasing the overall brightness of the image perceived by the human eye and enhancing the contrast at low grayscale. The main method of Gamma correction currently used is the table lookup method. The implementation mechanism of the table lookup method is to map the Gamma curve sampling to the storage unit indexed by the grayscale value. The system completes the Gamma correction based on the grayscale value of the input image pixel and the mapping value of the table lookup.
[0003] However, in the prior art, a level 1 LUT table is used for interpolation, and the LUT table requires many storage units, and the gamma correction effect is limited. Summary of the invention
[0004] The technical problem to be solved by the present invention is to provide a method and system for gamma correction in view of the above-mentioned defects of the prior art. The present invention performs gamma correction on the graphics before the image is displayed, and through a two-level lookup table, the correction accuracy is higher and the correction result is closer to the gamma curve.
[0005] The technical solution adopted by the present invention to solve the problem is as follows:
[0006] In a first aspect, the present invention provides a gamma correction method, comprising:
[0007] The grayscale values in the Gamma curve are quantized in two stages, and the quantized grayscale values and the corresponding grayscale stage numbers are used to form a first-stage lookup table and a second-stage lookup table respectively;
[0008] Obtaining an original grayscale value of an image pixel, searching for a grayscale value and a brightness value corresponding to the original grayscale value in the first-level lookup table, and obtaining a first corrected grayscale value through an interpolation operation on the search result;
[0009] The grayscale value and the brightness value corresponding to the first corrected grayscale value are searched in the second-level lookup table, and the second corrected grayscale value is obtained through interpolation operation according to the search result.
[0010] Preferably, the grayscale values in the Gamma curve are quantized in two stages, and a first-stage lookup table and a second-stage lookup table are formed by the quantized grayscale values and the corresponding grayscale segment numbers, specifically including:
[0011] The gamma curve is equally divided into N0 segments, and the grayscale value of each segment on the gamma curve is quantized into a grayscale value, and a first-level lookup table is formed by the quantized first quantized grayscale value and the first grayscale segment number;
[0012] The Gamma curve is averaged into N1 segments, and the grayscale value of each segment on the Gamma curve is quantized into a grayscale value, and the second-level lookup table is formed by the quantized second quantized grayscale value and the second grayscale segment number.
[0013] Preferably, the acquiring of the original grayscale value of the image pixel, searching the grayscale value and the brightness value corresponding to the original grayscale value in the first-level lookup table, and obtaining the first corrected grayscale value through interpolation operation of the search result specifically includes:
[0014] Acquire an image, and calculate the original grayscale value of the image pixels;
[0015] Scale the original grayscale value to the grayscale value range in the first-level lookup table;
[0016] Reading in the first-level lookup table two integer first grayscale values and second grayscale values closest to the scaled original grayscale value, and reading corresponding first brightness values and second brightness values according to the first grayscale value and the second grayscale value;
[0017] Through interpolation operation, a first corrected grayscale value corresponding to the original grayscale value is obtained according to the scaled decimal part of the original grayscale value, the first brightness value, and the second brightness value.
[0018] Preferably, searching the grayscale value and brightness value corresponding to the first corrected grayscale value in the second-level lookup table, and obtaining the second corrected grayscale value by interpolation operation according to the search result, specifically includes:
[0019] scaling the first corrected grayscale value to a grayscale value range in the second level lookup table;
[0020] Reading in the second-level lookup table two integer third grayscale values and fourth grayscale values closest to the scaled first correction grayscale value, and reading corresponding third brightness values and fourth brightness values according to the third grayscale value and the fourth grayscale value;
[0021] Through interpolation operation, a second corrected grayscale value corresponding to the first corrected grayscale value is obtained according to the scaled decimal part of the first corrected grayscale value, the third brightness value, and the fourth brightness value.
[0022] Preferably, the scaling ratio of the original grayscale value is 32, and the scaling ratio of the first corrected grayscale value is 16.
[0023] In a second aspect, the present invention further provides a gamma correction system, comprising:
[0024] A lookup table construction module is used to perform two-level segment quantization on the grayscale values in the Gamma curve, and form a first-level lookup table and a second-level lookup table respectively from the quantized grayscale values and the corresponding grayscale segment numbers;
[0025] A first operation module, used for obtaining an original grayscale value of an image pixel, searching the grayscale value and the brightness value corresponding to the original grayscale value in the first-level lookup table, and obtaining a first corrected grayscale value through an interpolation operation on the search result;
[0026] The second operation module is used to search the grayscale value and brightness value corresponding to the first corrected grayscale value in the second-level lookup table, and obtain the second corrected grayscale value through interpolation operation according to the search result.
[0027] Preferably, the lookup table building module includes:
[0028] A first lookup table construction unit is used to divide the Gamma curve into N0 segments, and quantize the grayscale value of each segment on the Gamma curve into a grayscale value, and form a first-level lookup table with the quantized first quantized grayscale value and the first grayscale segment number;
[0029] The second lookup table construction unit is used to average the Gamma curve into N1 segments, and quantize the grayscale value of each segment on the Gamma curve into a grayscale value, and form a second-level lookup table with the quantized second quantized grayscale value and the second grayscale segment number.
[0030] Preferably, the first operation module includes:
[0031] A grayscale calculation unit, used to acquire an image and calculate the original grayscale value of the image pixel;
[0032] A first grayscale scaling unit, used to scale the original grayscale value to a grayscale value range in the first level lookup table;
[0033] A first brightness reading unit, configured to read two integer first grayscale values and second grayscale values closest to the scaled original grayscale value in a first level lookup table, and read the corresponding first brightness value and second brightness value according to the first grayscale value and the second grayscale value;
[0034] The first grayscale operation unit is used to obtain a first corrected grayscale value corresponding to the original grayscale value according to the scaled decimal part of the original grayscale value, the first brightness value, and the second brightness value through interpolation operation.
[0035] Preferably, the second operation module includes:
[0036] A second grayscale scaling unit, configured to scale the first corrected grayscale value to a grayscale value range in the second-level lookup table;
[0037] A second brightness reading unit is used to read two integer third grayscale values and fourth grayscale values closest to the scaled first correction grayscale value in the second level lookup table, and read the corresponding third brightness value and fourth brightness value according to the third grayscale value and the fourth grayscale value;
[0038] The second grayscale operation unit is used to obtain a second corrected grayscale value corresponding to the first corrected grayscale value according to the scaled decimal part of the first corrected grayscale value, the third brightness value, and the fourth brightness value through interpolation operation.
[0039] Preferably, the scaling ratio of the original grayscale value is 32, and the scaling ratio of the first corrected grayscale value is 16.
[0040] The beneficial effects of the present invention are as follows: the present invention provides a method and system for gamma correction. The present invention performs gamma correction on graphics before image display. Through a two-level lookup table, the correction result is closer to the gamma curve, which conforms to the human eye's perception characteristics of image brightness, improves the overall brightness of the image perceived by the human eye, and enhances the contrast at low grayscale. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0042] Figure 1 The figure is a flow chart of the gamma correction method of the present invention.
[0043] Figure 2 It is the Gamma curve diagram of the segmented sampling of the present invention. DETAILED DESCRIPTION
[0044] In order to make the purpose, technical solution and advantages of the present invention clearer and more specific, the present invention is further described in detail below with reference to the accompanying drawings and examples. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.
[0045] It should be noted that if the embodiments of the present invention involve directional indications (such as up, down, left, right, front, back, etc.), the directional indications are only used to explain the relative position relationship, movement status, etc. between the components under a certain specific posture (as shown in the accompanying drawings). If the specific posture changes, the directional indication will also change accordingly.
[0046] Gamma correction is a nonlinear operation on the grayscale value of the input image, which makes the grayscale value of the output image exponentially related to the grayscale value of the input image. This exponent is Gamma. Usually the Gamma value is 2.2, but Gamma of 2.2 is not conducive to image recognition by the human eye. When the Gamma value is less than 1, the overall brightness of the image is improved, and the contrast of low grayscale is increased, which is more conducive to distinguishing image details at low grayscale values. Therefore, Gamma correction is required to more effectively preserve image brightness information.
[0047] In order to solve the problems of the prior art, the present invention provides a method for gamma correction, comprising: performing two-level segmented quantization on the grayscale values in the gamma curve, and forming a first-level lookup table and a second-level lookup table respectively according to the quantized grayscale values and the corresponding grayscale segment numbers; obtaining the original grayscale values of the image pixels, searching the grayscale values and brightness values corresponding to the original grayscale values in the first-level lookup table, and obtaining a first corrected grayscale value through interpolation operation on the search result; searching the grayscale values and brightness values corresponding to the first corrected grayscale value in the second-level lookup table, and obtaining a second corrected grayscale value through interpolation operation according to the search result.
[0048] The present invention adopts a two-level lookup table, so that the correction accuracy is higher and the storage units consumed are fewer. For example, for a 256-grayscale image, the conventional method requires 256 storage units, but by adopting a two-level lookup table, the first level depth is 8, the second level depth is 16, and the storage unit depth only needs 24, which is greatly reduced compared with the original storage unit. This two-level lookup table needs to be constructed before the operation.
[0049] Specifically, the steps for constructing the first-level lookup table are as follows: divide the Gamma curve into N0 segments, and quantize the grayscale value of each segment on the Gamma curve into a grayscale value, and the first-level lookup table is composed of the quantized first quantized grayscale value and the first grayscale segment number L1. The number of sampling points for quantizing the grayscale value of each segment is different. In the area where the curve changes steeply, more points are selected, and in the area where the curve changes gently, relatively fewer points are selected. Among them, 0≤L1≤N0-1, N0 is an integer power of 2, as shown in Table 1, the Gamma curve is divided into 8 segments.
[0050] The following is an example of a 256-grayscale image:
[0051] Divide the Gamma curve into 8 segments. For details, please refer to Figure 2 According to the characteristics of the Gamma curve, 16 sampling points are selected. The number of sampling points corresponds to the depth of the second-level lookup table. These 16 points are distributed in 8 grayscale ranges to obtain 8 grayscale values. The front part of the Gamma curve is steep, so more points are selected. The back end of the Gamma curve is relatively flat, so fewer points are selected, as shown in Table 1:
[0052] Grayscale segment number 1 2 3 4 5 6 7 8 Number of sampling points 5 3 3 1 1 1 1 1
[0053] If a segment has multiple sampling points, the gray value is the average value of the gray values corresponding to the multiple sampling points, and the corresponding gray segment number is N0-1. The first gray segment number and the corresponding first quantized gray value constitute the first-level lookup table, as shown in Table 2:
[0054] First Lookup Table Number 0 1 2 3 4 5 6 7 Gray value 80 128 176 192 208 224 240 255
[0055] Furthermore, the steps for constructing the second-level lookup table are as follows: average the Gamma curve into N1 segments, and quantize the grayscale value of each segment on the Gamma curve into a grayscale value, the number of sampling points for quantizing the grayscale value of each segment is the same, and the second-level lookup table is formed by the quantized second quantized grayscale value and the second grayscale segment number L2. Wherein, N1 = image grayscale value / (N0*number of sampling points per segment), 0≤L2≤N1-1, N1 is an integer power of 2, and the Gamma curve is evenly divided into 16 segments.
[0056] Further, let's take a 256-grayscale image as an example:
[0057] The steps for constructing the second-level lookup table are as follows: L2 = image grayscale value / (L1*number of sampling points per segment), with 256 / 8=32 as the offset, 32 / (number of sampling points per segment) as the step length, and the number of sampling points per segment is selected as 2, then 16 grayscale coordinates G are calculated. x (x=0,1,..,15), and substitute it into the normalized Gamma function Gamma(Gx). Each grayscale value is the average of the grayscale values of the two sampling points, and the corresponding grayscale segment number is: image grayscale value / (N1*number of sampling points per segment)-1. The second-level lookup table is composed of grayscale segment numbers and corresponding grayscale values, as shown in Table 2:
[0058] Second level lookup table number 0 1 2 3 4 5 6 7 Gray value 6 15 19 26 32 43 53 64 Second level lookup table number 8 9 10 11 12 13 14 15 Gray value 75 86 96 128 160 192 224 255
[0059] After the construction of the first-level lookup table and the second-level lookup table is completed, the first calibration can be performed.
[0060] Specifically, an image is acquired, and the original grayscale value of the image pixel is calculated; the original grayscale value is scaled to the grayscale value range in the first-level lookup table, preferably, the scaling ratio is 32, and the scaled grayscale value is the original grayscale value / 32, but the scaling ratio is not limited to this. The image pixel reading method is a conventional technology and is not described in detail here.
[0061] In the first-level lookup table, read the two integer first grayscale value and second grayscale value closest to the scaled grayscale value, and read the corresponding first brightness value and second brightness value according to the first grayscale value and the second grayscale value; that is, scale the original grayscale value lv0 to the range of [0, 7] to obtain the integer part lv0_int and the decimal part lv0_sub, then select the two integers lv0_int and lv0_int+1 as indexes, and read the corresponding brightness values lut0(lv0_int) and lut0(lv0_int+1) according to the first-level lookup table. Through interpolation operation, the first corrected grayscale value corresponding to the original grayscale value is obtained according to the scaled decimal part lv0_sub of the original grayscale value, the first brightness value, and the second brightness value. That is, according to lv0_sub, lut0(lv0_int), and lut0(lv0_int+1), the first corrected grayscale value lv1 is obtained through the interpolation algorithm, and the calculation formula is:
[0062] lv1=lut0(lv0_int)+(lut0(lv0_int+1)-lut0(lv0_int))*lv0_sub.
[0063] Furthermore, the second correction can be performed again. The first correction grayscale value is scaled to the grayscale value range in the second level lookup table. Preferably, the scaling ratio is 16, and the scaled grayscale value is the first correction grayscale value / 16, but the scaling ratio is not limited thereto.
[0064] In the second-level lookup table, read the two integer third grayscale values and fourth grayscale values closest to the scaled first corrected grayscale value, and read the corresponding third brightness value and fourth brightness value according to the third grayscale value and the fourth grayscale value; that is, scale the first corrected grayscale value lv1 to the grayscale value range [0, 15] in the second lookup table, that is: lv1 / 16, and get the integer part lv1_int and the decimal part lv1_sub, then you can select the two integers lv1_int and lv1_int+1 as indexes, and read the corresponding brightness values lut1(lv1_int) and lut1(lv1_int+1) according to the second-level lookup table. Through interpolation operation, the second corrected grayscale value corresponding to the first corrected grayscale value is obtained according to the scaled decimal part lv1_sub of the first corrected grayscale value, the third brightness value, and the fourth brightness value. That is, according to (lv1_sub, lut1(lv1_int), lut1(lv1_int+1), the second corrected grayscale value lv2 is obtained by the interpolation algorithm, and the calculation formula is:
[0065] lv2=lut1(lv1_int)+(lut1(lv1_int+1)-lut1(lv1_int))*lv1_sub.
[0066] Based on the above-mentioned Gamma correction method, the present invention also provides a Gamma correction system including:
[0067] A lookup table construction module is used to perform two-level segment quantization on the grayscale values in the Gamma curve, and form a first-level lookup table and a second-level lookup table respectively by using the quantized grayscale values and the corresponding grayscale segment numbers;
[0068] A first operation module is used to obtain the original grayscale value of the image pixel, search the grayscale value and brightness value corresponding to the original grayscale value in the first level lookup table, and obtain the first corrected grayscale value through interpolation operation of the search result;
[0069] The second operation module is used to search the grayscale value and the brightness value corresponding to the first corrected grayscale value in the second level lookup table, and obtain the second corrected grayscale value through interpolation operation according to the search result.
[0070] Among them, the lookup table building module includes:
[0071] A first lookup table construction unit is used to divide the Gamma curve into N0 segments, and quantize the grayscale value of each segment on the Gamma curve into a grayscale value, and form a first-level lookup table with the quantized first quantized grayscale value and the first grayscale segment number;
[0072] The second lookup table construction unit is used to average the Gamma curve into N1 segments, and quantize the grayscale value of each segment on the Gamma curve into a grayscale value, and form a second-level lookup table with the quantized second quantized grayscale value and the second grayscale segment number.
[0073] Wherein, the first operation module includes:
[0074] A grayscale calculation unit, used to acquire an image and calculate the original grayscale value of the image pixels;
[0075] A first grayscale scaling unit, used to scale the original grayscale value to a grayscale value range in the first level lookup table;
[0076] A first brightness reading unit is used to read two integer first grayscale values and second grayscale values closest to the scaled original grayscale value in the first level lookup table, and read the corresponding first brightness value and second brightness value according to the first grayscale value and the second grayscale value;
[0077] The first grayscale operation unit is used to obtain a first corrected grayscale value corresponding to the original grayscale value according to the scaled decimal part of the original grayscale value, the first brightness value, and the second brightness value through interpolation operation.
[0078] Wherein, the second operation module includes:
[0079] A second grayscale scaling unit, used for scaling the first correction grayscale value to a grayscale value range in the second level lookup table;
[0080] A second brightness reading unit is used to read two integer third grayscale values and fourth grayscale values closest to the scaled first correction grayscale value in the second level lookup table, and read the corresponding third brightness value and fourth brightness value according to the third grayscale value and the fourth grayscale value;
[0081] The second grayscale operation unit is used to obtain a second corrected grayscale value corresponding to the first corrected grayscale value according to the scaled decimal part of the first corrected grayscale value, the third brightness value, and the fourth brightness value through interpolation operation.
[0082] The scaling ratio of the original grayscale value is 32, and the scaling ratio of the first corrected grayscale value is 16.
[0083] The present invention provides a method and system for gamma correction. The present invention performs gamma correction on a graphic before displaying the image. Through a two-level lookup table, the correction result is closer to the gamma curve, which conforms to the human eye's perception characteristics of image brightness, improves the overall brightness of the image perceived by the human eye, and enhances the contrast at low grayscale.
[0084] It should be understood that the application of the present invention is not limited to the above examples. For ordinary technicians in this field, improvements or changes can be made based on the above description. All these improvements and changes should fall within the scope of protection of the claims attached to the present invention.
Claims
1. A method of gamma correction, It is characterized in that include: The grayscale values in the Gamma curve are quantized in two stages, and the quantized grayscale values and the corresponding grayscale segment numbers are used to form a first-stage lookup table and a second-stage lookup table, respectively, specifically including: dividing the Gamma curve into N0 stages, and quantizing the grayscale value of each stage on the Gamma curve into a grayscale value, and forming a first-stage lookup table with the quantized first quantized grayscale value and the first grayscale segment number; dividing the Gamma curve into N1 stages, and quantizing the grayscale value of each stage on the Gamma curve into a grayscale value, and forming a second-stage lookup table with the quantized second quantized grayscale value and the second grayscale segment number; The original grayscale value of the image pixel is obtained, the grayscale value and the brightness value corresponding to the original grayscale value are searched in the first-level lookup table, and the first corrected grayscale value is obtained by interpolation operation of the search result, specifically including: obtaining an image, and calculating the original grayscale value of the image pixel; scaling the original grayscale value to the grayscale value range in the first-level lookup table; reading the two integer first grayscale value and second grayscale value closest to the scaled original grayscale value in the first-level lookup table, and reading the corresponding first brightness value and second brightness value according to the first grayscale value and the second grayscale value; and obtaining the first corrected grayscale value corresponding to the original grayscale value according to the decimal part of the scaled original grayscale value, the first brightness value, and the second brightness value through interpolation operation; Searching the grayscale value and brightness value corresponding to the first corrected grayscale value in the second-level lookup table, and obtaining the second corrected grayscale value through interpolation operation according to the search result, specifically includes: scaling the first corrected grayscale value to the grayscale value range in the second-level lookup table; reading the two integer third grayscale value and fourth grayscale value closest to the scaled first corrected grayscale value in the second-level lookup table, and reading the corresponding third brightness value and fourth brightness value according to the third grayscale value and the fourth grayscale value; and obtaining the second corrected grayscale value corresponding to the first corrected grayscale value through interpolation operation according to the scaled decimal part of the first corrected grayscale value, the third brightness value, and the fourth brightness value.
2. The gamma correction method according to claim 1, It is characterized in that The scaling ratio of the original grayscale value is 32, and the scaling ratio of the first corrected grayscale value is 16.
3. A gamma correction system, applicable to the gamma correction method according to claim 1 or 2, It is characterized in that include: A lookup table construction module is used to perform two-level segment quantization on the grayscale values in the Gamma curve, and form a first-level lookup table and a second-level lookup table respectively from the quantized grayscale values and the corresponding grayscale segment numbers; A first operation module, used for obtaining an original grayscale value of an image pixel, searching the grayscale value and the brightness value corresponding to the original grayscale value in the first-level lookup table, and obtaining a first corrected grayscale value through an interpolation operation on the search result; The second operation module is used to search the grayscale value and brightness value corresponding to the first corrected grayscale value in the second-level lookup table, and obtain the second corrected grayscale value through interpolation operation according to the search result.
4. The gamma correction system according to claim 3, It is characterized in that The lookup table building module includes: A first lookup table construction unit is used to divide the Gamma curve into N0 segments, and quantize the grayscale value of each segment on the Gamma curve into a grayscale value, and form a first-level lookup table with the quantized first quantized grayscale value and the first grayscale segment number; The second lookup table construction unit is used to divide the Gamma curve into N1 segments, and quantize the grayscale value of each segment on the Gamma curve into a grayscale value, and form a second-level lookup table with the quantized second quantized grayscale value and the second grayscale segment number.
5. The gamma correction system according to claim 3, It is characterized in that The first operation module comprises: A grayscale calculation unit, used to acquire an image and calculate the original grayscale value of the image pixel; A first grayscale scaling unit, used to scale the original grayscale value to a grayscale value range in the first level lookup table; A first brightness reading unit, configured to read two integer first grayscale values and second grayscale values closest to the scaled original grayscale value in a first level lookup table, and read the corresponding first brightness value and second brightness value according to the first grayscale value and the second grayscale value; The first grayscale operation unit is used to obtain a first corrected grayscale value corresponding to the original grayscale value according to the scaled decimal part of the original grayscale value, the first brightness value, and the second brightness value through interpolation operation.
6. The gamma correction system according to claim 5, It is characterized in that The second operation module comprises: A second grayscale scaling unit, configured to scale the first corrected grayscale value to a grayscale value range in the second-level lookup table; A second brightness reading unit is used to read two integer third grayscale values and fourth grayscale values closest to the scaled first correction grayscale value in the second level lookup table, and read the corresponding third brightness value and fourth brightness value according to the third grayscale value and the fourth grayscale value; The second grayscale operation unit is used to obtain a second corrected grayscale value corresponding to the first corrected grayscale value according to the scaled decimal part of the first corrected grayscale value, the third brightness value, and the fourth brightness value through interpolation operation.
7. The gamma correction system according to claim 6, It is characterized in that The scaling ratio of the original grayscale value is 32, and the scaling ratio of the first corrected grayscale value is 16.
