White balance method, apparatus, and computer-readable storage medium

CN122845779APending Publication Date: 2026-09-29SHENZHEN MICROBT ELECTRONICS TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510362171.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-25
Publication Date
2026-09-29

AI Technical Summary

Benefits of technology

[0045]上述实施例中,对于任一场景的场景图像,先将该图像划分为多个块,然后对于每一块,根据该块对应的二维点在二维RG-BG坐标系的邻域内分布的块的二维点的密集程度,确定该块的白平衡后验权重,从而:根据对白平衡的贡献大小为块赋予对应的白平衡后验权重;然后,根据该场景图像的每一块的rg、bg、白平衡先验权重、以及白平衡后验权重,计算该场景图像的R、G通道均值比和B、G通道均值比,从而通过:根据对白平衡贡献的大小为块赋予对应的白平衡后验权重,提高了复杂场景下,尤其是同时存在高色温和低色温场景下的白平衡处理的准确度,同时无需复杂的计算,也无需任何训练数据,降低了白平衡处理的复杂度,也提高了白平衡处理速度。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122845779A_ABST
    Figure CN122845779A_ABST
Patent Text Reader

Abstract

This invention proposes a white balance method, apparatus, and computer-readable storage medium. The method includes: dividing a scene image into multiple blocks, where the scene image is an RGB image or a RAW image; determining the posterior white balance weight of each block based on the density of the two-dimensional points of the block distributed in the neighborhood of the block's rg and bg coordinates; calculating the mean ratio of the R and G channels and the mean ratio of the B and G channels of the scene image based on the rg, bg, prior white balance weight, and posterior white balance weight of each block; and performing white balance processing on the scene image based on the mean ratio of the R and G channels and the mean ratio of the B and G channels. This invention improves the accuracy and speed of white balance processing in complex scenes.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer information processing technology, and more particularly to white balance methods, apparatus and computer-readable storage media. Background Technology

[0002] Automatic white balance is a crucial concept in image processing, computer vision, and digital imaging. It's primarily used to adjust the colors in an image, making photos taken under different lighting conditions appear more natural and closer to what the human eye sees. White balance refers to adjusting the colors of an image under different light sources so that white objects appear white in the image. It's somewhat similar to adjusting white balance in camera settings, but automatic white balance is done automatically by an algorithm, eliminating the need for manual adjustment.

[0003] There are many methods for automatic white balance, such as those based on the gray-world hypothesis, white region detection, color constancy, statistical learning, and deep learning. Each method has its advantages, disadvantages, and applicable scenarios.

[0004] The basic idea behind methods based on the gray-world assumption is that in a natural scene, the average color of all colors is close to gray; that is, regardless of changes in the light source, the average color of the scene should be close to neutral gray. Therefore, the algorithm can first calculate the average color of the image and then adjust the white balance gain to make the average color neutral gray. This method is simple to implement, but it is sensitive to image content. If there are large areas of red, green, or blue objects in the image, it may lead to incorrect adjustments.

[0005] The basic idea behind white region detection methods is to assume the presence of white or near-white objects in an image and determine the white balance gain by detecting these regions. This typically involves converting from RGB to HSV or YUV color spaces and then searching for regions with high brightness and low saturation (these regions are most likely to be white). The advantage of this method is its low computational complexity, but the disadvantage is that if there are no white regions in the image or if the white regions are overexposed or covered by shadows, the accuracy of the results will be affected.

[0006] The basic idea behind color constancy-based methods is that color constancy refers to the human visual system's ability to correctly identify the colors of objects under different lighting conditions. This approach attempts to mimic the human brain's processing method by analyzing the color distribution in an image to identify patterns in color changes under different lighting conditions, thereby adjusting the white balance gain. This may involve statistical analysis of color histograms and then adjusting the gain based on the histogram distribution. This method may be more effective when processing images under complex lighting conditions, but it can be more complex to implement.

[0007] Statistical learning-based methods typically utilize large amounts of data to train white balance models. For example, regression models or support vector machines are used to predict the appropriate white balance gain. The advantage of this approach is its ability to adapt to a wider range of lighting conditions, but it requires sufficient training data and can potentially be time-consuming.

[0008] In recent years, deep learning has made significant progress in image processing, and automatic white balance is no exception. Deep learning methods typically use CNNs (Convolutional Neural Networks) to analyze images and learn how to adjust white balance under different lighting conditions. The advantage of this approach is its ability to handle complex lighting variations, even under highly uneven lighting conditions. However, this method requires substantial training data and computational resources, and the model's interpretability may be low, which can be a problem in some applications.

[0009] In practical applications, the performance of automatic white balance methods is affected by a variety of factors. For example, the complexity of lighting conditions, including the type, intensity, and direction of the light source, will affect the effectiveness of automatic white balance. Furthermore, the image content itself is also important; if the image lacks neutral tones or white areas, the automatic white balance algorithm may fail to adjust the colors correctly. Computational efficiency is also a key factor, especially in real-time applications where the algorithm needs to complete processing within a reasonable timeframe. Summary of the Invention

[0010] This invention proposes a white balance method and apparatus to improve the accuracy and speed of white balance processing in complex scenes; this invention also proposes a non-transient computer-readable storage medium and electronic device to improve the accuracy and speed of white balance processing in complex scenes.

[0011] The technical solution of this invention is implemented as follows:

[0012] A white balance method, the method comprising:

[0013] Acquire a scene image of any scene and divide the scene image into multiple blocks. The scene image is an RGB image or a RAW image.

[0014] For each block of the scene image, calculate the R-G channel mean ratio of the block: rg, and the B-G channel mean ratio of the block: bg;

[0015] Mark the two-dimensional points corresponding to rg and bg of each block of the scene image on the two-dimensional RG-BG coordinate system;

[0016] For each block of the scene image, the white balance posterior weight of the block is determined based on the density of the two-dimensional points of the block distributed in the neighborhood of the corresponding two-dimensional point in the two-dimensional RG-BG coordinate system.

[0017] Based on the rg, bg, white balance prior weight, and white balance posterior weight of each block of the scene image, calculate the mean ratio of the R and G channels and the mean ratio of the B and G channels of the scene image.

[0018] Based on the average ratio of the R and G channels and the average ratio of the B and G channels of the scene image, white balance processing is performed on the scene image.

[0019] The white balance prior weights for each patch of the scene image are obtained in the following way:

[0020] The positions of each standard light source are pre-marked in the two-dimensional RG-BG coordinate system. Then, the two-dimensional RG-BG coordinate system is divided into multiple regions according to the distance from each standard light source from near to far. A white balance prior weight is set for each region, and the region closer to each standard light source has a larger white balance prior weight.

[0021] For each block of the scene image, first determine the region of the block's rg and bg in the two-dimensional RG-BG coordinate system based on the block's rg and bg, and then use the white balance prior weight of the region as the white balance prior weight of the block.

[0022] The determination of the white balance posterior weights for this block includes:

[0023] The two-dimensional RG-BG coordinate system is pre-divided into grids according to a preset single grid size;

[0024] Furthermore, for each block of the scene image, the grid where the corresponding two-dimensional point of the block is located is determined, the number of blocks corresponding to the two-dimensional point of the block of the scene image falling into the grid is counted, and the number of blocks is used as the white balance posterior weight of the block.

[0025] The step of calculating the R / G channel mean ratio of the scene image based on the rg, bg, white balance prior weight, and white balance posterior weight of each block of the scene image includes:

[0026] For each block of the scene image, calculate the first product of the block's rg, the block's white balance prior weight, and the block's white balance posterior weight, and calculate the second product of the block's white balance prior weight and the block's white balance posterior weight; sum the first products of all blocks in the scene image to obtain the first sum; sum the second products of all blocks in the scene image to obtain the second sum; use the ratio of the first sum to the second sum as the R and G channel mean ratio of the scene image.

[0027] The step of calculating the B and G channel mean ratio of the scene image based on the rg, bg, white balance prior weight, and white balance posterior weight of each block of the scene image includes:

[0028] For each block of the scene image, calculate the third product of the block's bg, the block's white balance prior weight, and the block's white balance posterior weight, and calculate the second product of the block's white balance prior weight and the block's white balance posterior weight; sum the third products of all blocks in the scene image to obtain the third sum; sum the second products of all blocks in the scene image to obtain the second sum; use the ratio of the third sum to the second sum as the B and G channel mean ratio of the scene image.

[0029] After calculating the mean ratio of the B and G channels of the block (bg), and before marking the two-dimensional points corresponding to rg and bg of each block of the scene image on the two-dimensional RG-BG coordinate system, the method further includes:

[0030] For each block of the scene image, the (rg, bg) range to which the rg and bg of the block belong is queried in the misleading color recognition table. If found, it is determined whether the current scene sensitivity and / or the brightness of the block fall within the scene sensitivity range and / or the area brightness range corresponding to the (rg, bg) range to which the block belongs in the misleading color recognition table. If so, the block is determined to be a misleading color block and does not participate in the subsequent process; otherwise, it is confirmed that the block does not belong to the misleading color block, and the action of marking the two-dimensional points corresponding to the rg and bg of each block of the scene image on the two-dimensional RG-BG coordinate system is performed.

[0031] After calculating the R / G channel mean ratio and the B / G channel mean ratio of the scene image, the method further includes:

[0032] The two-dimensional points corresponding to the rg and bg of the known standard light sources are marked on the two-dimensional RG-BG coordinate system; the Planck trajectory is fitted according to the two-dimensional points corresponding to the multiple standard light sources; multiple points are uniformly selected on the Planck trajectory, and the color temperature of each selected point is obtained by fitting according to the color temperature of each standard light source; the selected multiple points and each standard light source are combined to form a reference light source set.

[0033] Calculate the distances between the two-dimensional points corresponding to the mean ratios of the R and G channels and the mean ratios of the B and G channels of the scene image, and the two-dimensional points corresponding to the rg and bg of each reference light source in the reference light source set. Select the two reference light sources with the smallest distances and denote them as the first reference light source and the second reference light source, respectively.

[0034] Connect the two two-dimensional points corresponding to the first and second reference light sources with a straight line. Draw a perpendicular line from the two-dimensional point corresponding to the scene image to the straight line. Calculate the first distance and the second distance between the foot of the perpendicular and the two two-dimensional points corresponding to the first and second reference light sources, respectively. Normalize the first distance and the second distance to obtain the first weight and the second weight.

[0035] Multiply the color temperature of the first reference light source by the second weight to obtain the first product; multiply the color temperature of the second reference light source by the first weight to obtain the second product; and use the sum of the first product and the second product as the color temperature of the light source used in the scene image.

[0036] The step of performing white balance processing on the scene image based on the mean ratio of the R and G channels and the mean ratio of the B and G channels includes:

[0037] Calculate the R-channel gain and B-channel gain of the scene image based on the R-channel mean ratio and B-channel mean ratio of the scene image; adjust the R-channel value of all pixels in the scene image based on the R-channel gain, and adjust the B-channel value of all pixels in the scene image based on the B-channel gain.

[0038] After marking the two-dimensional points corresponding to the rg and bg of each block of the scene image on the two-dimensional RG-BG coordinate system, and before determining the white balance posterior weight of each block of the scene image based on the density of the two-dimensional points of the block distributed in the neighborhood of the two-dimensional RG-BG coordinate system, the method further includes:

[0039] Determine if the following condition is met: the proportion of blocks with a white balance prior weight greater than 0 in all blocks of the scene image is greater than a preset threshold. If so, then perform the action of determining the white balance posterior weight of each block of the scene image based on the density of the two-dimensional points of the blocks distributed in the neighborhood of the two-dimensional RG-BG coordinate system corresponding to the block. Otherwise, directly use the mean of rg of all blocks of the scene image as the mean ratio of R and G channels of the scene image, and directly use the mean of bg of all blocks of the scene image as the mean ratio of B and G channels of the scene image.

[0040] A white balance device, the device comprising:

[0041] The block partitioning and calculation module acquires a scene image of any scene and divides the scene image into multiple blocks, wherein the scene image is an RGB image or a RAW image; for each block of the scene image, the average ratio of the R and G channels of the block: rg, and the average ratio of the B and G channels of the block: bg are calculated.

[0042] The posterior weight determination module marks the two-dimensional points corresponding to rg and bg of each block of the scene image on the two-dimensional RG-BG coordinate system; for each block of the scene image, the white balance posterior weight of the block is determined based on the density of the two-dimensional points of the block distributed in the neighborhood of the two-dimensional RG-BG coordinate system corresponding to the two-dimensional points of the block.

[0043] The white balance processing module calculates the ratio of the mean values ​​of the R and G channels and the ratio of the mean values ​​of the B and G channels of the scene image based on the rg, bg, white balance prior weights, and white balance posterior weights of each block of the scene image; and performs white balance processing on the scene image based on the ratio of the mean values ​​of the R and G channels and the ratio of the mean values ​​of the B and G channels.

[0044] A non-transitory computer-readable storage medium storing instructions that, when executed by a processor, cause the processor to perform any of the white balance methods described above.

[0045] In the above embodiments, for any scene image, the image is first divided into multiple blocks. Then, for each block, the white balance posterior weight of the block is determined based on the density of the two-dimensional points of the block distributed in the neighborhood of the two-dimensional RG-BG coordinate system. Thus, the block is assigned a corresponding white balance posterior weight according to its contribution to white balance. Then, based on the rg, bg, white balance prior weight, and white balance posterior weight of each block of the scene image, the mean ratio of the R and G channels and the mean ratio of the B and G channels of the scene image are calculated. Thus, by assigning a corresponding white balance posterior weight to the block according to its contribution to white balance, the accuracy of white balance processing in complex scenes, especially in scenes with both high and low color temperatures, is improved. At the same time, no complex calculations or training data are required, reducing the complexity of white balance processing and improving the speed of white balance processing. Attached Figure Description

[0046] To more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings used in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0047] Figure 1 This is a flowchart of a white balance method provided in an embodiment of the present invention;

[0048] Figure 2 This is a schematic diagram of the distribution of the rg and bg of each block of the RGB image in a two-dimensional RG-BG coordinate system in a scene of an application example of the present invention.

[0049] Figure 3 for Figure 2 A schematic diagram of the number of blocks corresponding to the two-dimensional points of the blocks falling into each grid in the middle 22 (this number is the white balance posterior weight of the falling blocks);

[0050] Figure 4 A schematic diagram showing how the two-dimensional RG-BG coordinate system is divided into multiple regions according to the distance from each standard light source from near to far.

[0051] Figure 5 To be Figure 2 The two-dimensional points corresponding to (rg, bg) of each block in the 22 are placed into Figure 4 The diagram in the image;

[0052] Figure 6 Example image showing a misleading color range (rg, bg);

[0053] Figure 7 This is a schematic diagram of the rg, bg, and brightness of each block in an RGB image of a certain scene.

[0054] Figure 8 A schematic diagram for fitting Planck trajectories based on rg and bg values ​​of seven standard light sources and determining the set of reference light sources;

[0055] Figure 9 According to Figure 8 A schematic diagram illustrating the color temperature of the light source used in calculating the Planck trajectory of an RGB image;

[0056] Figure 10 The original RGB image and the image after white balance processing of the original RGB image using the embodiments of the present invention are given as an application example of the present invention.

[0057] Figure 11 The original RGB image and the image after white balance processing of the original RGB image using the embodiments of the present invention are given as another application example of the present invention;

[0058] Figure 12 This is a schematic diagram of the structure of a white balance device provided in an embodiment of the present invention. Detailed Implementation

[0059] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0060] The terms “first,” “second,” “third,” “fourth,” etc. (if present) in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a particular order or sequence. It should be understood that such data can be interchanged where appropriate so that embodiments of the invention described herein can be implemented, for example, in orders other than those illustrated or described herein. Furthermore, the terms “comprising” and “having,” and any variations thereof, are intended to cover a non-exclusive inclusion. For example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0061] Figure 1 This is a flowchart of a white balance method provided in an embodiment of the present invention. Figure 1 As shown, the specific steps are as follows:

[0062] Step 101: Obtain a scene image of any scene and divide the scene image into multiple blocks, wherein the scene image is an RGB image or a RAW image.

[0063] For example: The size of the scene image is A*B, where A is the width of the scene image and B is the height of the scene image; if the size of each block is a*b, where a is the width of the block and b is the height of the block, then the scene image is divided into multiple a*b blocks.

[0064] Step 102: For each block of the scene image, calculate the average ratio of the R and G channels of the block: rg, and the average ratio of the B and G channels of the block: bg.

[0065] For example, if the size of a block in a scene image is a*b, then for each block, calculate the mean values ​​of the R, G, and B channels of the a*b pixels in that block. Then, the rg of that block = the mean value of the R channel of that block * M / the mean value of the G channel of that block, and the bg of that block = the mean value of the B channel of that block * M / the mean value of the G channel of that block. Here, M is a relatively large positive integer. The reason for adding the coefficient M to the numerator is to ensure that the rg and bg of that block are ultimately integers. The value of M can be determined based on experience, for example, M = 1024.

[0066] Step 103: Mark the two-dimensional points corresponding to rg and bg of each block of the scene image on the two-dimensional RG-BG coordinate system.

[0067] Figure 2This is a schematic diagram illustrating the distribution of an RGB image of a scene and the rg and bg values ​​of each block in the RGB image in a two-dimensional RG-BG coordinate system, as shown in an application example of the present invention. 21 represents the RGB image of the scene, and 22 represents the distribution of two-dimensional points corresponding to the rg and bg values ​​of each block in the RGB image in the two-dimensional RG-BG coordinate system. The horizontal coordinate of 22 is rg, and the vertical coordinate is bg; the horizontal coordinate ranges from 300 to 1200, and the vertical coordinate ranges from 150 to 700; each hollow black-bordered cross in 22 (e.g., 221) represents the (rg, bg) value of a block. Figure 2 The seven solid red crosses represent the (rg, bg) positions of the standard light sources D75, D65, D50, CWF, TL84, A, and H, respectively.

[0068] Step 104: For each block of the scene image, determine the white balance posterior weight of the block based on the density of the two-dimensional points of the block distributed in the neighborhood of the corresponding two-dimensional point in the two-dimensional RG-BG coordinate system.

[0069] The denser the two-dimensional points of the block are distributed in the neighborhood of the two-dimensional RG-BG coordinate system, the greater the posterior weight of the white balance of the block.

[0070] In one optional embodiment, step 104 specifically includes: pre-dividing the two-dimensional RG-BG coordinate system into a grid according to a preset single grid size; and for each block of the scene image, determining the grid where the corresponding two-dimensional point of the block is located, counting the number of blocks corresponding to the two-dimensional point of the block of the scene image falling within the grid, and using the number of blocks as the white balance posterior weight of the block. The specific size of the single grid can be determined empirically while considering both computational accuracy and computational speed.

[0071] by Figure 2 Taking 22 as an example, the two-dimensional RG-BG coordinate system is divided into 27*15 grids according to the preset single grid size. Then, taking any block x of 21 as an example, let (rg, bg) of this block fall into the m-th grid of the two-dimensional RG-BG coordinate system, and let p blocks of the RGB image fall into (rg, bg) within this grid. Then the white balance posterior weight of these p blocks (including block x) is p.

[0072] Figure 3 for Figure 2 A schematic diagram of the number of blocks corresponding to the two-dimensional points of the blocks falling into each grid in the diagram (this number is the white balance posterior weight of the falling blocks). The horizontal plane corresponds to the two-dimensional RG-BG coordinate system, and the vertical coordinate is the number of blocks corresponding to the two-dimensional points of the blocks falling into the grid (this number is the white balance posterior weight of the falling blocks).

[0073] Step 105: Calculate the mean ratio of the R and G channels and the mean ratio of the B and G channels of the scene image based on the rg, bg, white balance prior weight, and white balance posterior weight of each block of the scene image.

[0074] In one optional embodiment, the white balance prior weights for each patch of the scene image are obtained through the following steps 01-02:

[0075] Step 01: Pre-mark the location of each standard light source in the two-dimensional RG-BG coordinate system. Then, divide the two-dimensional RG-BG coordinate system into multiple regions according to the distance from each standard light source from near to far. Set a white balance prior weight for each region. The closer the region is to each standard light source, the greater its white balance prior weight.

[0076] Step 02: For each block of the scene image, first determine the region of the block's rg and bg in the two-dimensional RG-BG coordinate system based on the block's rg and bg, and then use the white balance prior weight of the region as the white balance prior weight of the block.

[0077] Figure 4 This diagram illustrates how the two-dimensional RG-BG coordinate system is divided into multiple regions according to their distance from standard light sources, from closest to farthest. (See diagram for example.) Figure 4 As shown, the yellow area in the middle represents the region closest to each standard light source, and its white balance prior weight is the largest. For example, the white balance prior weight of the yellow area can be represented as the maximum value of 255 (as shown in Figure 401, which is a yellow block, the white balance prior weight of block 401 is 255). The white balance prior weight of the brown area can be 127 (as shown in Figure 402, which is a brown block, the white balance prior weight of block 402 is 127). The white balance prior weight of the cyan area can be 63 (as shown in Figure 403, which is a cyan block, the white balance prior weight of block 403 is 63). The white balance prior weight of the sky blue area can be 31 (as shown in Figure 404, which is a sky blue block, the white balance prior weight of block 404 is 31). The white balance prior weight of the dark blue area is 0 (as shown in Figure 405, which is a dark blue block, the white balance prior weight of block 405 is 0). It should be noted that the criteria for dividing the areas and the values ​​of the white balance prior weights for each area can be set based on experience, etc.

[0078] Figure 5 To be Figure 2 The two-dimensional points corresponding to (rg, bg) of each block in the 22 are placed into Figure 4 The diagram is shown in the image.

[0079] In one optional embodiment, step 105 may specifically include the following steps 1051-1052:

[0080] Step 1051: For each block of the scene image, calculate the first product of the block's rg, the block's white balance prior weight, and the block's white balance posterior weight, and calculate the second product of the block's white balance prior weight and the block's white balance posterior weight; sum the first products of all blocks in the scene image to obtain the first sum; sum the second products of all blocks in the scene image to obtain the second sum; use the ratio of the first sum to the second sum as the R and G channel mean ratio of the scene image.

[0081] Step 1052: For each block of the scene image, calculate the third product of the block's bg, the block's white balance prior weight, and the block's white balance posterior weight; sum the third products of all blocks of the scene image to obtain the third sum; use the ratio of the third sum to the second sum as the B and G channel mean ratio of the scene image.

[0082] Specifically,

[0083] Among them, rg image Rg is the ratio of the average R and G channels of the scene image, N is the number of blocks in the scene image, and rg is the average value of the scene image. i wt represents the ratio of the average R and G channels of the i-th block. i c is the white balance prior weight for the i-th block. i Let bg be the white balance posterior weight of the i-th block. image The ratio of the mean values ​​of the B and G channels in the image of this scene, bg i Let be the ratio of the average values ​​of the B and G channels in the i-th block.

[0084] Step 106: Perform white balance processing on the scene image based on the average ratio of the R and G channels and the average ratio of the B and G channels.

[0085] In one optional embodiment, step 106 may specifically include: calculating the R channel gain and B channel gain of the scene image based on the R-G channel mean ratio and the B-G channel mean ratio of the scene image; adjusting the R channel value of all pixels in the scene image based on the R channel gain; and adjusting the B channel value of all pixels in the scene image based on the B channel gain.

[0086] Specifically,

[0087] Where Rgain is the R channel gain of the scene image, rg image Bg is the ratio of the mean values ​​of the R and G channels of the scene image, Bgain is the gain of the B channel of the scene image, and bg is the mean value of the B channel of the scene image. imageis the mean ratio of B channel to G channel of the scene image, q is a preset positive integer, 1<<q represents shifting 1 to the left by q bits in a binary manner, and 1<<q is used to convert 1 / rg and 1 / bg into integers.

[0088] In practical applications, if the scene image is a certain frame in a video stream, after calculating Rgain and Bgain of the current frame, a weighted sum of Rgain of the previous frame and Rgain of the current frame can be performed, and Rgain of the current frame is updated with the weighted sum. Meanwhile, a weighted sum of Bgain of the previous frame and Bgain of the current frame is performed, and Bgain of the current frame is updated with the weighted sum. Wherein, when performing the weighted sum calculation, smaller weights can be assigned to Rgain and Bgain of the previous frame, and larger weights can be assigned to Rgain and Bgain of the current frame. Specific values of the weights can be set based on experience and the like, which are not specifically limited in the present invention.

[0089] In the foregoing embodiment, for a scene image of any scene, the image is first divided into a plurality of blocks, then for each block, a white balance posterior weight of the block is determined according to the density of two-dimensional points of blocks distributed in a neighborhood of the two-dimensional point corresponding to the block in a two-dimensional RG-BG coordinate system, thereby: assigning a corresponding white balance posterior weight to the block according to the magnitude of its contribution to white balance; then, the mean ratio of R channel to G channel and the mean ratio of B channel to G channel of the scene image are calculated according to rg, bg, the white balance prior weight, and the white balance posterior weight of each block of the scene image, thereby, by assigning a corresponding white balance posterior weight to the block according to the magnitude of its contribution to white balance, the accuracy of white balance processing in complex scenes, especially in scenes where high color temperature and low color temperature coexist, is improved. Meanwhile, no complex calculation and no training data are required, which reduces the complexity of white balance processing and also improves the speed of white balance processing.

[0090] The white balance method provided by the embodiment of the present invention is based on the gray world assumption. Under this basis, objects closer to gray in a scene make greater contributions to white balance, and objects farther from gray make smaller contributions. However, after analyzing different scenes, the inventor found that in some scenes, for an object whose color is far from gray, rg and bg thereof still fall within the (rg, bg) range of gray objects, so that the white balance prior weight thereof is also large, which will affect the final white balance processing effect. For example: the road surface at night outdoors is a gray object, which makes a large contribution to white balance, while green plants in daytime outdoors are green objects, which make a small contribution to white balance, but rg and bg of the two are very close. The green in this scene is called a misleading color. That is, a misleading color refers to a color that is not neutral gray but whose rg and bg fall within the (rg, bg) range of neutral gray in some scenes. To further improve the accuracy of white balance processing, the present invention provides the following optimization solution:

[0091] Pre-calculate misleading colors for each scene. Specifically, calculate the (rg, bg) range, scene ISO (sensitivity) range, and / or area brightness range for each misleading color. Add the (rg, bg) range and scene ISO range, and / or area brightness range for each misleading color to a misleading color recognition table. The (rg, bg) range corresponds to the (rg, bg) range of neutral gray, and the scene ISO range and / or area brightness range are used to define the scene and / or area where the misleading color is located. Furthermore, after step 102... Before step 103, the process further includes: for each block of the scene image, querying the (rg, bg) range to which the block's rg and bg belong in the misleading color recognition table. If found, determining whether the current scene's ISO and / or the block's brightness fall within the scene's ISO range and / or the area's brightness range corresponding to the (rg, bg) range to which the block's rg and bg belong in the misleading color recognition table. If so, the block is determined to be a misleading color block and will not participate in subsequent processes; otherwise, the block is confirmed not to be a misleading color block, and step 103 continues. The (rg, bg) range corresponding to the misleading color is the set of all value pairs of the misleading color: rg and bg. From another perspective, each value pair of the misleading color: rg and bg actually corresponds to a one- or two-dimensional point (rg, bg) in the RG-BG coordinate system. Therefore, the set of all two-dimensional points (rg, bg) corresponding to all rg and bg value pairs of the misleading color constitutes the (rg, bg) range corresponding to the misleading color.

[0092] In practical applications, the (rg, bg) range of the misleading color, as well as the scene ISO range and area brightness range, can be obtained empirically. The (rg, bg) range of the misleading color can be a single region in the RG-BG coordinate system, or it can consist of multiple independent regions. For example, the (rg, bg) range of a misleading color is... Figure 6 Within the (rg, bg) range defined by the two red boxes 61 and 62, the scene ISO range is greater than 1600, and the area brightness range is greater than 180. It can be seen that: Figure 6The range (rg, bg) defined by the red box 61 can be expressed as: rg12 ≤ rg ≤ rg11 and bg12 ≤ bg ≤ bg11, where rg11 and rg12 are the maximum and minimum values ​​of rg defined by the red box 61, respectively, and bg11 and bg12 are the maximum and minimum values ​​of bg defined by the red box 61, respectively. Similarly, the range (rg, bg) defined by the red box 62 can be expressed as: rg22 ≤ rg ≤ rg11. Let rg21 and bg22 ≤ bg ≤ bg21, where rg21 and rg22 are the maximum and minimum values ​​of rg defined by the red box 62, and bg21 and bg22 are the maximum and minimum values ​​of bg defined by the red box 62. Then the range of (rg, bg) for the misleading color is: rg12 ≤ rg ≤ rg11 and bg12 ≤ bg ≤ bg11, and rg22 ≤ rg ≤ rg21 and bg22 ≤ bg ≤ bg21.

[0093] Figure 7 This is a schematic diagram of the rg, bg, and brightness of each block in an RGB image of a certain scene. 71 represents the rg of each block in the RGB image of the scene, 72 represents the bg of each block in the RGB image of the scene, and 73 represents the brightness of each block in the RGB image of the scene.

[0094] In an optional embodiment, after step 103 and before step 104, the method further includes: determining whether the following condition is met: the proportion of blocks with a white balance prior weight greater than 0 in all blocks of the scene image is greater than a preset threshold. If so, step 104 is executed; otherwise, the average value of the rg of all blocks of the scene image is directly used as the average ratio of the R and G channels of the scene image, and the average value of the bg of all blocks of the scene image is directly used as the average ratio of the B and G channels of the scene image. The specific value of the preset threshold can be set according to experience, for example, the range of the preset threshold is: [5%, 15%].

[0095] In one optional embodiment, after calculating the R / G channel mean ratio and B / G channel mean ratio of the scene image in step 105, the color temperature of the light source used in the scene image can be further calculated, as follows:

[0096] Step 01: Mark the two-dimensional points corresponding to rg and bg of the known multiple standard light sources on the two-dimensional RG-BG coordinate system.

[0097] Step 02: Fit the Planck trajectory based on the two-dimensional points corresponding to the multiple standard light sources. Existing mature algorithms can be used for the fitting.

[0098] Step 03: Select multiple points uniformly on the Planck trajectory, and obtain the color temperature of each selected point by fitting the color temperature of each standard light source. Combine the selected points and each standard light source to form a reference light source set.

[0099] Step 04: Calculate the distances between the two-dimensional points corresponding to the mean ratios of the R and G channels and the mean ratios of the B and G channels of the scene image, and the two-dimensional points corresponding to the rg and bg of each reference light source in the reference light source set. Select the two reference light sources with the smallest distances, and denote them as the first reference light source and the second reference light source.

[0100] Step 05: Connect the two two-dimensional points corresponding to the first and second reference light sources with a straight line. Draw a perpendicular line from the two-dimensional point corresponding to the scene image to the straight line, and calculate the first distance and the second distance from the foot of the perpendicular to the two two-dimensional points corresponding to the first and second reference light sources, respectively.

[0101] Step 06: Normalize the first distance and the second distance to obtain the first weight and the second weight.

[0102] Step 07: Multiply the color temperature of the first reference light source by the second weight to obtain the first product; multiply the color temperature of the second reference light source by the first weight to obtain the second product.

[0103] Step 08: Use the sum of the first and second products as the color temperature of the light source used in the scene image.

[0104] For example: There are 7 standard light sources D75, D65, D50, CWF, TL84, A, and H, and the rg, bg, and color temperature of these 7 standard light sources are known. First, a Planck locus is fitted based on the rg and bg of these 7 standard light sources. Then, multiple points are uniformly selected on this locus, and the color temperature of each selected point is obtained by fitting the color temperature of each standard light source on the Planck locus. The selected points and the standard light sources on the Planck locus form a reference light source set. Figure 8 This diagram illustrates how Planck trajectories are fitted to the rg and bg values ​​of seven standard light sources to determine the reference light source set. Each solid red cross represents a standard light source, 81 represents the fitted Planck trajectory, and each hollow circle on the Planck trajectory represents a uniformly selected point that can be included in the reference light source set. It should be noted that if a standard light source CWF is not fitted to the Planck trajectory, it is not included in the reference light source set.

[0105] Let the mean ratios of the R and G channels and the B and G channels of the RGB image be rg0 and bg0, respectively. Calculate (rg0, bg0) and the ratio of (rg0, bg0) to the mean ratio of each reference light source in the reference light source set. j bg j The distance d between them j Where j = 1 to J, and J is the number of reference light sources in the reference set, such as:

[0106]

[0107] Then, select the two smallest d. j In the two-dimensional RG-BG coordinate system, the two smallest d j (rg) corresponding to standard light sources a and b a bg a (rg) b bg b Connect the points using straight lines; then draw a perpendicular line from (rg0, bg0) to this line, and calculate the distance from the foot of the perpendicular to (rg0, bg0). a bg a (rg) b bg b The distance t) a t b Then for t a t b After normalization, we obtain σ. a σ b ,but:

[0108] The color temperature of this RGB image = color temperature of standard light source a * σ b +Color temperature of standard light source b*σ a

[0109] Figure 9 According to Figure 8 A schematic diagram illustrating the color temperature of the light source used in calculating the Planck locus for RGB images. (See diagram for example.) Figure 9 As shown, wp(rg0, bg0) represents the ratio of the mean values ​​of the R and G channels and the mean value of the B and G channels of the RGB image. It can be seen that wp is closest to the reference light sources 91 and 92. Connect 91 and 92 with a straight line, and then draw a perpendicular line from wp to this line, with the foot of the perpendicular at O. Calculate the distances from O to 91 and 92 respectively, and let them be t. a t b , for t a t b After normalization, we obtain σ. a σ b ,but:

[0110] The color temperature of this RGB image = color temperature of the reference light source 91 * σ b + Color temperature of reference light source 92*σ a

[0111] Figure 10This invention provides an application example of an RGB image and an image after white balance processing of the original RGB image using an embodiment of the invention. The left image is the original RGB image, and the right image is the image after white balance processing of the left image using an embodiment of the invention. It can be seen that the left image contains both high color temperature (e.g., tall buildings and the sky) and low color temperature (e.g., the road surface). After processing the left image using the white balance method provided by this embodiment of the invention, the resulting right image is closer to the real effect seen by the human eye, and the colors are more consistent with the colors seen under natural light.

[0112] Figure 11 This invention provides another application example of the original RGB image and the image after white balance processing of the original RGB image using the embodiments of the present invention. The left image is the original RGB image, and the right image is the image after white balance processing of the left image using the embodiments of the present invention. It can be seen that the left image contains both high color temperature (e.g., tall buildings and the sky) and low color temperature (e.g., the road surface). After processing the left image using the white balance method provided by the embodiments of the present invention, the resulting right image is closer to the real effect seen by the human eye, and the colors are more consistent with the colors naturally perceived by the human eye.

[0113] Figure 12 This is a schematic diagram of the structure of a white balance device provided in an embodiment of the present invention. Figure 12 As shown, the device mainly includes: a block partitioning and calculation module 121, a posterior weight determination module 122, and a white balance processing module 123, wherein:

[0114] The block partitioning and calculation module 121 acquires a scene image of any scene and divides the scene image into multiple blocks, wherein the scene image is an RGB image or a RAW image; for each block of the scene image, it calculates the average ratio of the R and G channels of the block: rg, and the average ratio of the B and G channels of the block: bg.

[0115] The posterior weight determination module 122 marks the two-dimensional points corresponding to rg and bg of each block of the scene image on the two-dimensional RG-BG coordinate system; for each block of the scene image, the white balance posterior weight of the block is determined according to the density of the two-dimensional points of the block distributed in the neighborhood of the two-dimensional RG-BG coordinate system.

[0116] The white balance processing module 123 calculates the mean ratio of the R and G channels and the mean ratio of the B and G channels of the scene image based on the rg, bg, white balance prior weight, and white balance posterior weight of each block of the scene image; and performs white balance processing on the scene image based on the mean ratio of the R and G channels and the mean ratio of the B and G channels.

[0117] In one optional embodiment, in the white balance processing module 123, the white balance prior weight of each block of the scene image is obtained in the following way: the positions of each standard light source are pre-marked in the two-dimensional RG-BG coordinate system, and then the two-dimensional RG-BG coordinate system is divided into multiple regions according to the distance from each standard light source from near to far. A white balance prior weight is set for each region, and the closer the region is to each standard light source, the greater its white balance prior weight; for each block of the scene image, the region of the block's rg and bg in the two-dimensional RG-BG coordinate system is first determined according to the block's rg and bg, and then the white balance prior weight of the region is used as the white balance prior weight of the block.

[0118] In one optional embodiment, the posterior weight determination module 122 determines the white balance posterior weight of the block, including: pre-dividing the two-dimensional RG-BG coordinate system into a grid according to a preset single grid size; and for each block of the scene image, determining the grid where the two-dimensional point corresponding to the block is located, counting the number of blocks corresponding to the two-dimensional point of the block of the scene image that fall into the grid, and using the number of blocks as the white balance posterior weight of the block.

[0119] In one optional embodiment, the white balance processing module 123 calculates the mean ratio of the R and G channels and the mean ratio of the B and G channels of the scene image based on the rg, bg, white balance prior weight, and white balance posterior weight of each block of the scene image. This includes: for each block of the scene image, calculating the first product of the block's rg, the block's white balance prior weight, and the block's white balance posterior weight, and calculating the second product of the block's white balance prior weight and the block's white balance posterior weight; and processing all blocks of the scene image... The first products are added together to obtain the first sum; the second products of all blocks in the scene image are added together to obtain the second sum; the ratio of the first sum to the second sum is used as the R-G channel mean ratio of the scene image; for each block in the scene image, the third product of the block's bg, the block's white balance prior weight, and the block's white balance posterior weight is calculated; the third products of all blocks in the scene image are added together to obtain the third sum; the ratio of the third sum to the second sum is used as the B-G channel mean ratio of the scene image.

[0120] In one optional embodiment, before the posterior weight determination module 122 marks the two-dimensional points corresponding to the rg and bg of each block of the scene image on the two-dimensional RG-BG coordinate system, it further includes: for each block of the scene image, querying the (rg, bg) range to which the rg and bg of the block belong in the misleading color recognition table; if found, determining whether the ISO of the current scene and / or the brightness of the block fall within the scene ISO range and / or the regional brightness range corresponding to the (rg, bg) range to which the rg and bg of the block belong in the misleading color recognition table; if so, determining that the block is a misleading color block and does not participate in the subsequent process; otherwise, confirming that the block does not belong to the misleading color block, and performing the action of marking the two-dimensional points corresponding to the rg and bg of each block of the scene image on the two-dimensional RG-BG coordinate system; wherein, the (rg, bg) range corresponding to each misleading color, as well as the scene ISO range and / or the regional brightness range, are pre-calculated, and the (rg, bg) range corresponding to each misleading color, as well as the scene ISO range and / or the regional brightness range, are placed in the misleading color recognition table.

[0121] In an optional embodiment, the device further includes: a color temperature calculation module, configured to: calibrate two-dimensional points corresponding to the rg and bg of a plurality of known standard light sources on a two-dimensional RG-BG coordinate system; fit a Planck trajectory based on the two-dimensional points corresponding to the plurality of standard light sources; uniformly select a plurality of points on the Planck trajectory, and fit the color temperature of each selected point based on the color temperature of each standard light source, forming a reference light source set by combining the selected points and each standard light source; calculate the distances between the two-dimensional points corresponding to the mean ratio of the R and G channels and the mean ratio of the B and G channels of the scene image and the two-dimensional points corresponding to the rg and bg of each reference light source in the reference light source set, and select... Select two reference light sources with the smallest distance, denoted as the first reference light source and the second reference light source, respectively. Connect the two two-dimensional points corresponding to the first and second reference light sources with a straight line. Draw a perpendicular line from the two-dimensional point corresponding to the scene image to the straight line, and calculate the first distance and the second distance from the foot of the perpendicular to the two two-dimensional points corresponding to the first and second reference light sources, respectively. Normalize the first distance and the second distance to obtain the first weight and the second weight. Multiply the color temperature of the first reference light source by the second weight to obtain the first product. Multiply the color temperature of the second reference light source by the first weight to obtain the second product. Use the sum of the first product and the second product as the color temperature of the light source used in the scene image.

[0122] In one optional embodiment, the white balance processing module 123 performs white balance processing on the scene image based on the average ratio of the R and G channels and the average ratio of the B and G channels, including: calculating the R channel gain and B channel gain of the scene image based on the average ratio of the R and G channels and the average ratio of the B and G channels; adjusting the R channel value of all pixels in the scene image based on the R channel gain; and adjusting the B channel value of all pixels in the scene image based on the B channel gain.

[0123] In one optional embodiment, after the posterior weight determination module 122 marks the two-dimensional points corresponding to the rg and bg of each block of the scene image on the two-dimensional RG-BG coordinate system, and before determining the white balance posterior weight of each block of the scene image based on the density of the two-dimensional points of the blocks distributed in the neighborhood of the two-dimensional RG-BG coordinate system corresponding to the two-dimensional points of the block, the posterior weight determination module 122 further includes: determining whether the following condition is met: the proportion of the number of blocks with a white balance prior weight greater than 0 in all blocks of the scene image is greater than a preset threshold. If so, the action of determining the white balance posterior weight of each block of the scene image based on the density of the two-dimensional points of the blocks distributed in the neighborhood of the two-dimensional RG-BG coordinate system corresponding to the two-dimensional points of the block is performed; otherwise, the mean of the rg of all blocks of the scene image is directly used as the mean ratio of the R and G channels of the scene image, and the mean of the bg of all blocks of the scene image is directly used as the mean ratio of the B and G channels of the scene image.

[0124] This invention also provides a non-transitory computer-readable storage medium that stores instructions that, when executed by a processor, cause the processor to perform the white balance method as described in any of the foregoing embodiments.

[0125] This invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the white balance method as described in any of the foregoing embodiments.

[0126] Those skilled in the art will understand that the features described in the various embodiments and / or claims disclosed herein can be combined and / or combined in various ways, even if such combinations or combinations are not explicitly described in this application. In particular, without departing from the spirit and teachings of this application, the features described in the various embodiments and / or claims of this application can be combined and / or combined in various ways, and all such combinations and / or combinations fall within the scope of this application.

[0127] This document uses specific embodiments to illustrate the principles and implementation methods of the present invention. The descriptions of these embodiments are merely illustrative of the method and core concepts of the present invention and are not intended to limit this application. Those skilled in the art can make changes to the specific implementation methods and application scope based on the ideas, spirit, and principles of the present invention. Any modifications, equivalent substitutions, or improvements made should be included within the scope of protection of this application.

Claims

1. A white balance method, characterized in that, The method includes: Acquire a scene image of any scene and divide the scene image into multiple blocks. The scene image is an RGB image or a RAW image. For each block of the scene image, calculate the R-G channel mean ratio of the block: rg, and the B-G channel mean ratio of the block: bg; Mark the two-dimensional points corresponding to rg and bg of each block of the scene image on the two-dimensional RG-BG coordinate system; For each block of the scene image, the white balance posterior weight of the block is determined based on the density of the two-dimensional points of the block distributed in the neighborhood of the corresponding two-dimensional point in the two-dimensional RG-BG coordinate system. Based on the rg, bg, white balance prior weight, and white balance posterior weight of each block of the scene image, calculate the mean ratio of the R and G channels and the mean ratio of the B and G channels of the scene image. Based on the average ratio of the R and G channels and the average ratio of the B and G channels of the scene image, white balance processing is performed on the scene image.

2. The method according to claim 1, characterized in that, The white balance prior weights for each patch of the scene image are obtained in the following way: The positions of each standard light source are pre-marked in the two-dimensional RG-BG coordinate system. Then, the two-dimensional RG-BG coordinate system is divided into multiple regions according to the distance from each standard light source from near to far. A white balance prior weight is set for each region, and the region closer to each standard light source has a larger white balance prior weight. For each block of the scene image, first determine the region of the block's rg and bg in the two-dimensional RG-BG coordinate system based on the block's rg and bg, and then use the white balance prior weight of the region as the white balance prior weight of the block.

3. The method according to claim 1, characterized in that, The determination of the white balance posterior weights for this block includes: The two-dimensional RG-BG coordinate system is pre-divided into grids according to a preset single grid size; Furthermore, for each block of the scene image, the grid where the corresponding two-dimensional point of the block is located is determined, the number of blocks corresponding to the two-dimensional point of the block of the scene image falling into the grid is counted, and the number of blocks is used as the white balance posterior weight of the block.

4. The method according to any one of claims 1 to 3, characterized in that, The step of calculating the R / G channel mean ratio of the scene image based on the rg, bg, white balance prior weight, and white balance posterior weight of each block of the scene image includes: For each block of the scene image, calculate the first product of the block's rg, the block's white balance prior weight, and the block's white balance posterior weight, and calculate the second product of the block's white balance prior weight and the block's white balance posterior weight; sum the first products of all blocks in the scene image to obtain the first sum; sum the second products of all blocks in the scene image to obtain the second sum; use the ratio of the first sum to the second sum as the R and G channel mean ratio of the scene image.

5. The method according to any one of claims 1 to 3, characterized in that, The step of calculating the B and G channel mean ratio of the scene image based on the rg, bg, white balance prior weight, and white balance posterior weight of each block of the scene image includes: For each block of the scene image, calculate the third product of the block's bg, the block's white balance prior weight, and the block's white balance posterior weight, and calculate the second product of the block's white balance prior weight and the block's white balance posterior weight; sum the third products of all blocks in the scene image to obtain the third sum; sum the second products of all blocks in the scene image to obtain the second sum; use the ratio of the third sum to the second sum as the B and G channel mean ratio of the scene image.

6. The method according to claim 1, characterized in that, After calculating the mean ratio of the B and G channels of the block (bg), and before marking the two-dimensional points corresponding to rg and bg of each block of the scene image on the two-dimensional RG-BG coordinate system, the method further includes: For each block of the scene image, the (rg, bg) range to which the rg and bg of the block belong is queried in the misleading color recognition table. If found, it is determined whether the current scene sensitivity and / or the brightness of the block fall within the scene sensitivity range and / or the area brightness range corresponding to the (rg, bg) range to which the block belongs in the misleading color recognition table. If so, the block is determined to be a misleading color block and does not participate in the subsequent process; otherwise, it is confirmed that the block does not belong to the misleading color block, and the action of marking the two-dimensional points corresponding to the rg and bg of each block of the scene image on the two-dimensional RG-BG coordinate system is performed.

7. The method according to claim 1, characterized in that, After calculating the R / G channel mean ratio and the B / G channel mean ratio of the scene image, the method further includes: The two-dimensional points corresponding to the rg and bg of the known standard light sources are marked on the two-dimensional RG-BG coordinate system; the Planck trajectory is fitted according to the two-dimensional points corresponding to the multiple standard light sources; multiple points are uniformly selected on the Planck trajectory, and the color temperature of each selected point is obtained by fitting according to the color temperature of each standard light source; the selected multiple points and each standard light source are combined to form a reference light source set. Calculate the distances between the two-dimensional points corresponding to the mean ratios of the R and G channels and the mean ratios of the B and G channels of the scene image, and the two-dimensional points corresponding to the rg and bg of each reference light source in the reference light source set. Select the two reference light sources with the smallest distances and denote them as the first reference light source and the second reference light source, respectively. Connect the two two-dimensional points corresponding to the first and second reference light sources with a straight line. Draw a perpendicular line from the two-dimensional point corresponding to the scene image to the straight line. Calculate the first distance and the second distance between the foot of the perpendicular and the two two-dimensional points corresponding to the first and second reference light sources, respectively. Normalize the first distance and the second distance to obtain the first weight and the second weight. Multiply the color temperature of the first reference light source by the second weight to obtain the first product; multiply the color temperature of the second reference light source by the first weight to obtain the second product; and use the sum of the first product and the second product as the color temperature of the light source used in the scene image.

8. The method according to claim 1, characterized in that, The step of performing white balance processing on the scene image based on the mean ratio of the R and G channels and the mean ratio of the B and G channels includes: Calculate the R-channel gain and B-channel gain of the scene image based on the R-channel mean ratio and B-channel mean ratio of the scene image; adjust the R-channel value of all pixels in the scene image based on the R-channel gain, and adjust the B-channel value of all pixels in the scene image based on the B-channel gain.

9. The method according to claim 1, characterized in that, After marking the two-dimensional points corresponding to the rg and bg of each block of the scene image on the two-dimensional RG-BG coordinate system, and before determining the white balance posterior weight of each block of the scene image based on the density of the two-dimensional points of the block distributed in the neighborhood of the two-dimensional RG-BG coordinate system, the method further includes: Determine if the following condition is met: the proportion of blocks with a white balance prior weight greater than 0 in all blocks of the scene image is greater than a preset threshold. If so, then perform the action of determining the white balance posterior weight of each block of the scene image based on the density of the two-dimensional points of the blocks distributed in the neighborhood of the two-dimensional RG-BG coordinate system corresponding to the block. Otherwise, directly use the mean of rg of all blocks of the scene image as the mean ratio of R and G channels of the scene image, and directly use the mean of bg of all blocks of the scene image as the mean ratio of B and G channels of the scene image.

10. A white balance device, characterized in that, The device includes: The block partitioning and calculation module acquires a scene image of any scene and divides the scene image into multiple blocks, wherein the scene image is an RGB image or a RAW image; for each block of the scene image, the average ratio of the R and G channels of the block: rg, and the average ratio of the B and G channels of the block: bg are calculated. The posterior weight determination module marks the two-dimensional points corresponding to rg and bg of each block of the scene image on the two-dimensional RG-BG coordinate system; for each block of the scene image, the white balance posterior weight of the block is determined based on the density of the two-dimensional points of the block distributed in the neighborhood of the two-dimensional RG-BG coordinate system corresponding to the two-dimensional points of the block. The white balance processing module calculates the ratio of the mean values ​​of the R and G channels and the ratio of the mean values ​​of the B and G channels of the scene image based on the rg, bg, white balance prior weights, and white balance posterior weights of each block of the scene image; and performs white balance processing on the scene image based on the ratio of the mean values ​​of the R and G channels and the ratio of the mean values ​​of the B and G channels.

11. A non-transitory computer-readable storage medium, characterized in that, The non-transitory computer-readable storage medium stores instructions, which, when executed by a processor, cause the processor to perform the white balance method as described in any one of claims 1 to 9.