Color correction method, electronic device and program product
By integrating a color correction model and training it with whiteboard images and standard color chart images, the relationship between brightness gain, gamma correction, and RGB correction is constructed, which solves the problem of insufficient accuracy in traditional color correction and achieves high-precision image color correction effect.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-08
- Publication Date
- 2026-04-07
AI Technical Summary
Traditional digital image color correction methods suffer from oversimplification, resulting in insufficient color correction accuracy, especially in areas with high color saturation or complex lighting, where obvious color shifts are easily produced.
An integrated color correction model is adopted, including flat field correction, gamma correction, white balance correction and color correction sub-model. By acquiring white board images and standard color card images, partial least squares regression, multinomial fitting and neural network training are used to construct the relationship between brightness gain multiplier, gamma correction and RGB value ratio to achieve high-precision color correction.
This technology enables automated, efficient, and high-precision color correction of images in complex shooting environments, improving the color cast problem in traditional methods and enhancing the accuracy and robustness of color correction.
Smart Images

Figure CN121814934A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of digital image processing, in particular to a color correction method, an electronic device and a program product. BACKGROUND
[0002] In the technical field of digital image processing, especially in the process of digital image acquisition, due to the influence of multiple factors such as shooting equipment (such as camera sensor, lens), environmental light conditions and image processing chain, the final color presented by the digital image often deviates from the color of the real scene. In order to obtain an image with accurate color and realistic visual effect, color correction has become an indispensable key link in the digital imaging process.
[0003] The traditional method is mainly a physical model method. It includes: flat field correction, which is used to correct the uneven brightness of the image caused by the lens dark corner or uneven illumination, usually relies on the "white field" image shot under ideal conditions, and the brightness attenuation is offset by simple pixel division. However, this method has extremely strict requirements for the shooting conditions of the white field image, and simple linear correction is difficult to cope with complex light changes; gamma correction, which is used to correct the nonlinear response of the image sensor to light intensity, usually uses a fixed gamma value (such as 2.2) for power function transformation. This "one-size-fits-all" approach cannot accurately fit the complex nonlinear response curve under different devices and different brightness environments; white balance, which is used to eliminate the overall color deviation caused by the inaccurate color temperature of the environment light, such as "gray world method" or "perfect reflection method", which assumes that the average value of the color of the image scene is gray, or there is a pure white / grey area in the scene. These assumptions do not hold in many real scenes (such as large-area single-color background), resulting in correction failure or introducing new color deviation; color transformation correction, which is used to correct the color deviation of the sensor itself, usually by shooting a standard color card (such as X-Rite ColorChecker), establishing a 3x3 color correction matrix (CCM), or using a higher-order polynomial regression model to fit the linear or nonlinear relationship between the actual color block color and the standard color block color.
[0004] It can be seen that the traditional color correction method uses a linear model or a fixed parameter model (such as a single gamma value, a 3x3 color correction matrix, etc.), which is too simplified and cannot accurately fit and correct the highly nonlinear color distortion caused by the coupling of multiple physical factors (such as light, device characteristics, optical system) and widely existing in digital images, resulting in insufficient correction accuracy, especially in areas with high color saturation or complex light, which is prone to obvious color deviation. SUMMARY
[0005] Therefore, the embodiments of the present application aim to provide a color correction method, an electronic device and a program product, which can improve the traditional digital image color correction method, and the model is too simplified, resulting in insufficient color correction accuracy, and obvious color deviation is prone to occur in areas with high color saturation or complex light.
[0006] To achieve the above technical purposes, the technical solutions adopted by the present application are as follows:
[0007] In a first aspect, the embodiments of the present application provide a color correction method, which comprises:
[0008] obtaining a to-be-processed image;
[0009] using a color correction model to perform flat field correction on the to-be-processed image to obtain a first intermediate image;
[0010] using the color correction model to perform gamma correction on the first intermediate image to obtain a second intermediate image;
[0011] using the color correction model to perform white balance correction on the second intermediate image to obtain a third intermediate image;
[0012] using the color correction model to perform color correction on the third intermediate image to obtain a fourth intermediate image as a target image after color correction.
[0013] In combination with the first aspect, in some optional embodiments, the color correction model comprises a flat field correction sub-model, a gamma correction sub-model, a white balance correction sub-model and a color correction sub-model.
[0014] Before the to-be-processed image is obtained, the method further comprises:
[0015] obtaining a whiteboard image and a standard color card image under the same shooting environment;
[0016] determining, according to the whiteboard image, a mapping relationship between an arbitrary first pixel point in a first target region in the whiteboard image and a luminance gain multiplier corresponding to the first pixel point as the flat field correction sub-model;
[0017] taking the standard color card image after flat field correction by the flat field correction sub-model as a first target image, and determining a mapping relationship between an actual shooting luminance value of an arbitrary second pixel point of a gray scale color block in the first target image and a preset standard luminance reference value corresponding to the second pixel point as the gamma correction sub-model;
[0018] determine a ratio relationship between an RGB value of an arbitrary third pixel point of a gray scale color block in the second target image and a preset standard RGB value corresponding to the third pixel point as the white balance correction sub-model;
[0019] determine a mapping relationship between an RGB value of an arbitrary fourth pixel point of a second target region in the third target image and a preset standard RGB value corresponding to the fourth pixel point as the color correction sub-model.
[0020] In some optional embodiments of the first aspect, the mapping relationship between the arbitrary first pixel point of the first target region in the whiteboard image and the luminance gain multiplier corresponding to the first pixel point is determined as the flat field correction sub-model according to the whiteboard image, including:
[0021] a white plane region in the whiteboard image is taken as the first target region, and a luminance gain multiplier matrix is determined according to luminance values of each first pixel point in the first target region, each element in the luminance gain multiplier matrix representing an inverse ratio of a luminance value of each first pixel point to a target luminance value, the target luminance value representing a maximum luminance value corresponding to all pixel points in the first target region;
[0022] coordinates of each first pixel point in the first target region and a luminance gain multiplier corresponding to the first pixel point are taken as first training data, and the first training data is trained by a partial least squares regression strategy to obtain an initial model representing a mapping relationship between the first pixel point and the luminance gain multiplier corresponding to the first pixel point;
[0023] the initial model is used to predict a luminance gain multiplier corresponding to each pixel point in the whiteboard image;
[0024] a luminance gain multiplier matrix is constructed according to the luminance gain multiplier corresponding to each pixel point in the whiteboard image to obtain the flat field correction sub-model.
[0025] In some optional embodiments of the first aspect, the mapping relationship between the real shot luminance value of the arbitrary second pixel point of the gray scale color block in the first target image and the preset standard luminance reference value corresponding to the second pixel point is determined as the gamma correction sub-model, including:
[0026] For each of the gray scale color blocks, the actual brightness value of each of the second pixel points of the gray scale color block and the preset standard brightness value corresponding to the second pixel point are taken as second training data, and a polynomial of different orders is determined within a preset order range according to the second training data.
[0027] A mean square error sequence corresponding to the polynomial of different orders is determined, and a gradient value of the mean square error sequence is determined.
[0028] When the gradient value of the mean square error sequence is minimum or lower than a preset threshold value, the corresponding polynomial is taken as the gamma correction sub-model.
[0029] In combination with the first aspect, in some optional embodiments, determining the ratio relationship between the RGB value of any third pixel point of a gray scale color block in the second target image and the preset standard RGB value corresponding to the third pixel point in the RGB channel as the white balance correction sub-model includes:
[0030] For each gray scale color block, the ratio of the RGB value to the preset standard RGB value in the RGB channel is determined.
[0031] According to the ratio in the RGB channel of all gray scale color blocks, a diagonal matrix is constructed as the white balance correction sub-model.
[0032] In combination with the first aspect, in some optional embodiments, determining the mapping relationship between the RGB value of any fourth pixel point of a second target region in the third target image and the preset standard RGB value corresponding to the fourth pixel point as the color correction sub-model includes:
[0033] For each color block in the third target image, a plurality of fourth pixel points are randomly selected in the color block, and a set of the plurality of fourth pixel points is taken as the second target region.
[0034] The RGB value corresponding to each fourth pixel point in the second target region is obtained.
[0035] The RGB value corresponding to the plurality of fourth pixel points and the preset standard RGB value are taken as third training data, and a preset neural network is used to train the third training data to determine the mapping relationship between the RGB value of any fourth pixel point in the third target image and the preset standard RGB value corresponding to the fourth pixel point as the color correction sub-model.
[0036] In combination with the first aspect, in some optional embodiments, between acquiring the RGB value corresponding to each fourth pixel point in the second target region and taking the RGB value corresponding to the plurality of fourth pixel points and the preset standard RGB value as third training data, determining the mapping relationship between the RGB value of any fourth pixel point in the second target region in the third target image and the preset standard RGB value corresponding to the fourth pixel point as the color correction sub-model further comprises:
[0037] performing polynomial expansion on the RGB value to obtain a color feature set;
[0038] taking the RGB value corresponding to the plurality of fourth pixel points and the preset standard RGB value as third training data comprises:
[0039] taking the color feature set corresponding to the plurality of fourth pixel points and the preset standard RGB value as the third training data.
[0040] In combination with the first aspect, in some optional embodiments, determining the mapping relationship between the RGB value of any fourth pixel point in the second target region in the third target image and the preset standard RGB value corresponding to the fourth pixel point as the color correction sub-model comprises:
[0041] segmenting the third target image into a plurality of sub-images as second target regions by using a preset clustering algorithm;
[0042] taking the pixel point corresponding to the color center of each second target region as a fourth pixel point;
[0043] taking the RGB value corresponding to the fourth pixel point and the preset standard RGB value as third training data, training the third training data by using a preset neural network, and determining the mapping relationship between the RGB value of the fourth pixel point and the preset standard RGB value corresponding to the fourth pixel point in the third target image as the color correction sub-model.
[0044] In the second aspect, the embodiments of the present application further provide an electronic device, which comprises a processor and a memory coupled with each other, and the memory stores a computer program. When the computer program is executed by the processor, the electronic device performs the method described above.
[0045] In the third aspect, the embodiments of the present application further provide a computer program product comprising a computer program. When the computer program is executed by a processor, the computer program implements the method described above.
[0046] The application with the above technical solution has the following advantages:
[0047] In the technical scheme provided in the present application, firstly, a to-be-processed image is acquired. Then, a color correction model is used to perform flat field correction on the to-be-processed image to obtain a first intermediate image. Then, the color correction model is used to perform gamma correction on the first intermediate image to obtain a second intermediate image. Then, the color correction model is used to perform white balance correction on the second intermediate image to obtain a third intermediate image. Finally, the color correction model is used to perform color correction on the third intermediate image to obtain a target image. In this way, the flat field correction, the gamma correction, the white balance correction and the color correction are integrated in the same color correction model, so that the automatic, efficient and high-precision color correction of the image under a complex shooting environment is realized. The problem that the traditional color correction mode is too simplified, which leads to insufficient correction accuracy, especially in the area with high color saturation or complex light, and obvious color deviation is easily generated is improved. BRIEF DESCRIPTION OF DRAWINGS
[0048] The present application can be further illustrated by the non-limiting embodiments shown in the accompanying drawings. It should be understood that the following drawings only show some embodiments of the present application, and therefore should not be considered as limiting the scope, and for those skilled in the art, other related drawings can also be obtained without creative labor.
[0049] Figure 1 The structural block diagram of the electronic device provided for the embodiments of the present application is shown.
[0050] Figure 2 The flowchart of the color correction method provided for the embodiments of the present application is shown.
[0051] Figure 3 The training flowchart of the color correction model provided for the embodiments of the present application is shown.
[0052] Figure 4 The flowchart of the color correction method provided for the embodiments of the present application is shown.
[0053] Icon: 100-electronic device; 101-processor; 102-memory. DETAILED DESCRIPTION
[0054] The present application will be described in detail below with reference to the accompanying drawings and specific embodiments. It should be noted that in the drawings or description, similar or identical parts are denoted by the same reference numerals, and the implementation not shown or described in the drawings is in the form known to those skilled in the art. In the description of the present application, the terms "first", "second", etc. are only used for differentiation and description, and cannot be understood as indicating or implying relative importance.
[0055] Please refer to Figure 1This application provides an electronic device 100 that may include a processor 101 and a memory 102. The memory 102 stores a computer program, which, when executed by the processor 101, enables the electronic device 100 to perform the corresponding steps in the color correction method described below.
[0056] In this embodiment, the processor 101 can be an integrated circuit chip with signal processing capabilities. The processor 101 can be a general-purpose processor. For example, the processor 101 can be a central processing unit (CPU), a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components, capable of implementing or executing the methods, steps, and logic block diagrams disclosed in the embodiments of this application.
[0057] The memory 102 can be, but is not limited to, random access memory, read-only memory, programmable read-only memory, erasable programmable read-only memory, electrically erasable programmable read-only memory, etc. In this embodiment, the memory 102 can be used to store the image to be processed, the color correction model, the first intermediate image, the second intermediate image, the third intermediate image, the target image, the whiteboard image, the standard color chart image, the first target area, the first target image, the second target image, the third target image, the second target area, etc. Of course, the memory 102 can also be used to store a program, which the processor 101 executes after receiving an execution instruction.
[0058] Understandable, Figure 1 The electronic device 100 shown is only a schematic diagram; the electronic device 100 may also include components that are more... Figure 1 More components are shown. Figure 1 The components shown can be implemented using hardware, software, or a combination thereof.
[0059] Please refer to Figure 2 This application also provides a color correction method, which can be applied to the above-mentioned electronic device 100, and the electronic device 100 performs or implements the steps of the method. The color correction method may include the following steps:
[0060] Step 210: Obtain the image to be processed;
[0061] Step 220: Using a color correction model, perform flat-field correction on the image to be processed to obtain a first intermediate image;
[0062] Step 230: Using the color correction model, perform gamma correction on the first intermediate image to obtain the second intermediate image;
[0063] Step 240: Using the color correction model, perform white balance correction on the second intermediate image to obtain the third intermediate image;
[0064] Step 250: Using the color correction model, perform color correction on the third intermediate image to obtain a fourth intermediate image, which serves as the target image after color correction.
[0065] In the above implementation, the image to be processed is first acquired. Then, a color correction model is used to perform flat-field correction on the image to be processed, obtaining a first intermediate image. Next, the color correction model is used to perform gamma correction on the first intermediate image, obtaining a second intermediate image. Subsequently, the color correction model is used to perform white balance correction on the second intermediate image, obtaining a third intermediate image. Finally, the color correction model is used to perform color correction on the third intermediate image, obtaining a fourth intermediate image, which serves as the color-corrected target image. In this way, by integrating flat-field correction, gamma correction, white balance correction, and color correction into the same color correction model, automated, efficient, and high-precision color correction of real-world images under complex shooting environments is achieved. This improves upon traditional digital image color correction methods, which suffer from overly simplified models leading to insufficient color correction accuracy, especially in areas with high color saturation or complex lighting conditions where significant color casts are easily produced.
[0066] The steps of the color correction method will be explained in detail below:
[0067] Prior to step 210, the method may further include:
[0068] Step 201: Obtain the whiteboard image and the standard color chart image under the same shooting environment;
[0069] Step 202: Based on the whiteboard image, determine the mapping relationship between any first pixel in the first target region of the whiteboard image and the brightness gain multiplier corresponding to the first pixel as the flat field correction sub-model.
[0070] Step 203: Take the standard color card image after flat field correction by the flat field correction sub-model as the first target image, and determine the mapping relationship between the actual brightness value of any second pixel point of the grayscale color block in the first target image and the preset standard brightness reference value corresponding to the second pixel point as the gamma correction sub-model.
[0071] Step 204: The standard color chart image after gamma correction by the gamma correction sub-model is used as the second target image. The ratio of the RGB value of any third pixel of the grayscale color block in the second target image to the preset standard RGB value corresponding to the third pixel in the RGB channel is determined as the white balance correction sub-model.
[0072] Step 205: The standard color chart image after white balance correction by the white balance correction sub-model is used as the third target image. The mapping relationship between the RGB value of any fourth pixel in the second target region in the third target image and the preset standard RGB value corresponding to the fourth pixel is determined as the color correction sub-model.
[0073] In step 201, the whiteboard image (i.e., the white panel image) and the standard color chart image (i.e., the X-Rite standard 24-color chart image) can be acquired using devices with shooting capabilities, such as cameras or webcams. During the shooting process, the shooting conditions (including but not limited to ambient lighting and device parameters) for the whiteboard image and the standard color chart image are the same. There are no specific limitations on the acquisition methods for the whiteboard image and the standard color chart image here; they can be captured under the same shooting conditions and uploaded to the processor 101 to facilitate subsequent color correction model construction.
[0074] In step 202, based on the whiteboard image, the mapping relationship representing any first pixel in the first target region of the whiteboard image and the brightness gain multiplier corresponding to the first pixel is determined as the flat-field correction sub-model, which may include:
[0075] The white planar area in the whiteboard image is taken as the first target area. A brightness gain multiplier matrix is determined based on the brightness value of each first pixel in the first target area. Each element in the brightness gain multiplier matrix represents the reciprocal of the ratio of the brightness value of each first pixel to the target brightness value. The target brightness value represents the maximum brightness value corresponding to all pixels in the first target area.
[0076] The coordinates of each first pixel in the first target region and the brightness gain multiplier corresponding to the first pixel are used as the first training data. The first training data are trained by the partial least squares regression strategy to obtain an initial model that represents the mapping relationship between the first pixel and the brightness gain multiplier corresponding to the first pixel.
[0077] Using the initial model, predict the brightness gain multiplier corresponding to each pixel in the whiteboard image;
[0078] The luminance gain multiplier matrix is constructed based on the luminance gain multiplier corresponding to each pixel in the whiteboard image, thus obtaining the flat field correction sub-model.
[0079] In this embodiment, the first target region (i.e., the white plane region) can be determined by pre-labeling by the experimenter or by identification and extraction using a neural network (such as a convolutional neural network or a recurrent neural network) with white plane recognition capabilities. In practical applications, this embodiment uses the pre-trained target detection model YOLO to automatically identify and locate the white plane in the whiteboard image and extract its bounding box coordinates. Compared to traditional flat-field correction methods that require the entire image to be an ideal white field, this embodiment only requires the image to contain a recognizable white region, greatly reducing the requirements for the reference image.
[0080] After locating the white plane as the first target region, the luminance channel information (L-channel information) of this first target region is extracted. The reciprocal of the ratio of the luminance value of each pixel in the first target region to the maximum luminance value of all pixels in the first target region is calculated as the luminance gain multiplier corresponding to that pixel. Then, the matrix is filled sequentially according to the pixel coordinates to obtain the local luminance gain matrix. The coordinates of each pixel in the first target region are then used as input, and the corresponding luminance gain multiplier (represented as the local luminance gain matrix in practical applications) is used as output to construct the first training data. Partial least squares regression is then used to train the first training data to learn the nonlinear mapping function from pixel coordinates to luminance gain multipliers, obtaining an initial model. This initial model essentially fits a complex three-dimensional surface that describes the illumination distribution. Using the trained initial model, the coordinates of all pixels covering the entire original image size (i.e., the image size for which the user needs color correction) are predicted (extrapolated) to generate a global, high-resolution luminance gain multiplier matrix. This matrix is the final output model of this step, i.e., the flat-field correction sub-model. (In practical applications, this embodiment can also use support vector regression, multilayer perceptron, or other methods to train the first training data, so as to achieve the function of fitting the nonlinear mapping function from coordinates to brightness gain multiplier.)
[0081] Thus, flat field correction of images is achieved based on the flat field correction sub-model, solving the problem of spatial brightness non-uniformity caused by lens vignetting and uneven lighting in real shooting.
[0082] In step 203, determining the mapping relationship between the actual brightness value of any second pixel in the grayscale color block of the first target image and the preset standard brightness reference value corresponding to the second pixel as the gamma correction sub-model may include:
[0083] For each grayscale color block, the actual brightness value of each second pixel of the grayscale color block and the preset standard brightness value corresponding to the second pixel are used as the second training data. Based on the second training data, polynomials of different orders are determined within a preset order range.
[0084] Determine the mean square error sequence corresponding to the polynomials of different orders, and the gradient value of the mean square error sequence;
[0085] When the gradient value of the mean square error sequence is minimized, or when the gradient value is lower than a preset threshold, the corresponding polynomial is used as the gamma correction sub-model.
[0086] In this embodiment, grayscale color blocks (usually six neutral color blocks from white to black) are first identified and extracted from the first target image. The identification and extraction method of grayscale color blocks is the same as that of the white plane mentioned above, and will not be repeated here. Then, the brightness value (i.e., the actual brightness value) of each pixel in the grayscale color block is extracted. The actual brightness value of each pixel in the grayscale color block and the preset standard brightness value corresponding to the pixel (i.e., the brightness value of the same grayscale color block in the ideal state of a 24-color card image without color correction) are used as the second training data. By iteratively testing polynomial functions of different orders, the mapping relationship between the actual brightness value and the preset standard brightness value is fitted. By analyzing the gradient of the fitting error as the polynomial order changes, an optimal order that can best balance the fitting accuracy and model complexity is automatically selected (i.e., the polynomial order when the gradient value is the smallest, or the gradient value is lower than the preset threshold for the first time), and the polynomial under the optimal order is used as the gamma correction sub-model.
[0087] Thus, gamma correction of the image is achieved based on the gamma correction sub-model, thereby accurately linearizing the nonlinear photoelectric response of the imaging sensor.
[0088] In step 204, determining the ratio of the RGB value of any third pixel in a grayscale patch in the second target image to the preset standard RGB value corresponding to that third pixel in the RGB channel as the white balance correction sub-model may include:
[0089] For each grayscale color block, determine the ratio of the RGB value to the preset standard RGB value in the RGB channel;
[0090] Based on the ratios on the RGB channels of all grayscale color blocks, a diagonal matrix is constructed as the white balance correction sub-model.
[0091] In this embodiment, for each grayscale patch in the second target image, the RGB value of each pixel in the grayscale patch is extracted, and the ratio of the RGB value to the preset standard RGB value (i.e., the RGB value of the same grayscale patch in an ideal state without color correction in a 24-color chart image) in the R (red), G (green), and B (blue) channels is calculated. In this embodiment, to enhance robustness, the median of the channel ratios calculated for all grayscale patches can be taken to obtain the final R, G, and B channel gain factors. These three factors are constructed into a 3x3 diagonal matrix, which is the output model of this step, i.e., the white balance correction sub-model.
[0092] Thus, white balance correction of the image is achieved based on the white balance correction sub-model, thereby correcting the global color shift caused by the ambient light color temperature.
[0093] In step 205, determining the mapping relationship between the RGB value of any fourth pixel in the second target region of the third target image and the preset standard RGB value corresponding to the fourth pixel as the color correction sub-model may include:
[0094] For each color block in the third target image, multiple fourth pixels are randomly selected from the color block, and the set of the multiple fourth pixels is taken as the second target region;
[0095] Obtain the RGB value corresponding to each fourth pixel in the second target region;
[0096] The RGB values corresponding to the plurality of fourth pixels and the preset standard RGB values are used as third training data. The preset neural network is used to train the third training data to determine the mapping relationship between the RGB values of any fourth pixel and the preset standard RGB values corresponding to the fourth pixel in the third target image, which is used as the color correction sub-model.
[0097] In this embodiment, each color block (a total of 24 color blocks) in the third target image is first identified and extracted. The method of color block identification and extraction is the same as that of the white plane mentioned above, and will not be repeated here.
[0098] For each color patch (a total of 24 color patches) in the third target image, multiple pixels (flexibly set according to user needs, such as 40, 50, 60, etc., this embodiment uses 50 as an example) are sampled from the internal region of the color patch (to avoid edge effects) as the second target region, and the RGB value of each pixel in the second target region is extracted. Then, the RGB value of each pixel is used as input, and the corresponding preset standard RGB value of the pixel is used as output to construct the third training data. The third training data is then trained through a preset neural network (the preset neural network can be flexibly set according to user needs, this embodiment uses a multilayer perceptron neural network MLPRegressor as an example) to fit the mapping function between the RGB value of each pixel and the preset standard RGB value. The trained preset neural network is used as the final output model, that is, the color correction sub-model.
[0099] In this embodiment, instead of simply calculating the average value, the RGB values of multiple pixels within the color block are sampled as the basis for constructing training data. This allows for the acquisition of high-density training data that better represents the color distribution of the color block and contains noise and texture information. Subsequently, a neural network learns a complex mapping function from "real-world color" to "ideal standard color," achieving a higher precision color correction effect and accurately correcting various color distortions caused by sensor spectral response deviations.
[0100] As an optional implementation, in step 205, after sampling the RGB values corresponding to multiple pixels, the following can also be done:
[0101] Polynomial expansion of the RGB values yields a color feature set;
[0102] Using the RGB values corresponding to the plurality of fourth pixel points and the preset standard RGB values as the third training data, including:
[0103] The color feature set corresponding to the plurality of fourth pixel points and the preset standard RGB value are used as the third training data.
[0104] In this embodiment, after sampling the RGB values of multiple pixels, the RGB values can be multinomially expanded to obtain a color feature set. For example, this embodiment performs multinomial feature expansion on the RGB values of each sampled pixel. That is, the original 3 features are expanded into 10 features as the color feature set, including [1, R, G, B, R², G², B², R*G, R*B, G*B]. After the multinomial expansion, the color feature set corresponding to the pixel obtained by the multinomial expansion is used as input, and the preset standard RGB values are used as output to construct the third training data. In this way, the original color relationships are mapped to a higher-dimensional feature space, enabling the linear model to learn non-linear relationships.
[0105] As an optional implementation, in step 205, if the image quality is poor, and the color block identification and extraction in the aforementioned third target image, as well as the failure of the sampling method for the fourth pixel, are used, the mapping relationship between the RGB value of any fourth pixel in the second target region of the third target image and the preset standard RGB value corresponding to the fourth pixel is determined as the color correction sub-model. This may include:
[0106] Using a preset clustering algorithm, the third target image is segmented into multiple sub-images, with each sub-image serving as a second target region;
[0107] The pixel corresponding to the color center of each second target region is taken as the fourth pixel.
[0108] The RGB value corresponding to the fourth pixel and the preset standard RGB value are used as the third training data. The preset neural network is used to train the third training data to determine the mapping relationship between the RGB value of the fourth pixel and the preset standard RGB value corresponding to the fourth pixel in the third target image, which is used as the color correction sub-model.
[0109] In this embodiment, the preset clustering algorithm can be any algorithm with pixel clustering functionality. This embodiment uses the K-Means clustering algorithm as an example. Based on the K-Means clustering algorithm, 24 color blocks in the third target image are identified, thereby segmenting the image into 24 sub-images. Each sub-image is then used as a second target region. After region segmentation, the pixel corresponding to the color center identified by the K-Means clustering algorithm is taken as the fourth pixel. The RGB value corresponding to the fourth pixel is used as input, and the preset standard RGB value is used as output to construct the third training data. This avoids program interruptions due to image quality issues and improves the generalization ability of the technical solution presented in this application.
[0110] In summary, please refer to Figure 3 (The parameter acquisition in the figure refers to the preset data, model architecture, etc. in steps 201 to 205 mentioned above, which will not be elaborated here. Data extraction refers to the self-check of each parameter, which is a routine step in model training, and will not be elaborated here.) This application provides a color correction model, including a flat field correction sub-model, a gamma correction sub-model, a white balance correction sub-model, and a color correction sub-model, which are used to perform flat field correction, gamma correction, white balance correction, and color correction on the input image, respectively.
[0111] After completing the construction and training of the color correction model described above, please refer to... Figure 4 The specific applications of the color correction model are as follows:
[0112] In step 210, after loading the trained color correction model and performing a model self-check to ensure that the model is complete and has been trained, the image to be processed is acquired by the device under random shooting conditions.
[0113] In step 220, the image to be processed is converted to the CIE Lab space, and its L channel is multiplied at the pixel level with the flat field correction sub-model in the color correction model. Then the result is converted back to the original color space to obtain the first intermediate image after flat field correction.
[0114] In step 230, the polynomial function represented by the gamma correction sub-model is applied to the entire luminance (L) channel of the first intermediate image to obtain the second intermediate image after gamma correction.
[0115] In step 240, the white balance correction sub-model is applied to each pixel of the second intermediate image through matrix multiplication to obtain the intermediate image after white balance correction.
[0116] In step 250, for the image that needs correction, each pixel is also expanded using a polynomial feature model, and then input into the trained color correction sub-model for prediction, to obtain the final output image with fully corrected colors, which is the target image. To address the memory bottleneck that may arise from high-resolution large images, this step can use a block-based prediction method.
[0117] In summary, the technical solution proposed in this application significantly improves the accuracy of image color correction and its ability to fit nonlinear distortions. Specifically, this application abandons the overly simplistic linear models and fixed parameters used in traditional methods. In the color transformation stage, by introducing polynomial feature generation and machine learning regression models (such as neural networks), this application can learn and fit the highly complex nonlinear color mapping relationship generated by the combined effects of device and lighting from a higher dimension. Compared with traditional 3x3 color correction matrices or low-order polynomials, this application can more accurately correct nonlinear color deviations such as hue distortion and saturation compression, resulting in more realistic and accurate colors in the corrected image. In addition, this application enhances the adaptability of the color correction process and reduces its dependence on ideal conditions. Specifically, this application introduces an adaptive mechanism in the key stages of color correction. For example, in flat-field correction, machine learning surface fitting and interpolation can infer the global, non-linear illumination distribution from just a small white area in the image, eliminating the need for a demanding, perfectly white-field image that perfectly matches the scene. In gamma correction, by iteratively solving the optimal order polynomial, the most suitable response curve can be adaptively generated for different devices and shooting parameters, rather than using a fixed gamma value. This adaptability makes this application exhibit stronger robustness and stability in real-world application scenarios with varying lighting conditions, not in laboratory settings.
[0118] It should be noted that those skilled in the art will understand that, for the sake of convenience and brevity, the specific working process of the above-mentioned electronic device 100 can be referred to the corresponding process of each step in the aforementioned method, and will not be elaborated further here.
[0119] This application also provides a computer program product, including a computer program that, when executed by processor 101, implements the color correction method as described in the above embodiments.
[0120] Based on the above description of the embodiments, those skilled in the art can clearly understand that this application can be implemented by hardware or by using software plus necessary general-purpose hardware platforms. Based on this understanding, the technical solution of this application can be embodied in the form of a software product. The software product can be stored in a non-volatile storage medium (such as CD-ROM, USB flash drive, mobile hard drive, etc.) and includes several instructions to cause a computer device (such as a personal computer, server, or network device, etc.) to execute the methods described in the various implementation scenarios of this application.
[0121] In summary, this application provides a color correction method, electronic device, and program product. In this technical solution, an image to be processed is first acquired. Then, a color correction model is used to perform flat-field correction on the image to be processed, obtaining a first intermediate image. Next, the color correction model is used to perform gamma correction on the first intermediate image, obtaining a second intermediate image. Subsequently, the color correction model is used to perform white balance correction on the second intermediate image, obtaining a third intermediate image. Finally, the color correction model is used to perform color correction on the third intermediate image, obtaining a fourth intermediate image, which serves as the target image after color correction. Thus, by integrating flat-field correction, gamma correction, white balance correction, and color correction into the same color correction model, automated, efficient, and high-precision color correction of real-world images under complex shooting environments is achieved. This improves upon traditional digital image color correction methods, which suffer from overly simplified models leading to insufficient color correction accuracy, especially in areas with high color saturation or complex lighting conditions where significant color casts are easily produced.
[0122] In the embodiments provided in this application, it should be understood that the disclosed methods can also be implemented in other ways. The method embodiments described above are merely illustrative. For example, the flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of methods and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, program segment, or part of code, which includes one or more executable instructions for implementing a specified logical function. It should also be noted that each block in a block diagram and / or flowchart, and combinations of blocks in block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions. Furthermore, the functional modules in the various embodiments of this application can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.
[0123] The above description is merely an embodiment of this application and is not intended to limit the scope of protection of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of protection of this application.
Claims
1. A color correction method, characterized in that, The method includes: Obtain the image to be processed; Using a color correction model, the image to be processed is flat-field corrected to obtain a first intermediate image; Using the color correction model, gamma correction is performed on the first intermediate image to obtain the second intermediate image; Using the color correction model, the second intermediate image is white-balanced to obtain the third intermediate image; Using the color correction model, the third intermediate image is color corrected to obtain a fourth intermediate image, which serves as the target image after color correction.
2. The method according to claim 1, characterized in that, The color correction model includes a flat field correction sub-model, a gamma correction sub-model, a white balance correction model, and a color correction model; Prior to acquiring the image to be processed, the method further includes: Acquire images of a whiteboard and a standard color chart under the same shooting conditions; Based on the whiteboard image, the mapping relationship between any first pixel in the first target region of the whiteboard image and the brightness gain multiplier corresponding to the first pixel is determined as the flat field correction sub-model. The standard color chart image after flat field correction by the flat field correction sub-model is used as the first target image. The mapping relationship between the actual brightness value of any second pixel point of the grayscale color block in the first target image and the preset standard brightness reference value corresponding to the second pixel point is determined as the gamma correction sub-model. The standard color chart image after gamma correction by the gamma correction sub-model is used as the second target image. The ratio of the RGB value of any third pixel of the grayscale color block in the second target image to the preset standard RGB value corresponding to the third pixel in the RGB channel is determined as the white balance correction sub-model. The standard color chart image after white balance correction by the white balance correction sub-model is used as the third target image. The mapping relationship between the RGB value of any fourth pixel in the second target region in the third target image and the preset standard RGB value corresponding to the fourth pixel is determined as the color correction sub-model.
3. The method according to claim 2, characterized in that, Based on the whiteboard image, the mapping relationship between any first pixel in the first target region of the whiteboard image and the brightness gain multiplier corresponding to the first pixel is determined as the flat-field correction sub-model, including: The white planar area in the whiteboard image is taken as the first target area. A brightness gain multiplier matrix is determined based on the brightness value of each first pixel in the first target area. Each element in the brightness gain multiplier matrix represents the reciprocal of the ratio of the brightness value of each first pixel to the target brightness value. The target brightness value represents the maximum brightness value corresponding to all pixels in the first target area. The coordinates of each first pixel in the first target region and the brightness gain multiplier corresponding to the first pixel are used as the first training data. The first training data is trained by the partial least squares regression strategy to obtain an initial model that represents the mapping relationship between the first pixel and the brightness gain multiplier corresponding to the first pixel. Using the initial model, predict the brightness gain multiplier corresponding to each pixel in the whiteboard image; The luminance gain multiplier matrix is constructed based on the luminance gain multiplier corresponding to each pixel in the whiteboard image, thus obtaining the flat field correction sub-model.
4. The method according to claim 2, characterized in that, Determining the mapping relationship between the actual brightness value of any second pixel in a grayscale color block in the first target image and the preset standard brightness reference value corresponding to the second pixel as the gamma correction sub-model includes: For each grayscale color block, the actual brightness value of each second pixel of the grayscale color block and the preset standard brightness value corresponding to the second pixel are used as the second training data. Based on the second training data, polynomials of different orders are determined within a preset order range. Determine the mean square error sequence corresponding to the polynomials of different orders, and the gradient value of the mean square error sequence; When the gradient value of the mean square error sequence is minimized, or when the gradient value is lower than a preset threshold, the corresponding polynomial is used as the gamma correction sub-model.
5. The method according to claim 2, characterized in that, Determining the ratio of the RGB value of any third pixel in a grayscale patch in the second target image to the preset standard RGB value corresponding to that third pixel in the RGB channels as the white balance correction sub-model includes: For each grayscale color block, determine the ratio of the RGB value to the preset standard RGB value in the RGB channel; Based on the ratios on the RGB channels of all grayscale color blocks, a diagonal matrix is constructed as the white balance correction sub-model.
6. The method according to claim 2, characterized in that, Determining the mapping relationship between the RGB value of any fourth pixel in the second target region of the third target image and the preset standard RGB value corresponding to the fourth pixel as the color correction sub-model includes: For each color block in the third target image, multiple fourth pixels are randomly selected from the color block, and the set of the multiple fourth pixels is taken as the second target region; Obtain the RGB value corresponding to each fourth pixel in the second target region; The RGB values corresponding to the plurality of fourth pixels and the preset standard RGB values are used as third training data. The preset neural network is used to train the third training data to determine the mapping relationship between the RGB values of any fourth pixel and the preset standard RGB values corresponding to the fourth pixel in the third target image, which is used as the color correction sub-model.
7. The method according to claim 6, characterized in that, The process of determining a mapping relationship between the RGB value of any fourth pixel in the second target region and the preset standard RGB value, representing the mapping relationship between the RGB value of any fourth pixel in the second target region and the preset standard RGB value corresponding to the fourth pixel in the third target image, as the color correction sub-model, between acquiring the RGB value corresponding to each fourth pixel in the second target region and using the RGB values corresponding to the plurality of fourth pixels and the preset standard RGB value as the third training data, further includes: Polynomial expansion of the RGB values yields a color feature set; The RGB values corresponding to the plurality of fourth pixel points and the preset standard RGB values are used as the third training data, including: The color feature set corresponding to the plurality of fourth pixel points and the preset standard RGB value are used as the third training data.
8. The method according to claim 6, characterized in that, Determining the mapping relationship between the RGB value of any fourth pixel in the second target region of the third target image and the preset standard RGB value corresponding to the fourth pixel as the color correction sub-model includes: Using a preset clustering algorithm, the third target image is segmented into multiple sub-images, with each sub-image serving as a second target region; The pixel corresponding to the color center of each second target region is taken as the fourth pixel. The RGB value corresponding to the fourth pixel and the preset standard RGB value are used as the third training data. The preset neural network is used to train the third training data to determine the mapping relationship between the RGB value of the fourth pixel and the preset standard RGB value corresponding to the fourth pixel in the third target image, which is used as the color correction sub-model.
9. An electronic device, characterized in that, The electronic device includes a processor and a memory coupled together, the memory storing a computer program that, when executed by the processor, causes the electronic device to perform the method as described in any one of claims 1-8.
10. A computer program product, characterized in that, It includes a computer program that, when executed by a processor, implements the method as described in any one of claims 1-8.