Image processing method, system, electronic device, readable storage medium and chip
Through the pre-calibrated preset shadow compensation table and target compensation weight, the target shadow compensation table is adaptively interpolated, solving the problem of the unsatisfactory lens shadow compensation effect in complex light source scenes in the prior art, and achieving efficient color compensation.
Patent Information
- Application Number
- CN202211379996.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-04
- Publication Date
- 2025-04-22
- Estimated Expiration
- 2042-11-04
AI Technical Summary
The prior art is difficult to effectively adapt to complex light source scenes when processing images, resulting in unsatisfactory lens shadow compensation effect.
By pre-calibrated small number of preset shadow compensation tables, the target compensation combination and their respective target compensation weights are obtained, and the target shadow compensation table closest to the light source color temperature when shooting the to-process image is adaptively interpolated.
Effectively compensate for the problem of uneven color, improve image quality, and minimize compensation effect error.
Smart Images

Figure CN115914601B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of image processing technology, and in particular to an image processing method, system, electronic device, readable storage medium and chip. Background Art
[0002] Due to the physical characteristics of the lens, images captured through the lens often have problems with Luma Shading (uneven brightness) and Color Shading (uneven color).
[0003] Color Shading is manifested as the inconsistency between the color of the center of the image and the surrounding colors. Images captured under light sources of different color temperatures have different attenuation trends for the three color channels of R, G, and B, resulting in color shading, which seriously affects the quality of the image.
[0004] In order to solve the problem of color shading in images, it is usually necessary to use the LSC (Lens Shading Correction) module included in the image signal processor to perform lens shading compensation on the original image obtained by shooting.
[0005] In the prior art, multiple original images are usually taken under multiple standard light sources (D65, TL84, CWF, etc.), and lens shading compensation tables under various light sources are calibrated based on these original images and stored for future use. When shooting images in actual scenes, the stored shading compensation table is called according to the current scene light source to perform color shading compensation on the current scene light source image.
[0006] However, due to the limited number of light sources available for calibration, it is impossible to calibrate light sources of all color temperatures. In addition, the actual ambient light source is more complex than the calibrated light source and may be a mixed light source, such as the light source near the window in the room. Directly calling the pre-calibrated compensation table cannot adapt well to complex light source scenes, and the lens shadow compensation effect is not ideal. Summary of the invention
[0007] To solve the above technical problems, the present disclosure provides an image processing method, system, electronic device, readable storage medium and chip. By using a small number of pre-calibrated preset shadow compensation tables, a target compensation combination that can minimize the error of the compensation effect and the target compensation weights of each of the two preset shadow compensation tables are obtained, and a target shadow compensation table that is closest to the color temperature of the light source when the image to be processed is captured is adaptively interpolated to effectively compensate for the problem of color unevenness.
[0008] In a first aspect, the present disclosure provides an image processing method, the method comprising:
[0009] Acquire a plurality of preset shadow compensation tables, wherein the plurality of preset shadow compensation tables are calibrated according to light sources of different color temperatures;
[0010] Obtaining a plurality of compensation combinations according to the plurality of preset shadow compensation tables, wherein each of the compensation combinations includes two different preset shadow compensation tables;
[0011] Obtaining a compensation effect error of each compensation combination on a first processed image, where the first processed image is a downsampled image of the image to be processed;
[0012] A target compensation combination is selected according to the compensation effect error to compensate the image to be processed.
[0013] Preferably, the step of obtaining the compensation effect error of each compensation combination on the first processed image comprises:
[0014] Compensating the first processed image using the compensation combination to obtain a second processed image;
[0015] Acquire at least one target flat area in the second processed image;
[0016] Calculate the target feature value of each target flat area according to the color value of each target flat area;
[0017] The compensation effect error is calculated according to the target characteristic values of all the target flat areas.
[0018] Preferably, the step of respectively calculating the target feature value of the target flat area according to the color value of each target flat area comprises:
[0019] Acquire a first error value and a second error value of the target flat area, wherein the first error value is determined according to a first characteristic value of pixels in the target flat area, and the second error value is determined according to a second characteristic value of pixels in the target flat area;
[0020] The target characteristic value of the target flat area is obtained by calculating the sum of the first error value and the second error value of the target flat area.
[0021] Preferably, the first error value is the variance of the first eigenvalue, and the first eigenvalue is determined according to the ratio of the R value to the G value of the pixel in the target flat area; the second error value is the variance of the second eigenvalue, and the second eigenvalue is determined according to the ratio of the B value to the G value of the pixel in the target flat area.
[0022] Preferably, the value range of the first eigenvalue is the logarithmic domain of R / G of the pixels in the target flat area, and the value range of the second eigenvalue is the logarithmic domain of B / G of the pixels in the target flat area, wherein the R is the R value in the three-color value, the B is the B value in the three-color value, and the G is the G value in the three-color value.
[0023] Preferably, the step of acquiring at least one target flat area in the second processed image comprises:
[0024] Mapping pixels of the second processed image to a two-dimensional color space, wherein coordinates of the pixels of the second processed image in the two-dimensional color space represent ratios of R values to G values in three-color values and ratios of B values to G values in three-color values;
[0025] Dividing the two-dimensional color space into a plurality of feature regions whose length is a first threshold and whose width is a second threshold;
[0026] Dividing a flat area in the second processed image according to each of the characteristic areas, pixels in the same flat area belong to the same characteristic area in the two-dimensional color space;
[0027] The target flat area is selected from the flat areas, the number of pixels contained in the target flat area is greater than a preset number, or when sorting from high to low according to the number of pixels contained, the sorting position of the target flat area is not lower than a preset lowest sorting position.
[0028] Preferably, before the step of selecting the target flat area from the flat areas, the method further includes:
[0029] Pixels in the flat area whose pixel brightness does not conform to a preset brightness range are eliminated.
[0030] Preferably, the step of compensating the first processed image using the compensation combination comprises:
[0031] The first processed image is compensated together using the two preset shadow compensation tables in the compensation combination according to their respective target compensation weights; wherein the sum of the compensation weights is 1.
[0032] Preferably, the step of obtaining the target compensation weight includes:
[0033] According to the binary search method and / or the N-point search method, the compensation weights of the two preset shadow compensation tables in the compensation combination are iteratively optimized, and the respective target compensation weights are determined according to the compensation effect error calculated in each iteration and the preset number of iterations.
[0034] Preferably, the plurality of preset shadow compensation tables are calibrated according to a first preset light source, a second preset light source and a third preset light source respectively; wherein the color temperatures of the first preset light source, the second preset light source and the third preset light source increase in sequence.
[0035] Preferably, the step of obtaining a plurality of compensation combinations according to the plurality of preset shadow compensation tables comprises:
[0036] Sorting the plurality of preset shadow compensation tables according to preset rules to obtain a sorting result;
[0037] Every two adjacent preset shadow compensation tables in the sorting result are combined into the compensation combination.
[0038] Preferably, the step of sorting the plurality of preset shadow compensation tables according to preset rules to obtain a sorting result comprises:
[0039] Acquire images captured under light sources having color temperatures corresponding to the plurality of preset shadow compensation tables;
[0040] Acquire a third characteristic value in each of the captured images, wherein the third characteristic value is determined according to three color values of pixels in the captured images;
[0041] The captured images are sorted according to the third characteristic values corresponding to the plurality of preset shadow compensation tables to obtain the sorting result.
[0042] Preferably, the third eigenvalue is the average value of the fourth eigenvalue of the pixels in the captured image, or the third eigenvalue is the variance of the fourth eigenvalue of the pixels in the captured image; wherein, the fourth eigenvalue is any one of R / G, G / R, B / G, G / B, R / G+B / G, G / R+G / B of the pixel, the R is the R value of the three-color value, the B is the B value of the three-color value, and the G is the G value of the three-color value.
[0043] Preferably, the step of sorting the plurality of preset shadow compensation tables according to preset rules to obtain a sorting result comprises:
[0044] The plurality of preset shadow compensation tables are sorted according to the color temperatures of the corresponding light sources to obtain the sorting result.
[0045] Preferably, the compensation effect error is the sum of the target characteristic values of all the target flat areas.
[0046] Preferably, the target compensation combination is the compensation combination corresponding to the smallest compensation effect error.
[0047] In a second aspect, the present disclosure provides an image processing system, the system comprising:
[0048] A compensation table acquisition module, used to acquire a plurality of preset shadow compensation tables, wherein the plurality of preset shadow compensation tables are calibrated according to light sources of different color temperatures;
[0049] A compensation table combination module, used for obtaining a plurality of compensation combinations according to the plurality of preset shadow compensation tables, wherein each of the compensation combinations includes two different preset shadow compensation tables;
[0050] An error acquisition module, used to acquire the compensation effect error of each compensation combination on a first processed image, where the first processed image is a downsampled image of the image to be processed;
[0051] An image compensation module is used to select a target compensation combination according to the compensation effect error to compensate the image to be processed.
[0052] Preferably, the error acquisition module includes:
[0053] a compensation unit, configured to compensate the first processed image using the compensation combination to obtain a second processed image;
[0054] a flat area division unit, configured to obtain at least one target flat area in the second processed image;
[0055] a flat area feature acquisition unit, configured to respectively calculate a target feature value of the target flat area according to a color value of each of the target flat areas;
[0056] A compensation effect error calculation unit is used to calculate the compensation effect error according to the target characteristic values of all the target flat areas.
[0057] Preferably, the flat area feature acquisition unit comprises:
[0058] A regional error value acquisition subunit, configured to acquire a first error value and a second error value of the target flat region, wherein the first error value is determined according to a first characteristic value of pixels in the target flat region, and the second error value is determined according to a second characteristic value of pixels in the target flat region;
[0059] The target characteristic value statistical subunit is used to calculate the sum of the first error value and the second error value of the target flat area to obtain the target characteristic value of the target flat area.
[0060] Preferably, the first error value is the variance of the first eigenvalue, and the first eigenvalue is determined according to the ratio of the R value to the G value of the pixel in the target flat area; the second error value is the variance of the second eigenvalue, and the second eigenvalue is determined according to the ratio of the B value to the G value of the pixel in the target flat area.
[0061] Preferably, the value range of the first eigenvalue is the logarithmic domain of the ratio of the R value to the G value of the pixels in the target flat area, and the value range of the second eigenvalue is the logarithmic domain of the ratio of the B value to the G value of the pixels in the target flat area, wherein the R value is the R value in the three-color value, the B value is the B value in the three-color value, and the G value is the G value in the three-color value.
[0062] Preferably, the flat area division unit comprises:
[0063] A color space mapping subunit is used to map the pixels of the second processed image to a two-dimensional color space, wherein the coordinates of the pixels of the second processed image in the two-dimensional color space represent the ratio of the R value to the G value in the three-color value and the ratio of the B value to the G value in the three-color value;
[0064] A flat region division subunit, used for dividing the two-dimensional color space into a plurality of feature regions with a length equal to a first threshold and a width equal to a second threshold;
[0065] a flat region division subunit, configured to divide a flat region in the second processed image according to each of the characteristic regions, wherein pixels in the same flat region belong to the same characteristic region in the two-dimensional color space;
[0066] The target flat area screening subunit is used to select the target flat area from the flat areas, the number of pixels contained in the target flat area is greater than a preset number, or when sorting from high to low according to the number of pixels contained, the sorting position of the target flat area is not lower than a preset lowest sorting position.
[0067] Preferably, the error acquisition module further comprises a flat region optimization unit for eliminating pixels in the flat region whose pixel brightness does not conform to a preset brightness range.
[0068] Preferably, the compensation unit is used to use the two preset shadow compensation tables in the compensation combination to jointly compensate the first processed image according to their respective target compensation weights; wherein the sum of the compensation weights is 1.
[0069] Preferably, the compensation unit includes a weight optimization unit, which is used to iteratively optimize the compensation weights of each of the two preset shadow compensation tables in the compensation combination according to a binary search method and / or an N-point search method, and determine the respective target compensation weights according to the compensation effect error calculated in each iteration and a preset number of iterations.
[0070] Preferably, the plurality of preset shadow compensation tables are calibrated according to a first preset light source, a second preset light source and a third preset light source respectively; wherein the color temperatures of the first preset light source, the second preset light source and the third preset light source increase in sequence.
[0071] Preferably, the compensation table combination module includes:
[0072] A compensation table sorting unit, used for sorting the plurality of preset shadow compensation tables according to preset rules to obtain a sorting result;
[0073] The compensation table combination unit is used to form the compensation combination by combining every two adjacent preset shadow compensation tables in the sorting result.
[0074] Preferably, the compensation table sorting unit comprises:
[0075] The first compensation table sorting subunit is used to sort the plurality of preset shadow compensation tables according to the color temperatures of the corresponding light sources to obtain the sorting result.
[0076] Preferably, the compensation table sorting unit comprises:
[0077] A captured image acquisition subunit, used to acquire captured images under light sources of color temperatures corresponding to the plurality of preset shadow compensation tables;
[0078] A third characteristic value acquisition subunit, used to acquire a third characteristic value in each of the captured images, wherein the third characteristic value is determined according to three color values of pixels in the captured image;
[0079] The second compensation table sorting subunit is used to sort the captured images according to the third characteristic values corresponding to the plurality of preset shadow compensation tables to obtain the sorting result.
[0080] Preferably, the third eigenvalue is the average value of the ratio of the R value to the G value of the pixels in the captured image, or the third eigenvalue is the average value of the ratio of the B value to the G value of the pixels in the captured image, or the third eigenvalue is the variance of the ratio of the R value to the G value of the pixels in the captured image, or the third eigenvalue is the variance of the ratio of the B value to the G value of the pixels in the captured image.
[0081] Preferably, the compensation effect error is the sum of the target characteristic values of all the target flat areas.
[0082] Preferably, the target compensation combination is the compensation combination corresponding to the smallest compensation effect error.
[0083] In a third aspect, the present disclosure provides an electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the image processing method described in the first aspect and any possible design thereof when executing the computer program.
[0084] In a fourth aspect, the present disclosure provides a computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the image processing method described in the first aspect and any possible design thereof is implemented.
[0085] In a fifth aspect, the present disclosure provides a chip, which executes the image processing method described in the first aspect and any possible design thereof.
[0086] The positive and progressive effects of this disclosure are:
[0087] The image processing method, system, electronic device, readable storage medium and chip provided by the present disclosure can be used for lens shading compensation in various electronic devices that use cameras for shooting and previewing, such as mobile phones, industrial cameras, network cameras, tablet computer cameras, game console cameras, video-enabled smart watches, security cameras, camera modules, etc. The present disclosure obtains a target compensation combination that can minimize the error of the compensation effect and the target compensation weights of the two preset shadow compensation tables, and adaptively interpolates a target shadow compensation table that is closest to the color temperature of the light source when shooting the image to be processed, effectively compensating for the problem of uneven color.
[0088] In a preferred embodiment, the present disclosure can obtain a target shadow compensation table suitable for compensating the image to be processed through very few preset shadow compensation tables, and accurately compensate for the problem of uneven color. The present disclosure also downsamples the image to be processed to obtain a first processed image, maps the pixels of the first processed image into a two-dimensional color space to quickly determine the flat area, removes the darker and brighter pixels in the flat area, and selects several flat areas containing a large number of pixels as the target flat area, avoiding the use of a small flat area resulting in a large error in the calculation of the target characteristic value, improving the accuracy of the compensation effect error, thereby ensuring that the compensation weight calculation of each of the two preset shadow compensation tables in the target compensation combination is more accurate, so that the target shadow compensation table obtained by the final interpolation is closer to the shadow compensation table obtained by the light source calibration corresponding to the image to be processed. BRIEF DESCRIPTION OF THE DRAWINGS
[0089] Figure 1 A flowchart of an image processing method provided in Embodiment 1 of the present disclosure;
[0090] Figure 2 A schematic diagram of two-dimensional color space mapping of the image processing method provided in Embodiment 1 of the present disclosure;
[0091] Figure 3 A schematic diagram of a module of an image processing system provided in Embodiment 2 of the present disclosure;
[0092] Figure 4A schematic diagram of the structure of an electronic device provided in Embodiment 3 of the present disclosure. DETAILED DESCRIPTION
[0093] The present disclosure is further described below by way of examples, but the present disclosure is not limited to the scope of the examples.
[0094] In the following, the terms "first" and "second" are used for descriptive purposes only and are not to be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of the features. In the description of this embodiment, unless otherwise specified, "plurality" means two or more.
[0095] It should be noted that the execution subject of the image processing method provided in this embodiment may be a separate chip, a chip module or a UE, or may be a chip or a chip module integrated in the UE.
[0096] The image processing system described in the embodiment may be a separate chip, a chip module or a UE, or a chip or a chip module integrated in a UE. The various modules / units included in the image processing system may be software modules / units, hardware modules / units, or partly software modules / units and partly hardware modules / units.
[0097] For example, for each device or product applied to or integrated in a chip, each module / unit contained therein may be implemented in the form of hardware such as circuits, or at least some of the modules / units may be implemented in the form of software programs, which run on a processor integrated inside the chip, and the remaining modules / units may be implemented in the form of hardware such as circuits; for each device or product applied to or integrated in a chip module, each module / unit contained therein may be implemented in the form of hardware such as circuits, and different modules / units may be located in the same component (such as a chip, circuit module, etc.) or different components of the chip module, or at least some of the modules / units may be implemented in the form of software programs. / unit can be implemented in the form of a software program, which runs on a processor integrated inside the chip module, and the remaining modules / units can be implemented in the form of hardware such as circuits; for various devices and products applied to or integrated in the UE, the various modules / units contained therein can be implemented in the form of hardware such as circuits, and different modules / units can be located in the same component (for example, chip, circuit module, etc.) or different components in the terminal, or, at least some modules / units can be implemented in the form of a software program, which runs on a processor integrated inside the UE, and the remaining modules / units can be implemented in the form of hardware such as circuits.
[0098] Example 1
[0099] This embodiment provides an image processing method.
[0100] like Figure 1 As shown, the image processing method includes steps S1-S4:
[0101] Step S1, obtaining a plurality of preset shadow compensation tables, wherein the plurality of preset shadow compensation tables are calibrated according to light sources of different color temperatures;
[0102] Step S2, obtaining a plurality of compensation combinations according to a plurality of preset shadow compensation tables, wherein each compensation combination includes two different preset shadow compensation tables;
[0103] Step S3, obtaining the compensation effect error of each compensation combination on the first processed image, where the first processed image is a downsampled image of the image to be processed;
[0104] Step S4: Select a target compensation combination according to the compensation effect error to compensate the image to be processed to obtain a target processed image.
[0105] In step S1 , a number of preset shadow compensation tables can be obtained by calibration based on images captured under light sources of different color temperatures.
[0106] For example, in a darkroom environment, adjust the parameters of the shooting equipment to the shooting requirements, cover the lens with frosted glass, shoot at the center of the light box under light sources of different color temperatures, and obtain the shot images used to calibrate the shadow compensation table. The shot images are input into the analysis software respectively, and the exposure under light sources of different color temperatures is analyzed to obtain several shadow compensation tables for compensating the shot images under light sources of different color temperatures, which are stored as preset shadow compensation tables for standby use.
[0107] In a feasible implementation, several preset shadow compensation tables are calibrated according to the first preset light source, the second preset light source, and the third preset light source, respectively; wherein the color temperatures of the first preset light source, the second preset light source, and the third preset light source increase in sequence.
[0108] Exemplarily, the first preset light source adopts any light source with a color temperature below 3300K, and according to the captured image under the first preset light source, a preset shadow compensation table for compensating the captured image under the low color temperature light source can be calibrated. The second preset light source adopts any light source between 3300K and 5300K, and according to the captured image under the second preset light source, a preset shadow compensation table for compensating the captured image under the medium color temperature light source can be calibrated. The third preset light source adopts any light source above 5300K, and according to the captured image under the third preset light source, a preset shadow compensation table for compensating the captured image under the high color temperature light source can be calibrated.
[0109] In step S2, every two preset shadow compensation tables may be grouped into a plurality of compensation combinations according to a preset rule.
[0110] In a feasible implementation manner, step S2 specifically includes:
[0111] Sorting a number of preset shadow compensation tables according to the color temperatures of the corresponding light sources to obtain a sorting result;
[0112] Every two adjacent preset shadow compensation tables in the sorting result are combined into a compensation combination.
[0113] Exemplarily, compensation table A is obtained by calibration based on a low color temperature light source, compensation table B is obtained by calibration based on a medium color temperature light source, and compensation table C is obtained by calibration based on a high color temperature light source. Therefore, the sorting result obtained by sorting according to the color temperature of the corresponding light source should be: compensation table A, compensation table B, compensation table C. Every two adjacent preset shadow compensation tables in the sorting result are combined into a compensation combination to obtain a first compensation combination including compensation table A and compensation table B, and a second compensation combination including compensation table B and compensation table C.
[0114] In another feasible implementation manner, step S2 specifically includes:
[0115] Acquire images captured under light sources having color temperatures corresponding to the plurality of preset shadow compensation tables;
[0116] Acquire a third characteristic value in each of the captured images, wherein the third characteristic value is determined according to three color values of pixels in the captured images;
[0117] The captured images are sorted according to the third characteristic values corresponding to the plurality of preset shadow compensation tables to obtain the sorting result.
[0118] The third eigenvalue is an average value of the fourth eigenvalues of the pixels in the captured image, or the third eigenvalue is a variance of the fourth eigenvalues of the pixels in the captured image.
[0119] The fourth characteristic value is any one of R / G, G / R, B / G, G / B, R / G+B / G, and G / R+G / B of the pixel, where R is the R value of the three-color value, B is the B value of the three-color value, and G is the G value of the three-color value.
[0120] Exemplarily, the ratio of the R value to the G value of each pixel in the captured image is calculated to obtain R / G, and the average value of R / G is calculated to obtain the third eigenvalue. Alternatively, the average value of R / G is calculated first, and then the variance of R / G is calculated based on the R / G of each pixel and the average value of R / G to obtain the third eigenvalue.
[0121] In step S3, each compensation combination is used to compensate the first processed image respectively, and the compensation effect error of each compensation combination is calculated. The first processed image is a downsampled image of the image to be processed.
[0122] In a feasible implementation manner, step S3 specifically includes:
[0123] Step S31, using the compensation combination to compensate the first processed image to obtain a second processed image;
[0124] Step S32, acquiring at least one target flat area in the second processed image;
[0125] Step S33, calculating the target feature value of each target flat area according to the color value of each target flat area;
[0126] Step S34: Calculate the compensation effect error according to the target characteristic values of all the target flat areas.
[0127] In step S31, two preset shadow compensation tables in the compensation combination are used to jointly compensate the first processed image according to their respective compensation weights; wherein the sum of the compensation weights is 1.
[0128] Specifically, if the compensation combination includes a first compensation table and a second compensation table, the first compensation table is used to compensate the first processed image according to the first compensation weight, and then the second compensation table is superimposed to compensate the first processed image according to the second compensation weight to obtain the second processed image.
[0129] If the first processed image of different color channels is recorded as M1, the first compensation table is recorded as table1, the first compensation weight is recorded as ratio1, the second compensation table is recorded as table2, and the second compensation weight is recorded as ratio2, the calculation formula for the second processed image M2 corresponding to different color channels is:
[0130] M2=M1*table1*ratio1+M1*table2*ratio2;
[0131] The compensation weights may be pre-set, or the first compensation weight and the second compensation weight that can minimize the compensation effect error may be obtained by repeatedly adjusting the compensation weights of the two preset shadow compensation tables in the compensation combination.
[0132] In a feasible implementation manner, the initial compensation weights of the two preset shadow compensation tables in the compensation combination are adjusted multiple times according to the preset weight accuracy to obtain the respective target compensation weights.
[0133] Exemplarily, the initial compensation weight of the first compensation table is 0, the initial compensation weight of the second compensation table is 1, and the preset compensation accuracy is 0.1. Among them, since the sum of the compensation weight of the second compensation table and the compensation weight of the first compensation table is always 1, when the initial compensation weight of the first compensation table is increased by 0.1, the initial compensation weight of the second compensation table needs to be subtracted by 0.1. The compensation effect error of the initial compensation weight of the first compensation table plus 0.1 is calculated respectively, and the compensation weights of the first compensation table and the second compensation table corresponding to the smallest compensation effect error are selected as their respective target compensation weights.
[0134] In another feasible implementation, since the actual ambient color temperature changes linearly, it is not necessary to gradually adjust the compensation weight according to the preset compensation accuracy. The compensation weights of each of the two preset shadow compensation tables in the compensation combination can be iteratively optimized according to the binary search method and / or the N-point search method, and the respective target compensation weights can be determined based on the compensation effect error calculated in each iteration and the preset number of iterations.
[0135] Take binary search as an example:
[0136] Before the first iteration, the value range of the first compensation weight is [0, 1], and the value range of the second compensation weight is [0, 1].
[0137] Perform the first iteration according to the value range of the first compensation weight and the second compensation weight. Obtain the compensation effect error W11 when the first compensation weight is 0 and the second compensation weight is 1, the compensation effect error W12 when the first compensation weight is 0.5 and the second compensation weight is 0.5, and the compensation effect error W13 when the first compensation weight is 1 and the second compensation weight is 0. Compare the compensation effect errors W11, W12, and W13 to obtain the first compensation weight and the second compensation weight when the compensation effect error is the smallest.
[0138] If the preset number of iterations is greater than 1, the second iteration is performed after narrowing the value ranges of the first compensation weight and the second compensation weight.
[0139] Exemplarily, when W11 is minimum, W21 is equal to W11, W23 is equal to W12, and the compensation effect error W22 with the first compensation weight being 0.25 and the second compensation weight being 0.75 is obtained. Comparing the compensation effect errors W21, W22, and W23, the first compensation weight and the second compensation weight are obtained when the compensation effect error is minimum. The same is true when W13 is minimum.
[0140] When W12 is minimum, W22 is equal to W12, and the compensation effect error W21 with the first compensation weight of 0.25 and the second compensation weight of 0.75, and the compensation effect error W23 with the first compensation weight of 0.75 and the second compensation weight of 0.25 are obtained respectively. Compare the compensation effect errors W21, W22, and W23 to obtain the first compensation weight and the second compensation weight when the compensation effect error is minimum.
[0141] If the preset number of iterations is greater than 2, the value ranges of the first compensation weight and the second compensation weight are narrowed again according to the above steps, and the iterative optimization is continued.
[0142] That is, the compensation effect errors corresponding to the boundary values and intermediate values of the first compensation weight and the second compensation weight are compared to continuously narrow the value range of the first compensation weight and the second compensation weight until the number of iterations reaches the preset number of iterations, and the first compensation weight and the second compensation weight corresponding to the minimum compensation effect error are used as the target compensation weights of the two preset shadow compensation tables in the compensation combination.
[0143] In step S32, since the color is relatively flat when the ratio of the R value to the G value and the ratio of the B value to the G value of the three color values of the image pixels vary within a small range, the target flat area in the second processed image can be divided according to the ratio of the R value to the G value and the ratio of the B value to the G value of the three color values of the pixels in the second processed image.
[0144] In a feasible implementation manner, step S32 specifically includes:
[0145] Step S321, mapping pixels of the second processed image to a two-dimensional color space, wherein the coordinates of the pixels of the second processed image in the two-dimensional color space respectively represent the ratio of the R value to the G value in the three-color values and the ratio of the B value to the G value in the three-color values;
[0146] Step S322, dividing the two-dimensional color space into a plurality of feature regions whose length is a first threshold and whose width is a second threshold;
[0147] Step S323, dividing a flat area in the second processed image according to each characteristic area, and pixels in the same flat area belong to the same characteristic area in the two-dimensional color space;
[0148] Step S324: Select a target flat area from the flat areas, the number of pixels contained in the target flat area is greater than a preset number, or when sorting from high to low according to the number of pixels contained, the sorting position of the target flat area is not lower than a preset lowest sorting position.
[0149] Exemplarily, firstly, the ratio of the R value to the G value and the ratio of the B value to the G value in the three color values of each pixel in the second processed image are calculated as the coordinates of the pixel, and the pixels of the second processed image are mapped to Figure 2 The two-dimensional color space shown in the center left.
[0150] Then, the two-dimensional color space is divided into a plurality of feature regions with a length of step_x and a width of step_y by a preset first threshold value step_x and a second threshold value step_y, each of which includes a plurality of pixels. Each feature region corresponds to one or more flat regions in the second processed image. Flat regions are divided in the second processed image according to each feature region. Among them, the pixels in the same flat region all belong to the same feature region in the two-dimensional color space.
[0151] That is, by means of the preset first threshold step_x and second threshold step_y, the difference in R / G values between pixels in the flat area is controlled within the first threshold step_x, and the difference in B / G values between pixels in the flat area is controlled within the second threshold step_y, so that the R / G values and B / G values between pixels in the flat area vary within a smaller range to ensure color flatness in the area.
[0152] like Figure 2 As shown in the middle right part, the pixels in the flat area A all belong to the characteristic area c1 in the two-dimensional color space, and the pixels in the flat area B all belong to the characteristic area c2 in the two-dimensional color space. That is, if the pixels in the same characteristic area are adjacent in the second processed image, they can form a flat area.
[0153] Finally, the flat area with the largest number of pixels is selected as the target flat area. That is, the number of pixels contained in the target flat area needs to be greater than the preset number, or when sorting from high to low according to the number of pixels contained, the sorting position of the target flat area is not lower than the preset lowest sorting position.
[0154] In addition, in order to eliminate the influence of darker and brighter pixels on the compensation effect error, before step S324, the step of eliminating pixels in the flat area whose pixel brightness does not meet the preset brightness range is also included.
[0155] In step S33, a target feature value for characterizing a compensation effect error is obtained for each target flat area according to the color value of each target flat area.
[0156] In a feasible implementation manner, step S33 specifically includes:
[0157] Step S331, obtaining a first error value and a second error value of the target flat area, wherein the first error value is determined according to a first characteristic value of pixels in the target flat area, and the second error value is determined according to a second characteristic value of pixels in the target flat area;
[0158] Step S332: Calculate the sum of the first error value and the second error value of the target flat area to obtain the target characteristic value of the target flat area.
[0159] The first error value is the variance of the first eigenvalue, and the first eigenvalue is determined according to the ratio of the R value to the G value of the pixel in the target flat area; the second error value is the variance of the second eigenvalue, and the second eigenvalue is determined according to the ratio of the B value to the G value of the pixel in the target flat area.
[0160] Exemplarily, the value range of the first eigenvalue is the logarithmic domain of R / G of the pixels in the target flat area, and the value range of the second eigenvalue is the logarithmic domain of B / G of the pixels in the target flat area, wherein the R is the R value in the three-color value, the B is the B value in the three-color value, and the G is the G value in the three-color value. That is, the base can be determined as needed to determine the first eigenvalue and the second eigenvalue.
[0161] In step S34, the target feature values of each target flat area are added together to obtain the compensation effect error of the compensation combination on the entire first processed image. That is, the compensation effect error is the sum of the target feature values of all the target flat areas.
[0162] In step S4, a compensation combination that meets the preset compensation effect error range can be selected as a target compensation combination to compensate the image to be processed as needed.
[0163] Specifically, the compensation combination with the smallest compensation effect error can be selected as the target compensation combination. The target compensation table is calculated according to the two preset compensation shadow tables in the target compensation combination and their respective target compensation weights, and the target compensation table is used to compensate the image to be processed to obtain the target processed image.
[0164] Exemplarily, the first preset shadow compensation table in the target compensation combination is recorded as T1, and its target compensation weight is recorded as R1; the second preset shadow compensation table is recorded as T2, and its target compensation weight is recorded as R2. The calculation formula of the target compensation table T3 is:
[0165] T3 = T1*R1+T2*R2;
[0166] The image processing method provided in this embodiment can be used for lens shading compensation in various electronic devices that use cameras for shooting and previewing, such as mobile phones, industrial cameras, network cameras, tablet computer cameras, game console cameras, video-enabled smart watches, security cameras, and camera modules. The image processing method uses a small number of pre-calibrated preset shading compensation tables to obtain a target compensation combination that can minimize the error of the compensation effect and the target compensation weights of the two preset shading compensation tables, and adaptively interpolates a target shading compensation table that is closest to the color temperature of the light source when the image to be processed is shot, effectively compensating for the problem of uneven color.
[0167] Example 2
[0168] This embodiment provides an image processing system.
[0169] like Figure 3 As shown, the image processing system comprises:
[0170] A compensation table acquisition module 1 is used to acquire a plurality of preset shadow compensation tables, wherein the plurality of preset shadow compensation tables are calibrated according to light sources of different color temperatures;
[0171] A compensation table combination module 2, used to obtain a plurality of compensation combinations according to a plurality of preset shadow compensation tables, wherein each compensation combination includes two different preset shadow compensation tables;
[0172] The error acquisition module 3 is used to obtain the compensation effect error of each compensation combination on the first processed image, where the first processed image is a downsampled image of the image to be processed;
[0173] The image compensation module 4 is used to select a target compensation combination according to the compensation effect error to compensate the image to be processed.
[0174] The plurality of preset shadow compensation tables in the compensation table acquisition module 1 can be obtained by calibration based on images captured under light sources of different color temperatures.
[0175] For example, in a darkroom environment, adjust the parameters of the shooting equipment to the shooting requirements, cover the lens with frosted glass, shoot at the center of the light box under light sources of different color temperatures, and obtain the shot images used to calibrate the shadow compensation table. The shot images are input into the analysis software respectively, and the exposure under light sources of different color temperatures is analyzed to obtain several shadow compensation tables for compensating the shot images under light sources of different color temperatures, which are stored as preset shadow compensation tables for standby use.
[0176] In a feasible implementation, several preset shadow compensation tables are calibrated according to the first preset light source, the second preset light source, and the third preset light source, respectively; wherein the color temperatures of the first preset light source, the second preset light source, and the third preset light source increase in sequence.
[0177] Exemplarily, the first preset light source adopts any light source with a color temperature below 3300K, and according to the captured image under the first preset light source, a preset shadow compensation table for compensating the captured image under the low color temperature light source can be calibrated. The second preset light source adopts any light source between 3300K and 5300K, and according to the captured image under the second preset light source, a preset shadow compensation table for compensating the captured image under the medium color temperature light source can be calibrated. The third preset light source adopts any light source above 5300K, and according to the captured image under the third preset light source, a preset shadow compensation table for compensating the captured image under the high color temperature light source can be calibrated.
[0178] The compensation table combination module 2 is used to group every two preset shadow compensation tables into a plurality of compensation combinations according to preset rules.
[0179] In a feasible implementation manner, the compensation table combination module 2 includes:
[0180] A compensation table sorting unit, used for sorting the plurality of preset shadow compensation tables according to preset rules to obtain a sorting result;
[0181] The compensation table combination unit is used to form the compensation combination by combining every two adjacent preset shadow compensation tables in the sorting result.
[0182] In a feasible implementation manner, the compensation table sorting unit includes:
[0183] The first compensation table sorting subunit is used to sort a plurality of preset shadow compensation tables according to the color temperatures of the corresponding light sources to obtain a sorting result.
[0184] Exemplarily, compensation table A is obtained by calibration based on a low color temperature light source, compensation table B is obtained by calibration based on a medium color temperature light source, and compensation table C is obtained by calibration based on a high color temperature light source. Therefore, the sorting result obtained by sorting according to the color temperature of the corresponding light source should be: compensation table A, compensation table B, compensation table C. Every two adjacent preset shadow compensation tables in the sorting result are combined into a compensation combination to obtain a first compensation combination including compensation table A and compensation table B, and a second compensation combination including compensation table B and compensation table C.
[0185] In another feasible implementation manner, the compensation table sorting unit includes:
[0186] A captured image acquisition subunit, used to acquire captured images under light sources of color temperatures corresponding to the plurality of preset shadow compensation tables;
[0187] A third characteristic value acquisition subunit, used to acquire a third characteristic value in each of the captured images, wherein the third characteristic value is determined according to three color values of pixels in the captured image;
[0188] The second compensation table sorting subunit is used to sort the captured images according to the third characteristic values corresponding to the plurality of preset shadow compensation tables to obtain the sorting result.
[0189] The third eigenvalue is an average value of the fourth eigenvalues of the pixels in the captured image, or the third eigenvalue is a variance of the fourth eigenvalues of the pixels in the captured image.
[0190] The fourth characteristic value is any one of R / G, G / R, B / G, G / B, R / G+B / G, and G / R+G / B of the pixel, where R is the R value of the three-color value, B is the B value of the three-color value, and G is the G value of the three-color value.
[0191] Exemplarily, the ratio of the R value to the G value of each pixel in the captured image is calculated to obtain R / G, and the average value of R / G is calculated to obtain the third eigenvalue. Alternatively, the average value of R / G is calculated first, and then the variance of R / G is calculated based on the R / G of each pixel and the average value of R / G to obtain the third eigenvalue.
[0192] The error acquisition module 3 is used to use each compensation combination to compensate the first processed image respectively, and calculate the compensation effect error of each compensation combination. Wherein, the first processed image is a downsampled image of the image to be processed.
[0193] In a feasible implementation manner, the error acquisition module 3 includes:
[0194] a compensation unit, configured to compensate the first processed image using the compensation combination to obtain a second processed image;
[0195] a flat area division unit, configured to obtain at least one target flat area in the second processed image;
[0196] a flat area feature acquisition unit, configured to respectively calculate a target feature value of the target flat area according to a color value of each of the target flat areas;
[0197] A compensation effect error calculation unit is used to calculate the compensation effect error according to the target characteristic values of all the target flat areas.
[0198] The compensation unit is used to use two preset shadow compensation tables in the compensation combination to jointly compensate the first processed image according to respective compensation weights; wherein the sum of the compensation weights is 1.
[0199] Specifically, if the compensation combination includes a first compensation table and a second compensation table, the first compensation table is used to compensate the first processed image according to the first compensation weight, and then the second compensation table is superimposed to compensate the first processed image according to the second compensation weight to obtain the second processed image.
[0200] If the first processed image of different color channels is recorded as M1, the first compensation table is recorded as table1, the first compensation weight is recorded as ratio1, the second compensation table is recorded as table2, and the second compensation weight is recorded as ratio2, the calculation formula for the second processed image M2 corresponding to different color channels is:
[0201] M2=M1*table1*ratio1+M1*table2*ratio2;
[0202] The compensation weights may be pre-set, or the first compensation weight and the second compensation weight that can minimize the compensation effect error may be obtained by repeatedly adjusting the compensation weights of the two preset shadow compensation tables in the compensation combination.
[0203] In a feasible implementation, the compensation unit includes a first weight optimization unit, which is used to adjust the initial compensation weights of the two preset shadow compensation tables in the compensation combination multiple times according to the preset weight accuracy to obtain the respective target compensation weights.
[0204] Exemplarily, the initial compensation weight of the first compensation table is 0, the initial compensation weight of the second compensation table is 1, and the preset compensation accuracy is 0.1. Among them, since the sum of the compensation weight of the second compensation table and the compensation weight of the first compensation table is always 1, when the initial compensation weight of the first compensation table is increased by 0.1, the initial compensation weight of the second compensation table needs to be subtracted by 0.1. The compensation effect error of the initial compensation weight of the first compensation table plus 0.1 is calculated respectively, and the compensation weights of the first compensation table and the second compensation table corresponding to the smallest compensation effect error are selected as their respective target compensation weights.
[0205] In another feasible implementation, since the actual ambient color temperature changes linearly, there is no need to gradually adjust the compensation weight according to the preset compensation accuracy. The compensation unit includes a second weight optimization unit, which is used to iteratively optimize the compensation weights of each of the two preset shadow compensation tables in the compensation combination according to the binary search method and / or the N-point search method, and determine the respective target compensation weights according to the compensation effect error calculated in each iteration and the preset number of iterations.
[0206] Take binary search as an example:
[0207] Before the first iteration, the value range of the first compensation weight is [0, 1], and the value range of the second compensation weight is [0, 1].
[0208] Perform the first iteration according to the value range of the first compensation weight and the second compensation weight. Obtain the compensation effect error W11 when the first compensation weight is 0 and the second compensation weight is 1, the compensation effect error W12 when the first compensation weight is 0.5 and the second compensation weight is 0.5, and the compensation effect error W13 when the first compensation weight is 1 and the second compensation weight is 0. Compare the compensation effect errors W11, W12, and W13 to obtain the first compensation weight and the second compensation weight when the compensation effect error is the smallest.
[0209] If the preset number of iterations is greater than 1, the second iteration is performed after narrowing the value ranges of the first compensation weight and the second compensation weight.
[0210] Exemplarily, when W11 is minimum, W21 is equal to W11, W23 is equal to W12, and the compensation effect error W22 with the first compensation weight being 0.25 and the second compensation weight being 0.75 is obtained. Comparing the compensation effect errors W21, W22, and W23, the first compensation weight and the second compensation weight are obtained when the compensation effect error is minimum. The same is true when W13 is minimum.
[0211] When W12 is minimum, W22 is equal to W12, and the compensation effect error W21 with the first compensation weight of 0.25 and the second compensation weight of 0.75, and the compensation effect error W23 with the first compensation weight of 0.75 and the second compensation weight of 0.25 are obtained respectively. Compare the compensation effect errors W21, W22, and W23 to obtain the first compensation weight and the second compensation weight when the compensation effect error is minimum.
[0212] If the preset number of iterations is greater than 2, the value ranges of the first compensation weight and the second compensation weight are narrowed again according to the above steps, and the iterative optimization is continued.
[0213] That is, the compensation effect errors corresponding to the boundary values and intermediate values of the first compensation weight and the second compensation weight are compared to continuously narrow the value range of the first compensation weight and the second compensation weight until the number of iterations reaches the preset number of iterations, and the first compensation weight and the second compensation weight corresponding to the minimum compensation effect error are used as the target compensation weights of the two preset shadow compensation tables in the compensation combination.
[0214] Since the color is relatively flat when the ratio of the R value to the G value and the ratio of the B value to the G value of the three color values of the image pixels vary within a small range, the flat area division unit is used to divide the target flat area in the second processed image according to the ratio of the R value to the G value and the ratio of the B value to the G value of the three color values of the pixels in the second processed image.
[0215] In a feasible implementation manner, the flat area division unit includes:
[0216] A color space mapping subunit is used to map pixels of the second processed image to a two-dimensional color space, wherein the coordinates of the pixels of the second processed image in the two-dimensional color space represent the ratio of the R value to the G value in the three-color value and the ratio of the B value to the G value in the three-color value;
[0217] A feature region division subunit, used for dividing the two-dimensional color space into a plurality of feature regions with a length equal to a first threshold and a width equal to a second threshold;
[0218] A flat region division subunit is used to divide a flat region in the second processed image according to each characteristic region, and pixels in the same flat region belong to the same characteristic region in the two-dimensional color space;
[0219] The target flat area screening subunit is used to select a target flat area from the flat area, the number of pixels contained in the target flat area is greater than a preset number, or when sorting from high to low according to the number of pixels contained, the sorting position of the target flat area is not lower than a preset lowest sorting position.
[0220] Exemplarily, firstly, the ratio of the R value to the G value and the ratio of the B value to the G value in the three color values of each pixel in the second processed image are calculated as the coordinates of the pixel, and the pixels of the second processed image are mapped to Figure 2 The two-dimensional color space shown in the center left.
[0221] Then, the two-dimensional color space is divided into a plurality of feature regions with a length of step_x and a width of step_y by a preset first threshold value step_x and a second threshold value step_y, each of which includes a plurality of pixels. Each feature region corresponds to one or more flat regions in the second processed image. Flat regions are divided in the second processed image according to each feature region. Among them, the pixels in the same flat region all belong to the same feature region in the two-dimensional color space.
[0222] That is, by means of the preset first threshold step_x and second threshold step_y, the difference in R / G values between pixels in the flat area is controlled within the first threshold step_x, and the difference in B / G values between pixels in the flat area is controlled within the second threshold step_y, so that the R / G values and B / G values between pixels in the flat area vary within a smaller range to ensure color flatness in the area.
[0223] like Figure 2 As shown in the middle right part, the pixels in the flat area A all belong to the characteristic area c1 in the two-dimensional color space, and the pixels in the flat area B all belong to the characteristic area c2 in the two-dimensional color space. That is, if the pixels in the same characteristic area are adjacent in the second processed image, they can form a flat area.
[0224] Finally, the flat area with the largest number of pixels is selected as the target flat area. That is, the number of pixels contained in the target flat area needs to be greater than the preset number, or when sorting from high to low according to the number of pixels contained, the sorting position of the target flat area is not lower than the preset lowest sorting position.
[0225] In addition, in order to eliminate the influence of darker and brighter pixels on the compensation effect error, the error acquisition module 3 further includes a flat area optimization unit for eliminating pixels in the flat area whose pixel brightness does not meet the preset brightness range.
[0226] The flat region feature acquisition unit is used to obtain a target feature value for each target flat region for characterizing a compensation effect error according to a color value of each target flat region.
[0227] In a feasible implementation manner, the flat area feature acquisition unit includes:
[0228] A regional error value acquisition subunit, configured to acquire a first error value and a second error value of the target flat region, wherein the first error value is determined according to a first characteristic value of pixels in the target flat region, and the second error value is determined according to a second characteristic value of pixels in the target flat region;
[0229] The target characteristic value statistical subunit is used to calculate the sum of the first error value and the second error value of the target flat area to obtain the target characteristic value of the target flat area.
[0230] The first error value is the variance of the first eigenvalue, and the first eigenvalue is determined according to the ratio of the R value to the G value of the pixel in the target flat area; the second error value is the variance of the second eigenvalue, and the second eigenvalue is determined according to the ratio of the B value to the G value of the pixel in the target flat area.
[0231] Exemplarily, the value range of the first eigenvalue is the logarithmic domain of R / G of the pixels in the target flat area, and the value range of the second eigenvalue is the logarithmic domain of B / G of the pixels in the target flat area, wherein the R is the R value in the three-color value, the B is the B value in the three-color value, and the G is the G value in the three-color value. That is, the base can be determined as needed to determine the first eigenvalue and the second eigenvalue.
[0232] The compensation effect error calculation unit is used to add the target feature values of each target flat area to obtain the compensation effect error of the compensation combination on the entire first processed image. That is, the compensation effect error is the sum of the target feature values of all the target flat areas.
[0233] The image compensation module 4 is used to select a compensation combination that meets a preset compensation effect error range as a target compensation combination to compensate the image to be processed according to needs.
[0234] Specifically, the compensation combination with the smallest compensation effect error can be selected as the target compensation combination. The target compensation table is calculated according to the two preset compensation shadow tables in the target compensation combination and their respective target compensation weights, and the target compensation table is used to compensate the image to be processed to obtain the target processed image.
[0235] Exemplarily, the first preset shadow compensation table in the target compensation combination is recorded as T1, and its target compensation weight is recorded as R1; the second preset shadow compensation table is recorded as T2, and its target compensation weight is recorded as R2. The calculation formula of the target compensation table T3 is:
[0236] T3 = T1*R1+T2*R2;
[0237] The image processing system provided in this embodiment can be used for lens shading compensation in various electronic devices that use cameras for shooting and previewing, such as mobile phones, industrial cameras, network cameras, tablet computer cameras, game console cameras, video-enabled smart watches, security cameras, and camera modules. The image processing system obtains a target compensation combination that can minimize the error of the compensation effect and the target compensation weights of the two preset shadow compensation tables through a small number of pre-calibrated preset shadow compensation tables, and adaptively interpolates a target shadow compensation table that is closest to the color temperature of the light source when the image to be processed is shot, effectively compensating for the problem of uneven color.
[0238] Example 3
[0239] This embodiment provides an electronic device.
[0240] Figure 4 This is a schematic diagram of the structure of an electronic device provided in Embodiment 3 of the present disclosure. The electronic device includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, the image processing method described in Embodiment 1 is implemented. Figure 4 The electronic device 30 shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.
[0241] In practical applications, the electronic device may be a mobile phone, an industrial camera, a web camera, a tablet computer camera, a game console camera, a video-enabled smart watch, a security camera, a camera module, or other device products that use a camera for shooting and previewing.
[0242] like Figure 4As shown, the electronic device 30 may also be in the form of a general-purpose computing device, for example, it may be a server device. The components of the electronic device 30 may include, but are not limited to: at least one processor 31, at least one memory 32, and a bus 33 connecting different system components (including the memory 32 and the processor 31).
[0243] The bus 33 includes a data bus, an address bus, and a control bus.
[0244] The memory 32 may include volatile memory, such as random access memory (RAM) 321 and / or or cache The memory 322 may further include a read-only memory (ROM) 323 .
[0245] The memory 32 may also include a program / utility 325 having a set (at least one) of program modules 324, such program modules 324 including but not limited to: an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment.
[0246] The processor 31 executes various functional applications and data processing by running the computer programs stored in the memory 32, such as the image processing method described in Embodiment 1 of the present disclosure.
[0247] The electronic device 30 may also communicate with one or more external devices 34 (e.g., keyboards, pointing devices, etc.). Such communication may be performed via an input / output (I / O) interface 35. Furthermore, the model generating device 30 may also communicate with one or more networks (e.g., a local area network (LAN), a wide area network (WAN), and / or a public network, such as the Internet) via a network adapter 36. Figure 4 As shown, the network adapter 36 communicates with other modules of the model-generated device 30 via the bus 33. It should be understood that, although not shown in the figure, other hardware and / or software modules can be used in conjunction with the model-generated device 30, including but not limited to: microcode, device drivers, redundant processors, external disk drive arrays, RAID (disk array) systems, tape drives, and data backup storage systems, etc.
[0248] It should be noted that although several units / modules or sub-units / modules of the electronic device are mentioned in the above detailed description, this division is merely exemplary and not mandatory. In fact, according to the embodiments of the present disclosure, the features and functions of two or more units / modules described above can be embodied in one unit / module. Conversely, the features and functions of one unit / module described above can be further divided into multiple units / modules to be embodied.
[0249] Example 4
[0250] This embodiment provides a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, the image processing method described in Embodiment 1 is implemented.
[0251] The readable storage medium may include but is not limited to: a portable disk, a hard disk, a random access memory, a read-only memory, an erasable programmable read-only memory, an optical storage device, a magnetic storage device or any suitable combination of the above.
[0252] In a possible implementation manner, the present disclosure may also be implemented in the form of a program product, which includes a program code. When the program product is run on a terminal device, the program code is used to enable the terminal device to execute and implement the image processing method described in Example 1.
[0253] Among them, the program code for executing the present disclosure can be written in any combination of one or more programming languages, and the program code can be executed completely on the user device, partially on the user device, as an independent software package, partially on the user device and partially on a remote device, or completely on the remote device.
[0254] Although the specific embodiments of the present disclosure are described above, those skilled in the art should understand that this is only an example, and the protection scope of the present disclosure is defined by the appended claims. Those skilled in the art may make various changes or modifications to these embodiments without departing from the principles and essence of the present disclosure, but these changes and modifications all fall within the protection scope of the present disclosure.
Claims
1. An image processing method, characterized in that: The image processing method comprises: Acquire a plurality of preset shadow compensation tables, wherein the plurality of preset shadow compensation tables are calibrated according to light sources of different color temperatures; Obtaining a plurality of compensation combinations according to the plurality of preset shadow compensation tables, wherein each of the compensation combinations includes two different preset shadow compensation tables; Obtaining a compensation effect error of each compensation combination on a first processed image, where the first processed image is a downsampled image of the image to be processed; Selecting a target compensation combination according to the compensation effect error to compensate the image to be processed; The step of obtaining the compensation effect error of each compensation combination on the first processed image comprises: Compensating the first processed image using the compensation combination to obtain a second processed image; Acquire at least one target flat area in the second processed image; Calculate the target feature value of each target flat area according to the color value of each target flat area; Calculating the compensation effect error according to the target characteristic values of all the target flat areas; The step of acquiring at least one target flat area in the second processed image comprises: Mapping pixels of the second processed image to a two-dimensional color space, wherein coordinates of the pixels of the second processed image in the two-dimensional color space represent ratios of R values to G values in three-color values and ratios of B values to G values in three-color values; Dividing the two-dimensional color space into a plurality of feature regions whose length is a first threshold and whose width is a second threshold; Dividing a flat area in the second processed image according to each of the characteristic areas, pixels in the same flat area belong to the same characteristic area in the two-dimensional color space; The target flat area is selected from the flat areas, the number of pixels contained in the target flat area is greater than a preset number, or when sorting from high to low according to the number of pixels contained, the sorting position of the target flat area is not lower than a preset lowest sorting position.
2. The image processing method according to claim 1, characterized in that: The step of respectively calculating the target feature value of the target flat area according to the color value of each target flat area comprises: Acquire a first error value and a second error value of the target flat area, wherein the first error value is determined according to a first characteristic value of pixels in the target flat area, and the second error value is determined according to a second characteristic value of pixels in the target flat area; The target characteristic value of the target flat area is obtained by calculating the sum of the first error value and the second error value of the target flat area.
3. The image processing method according to claim 2, characterized in that: The first error value is the variance of the first eigenvalue, and the first eigenvalue is determined according to the ratio of the R value to the G value of the pixel in the target flat area; The second error value is a variance of the second eigenvalue, and the second eigenvalue is determined according to a ratio of a B value to a G value of a pixel in the target flat area.
4. The image processing method according to claim 2, characterized in that: The value range of the first eigenvalue is the logarithmic domain of R / G of the pixels in the target flat area, and the value range of the second eigenvalue is the logarithmic domain of B / G of the pixels in the target flat area, wherein the R is the R value in the three-color value, the B is the B value in the three-color value, and the G is the G value in the three-color value.
5. The image processing method according to claim 1, characterized in that: Before the step of selecting the target flat area from the flat area, the method further includes: Pixels in the flat area whose pixel brightness does not conform to a preset brightness range are eliminated.
6. The image processing method according to claim 1, characterized in that: The step of compensating the first processed image using the compensation combination comprises: The first processed image is compensated together using the two preset shadow compensation tables in the compensation combination according to their respective target compensation weights; wherein the sum of the compensation weights is 1.
7. The image processing method according to claim 6, characterized in that: The step of obtaining the target compensation weight comprises: According to the binary search method and / or the N-point search method, the compensation weights of the two preset shadow compensation tables in the compensation combination are iteratively optimized, and the respective target compensation weights are determined according to the compensation effect error calculated in each iteration and the preset number of iterations.
8. The image processing method according to claim 1, characterized in that: The plurality of preset shadow compensation tables are calibrated according to a first preset light source, a second preset light source, and a third preset light source, respectively; wherein the color temperatures of the first preset light source, the second preset light source, and the third preset light source increase in sequence.
9. The image processing method according to claim 1, characterized in that: The step of obtaining a plurality of compensation combinations according to the plurality of preset shadow compensation tables comprises: Sorting the plurality of preset shadow compensation tables according to preset rules to obtain a sorting result; Every two adjacent preset shadow compensation tables in the sorting result are combined into the compensation combination.
10. The image processing method according to claim 9, characterized in that: The step of sorting the plurality of preset shadow compensation tables according to preset rules to obtain a sorting result comprises: Acquire images captured under light sources having color temperatures corresponding to the plurality of preset shadow compensation tables; Acquire a third characteristic value in each of the captured images, wherein the third characteristic value is determined according to three color values of pixels in the captured images; The captured images are sorted according to the third characteristic values corresponding to the plurality of preset shadow compensation tables to obtain the sorting result.
11. The image processing method according to claim 10, characterized in that: The third eigenvalue is an average value of fourth eigenvalues of pixels in the captured image, or the third eigenvalue is a variance of the fourth eigenvalues of pixels in the captured image; Among them, the fourth characteristic value is any one of R / G, G / R, B / G, G / B, R / G+B / G, and G / R+G / B of the pixel, the R is the R value of the three-color value, the B is the B value of the three-color value, and the G is the G value of the three-color value.
12. The image processing method according to claim 9, characterized in that: The step of sorting the plurality of preset shadow compensation tables according to preset rules to obtain a sorting result comprises: The plurality of preset shadow compensation tables are sorted according to the color temperatures of the corresponding light sources to obtain the sorting result.
13. The image processing method according to claim 1, characterized in that: The compensation effect error is the sum of the target characteristic values of all the target flat areas.
14. The image processing method according to claim 1, characterized in that: The target compensation combination is the compensation combination corresponding to the smallest compensation effect error.
15. An image processing system, characterized in that: The system comprises: A compensation table acquisition module, used to acquire a plurality of preset shadow compensation tables, wherein the plurality of preset shadow compensation tables are calibrated according to light sources of different color temperatures; A compensation table combination module, used for obtaining a plurality of compensation combinations according to the plurality of preset shadow compensation tables, wherein each of the compensation combinations includes two different preset shadow compensation tables; An error acquisition module, used to acquire the compensation effect error of each compensation combination on a first processed image, where the first processed image is a downsampled image of the image to be processed; An image compensation module, used for selecting a target compensation combination according to the compensation effect error to compensate the image to be processed; The error acquisition module comprises: a compensation unit, configured to compensate the first processed image using the compensation combination to obtain a second processed image; a flat area division unit, configured to obtain at least one target flat area in the second processed image; a flat area feature acquisition unit, configured to respectively calculate a target feature value of the target flat area according to the color value of each target flat area; a compensation effect error calculation unit, configured to calculate the compensation effect error according to the target characteristic values of all the target flat areas; The flat area division unit comprises: A color space mapping subunit is used to map pixels of the second processed image to a two-dimensional color space, wherein the coordinates of the pixels of the second processed image in the two-dimensional color space represent the ratio of the R value to the G value in the three-color value and the ratio of the B value to the G value in the three-color value; A feature region division subunit, used for dividing the two-dimensional color space into a plurality of feature regions with a length equal to a first threshold and a width equal to a second threshold; A flat region division subunit is used to divide a flat region in the second processed image according to each characteristic region, and pixels in the same flat region belong to the same characteristic region in the two-dimensional color space; The target flat area screening subunit is used to select a target flat area from the flat area, the number of pixels contained in the target flat area is greater than a preset number, or when sorting from high to low according to the number of pixels contained, the sorting position of the target flat area is not lower than a preset lowest sorting position.
16. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the image processing method according to any one of claims 1 to 14 is implemented.
17. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the image processing method according to any one of claims 1 to 14 is implemented.
18. A chip, characterized in that: The chip includes a processor, and the processor is used to run a software program. When the software program is executed by the processor, the image processing method according to any one of claims 1 to 14 is implemented.
Citation Information
Patent Citations
Color shading correction method and device
CN114331907A
Image processing method and device
WO2019137396A1