Image processing method, device, storage medium and terminal
Through light source classification model identification and weighted calculation, the accuracy of image white balance processing is improved, solving the problem of inaccurate white balance in the existing technology in large areas of solid color or mixed color scenes, and achieving more accurate image color adjustment.
Patent Information
- Application Number
- CN202210051557.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-17
- Publication Date
- 2024-08-23
- Estimated Expiration
- 2042-01-17
AI Technical Summary
When existing white balance technology handles large-area solid or mixed-color scenes, the white balance results are not accurate enough. In particular, the multispectral sensor solution has poor white balance adjustment effects in these scenes.
By obtaining the color channel data of the target image collected by the camera, input it into the pre-trained light source classification model, identify the matching probability of the light source, and calculate the white balance gain based on these probabilities for image adjustment. This method uses different band spectral channel data from multispectral sensors and combines the light source classification model to identify and weight calculations of different light source types to improve the accuracy of white balance processing.
It improves the accuracy of image white balance processing, especially in complex color scenes, and can adjust image color more accurately, close to the visual effect of the human eye.
Smart Images

Figure CN114500969B
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing technology, and in particular to an image processing method, device, storage medium and terminal. Background Art
[0002] White balance (Auto White Balance, AWB for short) means making the image captured by the sensor close to the real picture seen by the human eye at different color temperatures. In other words, AWB can make the images of white objects taken at different color temperatures also appear white. In daily use, the camera of a mobile phone can be set to automatic white balance, which can meet the user's shooting needs in most cases. Using automatic white balance technology, the camera can automatically estimate the ambient color light and remove the influence of the light source on the image sensor, so that the camera can have the same color constancy as the human visual system. Summary of the invention
[0003] The embodiments of the present application provide an image processing method, device, computer storage medium and terminal, which can improve the accuracy of white balance processing of images. The technical solution is as follows:
[0004] In a first aspect, an embodiment of the present application provides an image processing method, the method comprising:
[0005] Get the color channel data of the target image captured by the camera;
[0006] Inputting the color channel data into a light source classification model to obtain a matching probability that the light source corresponding to the target image belongs to different preset types of light sources;
[0007] A white balance gain corresponding to the target image is determined based on the matching probability, and a white balance adjustment is performed on the target image based on the white balance gain.
[0008] In a second aspect, an embodiment of the present application provides an image processing device, the device comprising:
[0009] A data acquisition module, used to obtain color channel data of a target image acquired by a camera;
[0010] A light source identification module, used to input the color channel data into a light source classification model to obtain a matching probability that the light source corresponding to the target image belongs to different preset types of light sources;
[0011] An image adjustment module is used to determine a white balance gain corresponding to the target image based on the matching probability, and to perform white balance adjustment on the target image based on the white balance gain.
[0012] In a third aspect, an embodiment of the present application provides a computer storage medium, wherein the computer storage medium has a plurality of instructions, and the instructions are suitable for being loaded by a processor and executing the above-mentioned method steps.
[0013] In a fourth aspect, an embodiment of the present application provides a terminal, which may include: a memory and a processor; wherein the memory stores a computer program, and the computer program is suitable for being loaded by the memory and executing the above-mentioned method steps.
[0014] The beneficial effects brought by the technical solution provided by the embodiment of the present application include at least:
[0015] When the scheme of the embodiment of the present application is executed, the color channel data of the target image captured by the camera is obtained, the color channel data is input into the light source classification model, the matching probability that the light source corresponding to the target image belongs to different preset types of light sources is obtained, the white balance gain corresponding to the target image is determined based on the matching probability, and the white balance adjustment of the target image is performed based on the white balance gain. The present application identifies the color channel data of the target image through the light source classification model. The color channel data is actually spectral channel data of different bands. That is, the spectral channel data of different bands collected are identified through the light source classification model, and the matching probability that the light source corresponding to the target image belongs to different preset types of light sources can be accurately obtained. Then, the white balance gain of the target image is obtained based on the matching probability, which can improve the accuracy of white balance processing of the image. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without paying any creative work.
[0017] Figure 1 It is a flowchart of an image processing method provided in an embodiment of the present application;
[0018] Figure 2A is a schematic diagram of an image provided in an embodiment of the present application;
[0019] Figure 2B is a schematic diagram of another image provided in an embodiment of the present application;
[0020] Figure 3 is a flowchart of another image processing method provided in an embodiment of the present application;
[0021] Figure 4is a structural schematic diagram of an image processing device provided in an embodiment of the present application;
[0022] Figure 5 It is a structural diagram of a terminal provided in an embodiment of the present application. DETAILED DESCRIPTION
[0023] In order to make the purpose, features, and advantages of the embodiments of the present application more obvious and understandable, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of this application.
[0024] In the description of the present application, it should be understood that the terms "first", "second", etc. are only used for descriptive purposes and cannot be understood as indicating or implying relative importance. In the description of the present application, it should be noted that, unless otherwise clearly specified and limited, "including" and "having" and any of their variations are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not limited to the listed steps or units, but optionally also includes steps or units that are not listed, or optionally also includes other steps or units inherent to these processes, methods, products or devices. For those of ordinary skill in the art, the specific meanings of the above terms in the present application can be understood in specific circumstances. In addition, in the description of the present application, unless otherwise specified, "multiple" refers to two or more. "And / or" describes the association relationship of associated objects, indicating that there can be three relationships, for example, A and / or B, which can represent: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the associated objects before and after are an "or" relationship.
[0025] In the related art, more and more white balance solutions introduce multispectral sensors, and use the color temperature information collected by the multispectral sensor and the image information collected by the camera to adjust the white balance of the image. However, the white balance results obtained by these solutions are not accurate enough, especially when dealing with large areas of pure color scenes or mixed color scenes, the white balance results obtained are even more inaccurate.
[0026] The present application is described in detail below with reference to specific embodiments.
[0027] In the following method embodiments, for the sake of convenience, only the execution subject of each step is introduced and described as the terminal.
[0028] See also Figure 1, is a flow chart of an image processing method provided in an embodiment of the present application. Figure 1 As shown, the method of the embodiment of the present application may include the following steps:
[0029] S101, obtaining color channel data of a target image captured by a camera.
[0030] It is understandable that the color channel data may be spectral channel data of different bands, each spectral channel corresponds to a band, and different spectral channels correspond to different bands. In the field of multispectral imaging technology, the number of spectral channels is usually as many as dozens or even hundreds, and the bands corresponding to each spectral channel are often continuous.
[0031] According to some embodiments, obtaining the color channel data of the target image captured by the camera may be to obtain the spectral channel data of different bands collected by the multispectral sensor under the light source where the target image is currently located. It is understandable that the multispectral sensor can output spectral channel data of multiple different bands, for example, the number of spectral channels can be 8, 11, 13, etc., and the embodiments of the present application do not limit this. The light source where the target image is currently located may include many types, for example, the type of light source may be the common 40 light sources with a color temperature range of 2000K-9000K, and the embodiments of the present application do not limit the type of light source.
[0032] S102: Input the color channel data into a light source classification model to obtain a matching probability that the light source corresponding to the target image belongs to different preset types of light sources.
[0033] It can be understood that the light source classification model can be pre-trained and can identify the matching probability of color channel data belonging to different preset types of light sources. In the process of training the light source classification model, the training data used can be the color channel data of known light source types. For example, there are 40 preset light source types. For each light source type, the color channel data of multiple images under the light source type can be collected. In other words, each light source type can correspond to multiple color channel data, and each color channel data corresponds to a different image. These images can be divided according to color scenes, that is, each image can correspond to a color scene. The color scene represents the color information contained in the image. When an image contains only one color, the color scene of the image can be described as a monochrome scene; when an image contains multiple colors, the color scene of the image can be described as a mixed color scene. For example, see Figure 2A The image shown in FIG. 1 may be an image formed by a camera taking a picture of a blackboard. Obviously, the image contains only one color, and the color scene of the image may be a monochrome scene. For another example, see Figure 2BThe image shown may be a landscape image taken by a camera. Obviously, the image contains image elements of multiple different colors. The flowers, branches and leaves of the flowers, tree trunks, flowers on the trees, and the sky are all different colors. The color scene of the image can be described as a mixed color scene. Therefore, when training a light source classification model, for the same light source type, the color channel data of different images corresponding to different color scenes can be used to train the light source classification model, so that the light source classification model can accurately identify the matching probability of the target image belonging to different preset types of light sources based on the color channel data.
[0034] In some embodiments, the number of matching probabilities output by the light source classification model may be equal to the number of preset light source types, or may be less than the number of preset light source types. For example, there are 40 preset light source types, and the light source classification model may output 40 matching probabilities, which may be the matching probabilities that the target image belongs to the 40 preset light source types respectively; the light source classification model may also output only 3 matching probabilities, which may be the 3 matching probabilities with the largest median of the matching probabilities that the target image belongs to the 40 preset light source types respectively; for example, the light source classification model may also output only 1 matching probability, which is the probability with the largest median of the matching probabilities of the 40 preset light source types.
[0035] S103: Determine a white balance gain corresponding to the target image based on the matching probability, and perform white balance adjustment on the target image based on the white balance gain.
[0036] It can be understood that the white balance gain includes red gain, green gain and blue gain.
[0037] In some embodiments, the preset types of light sources corresponding to the three matching probabilities with the largest probability values can be determined based on the matching probabilities output by the light source classification model. When the number of matching probabilities output by the light source classification model is equal to the number of types of preset types of light sources, the matching probabilities can be arranged, and then the preset types of light sources corresponding to the three matching probabilities with the largest probability values can be found. In addition, the light source classification model can also directly output the three matching probabilities with the largest probability values, and then the preset types of light sources corresponding to these three matching probabilities can be determined. Further, the white balance gain corresponding to the target image can be calculated using the following formula.
[0038] (1)P1=p1 / (p1+p2+p3); P2=p2 / (p1+p2+p3); P3=p3 / (p1+p2+p3);
[0039] (2) Rgain=rgain_a*P1+rgain_b*P2+rgain_c*P3; Ggain=1; Bgain=bgain_a*P1+bgain_b*P2+bgain_c*P3.
[0040] Assume that the three preset types of light sources are light source a, light source b, and light source c, the matching probability corresponding to light source a is p1, the matching probability corresponding to light source b is p2, and the matching probability corresponding to light source c is p3; rgain represents the red calibration gain of each light source, ggain represents the green calibration gain of each light source, and bgain represents the blue calibration gain of each light source; Rgain represents the red gain in the white balance gain corresponding to the target image, Ggain represents the green gain in the white balance gain corresponding to the target image, and Bgain represents the blue gain in the white balance gain corresponding to the target image.
[0041] It can be understood that the above formula involves the red calibration gain, green calibration gain and blue calibration gain corresponding to each light source. For the calibration gain calculation process, the calibration gain corresponding to each light source can be calculated after the light source type is determined. Specifically, a gray card can be photographed with a camera under each light source, and then the r (R value), g (G value), and b (B value) of the gray in the raw image can be taken, and then rgain = g / r, ggain = 1, and bgain = g / b can be obtained, thereby obtaining the calibration gain corresponding to each light source.
[0042] From the above calculation formula, it can be known that P1 is the probability weight of light source a among the three light sources, P2 is the probability weight of light source b among the three light sources, and P3 is the probability weight of light source c among the three light sources. Then, the red gain in the white balance gain corresponding to the target image can be obtained by weighted summing the red calibration gains of the three light sources according to the probability weights, the blue gain in the white balance gain corresponding to the target image can be obtained by weighted summing the blue calibration gains of the three light sources according to the probability weights, and the green gain in the white balance gain corresponding to the target image can be set to 1. Furthermore, the R value, G value, and B value of the target image in the current environment can be multiplied by the red gain, green gain, and blue gain, respectively, to complete the white balance adjustment of the target image.
[0043] In another embodiment, the light source classification model can output a matching probability, which is the probability with the largest median value of the matching probabilities, and the preset type of light source corresponding to the matching probability can be determined. Further, the red calibration gain, green calibration gain, and blue calibration gain corresponding to the preset type of light source can be obtained. Further, the red calibration gain corresponding to the preset type of light source can be used as the red gain in the white balance gain corresponding to the target image, the green calibration gain corresponding to the preset type of light source can be used as the green gain in the white balance gain corresponding to the target image, and the blue calibration gain corresponding to the preset type of light source can be used as the blue gain in the white balance gain corresponding to the target image. Among them, for the acquisition process of the red calibration gain, green calibration gain, and blue calibration gain corresponding to the preset type of light source, please refer to the description in the above embodiment, which will not be repeated here.
[0044] When the scheme of the embodiment of the present application is executed, the color channel data of the target image captured by the camera is obtained, the color channel data is input into the light source classification model, the matching probability that the light source corresponding to the target image belongs to different preset types of light sources is obtained, the white balance gain corresponding to the target image is determined based on each matching probability, and the white balance adjustment of the target image is performed based on the white balance gain. The present application identifies the color channel data of the target image through the light source classification model. The color channel data is actually spectral channel data of different bands. That is, the spectral channel data of different bands collected is identified through the light source classification model, and the matching probability that the light source corresponding to the target image belongs to different preset types of light sources can be obtained. Then, the white balance gain of the target image is obtained based on the matching probability, which can improve the accuracy of white balance processing of the image.
[0045] See also Figure 3 , is a flow chart of an image processing method provided in an embodiment of the present application. Figure 3 As shown, the method of the embodiment of the present application may include the following steps:
[0046] S301, obtaining sample color channel data of sample images of different scenes captured by a camera under various preset light sources.
[0047] It is understandable that the scene can be a color scene, and the color scene can include a monochrome scene and a mixed color scene, that is, the scene can be a monochrome scene or a mixed color scene. A monochrome scene refers to an image that includes only objects of one color, for example, an image includes only a pure white wall, or an image includes only a pure black desktop. A mixed color scene refers to an image that includes objects of multiple colors, for example, an image can include objects of different colors such as blue sky, white clouds, and trees, or an image can include a person wearing clothes of different colors.
[0048] The preset type light source can be 40 common light sources with a color temperature range of 2000K-9000K.
[0049] The sample color channel data may be spectral channel data of different bands, each spectral channel corresponds to one band, and different spectral channels correspond to different bands. In the field of multispectral imaging technology, the number of spectral channels is usually as many as dozens or even hundreds, and the bands corresponding to each spectral channel are often continuous.
[0050] The calibration matrix may be a matrix used to restore the sample color channel data to the number of spectral channels of the full band. As can be seen from the above, the sample color channel data may be spectral channel data of different bands, and the wavelength ranges of these bands may be smaller than the wavelength range of the full band. Usually, the calibration matrix may be provided by the manufacturer of the multispectral sensor.
[0051] In some embodiments, there may be multiple preset types of light sources. Under each light source, the camera may capture sample images of each scene, and the multispectral sensor may obtain sample spectral channel data of each sample image under the current light source.
[0052] S302, respectively calculating the product of each sample color channel data and the calibration matrix to obtain first sample color channel data.
[0053] S303 , respectively performing first-order derivative calculations on the first sample color channel data to obtain second sample color channel data.
[0054] S304: Perform dimensionality reduction processing on each second sample color channel data to obtain each third sample color channel data.
[0055] S305: Use the third sample color channel data to train a light source classification model.
[0056] S302 - S305 are explained below.
[0057] The process of obtaining the third sample color channel data from the sample color channel data is actually a process of processing data. After the data processing process, the processed data is used to train the light source classification model, which can simplify the complexity of the light source classification model and improve the accuracy of the light source classification model.
[0058] Since the sample color channel data is the spectral channel data of different bands, and the wavelength range of these bands is smaller than the wavelength range of the full band, each sample color channel data and the calibration matrix can be multiplied to obtain the spectral channel data of the full band. For the convenience of description, the spectral channel data of the full band can be called the first sample color channel data. For example, the multi-spectral sensor used can have 13 spectral channels, and the spectral channel of the full band can be 100 spectral channels. Then the sample spectral channel data can be 13 values. After multiplying the calibration matrix, the first sample color channel data obtained can be 100 values. Further, the first sample color channel data can be calculated by the first-order derivative to obtain the second sample color channel data. Further, the second sample color channel data can be processed by dimensionality reduction to obtain the third sample color channel data. Since the first sample color channel data and the second sample color channel data are both high-dimensional data, after dimensionality reduction processing, data of tens of dimensions or even fewer dimensions can be obtained, that is, the third sample color channel data with fewer dimensions can be obtained to train the light source classification model. Usually, the dimension reduction process can adopt the principal component analysis (PCA) method.
[0059] The third sample color channel data is used to train the light source classification model. A neural network model can usually be selected. The training process of the neural network model can include the following steps: define a neural network containing multiple learnable parameters (weights); iteratively calculate the input data set; process the input data through a multi-layer network structure; calculate the loss value (the difference between the output value and the target value); back-propagate the gradient to the parameters of the neural network; and update the weight value in the network according to the update rule. In addition, a time series model such as a recurrent neural network (RNN) and a long short-term memory (LSTM) can also be selected for training, and the embodiment of the present application does not limit this.
[0060] S306, obtaining color channel data of the target image captured by the camera.
[0061] It is understandable that the target image currently captured by the camera must be captured under a certain light source. In order to identify the current light source, first, the color channel data of the target image captured by the multispectral sensor under the current light source can be obtained, that is, the spectral channel data of different bands output by the multispectral sensor can be obtained.
[0062] S307, calculating the product of the color channel data and the calibration matrix to obtain first color channel data.
[0063] S308: Perform a first-order derivative on the first color channel data to obtain second color channel data.
[0064] S309: Perform dimensionality reduction processing on the second color channel data to obtain third color channel data.
[0065] S307 - S309 are explained below.
[0066] As can be seen from S302-S305, in the process of training to obtain the light source classification model, the sample color channel data is first processed, and then the processed data is used to train the light source classification model. Therefore, when the light source classification model is used to identify the color channel data, the same data processing process is also required for the color channel data, that is, the color channel data and the calibration matrix can be multiplied to obtain the first color channel data, and then the first color channel data is first-order derived to obtain the second color channel data. Due to the limited wavelength range corresponding to the spectral channel data output by the multi-spectral sensor used in the embodiment of the present application, it is necessary to obtain the spectral channel data of the full band after multiplying with the calibration matrix. Then, the first color channel data is the spectral channel data of the full band, and the first color channel data and the second color channel data are both high-dimensional data, and then the high-dimensional data needs to be reduced for dimensionality reduction processing to obtain the third color channel data of lower dimensionality, and the PCA method can also be used for dimensionality reduction processing.
[0067] S310, inputting the third color channel data into a light source classification model to obtain matching probabilities that the light source corresponding to the target image belongs to different preset types of light sources, and determining a matching probability within a preset probability range among the matching probabilities.
[0068] In some embodiments, the third color channel data can be input into a pre-trained light source classification model for identification, and the light source classification model can output the matching probability that the light source corresponding to the target image belongs to different preset types of light sources. Further, determining the matching probability within the preset probability range among the matching probabilities can be understood as arranging the values of the multiple matching probabilities output by the light source classification model in order from large to small, and finding the matching probabilities of the preset number arranged in front, for example, the preset number can be three, and the three matching probabilities with the largest probability values can be found. Alternatively, determining the matching probability within the preset probability range among the matching probabilities can be understood as finding the matching probability whose probability value is greater than or equal to the probability threshold among the multiple matching probabilities output by the light source classification model, for example, the probability threshold can be set to 0.32.
[0069] S311, obtaining target type light sources corresponding to the matching probabilities within a preset probability range, and calculating the sum of the matching probabilities corresponding to the target type light sources.
[0070] In some embodiments, after sorting multiple matching probabilities, a preset number of matching probabilities arranged in front are found. For example, the preset number is set to three. The target type light sources corresponding to the three matching probabilities with the largest probability values can be determined, and the sum of these three matching probabilities can be calculated.
[0071] In some embodiments, when matching probabilities whose probability values are greater than or equal to a probability threshold are found from multiple matching probabilities, the target type light sources corresponding to these matching probabilities may be determined, and the sum of these matching probabilities may be calculated.
[0072] S312, respectively calculating the ratios of the matching probabilities corresponding to the target type light sources to the sum, and using the ratios as weights corresponding to the target type light sources.
[0073] In some embodiments, if the target type light sources determined in S311 are light source a, light source b, and light source c, respectively, the matching probability corresponding to light source a is p1, the matching probability corresponding to light source b is p2, and the matching probability corresponding to light source c is p3, the ratio of the matching probability corresponding to light source a to the total can be calculated, and P1=p1 / (p1+p2+p3), then P1 can be used as the weight corresponding to light source a; the ratio of the matching probability corresponding to light source b to the total can be calculated, and P2=p2 / (p1+p2+p3), then P2 can be used as the weight corresponding to light source b; the ratio of the matching probability corresponding to light source c to the total can be calculated, and P3=p3 / (p1+p2+p3), then P3 can be used as the weight corresponding to light source c.
[0074] S313, respectively acquiring spectral data of each gray card image captured by the camera under each target type of light source.
[0075] It can be understood that the spectral data may be values of three color channels, red (R), green (G), and blue (B), that is, the spectral data may include an R value, a G value, and a B value.
[0076] In some embodiments, each gray card image (image obtained by photographing the gray card) can be captured by a camera under the target classification light source, and these gray card images are saved in a raw format. Then, r (R value), g (G value), and b (B value) of each gray card image in a raw format can be obtained.
[0077] S314: Determine, based on the spectral data of each gray card image, a calibration gain corresponding to each of the target type light sources, wherein the calibration gain includes a red calibration gain, a blue calibration gain, and a green calibration gain.
[0078] In some embodiments, for each target type light source, the corresponding red calibration gain (rgain), green calibration gain (ggain), and blue calibration gain (bgain) may be calculated, and the specific calculation method may be: rgain=g / r, ggain=1, bgain=b / r.
[0079] S315, weighted summing up the red calibration gains corresponding to the target type light sources based on the weights corresponding to the target type light sources to obtain the red gain in the white balance gain corresponding to the target image, weighted summing up the blue calibration gains corresponding to the target type light sources based on the weights corresponding to the target type light sources to obtain the blue gain in the white balance gain corresponding to the target image, and using the preset value as the green gain in the white balance gain corresponding to the target image.
[0080] In some embodiments, the red gain (Rgain) in the white balance gain corresponding to the target image can be obtained by weighted summing the red calibration gains corresponding to each target type of light source. The specific calculation formula can be: Rgain = rgain_a*P1+rgain_b*P2+rgain_c*P3.
[0081] The blue gain (Bgain) in the white balance gain corresponding to the target image can be obtained by weighted summing the red calibration gains corresponding to each target type of light source. The specific calculation formula can be: Bgain = bgain_a*P1+bgain_b*P2+bgain_c*P3.
[0082] The preset value may be set to 1, and the green gain in the white balance gain corresponding to the target image may be set to 1.
[0083] S316: Perform white balance adjustment on the target image based on the red gain in the white balance gain, the blue gain in the white balance gain, and the green gain in the white balance gain.
[0084] In some embodiments, the white balance adjustment of the target image can be completed by multiplying the R value of the target image under the current light source by the red gain in the white balance gain, multiplying the G value of the target image under the current light source by the green gain in the white balance gain, and multiplying the B value of the target image under the current light source by the blue gain in the white balance gain.
[0085] When the scheme of the embodiment of the present application is executed, the sample color channel data of the sample images of different scenes collected under various light sources are first processed, and then the light source classification model is trained by the processed data, which can simplify the complexity of the light source classification model. Then, when the trained light source classification model is used to identify the color channel data of the target image collected by the camera, the color channel data can also be processed accordingly, and then the processed data is input into the light source classification model for identification, so that the matching probability of the target image belonging to different preset types of light sources can be obtained. Then, based on the matching probability of different light sources, the weights occupied by different light sources, and the calibration gains of different light sources, the white balance gain corresponding to the target image can be obtained, and then the white balance adjustment of the target image can be performed. Since the training data used in the light source classification model includes data of multiple light sources in different scenes, these scenes can include monochrome scenes or mixed color scenes, so the accuracy of the light source classification model in identifying the type of light source can be improved, and then the accuracy of white balance processing of the image can be improved.
[0086] See also Figure 4 , is a schematic diagram of the structure of an image processing device provided in an embodiment of the present application. The image processing device 400 can be implemented as all or part of the terminal through software, hardware, or a combination of both. The device 400 includes:
[0087] The data acquisition module 410 is used to acquire the color channel data of the target image acquired by the camera;
[0088] A light source identification module 420 is used to input the color channel data into a light source classification model to obtain a matching probability that the light source corresponding to the target image belongs to different preset types of light sources;
[0089] The image adjustment module 430 is configured to determine a white balance gain corresponding to the target image based on the matching probability, and perform white balance adjustment on the target image based on the white balance gain.
[0090] Optionally, the light source identification module 420 includes:
[0091] A first processing unit, configured to calculate the product of the color channel data and a calibration matrix to obtain first color channel data;
[0092] A second processing unit, configured to perform a first-order derivative on the first color channel data to obtain second color channel data;
[0093] A third processing unit, configured to perform dimensionality reduction processing on the second color channel data to obtain third color channel data;
[0094] The fourth processing unit is used to input the third color channel data into a light source classification model to obtain a matching probability that the light source corresponding to the target image belongs to different preset types of light sources.
[0095] Optionally, the image adjustment module 430 includes:
[0096] A first calculation unit, used to determine a matching probability within a preset probability range among the matching probabilities;
[0097] A second calculation unit, configured to determine, based on the matching probabilities within the preset probability range, weights corresponding to the target type light sources corresponding to the matching probabilities within the preset probability range;
[0098] A third calculation unit is used to obtain the calibration gain corresponding to each of the target type light sources;
[0099] The fourth calculation unit is used to obtain the white balance gain corresponding to the target image based on the weights corresponding to the target type light sources corresponding to the matching probabilities within the preset probability range and the calibration gains corresponding to the target type light sources.
[0100] Optionally, the second computing unit includes:
[0101] A light source type determination unit, configured to obtain target type light sources corresponding to the matching probabilities within a preset probability range;
[0102] A probability sum calculation unit, used to calculate the sum of the matching probabilities corresponding to the light sources of each target type;
[0103] The weight calculation unit is used to calculate the ratio of the matching probability corresponding to each of the target type light sources to the total, and use each of the ratios as the weight corresponding to each of the target type light sources.
[0104] Optionally, the third computing unit includes:
[0105] A data acquisition unit, used to respectively acquire spectral data of each gray card image captured by the camera under each target type of light source;
[0106] The calibration gain calculation unit is used to determine the calibration gain corresponding to each of the target type light sources based on the spectral data of each gray card image, and the calibration gain includes a red calibration gain, a blue calibration gain and a green calibration gain.
[0107] Optionally, the fourth computing unit includes:
[0108] A red gain calculation unit, configured to perform weighted summation of red calibration gains corresponding to each of the target type light sources based on the weights corresponding to each of the target type light sources, to obtain a red gain in the white balance gain corresponding to the target image;
[0109] A blue gain calculation unit, configured to perform weighted summation of blue calibration gains corresponding to each of the target type light sources based on the weights corresponding to each of the target type light sources, to obtain a blue gain in the white balance gain corresponding to the target image;
[0110] The green gain calculation unit is used to use a preset value as the green gain in the white balance gain corresponding to the target image.
[0111] Optionally, the device further comprises:
[0112] A sample acquisition module, used to acquire sample color channel data of sample images of different scenes captured by the camera under each preset type of light source;
[0113] The model training module is used to train the light source classification model using the sample color channel data.
[0114] Optionally, the model training module includes:
[0115] A first sample data processing unit, used for respectively calculating the product of each sample color channel data and a calibration matrix to obtain each first sample color channel data;
[0116] A second sample data processing unit, used for performing first-order derivative calculations on each of the first sample color channel data to obtain each of the second sample color channel data;
[0117] A third sample data processing unit, configured to perform dimensionality reduction processing on each second sample color channel data to obtain each third sample color channel data;
[0118] The fourth sample data processing unit is used to train a light source classification model by using the third sample color channel data to train the model.
[0119] Please refer to Figure 5 , Figure 5 A schematic diagram of the structure of a terminal provided in an embodiment of the present application. Figure 5 As shown, the terminal 1300 may include: at least one processor 1301 , at least one network interface 1304 , a user interface 1303 , a memory 1305 , a display screen component 1306 , and at least one communication bus 1302 .
[0120] The communication bus 1302 is used to realize the connection and communication between these components.
[0121] The user interface 1303 may include a display screen (Display) and a camera (Camera), and the optional user interface 1303 may also include a standard wired interface and a wireless interface.
[0122] The network interface 1304 may optionally include a standard wired interface or a wireless interface (such as a WI-FI interface).
[0123] Among them, the processor 1301 may include one or more processing cores. The processor 1301 uses various interfaces and lines to connect various parts in the entire terminal 1300, and executes various functions and processes data of the terminal 1300 by running or executing instructions, programs, code sets or instruction sets stored in the memory 1305, and calling data stored in the memory 1305. Optionally, the processor 1301 can be implemented in at least one hardware form of digital signal processing (Digital Signal Processing, DSP), field programmable gate array (Field-Programmable Gate Array, FPGA), and programmable logic array (Programmable Logic Array, PLA). The processor 1301 can integrate one or a combination of a central processing unit (Central Processing Unit, CPU), a graphics processing unit (Graphics Processing Unit, GPU) and a modem. Among them, the CPU mainly processes the operating system, user interface and application programs; the GPU is responsible for rendering and drawing the content to be displayed on the display screen; the modem is used to process wireless communication. It can be understood that the above-mentioned modem may not be integrated into the processor 1301, and it can be implemented separately through a chip.
[0124] Among them, the memory 1305 may include a random access memory (Random Access Memory, RAM) and may also include a read-only memory (Read-Only Memory). Optionally, the memory 1305 includes a non-transitory computer-readable storage medium. The memory 1305 can be used to store instructions, programs, codes, code sets or instruction sets. The memory 1305 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for at least one function (such as a touch function, a sound playback function, an image playback function, etc.), instructions for implementing the above-mentioned various method embodiments, etc.; the data storage area may store data involved in the above-mentioned various method embodiments, etc. The memory 1305 may also be optionally at least one storage device located away from the aforementioned processor 1301. As Figure 5 As shown, the memory 1305 as a computer storage medium may include an operating system, a network communication module, a user interface module, and a program of an image processing method.
[0125] exist Figure 5 In the terminal 1300 shown, the user interface 1303 is mainly used to provide an input interface for the user and obtain data input by the user; and the processor 1301 can be used to call the program of the image processing method stored in the memory 1305, and specifically perform the following operations:
[0126] Get the color channel data of the target image captured by the camera;
[0127] Inputting the color channel data into a light source classification model to obtain a matching probability that the light source corresponding to the target image belongs to different preset types of light sources;
[0128] A white balance gain corresponding to the target image is determined based on the matching probability, and a white balance adjustment is performed on the target image based on the white balance gain.
[0129] In one embodiment, when the processor 1301 executes the step of inputting the color channel data into the light source classification model to obtain the matching probability that the light source corresponding to the target image belongs to different preset types of light sources, the following operations are specifically performed:
[0130] Calculating the product of the color channel data and the calibration matrix to obtain first color channel data;
[0131] Taking a first-order derivative of the first color channel data to obtain second color channel data;
[0132] Performing dimensionality reduction processing on the second color channel data to obtain third color channel data;
[0133] The third color channel data is input into a light source classification model to obtain a matching probability that the light source corresponding to the target image belongs to different preset types of light sources.
[0134] In one embodiment, the processor 1301 performs the following operations when determining the white balance gain corresponding to the target image based on each of the matching probabilities:
[0135] Determining a matching probability within a preset probability range among the matching probabilities;
[0136] Determine, based on the matching probabilities within the preset probability range, weights corresponding to the target type light sources corresponding to the matching probabilities within the preset probability range;
[0137] Obtaining the calibration gain corresponding to each of the target type light sources;
[0138] Based on the weights corresponding to the target type light sources corresponding to the matching probabilities within the preset probability range and the calibration gains corresponding to the target type light sources, the white balance gain corresponding to the target image is obtained.
[0139] In one embodiment, the processor 1301 performs the following operations when determining the weights corresponding to the target type light sources corresponding to the preset number of matching probabilities based on the preset number of matching probabilities arranged in front:
[0140] Obtaining target type light sources corresponding to the matching probabilities within the preset probability range;
[0141] Calculate the sum of the matching probabilities corresponding to the target type light sources;
[0142] The ratios of the matching probabilities corresponding to the target type light sources to the sum are calculated respectively, and the ratios are used as the weights corresponding to the target type light sources respectively.
[0143] In one embodiment, the processor 1301 performs the following operations when executing the acquisition of the calibration gain corresponding to each of the target type light sources:
[0144] Respectively acquiring spectral data of each gray card image captured by the camera under each target type of light source;
[0145] Based on the spectral data of each gray card image, a calibration gain corresponding to each of the target type light sources is determined, and the calibration gain includes a red calibration gain, a blue calibration gain, and a green calibration gain.
[0146] In one embodiment, when the processor 1301 executes the step of obtaining the white balance gain corresponding to the target image based on the weights corresponding to the target type light sources corresponding to the preset number of matching probabilities and the calibration gains corresponding to the target type light sources, the processor 1301 specifically performs the following operations:
[0147] Based on the weights corresponding to the target type light sources, weighted sums are performed on the red calibration gains corresponding to the target type light sources to obtain the red gains in the white balance gains corresponding to the target image;
[0148] Based on the weights corresponding to the target type light sources, weighted sums are performed on the blue calibration gains corresponding to the target type light sources to obtain the blue gains in the white balance gains corresponding to the target image;
[0149] The preset value is used as the green gain in the white balance gain corresponding to the target image.
[0150] In one embodiment, before executing the step of acquiring the color channel data of the target image acquired by the camera, the processor 1301 further performs the following operations:
[0151] Obtain sample color channel data of sample images of different scenes captured by the camera under each preset type of light source;
[0152] The sample color channel data are used to train a light source classification model.
[0153] In one embodiment, the processor 1301 performs the following operations when executing the method of using each of the sample color channel data to train the light source classification model:
[0154] Calculating the product of each sample color channel data and the calibration matrix respectively to obtain each first sample color channel data;
[0155] Performing first-order derivative calculations on each of the first sample color channel data to obtain each of the second sample color channel data;
[0156] Performing dimensionality reduction processing on each second sample color channel data to obtain each third sample color channel data;
[0157] The third sample color channel data are used to train a light source classification model.
[0158] In addition, those skilled in the art will appreciate that the structure of the terminal 1300 shown in the above figures does not limit the terminal 1300, and the user terminal may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently. For example, the terminal 1300 also includes components such as a radio frequency circuit, an audio circuit, a WiFi component, a power supply, and a Bluetooth component, which will not be described in detail here.
[0159] An embodiment of the present application further provides a computer-readable storage medium, which stores at least one instruction, and the at least one instruction is used to be executed by a processor to implement the image processing method described in the above embodiments.
[0160] An embodiment of the present application further provides a computer program product, which stores at least one instruction, and the at least one instruction is loaded and executed by the processor to implement the image processing method described in the above embodiments.
[0161] Those skilled in the art should be aware that in one or more of the above examples, the functions described in the embodiments of the present application can be implemented with hardware, software, firmware or any combination thereof. When implemented using software, these functions can be stored in a computer-readable medium or transmitted as one or more instructions or codes on a computer-readable medium. Computer-readable media include computer storage media and communication media, wherein the communication media include any medium that is convenient for transmitting a computer program from one place to another. The storage medium can be any available medium that a general or special-purpose computer can access. The above is only an optional embodiment of the present application, and is not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application should be included in the protection scope of the present application.
Claims
1. An image processing method, characterized in that: The method comprises: Acquire color channel data of a target image captured by a camera, wherein the color channel data is spectral channel data of different bands; Inputting the color channel data into a light source classification model to obtain a matching probability that the light source corresponding to the target image belongs to different preset types of light sources; Determining a white balance gain corresponding to the target image based on the matching probability, and performing white balance adjustment on the target image based on the white balance gain; The determining the white balance gain corresponding to the target image based on the matching probability includes: Determine a matching probability within a preset probability range among the matching probabilities; determine the weights corresponding to the target type light sources corresponding to the matching probabilities within the preset probability range based on the matching probabilities within the preset probability range; obtain the calibration gains corresponding to the target type light sources; obtain the white balance gain corresponding to the target image based on the weights corresponding to the target type light sources corresponding to the matching probabilities within the preset probability range and the calibration gains corresponding to the target type light sources; The determining, based on the matching probabilities within the preset probability range, weights corresponding to the target type light sources corresponding to the matching probabilities within the preset probability range, includes: Obtain the target type light sources corresponding to the matching probabilities within the preset probability range; calculate the sum of the matching probabilities corresponding to the target type light sources; calculate the ratios of the matching probabilities corresponding to the target type light sources to the sum, and use the ratios as the weights corresponding to the target type light sources.
2. The method according to claim 1, characterized in that Inputting the color channel data into a light source classification model to obtain a matching probability that the light source corresponding to the target image belongs to different preset types of light sources includes: Calculating the product of the color channel data and the calibration matrix to obtain first color channel data; Taking a first-order derivative of the first color channel data to obtain second color channel data; Performing dimensionality reduction processing on the second color channel data to obtain third color channel data; The third color channel data is input into a light source classification model to obtain a matching probability that the light source corresponding to the target image belongs to different preset types of light sources.
3. The method according to claim 1, characterized in that The obtaining of the calibration gains corresponding to the target type light sources includes: Respectively acquiring spectral data of each gray card image captured by the camera under each target type of light source; Based on the spectral data of each gray card image, a calibration gain corresponding to each of the target type light sources is determined, and the calibration gain includes a red calibration gain, a blue calibration gain, and a green calibration gain.
4. The method according to claim 3, characterized in that The obtaining of the white balance gain corresponding to the target image based on the weights corresponding to the target type light sources corresponding to the matching probabilities within the preset probability range and the calibration gains corresponding to the target type light sources comprises: Based on the weights corresponding to the target type light sources, weighted sums are performed on the red calibration gains corresponding to the target type light sources to obtain the red gains in the white balance gains corresponding to the target image; Based on the weights corresponding to the target type light sources, weighted sums are performed on the blue calibration gains corresponding to the target type light sources to obtain the blue gains in the white balance gains corresponding to the target image; The preset value is used as the green gain in the white balance gain corresponding to the target image.
5. The method according to claim 1 or 2, characterized in that: Before acquiring the color channel data of the target image acquired by the camera, the method further includes: Obtain sample color channel data of sample images of different scenes captured by the camera under each preset type of light source; The sample color channel data are used to train a light source classification model.
6. The method according to claim 5, characterized in that The adopting of each of the sample color channel data to train the light source classification model comprises: Calculating the product of each sample color channel data and the calibration matrix respectively to obtain each first sample color channel data; Performing first-order derivative calculations on each of the first sample color channel data to obtain each of the second sample color channel data; Performing dimensionality reduction processing on each second sample color channel data to obtain each third sample color channel data; The third sample color channel data are used to train a light source classification model.
7. An image processing device, characterized in that: The device comprises: A data acquisition module, used to obtain color channel data of a target image acquired by a camera; A light source identification module, used to input the color channel data into a light source classification model to obtain a matching probability that the light source corresponding to the target image belongs to different preset types of light sources; An image adjustment module, configured to determine a white balance gain corresponding to the target image based on the matching probability, and perform white balance adjustment on the target image based on the white balance gain; The image adjustment module is used to determine the matching probability within the preset probability range among the matching probabilities; determine the weights corresponding to the target type light sources corresponding to the matching probabilities within the preset probability range based on the matching probabilities within the preset probability range; obtain the calibration gains corresponding to the target type light sources; obtain the white balance gain corresponding to the target image based on the weights corresponding to the target type light sources corresponding to the matching probabilities within the preset probability range and the calibration gains corresponding to the target type light sources; The image adjustment module is used to obtain the target type light sources corresponding to the matching probabilities within the preset probability range; calculate the sum of the matching probabilities corresponding to the target type light sources; calculate the ratios of the matching probabilities corresponding to the target type light sources to the sum, and use the ratios as the weights corresponding to the target type light sources.
8. A computer storage medium, characterized in that: The computer storage medium stores a plurality of instructions, and the instructions are suitable for being loaded by a processor and executing the method steps according to any one of claims 1 to 6.
9. A terminal, characterized in that: include: A processor and a memory; wherein the memory stores a computer program, and the computer program is suitable for being loaded by the processor and executing the method steps as claimed in any one of claims 1 to 6.
