Automatic white balance method and device based on color temperature estimation, electronic equipment and computer storage medium
By obtaining the color temperature curve and calculating the color difference value in blocks, calculating the color temperature point and pixel gain of the light source, the problem of poor white balance processing effect is solved, and more accurate automatic white balance correction is achieved, which is suitable for a variety of scenarios.
Patent Information
- Application Number
- CN202510538198.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-25
- Publication Date
- 2025-07-18
AI Technical Summary
When calculating the distance between the color difference channel block and the color temperature curve, the existing white balance processing method cannot accurately measure the difference, ignores the influence of the color difference channel block with a long distance, and does not consider the prior relationship between the light intensity and the light source, resulting in poor processing effect and limited application scenarios.
By obtaining the color temperature curve, the color difference value of the image block is calculated in blocks, the color temperature curve and the color difference value of the image block are used to calculate the final estimated light source color temperature point, and the pixel gain of automatic white balance is calculated based on the color temperature point and color difference value of the light source, and the original image is compensated.
It realizes more accurate scene light source color temperature estimation, the calculated pixel gain is more accurate, and the automatic white balance correction effect is better. It is suitable for all kinds of scenarios. The calculation process is simple, the resource consumption is less and it has stronger robustness.
Smart Images

Figure CN120343175A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image processing, and in particular to an automatic white balance method and device, an electronic device, and a computer storage medium based on color temperature estimation. Background Art
[0002] The human visual device has the characteristic of color constancy and is basically not affected by the change of the light source when observing an object. However, under different light conditions, the colors presented by an object are different for an image sensor. For example, it will be bluish under a clear sky and reddish under a candlelight. In order to eliminate the color influence of the light source on the imaging of the image sensor and simulate the color constancy of the human visual device to ensure that the white seen in any scene is truly white, it is necessary to perform white balance processing on the original image captured by the image sensor.
[0003] Existing white balance processing generally obtains the gains of each color channel of the original image by using the distance from the color difference channel block to the color temperature curve, and then uses this gain to compensate for the color deviation caused by the color temperature environment and the deviation of the color channel gain inherent in the imaging instrument itself, so that the finally displayed image can correctly reflect the true color of the object.
[0004] However, in the existing white balance processing method, when calculating the distance from the color difference channel block to the color temperature curve, the Euclidean distance is used for calculation, and the calculation method of the Euclidean distance cannot measure the difference between the color difference channel block and the color temperature curve well; at the same time, in the existing white balance processing method, only the color difference channel blocks that fall within a certain range from the color temperature curve will participate in the calculation, which not only ignores the influence of the color difference channel blocks that are far away on the color temperature estimation, but also results in a small number of effective color difference channel blocks in actual applications and insufficient coverage of the scene; in addition, the existing white balance processing method does not consider the prior relationship between the light intensity and the light source and calculates according to a unified standard under different light intensities. These problems lead to poor white balance processing effects and limited application scenarios in the existing method. Summary of the Invention
[0005] The purpose of the present invention is to provide an automatic white balance method and device, an electronic device, and a computer storage medium based on color temperature estimation to solve the problems of poor white balance processing effects and limited application scenarios in the existing method.
[0006] To solve the above technical problems, the present invention provides an automatic white balance method based on color temperature estimation, including: Obtain a color temperature curve; Divide the original image into blocks to obtain a plurality of image blocks; Calculate the color difference value of each image block; Use the color temperature curve and the color difference value of the image block to calculate the final estimated light source color temperature point; Calculate the pixel gain of automatic white balance according to the final estimated light source color temperature point and the color difference value of the image block; Use the calculated pixel gain to compensate the original image to obtain an image after automatic white balance correction.
[0007] Optionally, in the automatic white balance method based on color temperature estimation, the method for obtaining the color temperature curve includes: Shoot a color checker under different color temperature light sources to obtain color temperature images with different color temperatures; Calculate the R / G color difference value and B / G color difference value of each color temperature image; Use the R / G color difference value and B / G color difference value of each color temperature image as the horizontal and vertical coordinates of the curve for curve fitting to obtain the color temperature curve.
[0008] Optionally, in the automatic white balance method based on color temperature estimation, the method for calculating the R / G color difference value and B / G color difference value of each color temperature image includes: Perform shadow correction on the color temperature image; Obtain the mean values of the R channel, B channel, and G channel within a preset area of the corrected color temperature image; Use the mean values of the R channel, B channel, and G channel of each color temperature image to calculate the R / G color difference value and B / G color difference value of this color temperature image.
[0009] Optionally, in the automatic white balance method based on color temperature estimation, the method for calculating the color difference value of each image block includes: Calculate the mean values of the R channel, B channel, and G channel in each image block; Use the mean values of the R channel, B channel, and G channel of each image block to calculate the R / G color difference value and B / G color difference value of this image block; Set the brightness threshold; According to the brightness threshold, screen the image blocks that meet the requirements and obtain the effective image block ratio.
[0010] Optionally, in the automatic white balance method based on color temperature estimation, the method for calculating the final estimated light source color temperature point by using the color temperature curve and the color difference value of each image block includes: Traverse the color temperature curve according to the first step size, and use the color difference value of each image block to calculate the initial estimated light source color temperature point; Within the preset range of the initial estimated light source color temperature point, traverse the color temperature curve according to the second step size, and use the color difference value of each image block to calculate the final estimated light source color temperature point; Wherein, the second step size is smaller than the first step size.
[0011] Optionally, in the automatic white balance method based on color temperature estimation, the method of traversing the color temperature curve according to the first step length and calculating the initial estimated light source color temperature point by using the color difference value of each image block includes: Obtain a list of prior scores of light sources at different brightness levels; Traverse the color temperature curve according to the first step length, and calculate the sum of the distances between the color difference value of each image block and the color difference value of this color temperature point at each color temperature point to obtain a first distance value; Obtain the prior score corresponding to each color temperature point from the list of prior scores of light sources; Subtract the prior score corresponding to this color temperature point from the first distance value to obtain a second distance value; Use the color temperature point corresponding to the smallest second distance value as the initial estimated light source color temperature point.
[0012] Optionally, in the automatic white balance method based on color temperature estimation, the method of traversing the color temperature curve according to the second step length within the preset range of the initial estimated light source color temperature point and calculating the final estimated light source color temperature point by using the color difference value of each image block includes: Within the preset range of the initial estimated light source color temperature point, traverse the color temperature curve according to the second step length, and calculate the sum of the distances between the color difference value of each image block and the color difference value of this color temperature point at each color temperature point to obtain a third distance value; Obtain the prior score corresponding to each color temperature point from the list of prior scores of light sources; Subtract the prior score corresponding to this color temperature point from the third distance value to obtain a fourth distance value; Use the color temperature point corresponding to the smallest fourth distance value as the final estimated light source color temperature point.
[0013] Optionally, in the automatic white balance method based on color temperature estimation, the method of calculating the pixel gain of automatic white balance according to the final estimated light source color temperature point and the color difference value of the image block includes: Use the image blocks whose distances from the color difference value of the final estimated light source color temperature point are within the preset distance as reference image blocks; Calculate the difference between the distance between the color difference value of each reference image block and the color difference value of the final estimated light source color temperature point and the prior score to obtain a reference distance value; If the reference distance value is less than the preset distance threshold, use this reference image block as a valid reference image block; If the number of valid reference image blocks is less than the preset number threshold, calculate the pixel gain of automatic white balance by using the color difference value of the final estimated light source color temperature point; If the number of valid reference image blocks is greater than or equal to a preset number threshold, calculate the pixel gain of automatic white balance using the sum of the R channels, the sum of the B channels, and the sum of the G channels of all valid reference image blocks.
[0014] To solve the above technical problems, the present invention also provides an automatic white balance device based on color temperature estimation for implementing the automatic white balance method based on color temperature estimation described in any one of the above. The automatic white balance device based on color temperature estimation includes: An image acquisition module for acquiring an original image; A color temperature curve acquisition module for acquiring a color temperature curve; An image block color difference calculation module for dividing the original image into blocks to obtain a plurality of image blocks and calculating the color difference of each image block; A pixel gain calculation module for using the color temperature curve and the color difference of each image block to calculate a final estimated light source color temperature point, and calculating the pixel gain of automatic white balance according to the final estimated light source color temperature point and the color difference of the image block; A white balance compensation module for compensating the original image using the calculated pixel gain to obtain an image after automatic white balance correction; An image output module for outputting the image after automatic white balance correction.
[0015] To solve the above technical problems, the present invention also provides an electronic device including a memory, a processor, and an executable program stored on the memory and capable of being run by the processor; when the processor runs the executable program, it executes the automatic white balance method based on color temperature estimation described in any one of the above.
[0016] To solve the above technical problems, the present invention also provides a computer storage medium storing an executable program; when the executable program is executed, it implements the automatic white balance method based on color temperature estimation described in any one of the above.
[0017] The automatic white balance method, device, electronic device, and computer storage medium based on color temperature estimation provided by the present invention include: obtaining a color temperature curve; dividing the original image into blocks to obtain a plurality of image blocks; calculating the color difference value of each image block; using the color temperature curve and the color difference value of the image block to calculate the final estimated light source color temperature point; calculating the pixel gain of the automatic white balance according to the final estimated light source color temperature point and the color difference value of the image block; and using the calculated pixel gain to compensate the original image to obtain an image after automatic white balance correction. By dividing the original image into multiple image blocks and using the color difference value of the image block and the color temperature curve to calculate the estimated light source color temperature point, the estimated scene light source color temperature is more accurate, so that the calculated pixel gain is more precise and the effect of automatic white balance correction is better. At the same time, the calculation process of this automatic white balance method is simple, with less resource consumption and high efficiency, and has stronger robustness, being applicable to various scenarios, solving the problems of poor white balance processing effect and limited application scenarios in the prior art. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] Figure 1 is a flowchart of the automatic white balance method based on color temperature estimation provided in this embodiment; Figure 2 is a schematic diagram of the color temperature curve provided in this embodiment; Figure 3 is a schematic diagram of the image block division provided in this embodiment; Figure 4 is a flowchart of the method in step S4 provided in this embodiment; Figure 5 is a schematic diagram of the light source prior score list provided in this embodiment; Figure 6 is a schematic diagram of the color temperature curve corresponding to the process of obtaining the initial estimated light source color temperature point provided in this embodiment; Figure 7 is a schematic diagram of the color temperature curve corresponding to the process of obtaining the final estimated light source color temperature point provided in this embodiment; Figure 8 is a schematic diagram of the structure of the automatic white balance device based on color temperature estimation provided in this embodiment. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0019] The following further elaborates in detail on the automatic white balance method, device, electronic device, and computer storage medium based on color temperature estimation proposed by the present invention in conjunction with the accompanying drawings and specific embodiments. It should be noted that the accompanying drawings are all in a very simplified form and use non-precise scales, only for the purpose of facilitating and clearly assisting in explaining the objectives of the embodiments of the present invention. In addition, the structures shown in the accompanying drawings are often part of the actual structures. In particular, the accompanying drawings need to show different emphases and sometimes use different scales.
[0020] It should be noted that the "first", "second", etc. in the description, claims and accompanying drawings of the present invention are used to distinguish similar objects in order to describe the embodiments of the present invention, rather than to describe a specific order or sequence. It should be understood that the structures used in this way can be interchanged under appropriate circumstances. In addition, the terms "include" and "have" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, device, product or equipment that includes a series of steps or units does not necessarily have to be limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or are inherent to these processes, methods, products or equipment.
[0021] This embodiment provides an automatic white balance method based on color temperature estimation, as Figure 1 shown, including: S1. Obtain a color temperature curve; S2. Divide the original image into blocks to obtain a plurality of image blocks; S3. Calculate the color difference value of each image block; S4. Use the color temperature curve and the color difference value of the image block to calculate the final estimated light source color temperature point; S5. According to the final estimated light source color temperature point and the color difference value of the image block, calculate the pixel gain of the automatic white balance; S6. Use the calculated pixel gain to compensate the original image to obtain an image after automatic white balance correction.
[0022] The automatic white balance method, device, electronic device and computer storage medium based on color temperature estimation provided by this embodiment divide the original image into a plurality of image blocks, and use the color difference value of the image block and the color temperature curve to calculate the estimated light source color temperature point, so that the estimated scene light source color temperature is more accurate, thereby making the calculated pixel gain more accurate and the effect of automatic white balance correction better; at the same time, the calculation process of this automatic white balance method is simple, resource consumption is small, the efficiency is high, and it has stronger robustness and is applicable to various scenarios, solving the problems of poor white balance processing effect and limited application scenarios in the prior art.
[0023] It should be noted that in practical applications, the implementation order of steps S1 and steps S2, S3 can be swapped (perform steps S2, S3 first, and then perform step S1), or be synchronized (step S1 is synchronized with step S2 or step S3). The technical solutions with the adjusted step order without violating the gist of this application should also fall within the protection scope of this application.
[0024] Specifically, in this embodiment, the method for step S1, obtaining a color temperature curve, includes: S11. Photograph a color checker under different color temperature light sources to obtain color temperature images with different color temperatures.
[0025] In practical applications, a gray card or color card can be photographed under different color temperature light sources such as 7500K, 6500K, 5500K, 5000K, 4000K, 3200K, 2856K, etc. to obtain a color temperature image. Of course, in other embodiments, it is also possible to set the required color temperature for photographing according to actual needs, and this application does not limit this.
[0026] S12. Calculate the R / G color difference value and B / G color difference value of each color temperature image.
[0027] In order to accurately obtain the color difference value of the color temperature image, in this embodiment, first, perform lens shading correction on the color temperature image to ensure that the pixel values of each pixel point are accurate.
[0028] Then, obtain the average values of the R channel, B channel, and G channel within a preset area of the corrected color temperature image. In practical applications, the R channel, B channel, and G channel of the pixels in the central area of the color temperature image, or the R channel, B channel, and G channel of all the pixels in the entire color temperature image, can be obtained, and by calculating the average of each channel value, the average value of the R channel, the average value of the B channel, and the average value of the G channel are obtained.
[0029] Finally, using the average value of the R channel, the average value of the B channel, and the average value of the G channel of each color temperature image, calculate the R / G color difference value and B / G color difference value of this color temperature image, that is, take the ratio of the average value of the R channel to the average value of the G channel as the R / G color difference value; take the ratio of the average value of the B channel to the average value of the G channel as the B / G color difference value. The specific calculation method of the color difference is well known to those skilled in the art, and this application will not elaborate.
[0030] S13. Use the R / G color difference value and B / G color difference value of each color temperature image as the horizontal and vertical coordinates of the curve for curve fitting to obtain a color temperature curve.
[0031] In practical applications, the fitting method can be implemented by means such as piecewise broken line, quadratic curve fitting, cubic curve fitting, etc., and this application does not limit this.
[0032] In a specific embodiment, the color temperature curve obtained by using the piecewise broken line fitting method is as Figure 2 shown. Each point on this color temperature curve represents the corresponding color difference value under different R / G color difference values and B / G color difference values.
[0033] Furthermore, in this embodiment, in step S2, the original image is divided into blocks to obtain a plurality of image blocks. Specifically, as Figure 3 shown, the original image can be divided into M×N continuously distributed image blocks, and each image block contains a plurality of pixel points.
[0034] In practical applications, the segmentation method and number of image blocks can be comprehensively determined according to the size of the original image, the required accuracy of white balance correction, etc. To simplify the calculation, the size of each image block should be the same.
[0035] Furthermore, in this embodiment, the method for calculating the color difference value of each image block in step S3 includes: S31, calculating the mean values of the R channel, B channel, and G channel in each image block.
[0036] Specifically, in this embodiment, the R channel, B channel, and G channel of each pixel in the image block are obtained, and by separately averaging the R channel, B channel, and G channel of all pixels in the same image block, the R channel mean value, B channel mean value, and G channel mean value of this image block are obtained.
[0037] S32, using the R channel mean value, B channel mean value, and G channel mean value of each image block to calculate the R / G color difference value and B / G color difference value of this image block.
[0038] Specifically, in this embodiment, for each image block, the ratio of its R channel mean value to the G channel mean value is used as the R / G color difference value of this image block; the ratio of the B channel mean value to the G channel mean value is used as the B / G color difference value of this image block.
[0039] In order to further improve the accuracy of the calculated gain during the automatic white balance process, in this embodiment, image blocks that are too bright and too dark are also excluded, so as to avoid the interference of bright pixel points and bad pixel points on the white balance correction.
[0040] Specifically, in this embodiment, first, a brightness threshold is set, and the brightness threshold includes a brightness upper limit threshold and a brightness lower limit threshold, so as to judge bright image blocks and dark image blocks respectively; then, according to the brightness threshold, image blocks that meet the requirements are screened, and the effective image block ratio is obtained.
[0041] In a specific embodiment, if the G channel pixel value of the image block is less than the brightness lower limit threshold, it is judged as a dark image block and needs to be excluded; if the G channel pixel value of the image block is greater than the brightness upper limit threshold, it is judged as a bright image block and also needs to be excluded; only when the G channel pixel value of the image block is between the brightness upper limit threshold and the brightness lower limit threshold, will it be judged as an effective image block. And, the effective image block ratio ratio is the ratio of the number of effective image blocks to the total number of image blocks.
[0042] Of course, in other embodiments, corresponding brightness upper limit thresholds and brightness lower limit thresholds can be set for the R / G color difference value and B / G color difference value according to actual needs, so as to achieve fine adjustment of different color difference channels and improve the effect of white balance correction.
[0043] Further, in this embodiment, as Figure 4 shown, in step S4, the method for calculating the finally estimated light source color temperature point by using the color temperature curve and the color difference value of each image block includes: S41, Traverse the color temperature curve according to the first step length, and calculate the initial estimated light source color temperature point by using the color difference value of each image block.
[0044] Specifically, in this embodiment, step S41 specifically includes: S411, Obtain the list of prior scores of the light source at different brightness levels.
[0045] In practical applications, according to the preset rules, the list of prior scores of the light source can be constructed by using the scene brightness, color temperature, and prior scores. In this embodiment, considering that usually, when the scene is very bright, a larger (more likely) value may be selected for the daytime light source. Therefore, under these conditions, the indoor light source will be excluded; under medium and low light conditions, the indoor light source is likely to be favored. At the same time, low-brightness scenes are generally low-color-temperature light sources, such as indoor light sources and street lights at night; while high-brightness scenes are generally high-color-temperature light sources, such as a clear and cloudless noon. Therefore, according to the above selection method, a two-dimensional lookup table of scene brightness-color temperature-prior score can be established, so that the prior score corresponding to the current candidate color temperature can be obtained from the list of prior scores of the light source according to the brightness and the candidate color temperature. This embodiment provides an example of the list of prior scores of the light source, as Figure 5 shown.
[0046] S412, Traverse the color temperature curve according to the first step length, and calculate the sum of the distances between the color difference value of each image block and the color difference value of this color temperature point at each color temperature point to obtain the first distance value.
[0047] Specifically, the Manhattan distance (L1), Euclidean distance (L2), or ratio distance can be used to calculate the sum of the distances between the R / G color difference value of each image block and the R / G color difference value of this color temperature point and the sum of the distances between the B / G color difference value of the image block and the B / G color difference value of this color temperature point, and then the two distances are summed to obtain the first distance value S1. The specific implementation method of calculating the color difference distance is well known to those skilled in the art, and this application will not elaborate on it.
[0048] Preferably, after obtaining the first distance value, the first distance value can be scaled by using the effective image block ratio calculated in step S32, so as to further adjust the accuracy of the first distance value and make it better match the original image.
[0049] S413, Obtain the prior score corresponding to each color temperature point from the list of prior scores of the light source.
[0050] Specifically, the brightness of the scene can be estimated first, and then the estimated scene brightness value can be substituted into the list of prior scores of the light source to obtain its prior score: First, a gray card is photographed under preset brightness conditions to obtain a reference image. Generally, the preset brightness conditions are an environment with moderate brightness, such as a 600 lux illumination condition. When photographing the gray card under this condition, the pixel values in the obtained reference image are the pixel values for image grayscale conversion. At the same time, the exposure parameters when photographing the reference image can also be obtained, mainly including the shutter time and gain. In practical applications, the preset brightness conditions include but are not limited to illumination conditions, exposure parameters, etc. The preset brightness conditions can be obtained and set offline in advance and directly called and calculated during the brightness estimation in this step.
[0051] Then, the average pixel value of the original image after grayscale conversion and the exposure parameters are obtained. The method for obtaining the pixel values of the original image after grayscale conversion is well-known to those skilled in the art and will not be elaborated in this application. When calculating the average pixel value of the original image after grayscale conversion, the grayscale pixel values in the central area of the original image or the grayscale pixel values of the entire original image can be selected, and the average is calculated by averaging the selected grayscale pixel values. The categories of exposure parameters of the original image are the same as those of the reference image, mainly including the shutter time and gain.
[0052] Next, the ratio of the average pixel values and the ratio of the exposure parameters between the original image and the reference image are calculated. Specifically, it includes the ratio of the average pixel values (denoted as yRatio), the ratio of the shutter times (denoted as shutterRatio), and the ratio of the gains (denoted as gainRatio), where the relevant parameters of the reference image are used as the benchmark (denominator).
[0053] After that, the scene brightness of the original image is calculated using the ratio of the average pixel values and the ratio of the exposure parameters. Specifically, the scene brightness can be the product of the ratio of the average pixel values, the ratio of the shutter times, the ratio of the gains, and the environmental brightness when the reference image was photographed.
[0054] Finally, the calculated scene brightness is substituted into the list of prior scores of the light source to obtain its prior score.
[0055] S414, subtract the prior score corresponding to the color temperature point from the first distance value to obtain the second distance value S2.
[0056] S415, use the color temperature point corresponding to the smallest second distance value as the initial estimated light source color temperature point.
[0057] In a specific embodiment, as Figure 6 shown, the initial estimated light source color temperature point confirmed through step S41 is 4430K.
[0058] So far, the initial estimated light source color temperature point has been obtained through a rough estimate. Since a relatively large first step size is adopted in step S41, the computational load can be reduced, thereby achieving the improvement of the device efficiency while reducing the power consumption of the device.
[0059] S42. Within the preset range of the initial estimated light source color temperature point, traverse the color temperature curve according to the second step size, and calculate the final estimated light source color temperature point by using the color difference value of each image block; wherein, the second step size is smaller than the first step size.
[0060] Specifically, in this embodiment, similar to the implementation manner of step S41, the specific implementation manner of step S42 includes: First, within the preset range of the initial estimated light source color temperature point, traverse the color temperature curve according to the second step size, and calculate the sum of the distances between the color difference value of each image block and the color difference value of this color temperature point at each color temperature point to obtain the third distance value S3; then, obtain the prior score corresponding to each color temperature point from the light source prior score list; next, subtract the prior score corresponding to the corresponding color temperature point from the third distance value to obtain the fourth distance value S4; finally, use the color temperature point corresponding to the smallest fourth distance value as the final estimated light source color temperature point.
[0061] In a specific embodiment, as Figure 7 shown, by performing a fine search near the initial estimated light source color temperature point of 4430K confirmed in step S41, an accurate final estimated light source color temperature point can be obtained.
[0062] In practical applications, the preset range can be determined according to actual requirements, such as the accuracy requirement of white balance correction. Of course, the larger the preset range, the more accurate the calculation result, but the computational amount is larger and the resource consumption is greater. In practical applications, it is necessary to balance various factors to comprehensively determine the preset range.
[0063] So far, the final estimated light source color temperature point has been obtained through a fine estimate. Since the step size of the second step size adopted in step S42 is smaller than the first step size, the light source color temperature point can be determined more accurately. By first making a rough estimate and then a fine estimate, the computational load can be saved, thereby achieving the improvement of the device efficiency while reducing the power consumption of the device.
[0064] In addition, in practical applications, when performing the rough search in step S41, the traversal method can be uniform traversal or non-uniform traversal; when performing the fine search in step S42, the traversal method is uniform traversal to ensure the accuracy of the obtained final estimated light source color temperature point.
[0065] Further, in this embodiment, step S5. The method for calculating the pixel gain of automatic white balance according to the final estimated light source color temperature point and the color difference value of the image block includes: S51, take the image blocks whose distance from the color difference value of the finally estimated light source color temperature point is within a preset distance as reference image blocks.
[0066] Specifically, in practical applications, the preset distance should be a relatively small value, so as to select the image blocks with a relatively close distance from the color difference value of the finally estimated light source color temperature point as reference image blocks. Among them, the specific value of the preset distance can be reasonably set according to the actual situation, and this application does not limit it.
[0067] S52, calculate the difference between the distance between the color difference value of each reference image block and the color difference value of the finally estimated light source color temperature point and the prior score to obtain a reference distance value.
[0068] Specifically, in a specific embodiment, the distance between the R / G color difference value of the reference image block and the R / G color difference value of the finally estimated light source color temperature point can be expressed as: deltaR = rg / ct_rg - 1, where rg represents the R / G color difference value of the reference image block, and ct_rg represents the R / G color difference value of the finally estimated light source color temperature point; similarly, the distance between the B / G color difference value of the reference image block and the B / G color difference value of the finally estimated light source color temperature point can be expressed as: deltaB = bg / ct_bg - 1, where bg represents the B / G color difference value of the reference image block, and ct_bg represents the B / G color difference value of the finally estimated light source color temperature point; take the absolute value of the distances corresponding to the R / G color difference value and the B / G color difference value and sum them to obtain the distance between the color difference value of the reference image block and the color difference value of the finally estimated light source color temperature point, that is, delta1 = abs(deltaR) + abs(deltaB), where abs( ) represents the absolute value operation; the reference distance value can be expressed as: delta2 = delta1 - prior, where prior represents the prior score corresponding to the finally estimated light source color temperature point in the light source prior score list.
[0069] In practical applications, when calculating the distance between the color difference value of the reference image block and the color difference value of the finally estimated light source color temperature point, that is, the color difference distance delta1 between the color difference value of the reference image block and the color temperature curve, the effective image block ratio ratio can also be used to scale the calculation result of the distance value to achieve precise adjustment of the calculation result of the distance value. At this time, the reference distance value can be expressed as: delta2 = delta1 / ratio - prior.
[0070] S53, if the reference distance value is less than the preset distance threshold, then take this reference image block as a valid reference image block.
[0071] In a specific embodiment, the distance threshold can be reasonably set according to the actual situation. By adjusting the distance threshold, the intensity and accuracy of white balance correction can be adjusted.
[0072] S54-1, if the number of valid reference image blocks is less than the preset number threshold, calculate the pixel gain of automatic white balance using the color difference value of the finally estimated light source color temperature point.
[0073] Specifically, directly use the reciprocal of the color difference value of the finally estimated light source color temperature point as the pixel gain of automatic white balance. That is, for the pixel gain of the R channel, it can be expressed as: Rgain = 1 / ct_rg; for the pixel gain of the B channel, it can be expressed as: Bgain = 1 / ct_bg.
[0074] S54-2, if the number of valid reference image blocks is greater than or equal to the preset number threshold, calculate the pixel gain of automatic white balance using the sum of the R channels, the sum of the B channels, and the sum of the G channels of all valid reference image blocks.
[0075] Specifically, use the ratio of the sum of the R channels to the sum of the G channels of all valid reference image blocks as the pixel gain of the R channel, that is, Rgain = R_sum / G_sum, where R_sum represents the sum of the R channel values of all valid reference image blocks, and G_sum represents the sum of the G channel values of all valid reference image blocks; similarly, use the ratio of the sum of the B channels to the sum of the G channels of all valid reference image blocks as the pixel gain of the B channel, that is, Bgain = B_sum / G_sum, where B_sum represents the sum of the B channel values of all valid reference image blocks, and G_sum represents the sum of the G channel values of all valid reference image blocks.
[0076] Further, in this embodiment, in step S6, use the calculated pixel gain to compensate the original image to obtain an image after automatic white balance correction.
[0077] Specifically, multiply the original R channel value of the original image by the pixel gain of the R channel to obtain the R channel value after white balance correction; similarly, multiply the original B channel value of the original image by the pixel gain of the B channel to obtain the B channel value after white balance correction. Combine the R channel value after white balance correction, the B channel value after white balance correction, and the original G channel value to obtain an image after white balance correction.
[0078] The automatic white balance method based on color temperature estimation provided in this embodiment can meet the color temperature estimation in various scenarios and obtain a more accurate color temperature estimation result with less computational effort by first roughly traversing the color temperature curve and then finely traversing the color temperature curve for color temperature estimation. The automatic white balance method based on color temperature estimation provided in this embodiment screens image blocks through a color difference threshold during color temperature estimation, thereby avoiding the deviation influence of bright image blocks and dark image blocks on the calculation result and ensuring the accuracy and reliability of the calculation result. The automatic white balance method based on color temperature estimation provided in this embodiment calibrates the distance using the prior score during distance calculation by constructing a prior score list of light sources, ensuring a more accurate light source estimation result. The automatic white balance method based on color temperature estimation provided in this embodiment differentiates the calculation method of pixel gain according to the number of effective reference image blocks, making the calculation result of pixel gain more accurate and more in line with actual requirements and ensuring the effect of white balance correction.
[0079] This embodiment also provides an automatic white balance device based on color temperature estimation for implementing the automatic white balance method based on color temperature estimation as described above, as Figure 8 shown, including: An image acquisition module for acquiring an original image; A color temperature curve acquisition module for acquiring a color temperature curve; An image block color difference calculation module for dividing the original image into multiple image blocks and calculating the color difference value of each image block; A pixel gain calculation module for calculating the final estimated light source color temperature point using the color temperature curve and the color difference value of the image block, and calculating the pixel gain for automatic white balance according to the final estimated light source color temperature point and the color difference value of the image block; A white balance compensation module for compensating the original image using the calculated pixel gain to obtain an image after automatic white balance correction; An image output module for outputting the image after automatic white balance correction.
[0080] In practical applications, the color temperature curve acquisition module can obtain the color temperature curve offline and store the obtained color temperature curve in the memory, so that when the automatic white balance device performs automatic white balance, the pre-stored color temperature curve can be directly called from the memory, thereby improving the processing efficiency of automatic white balance.
[0081] The automatic white balance device based on color temperature estimation provided in this embodiment divides the original image into multiple image blocks through an image block color difference calculation module, and uses a pixel gain calculation module to calculate and estimate the light source color temperature point according to the color difference value of the image block and the color temperature curve, so that the estimated scene light source color temperature is more accurate, thereby making the calculated pixel gain more precise and the effect of automatic white balance correction better. At the same time, the automatic white balance device distinguishes calculations and cooperates with each other through each functional module, making the calculation process of each functional module simple, with less overall resource consumption, high efficiency, and stronger robustness, suitable for various scenarios, and solving the problems of poor white balance processing effect and limited application scenarios in the prior art.
[0082] In addition, this embodiment also provides an electronic device, including a memory, a processor, and an executable program stored on the memory and capable of running by the processor. When the processor runs the executable program, it executes the automatic white balance method based on color temperature estimation as described above.
[0083] In addition, this embodiment also provides a computer storage medium, which stores an executable program. When the executable program is executed, it implements the automatic white balance method based on color temperature estimation as described above.
[0084] It should be noted that the various embodiments in this specification are described in a progressive manner. The key point of each embodiment is the difference from other embodiments. The same or similar parts among the various embodiments can be referred to each other. In addition, the different parts among the various embodiments can also be combined and used with each other, and the present invention does not limit this.
[0085] The automatic white balance method, device, electronic device, and computer storage medium based on color temperature estimation provided in this embodiment include: obtaining a color temperature curve; dividing the original image into blocks to obtain multiple image blocks; calculating the color difference value of each image block; using the color temperature curve and the color difference value of the image block to calculate and obtain the final estimated light source color temperature point; calculating the pixel gain of automatic white balance according to the final estimated light source color temperature point and the color difference value of the image block; and using the calculated pixel gain to compensate the original image to obtain an image after automatic white balance correction. By dividing the original image into multiple image blocks and using the color difference value of the image block and the color temperature curve to calculate and estimate the light source color temperature point, the estimated scene light source color temperature is more accurate, thereby making the calculated pixel gain more precise and the effect of automatic white balance correction better. At the same time, the automatic white balance method has a simple calculation process, less resource consumption, high efficiency, and stronger robustness, is suitable for various scenarios, and solves the problems of poor white balance processing effect and limited application scenarios in the prior art.
[0086] The above description is only a description of the preferred embodiments of the present invention and does not limit the scope of the present invention in any way. Any changes and modifications made by those of ordinary skill in the art of the present invention based on the above disclosure shall fall within the scope of protection of the claims.
Claims
1. An automatic white balance method based on color temperature estimation, characterized in that, Including: Obtain a color temperature curve; Divide the original image into blocks to obtain multiple image blocks; Calculate the color difference value of each image block; Use the color temperature curve and the color difference value of the image block to calculate the final estimated light source color temperature point; According to the final estimated light source color temperature point and the color difference value of the image block, calculate the pixel gain for automatic white balance; Use the calculated pixel gain to compensate the original image to obtain an image after automatic white balance correction.
2. The automatic white balance method based on color temperature estimation according to claim 1, wherein The method for obtaining the color temperature curve includes: Shoot a color checker under different color temperature light sources to obtain color temperature images with different color temperatures; Calculate the R / G color difference value and the B / G color difference value of each color temperature image; Use the R / G color difference value and the B / G color difference value of each color temperature image as the horizontal and vertical coordinates of the curve for curve fitting to obtain the color temperature curve.
3. The automatic white balance method based on color temperature estimation according to claim 2, wherein The method for calculating the R / G color difference value and the B / G color difference value of each color temperature image includes: Perform shadow correction on the color temperature image; Obtain the average values of the R channel, B channel, and G channel within a preset area of the corrected color temperature image; Use the average value of the R channel, the average value of the B channel, and the average value of the G channel of each color temperature image to calculate the R / G color difference value and the B / G color difference value of this color temperature image.
4. The automatic white balance method based on color temperature estimation according to claim 1, wherein The method for calculating the color difference value of each image block includes: Calculate the average values of the R channel, B channel, and G channel in each image block; Use the average value of the R channel, the average value of the B channel, and the average value of the G channel of each image block to calculate the R / G color difference value and the B / G color difference value of this image block; Set a brightness threshold; According to the brightness threshold, screen out the image blocks that meet the requirements and obtain the proportion of valid image blocks.
5. The automatic white balance method based on color temperature estimation according to claim 1, characterized in that The method for using the color temperature curve and the color difference value of each image block to calculate the final estimated light source color temperature point includes: Traverse the color temperature curve at the first step length, and use the color difference value of each image block to calculate the initial estimated light source color temperature point; Within the preset range of the initial estimated light source color temperature point, traverse the color temperature curve at the second step length, and use the color difference value of each image block to calculate the final estimated light source color temperature point; Wherein, the second step length is less than the first step length.
6. The automatic white balance method based on color temperature estimation according to claim 5, characterized in that, The method for traversing the color temperature curve at the first step length and using the color difference value of each image block to calculate the initial estimated light source color temperature point includes: Obtain a list of prior scores of light sources at different brightness levels; Traverse the color temperature curve at the first step length, and at each color temperature point, calculate the sum of the distances between the color difference value of each image block and the color difference value of this color temperature point to obtain a first distance value; Obtain the prior score corresponding to each color temperature point from the list of prior scores of light sources; Subtract the prior score corresponding to the color temperature point from the first distance value to obtain a second distance value; Use the color temperature point corresponding to the smallest second distance value as the initial estimated light source color temperature point.
7. The automatic white balance method based on color temperature estimation according to claim 6, wherein The method for traversing the color temperature curve at the second step length within the preset range of the initial estimated light source color temperature point and using the color difference value of each image block to calculate the final estimated light source color temperature point includes: Within the preset range of the initial estimated light source color temperature point, traverse the color temperature curve at the second step length, and at each color temperature point, calculate the sum of the distances between the color difference value of each image block and the color difference value of this color temperature point to obtain a third distance value; Obtain the prior score corresponding to each color temperature point from the list of prior scores of the light source; Subtract the prior score corresponding to its corresponding color temperature point from the third distance value to obtain a fourth distance value; Take the color temperature point corresponding to the smallest fourth distance value as the finally estimated light source color temperature point.
8. The automatic white balance method based on color temperature estimation according to claim 6, characterized in that, The method for calculating the pixel gain of automatic white balance according to the finally estimated light source color temperature point and the color difference value of the image block includes: Take the image blocks whose distance from the color difference value of the finally estimated light source color temperature point is within a preset distance as reference image blocks; Calculate the difference between the distance between the color difference value of each reference image block and the color difference value of the finally estimated light source color temperature point and the prior score to obtain a reference distance value; If the reference distance value is less than the preset distance threshold, then take this reference image block as a valid reference image block; If the number of valid reference image blocks is less than the preset number threshold, then calculate the pixel gain of automatic white balance using the color difference value of the finally estimated light source color temperature point; If the number of valid reference image blocks is greater than or equal to the preset number threshold, then calculate the pixel gain of automatic white balance using the sum of the R channels, the sum of the B channels, and the sum of the G channels of all valid reference image blocks.
9. An automatic white balance device based on color temperature estimation is used to implement the automatic white balance method based on color temperature estimation according to any one of claims 1 to 8, and is characterized in that, The automatic white balance device based on color temperature estimation includes: An image acquisition module for acquiring an original image; A color temperature curve acquisition module for acquiring a color temperature curve; An image block color difference calculation module for dividing the original image into multiple image blocks and calculating the color difference value of each image block; A pixel gain calculation module for using the color temperature curve and the color difference value of each image block to calculate the finally estimated light source color temperature point, and calculating the pixel gain of automatic white balance according to the finally estimated light source color temperature point and the color difference value of the image block; A white balance compensation module for compensating the original image using the calculated pixel gain to obtain an image after automatic white balance correction; An image output module for outputting the image after automatic white balance correction.
10. An electronic device, characterized in that, It includes a memory, a processor, and an executable program stored on the memory and capable of being run by the processor; when the processor runs the executable program, it executes the automatic white balance method based on color temperature estimation according to any one of claims 1 to 8.
11. A computer storage medium, characterized in that, The computer storage medium stores an executable program; when the executable program is executed, it implements the automatic white balance method based on color temperature estimation according to any one of claims 1 to 8.