Color correction method and device, electronic equipment and storage medium
By adjusting the white balance and performing weighted fitting on the color chart image, a target color correction matrix is generated, which solves the problem of low color correction accuracy in traditional color correction methods and achieves higher color correction accuracy and precision.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SHENZHEN SMARTMORE TECH CO LTD
- Filing Date
- 2022-11-02
- Publication Date
- 2026-04-21
AI Technical Summary
Traditional color correction methods have inconsistent levels of color reproduction across different colors, resulting in low color correction accuracy.
By adjusting the white balance of the actual color values of each color block in the color chart image, white balance color block values are generated. The color distance between the target color block and the non-target color block is calculated, the weight matrix is determined, and the color block values are weighted and fitted based on the weight matrix to generate the target color correction matrix, which is used to correct the color of the target image.
It improves the accuracy and precision of color correction, ensuring accurate restoration of the image after color correction.
Smart Images

Figure CN115965541B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of image technology, and in particular to a color correction method, apparatus, electronic device, and storage medium. Background Technology
[0002] With the development of image technology, color correction techniques have emerged. When correcting colors, two standard light sources with a certain color temperature difference are selected. Based on the true values of color chart images captured under different standard light source environments and the standard values of the color chart, color correction matrices corresponding to different standard light sources are obtained. When images are acquired under different ambient light sources, the color correction matrices corresponding to different standard light sources are interpolated to obtain the color correction matrix corresponding to the ambient light source. This ambient light source-specific color correction matrix is then used to perform color correction processing on the acquired images.
[0003] However, traditional color correction methods produce different degrees of correction and restoration for each color, resulting in varying degrees of error in the corrected colors and thus low accuracy in color correction. Summary of the Invention
[0004] Therefore, it is necessary to provide a color correction method, apparatus, electronic device, and computer-readable storage medium that can improve the accuracy of correction in order to address the above-mentioned technical problems.
[0005] Firstly, this application provides a color correction method. The method includes:
[0006] White balance adjustment is performed on the actual color block values of each color block in the color chart image to obtain the white balance color block values corresponding to each color block;
[0007] Based on the white balance color values corresponding to the target color block and the non-target color block in each color block, the color distance between the target color block and the non-target color block is determined, and the distance matrix is obtained;
[0008] Determine the weight matrix based on the distance matrix;
[0009] The white balance color block value and the standard color block value of each color block are weighted and fitted based on the weight matrix; the standard color block value is the standard printing value of each color block in the color card.
[0010] The target color correction matrix is generated based on the weighted fitting results; the target color correction matrix is used to perform color correction processing on the acquired target image.
[0011] In one embodiment, white balance adjustment is performed on the actual color patch values of each color patch in the color chart image to obtain the white balance color patch value corresponding to each color patch, including:
[0012] Select the specified color patch from the color patch of the color chart image for white balance adjustment;
[0013] Determine the white balance parameters corresponding to the color chart image based on the color swatch value of the specified color swatch in the color chart image;
[0014] Based on the white balance parameters corresponding to the color chart image, the actual color values of each color block in the color chart image are adjusted for white balance.
[0015] In one embodiment, a target color correction matrix corresponding to the target color patch is generated based on the weighted fitting result; the target color correction matrix is used to perform color correction processing on the captured target image, including:
[0016] Generate candidate color correction matrices corresponding to the target color patches based on the weighted fitting results;
[0017] The white balance values of each color block in the color block image are corrected based on the candidate color correction matrix, and the corrected white balance values are used as the new white balance values. The process then returns to the step of performing a weighted fitting of the white balance values of each color block and the standard color block values of each color block based on the weight matrix for iterative processing. The candidate color correction matrix corresponds to the white balance values of the color blocks after correction based on the candidate color correction matrix.
[0018] From the multiple candidate color correction matrices obtained through iterative processing, select the candidate color correction matrix corresponding to the white balance color block value that has the highest degree of fit with the standard color block value;
[0019] Based on the selected candidate color correction matrices, determine the target color correction matrix corresponding to the target color patch.
[0020] In one embodiment, a weighted fitting is performed on the white balance color patch value and the standard color patch value of each color patch based on a weight matrix, including:
[0021] Calculate the color difference between the white balance color patch value and the standard color patch value for the same color patch to obtain the color difference value corresponding to the color patch;
[0022] Calculate the weighted average of the color difference values corresponding to each color block based on the weight matrix;
[0023] Based on the weighted fitting results, a candidate color correction matrix is generated corresponding to the target color patch, including:
[0024] The corresponding candidate color correction matrix is determined based on the weighted average value;
[0025] From the multiple candidate color correction matrices obtained through iterative processing, the candidate color correction matrix corresponding to the white balance color patch value that best fits the standard color patch value is selected, including:
[0026] From the multiple candidate color correction matrices obtained through iterative processing, select the candidate color correction matrix that corresponds to the minimum weighted average value.
[0027] In one embodiment, there are multiple target color blocks; the method further includes:
[0028] For each pixel in the target image, calculate the distance between the pixel and each of the multiple target color patches;
[0029] Use the target color correction matrix corresponding to the target color block closest to the pixel as the color correction matrix of the pixel;
[0030] The color of each pixel is corrected using a color correction matrix.
[0031] In one embodiment, there are multiple color chart images; these multiple color chart images are images captured under different standard light sources; the same target color patch in the color chart images acquired under different standard light sources corresponds to different target color correction matrices; the target image is acquired under ambient light; the method further includes:
[0032] The color temperatures of the ambient light source and each standard light source were determined separately, resulting in multiple standard light source color temperatures and ambient light source color temperatures.
[0033] The interpolation weights are determined based on the color temperatures of multiple standard light sources and the ambient light source.
[0034] The target color correction matrix corresponding to the target color block under different standard light sources is calculated by weighting the interpolation weights to obtain the comprehensive color correction matrix corresponding to the target color block.
[0035] In one embodiment, the method further includes:
[0036] Determine the white balance parameters corresponding to each of the multiple color chart images;
[0037] The target white balance parameters are obtained by weighting each white balance parameter according to the interpolation weights.
[0038] The target image is color corrected based on the integrated color correction matrix and the target white balance parameters.
[0039] Secondly, this application also provides a color correction device. The device includes:
[0040] The white balance adjustment module is used to adjust the white balance of each color block in the color chart image to obtain the white balance color block value corresponding to each color block.
[0041] The determination module is used to determine the color distance between the target color block and the non-target color block based on the white balance color block values corresponding to the target color block and the non-target color block in each color block, and obtain a distance matrix; and determine a weight matrix based on the distance matrix.
[0042] The weighted fitting module is used to perform weighted fitting on the white balance color block value and the standard color block value of each color block based on the weight matrix; the standard color block value is the standard printing value of each color block in the color chart; and to generate the target color correction matrix corresponding to the target color block based on the weighted fitting result; the target color correction matrix is used to perform color correction processing on the acquired target image.
[0043] Thirdly, this application also provides an electronic device. The electronic device includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program to implement the steps of the method described above.
[0044] Fourthly, this application also provides a computer-readable storage medium. The computer-readable storage medium stores a computer program thereon, which, when executed by a processor, implements the steps of the above-described method.
[0045] The aforementioned color correction method, apparatus, electronic device, and storage medium adjust the white balance of each color block in a color chart image to obtain the white balance color block value corresponding to each color block; determine the color distance between the target color block and non-target color blocks based on the white balance color block values corresponding to the target and non-target color blocks respectively, obtaining a distance matrix; determine a weight matrix based on the distance matrix; perform a weighted fitting of the white balance color block value and the standard color block value of each color block based on the weight matrix; the standard color block value is the standard printing value of each color block in the color chart; generate a target color correction matrix corresponding to the target color block based on the weighted fitting result; the target color correction matrix is used to perform color correction processing on the acquired target image. When fitting the color correction matrix, the color distance between the non-target color block and the target color block is used as the weight for the weighted fitting, giving the determined target color correction matrix a distance optimization bias. Therefore, using the target color correction matrix to perform color correction on the image can improve the accuracy of color correction. Attached Figure Description
[0046] Figure 1 This is a diagram illustrating the application environment of the color correction method in one embodiment;
[0047] Figure 2 This is a flowchart illustrating a color correction method in one embodiment;
[0048] Figure 3 This is a flowchart illustrating the weighted fitting process in one embodiment;
[0049] Figure 4 This is a structural block diagram of a color correction device in one embodiment;
[0050] Figure 5 Here is a block diagram of the weighted fitting module in one embodiment;
[0051] Figure 6 This is a diagram of the internal structure of an electronic device in one embodiment;
[0052] Figure 7 This is a diagram of the internal structure of an electronic device in another embodiment. Detailed Implementation
[0053] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0054] The color correction method provided in this application embodiment can be applied to, for example... Figure 1 In the application environment shown, the image acquisition device 101 acquires an image of the color card 103 under a standard light source 104. The image acquisition device 101 then sends the acquired color card image to the electronic device 102. The electronic device 102 determines a color correction matrix based on the actual color block values of each color block in the received color card image and the standard color block values of each color block in the color card 103. The image acquisition device 101 then performs color correction processing on the acquired image based on the color correction matrix.
[0055] Specifically, electronic device 102 adjusts the white balance of each color block in the color chart image of color chart 103 to obtain the white balance color block value corresponding to each color block; electronic device 102 determines the color distance between the target color block and the non-target color block based on the white balance color block values corresponding to the target color block and the non-target color block respectively, and obtains a distance matrix. Electronic device 102 determines a weight matrix based on the distance matrix. Electronic device 102 performs weighted fitting on the white balance color block value and the standard color block value of each color block based on the weight matrix. Electronic device 102 generates a target color correction matrix corresponding to the target color block based on the weighted fitting result; the target color correction matrix is used to perform color correction processing on the target image acquired by image acquisition device 101.
[0056] It should be noted that the electronic device 102 can exist independently outside the image acquisition device 101 or be integrated into the image acquisition device 101. The color chart in the following method embodiments uses a 24-color chart as an example to illustrate this method embodiment. It should be understood that using a 24-color chart as an example is merely for explaining this application and is not intended to limit this application. Various color charts, such as 48-color charts, can be used as needed, and this embodiment does not impose any limitations on them.
[0057] In one embodiment, such as Figure 2 As shown, a color correction method is provided, which is applied to... Figure 1 Taking electronic device 102 as an example, the following steps are included:
[0058] Step 201: Adjust the white balance of the actual color block values of each color block in the color chart image to obtain the white balance color block values corresponding to each color block.
[0059] The color patch value refers to the red, green, and blue channel values of each color patch. The actual color patch value is the red, green, and blue channel values of each color patch in the captured color chart image. In other words, the actual color patch value is used to characterize the color of the color patch in the color chart image. For example, when the red, green, and blue channel values of a certain color patch in the color chart image are 255, 255, and 255 respectively, we know that the color of this color patch is white.
[0060] White balance color values are the values obtained after adjusting the white balance of the actual color swatches. In essence, adjusting the white balance of the actual color swatches restores the true colors of the color chart image.
[0061] Specifically, under standard light source, the image acquisition device captures an image of the color chart and sends the captured image to the electronic device. The electronic device determines the white balance parameters based on the color values of specified color patches in the color chart image, and multiplies the red, green, and blue channel values of all color patches in the color chart image with the white balance parameters to obtain the white balance adjusted color patch values, i.e., the white balance color patch values.
[0062] It should be noted that the color chart image is an image obtained by an image acquisition device from the color chart. Therefore, the types, quantities, and relative positions of the color blocks in the color chart image are the same as those in the color chart.
[0063] In some embodiments, the average value of the red, green and blue channels of each pixel in the central region of each color block in the color chart image is taken as the actual color block value of each color block.
[0064] Step 202: Determine the color distance between the target color block and the non-target color block based on the white balance color block values corresponding to the target color block and the non-target color block in each color block, and obtain the distance matrix.
[0065] Here, the target color patch is a color patch selected from the color chart image to determine the color correction matrix. That is, the color correction matrix determined by the target color patch is used to correct the colors of color patches that are close to the target color patch. It can be understood that one color patch represents one color.
[0066] Non-target color patches are the remaining color patches in a color chart image, excluding the target color patch. In other words, non-target color patches are only used to represent the remaining color patches in a color chart image, excluding the target color patch.
[0067] Color distance refers to the difference between two colors. The greater the distance, the greater the difference between the two colors, meaning the lower their similarity. Conversely, the smaller the distance, the closer the two colors are, meaning the higher their similarity. In other words, the similarity between two colors is positively correlated with color distance.
[0068] The color distance matrix is a matrix composed of the color distances between the target color patch and each non-target color patch. In other words, the color distance matrix reflects the similarity distribution between each non-target color patch and the target color patch.
[0069] Specifically, the electronic device can multiply the color values of the target color patch and the non-target color patch by white balance parameters to obtain the white balance color values corresponding to the target color patch and the non-target color patch, respectively. The electronic device can then convert these white balance color values into specific color parameters for a specific color space. Finally, based on these specific color parameters, the electronic device can calculate the color distance between the target and non-target color patches, obtaining a distance matrix.
[0070] In some embodiments, the specific color space is the CIE xyY color space, and the corresponding specific color parameters are xy (chroma) and Y (luminance). The white balance color swatch values corresponding to the target color swatch and the non-target color swatch are respectively converted to their corresponding xy and Y values in the CIE xyY color space. The Euclidean distance between the xy values of the target color swatch and the non-target color swatch is calculated as the color distance between the target color swatch and the non-target color swatch.
[0071] In some embodiments, the target color patch is the 13th color patch in the 24-color chart, and the Euclidean distance between the xy values of each non-target color patch and the xy values of the 13th color patch is used as the distance matrix corresponding to the 13th color patch. 13 The Euclidean distance formula used is as follows:
[0072]
[0073] in, ccmean is the Euclidean distance between the i-th non-target color block and the 13th color block, where i ranges from [1, 24]. xy13 It is the xy value of color block number 13, ccmean. xyi It is the xy value of the i-th non-target color block.
[0074] Step 203: Determine the weight matrix based on the distance matrix.
[0075] The weight matrix includes multiple weights, each corresponding to a different non-target color patch. These weights characterize the degree of influence of each non-target color patch on the target color correction matrix during the weighted fitting process. It can be understood that the magnitude of a weight in the weight matrix is negatively correlated with the color distance in the distance matrix. That is, the smaller the color distance between a non-target color patch and the target color patch, the larger the weight corresponding to that non-target color patch, and therefore the greater its influence on the target color correction matrix. Conversely, the larger the color distance between a non-target color patch and the target color patch, the smaller the weight corresponding to that non-target color patch, and therefore the smaller its influence on the target color correction matrix.
[0076] In other words, the target color correction matrix has higher accuracy in color correction for non-target color blocks that are closer to the target color block in terms of color distance.
[0077] Specifically, the electronic device determines the weight matrix based on the color distances between the target color block and each non-target color block in the distance matrix.
[0078] In some embodiments, color block 13 is the target color block, and the weights of color block 13 and each non-target color block are calculated using the following formula to obtain the weight matrix.
[0079]
[0080] Among them, ccmweight 13 It is the weight matrix of color block number 13, and the value of i ranges from [1, 24].
[0081] Step 204: Perform a weighted fitting of the white balance color block value and the standard color block value of each color block based on the weight matrix; the standard color block value is the standard printing value of each color block in the color card.
[0082] The standard color swatch value is the standard printing value of the red, green, and blue channels for each color swatch in the color chart. In other words, the standard color swatch value can be calculated theoretically.
[0083] Specifically, the electronic device calculates a weighted average of the color difference values for each color block based on the white balance color block value and the standard color block value of each color block, as well as the weight matrix. An optimization algorithm is then used to perform a weighted fitting based on the weighted average to obtain the color correction matrix.
[0084] Step 205: Generate the target color correction matrix corresponding to the target color block based on the weighted fitting result; the target color correction matrix is used to perform color correction processing on the acquired target image.
[0085] The target color correction matrix is the color correction matrix corresponding to the target color patch. In other words, the target color correction matrix has higher accuracy for non-target color patches whose color distance from the target color patch is smaller.
[0086] The target image is an image that requires color correction. That is, the target image needs to be color corrected using a target color correction matrix.
[0087] Specifically, the electronic device performs color correction on the white balance color patch values of each color patch based on the weighted fitting color correction matrix, and then executes step 204 again to obtain a new color correction matrix. The target color correction matrix is determined based on the degree of fit between the color-corrected white balance color patch values and the standard color patch values.
[0088] It should be noted that the determined target color correction matrix can be stored in the image acquisition device. When the image acquisition device subsequently acquires images, it uses the target color correction matrix to perform color correction processing on the acquired images.
[0089] In the aforementioned color correction method, white balance adjustments are made to the actual color values of each color block in the color chart image to obtain the corresponding white balance color block value. Based on the white balance color block values corresponding to the target and non-target color blocks in each color block, the color distance between the target and non-target color blocks is determined, resulting in a distance matrix. A weight matrix is then determined based on the distance matrix. A weighted fitting is performed on the white balance color block value and the standard color block value of each color block based on the weight matrix. The standard color block value is the standard printing value of each color block in the color chart. A target color correction matrix corresponding to the target color block is generated based on the weighted fitting result. The target color correction matrix is used to perform color correction processing on the acquired target image. When fitting the color correction matrix, the color distance between the non-target color block and the target color block is used as the weight for the weighted fitting, giving the determined target color correction matrix a distance optimization bias. Therefore, using the target color correction matrix to perform color correction on the image can improve the accuracy and precision of color correction.
[0090] In one embodiment, adjusting the white balance of the actual color block values of each color block in the color chart image to obtain the white balance color block value corresponding to each color block includes: selecting a specified color block for white balance adjustment from the color blocks in the color chart image; determining the white balance parameter corresponding to the color chart image based on the color block value of the specified color block in the color chart image; and adjusting the white balance of the actual color block values of each color block in the color chart image based on the white balance parameter corresponding to the color chart image.
[0091] The designated color swatch is a specific color swatch within the color chart image. This designated color swatch is used to adjust the white balance of the color chart image.
[0092] Specifically, the electronic device selects a specified color patch from the color swatch image and determines the patch value (i.e., red, green, and blue channel values) of that patch in the color swatch image. Using the green channel value as a reference, it determines the proportional relationship between the red and green channel values, as well as the proportional relationship between the blue and green channel values. Based on these proportional relationships, it determines the white balance parameters corresponding to the color swatch image. Finally, it multiplies the actual patch value of each color patch in the color swatch image by the white balance parameters to obtain the adjusted patch value, i.e., the white balance patch value.
[0093] In some embodiments, the white balance parameters corresponding to the color chart image are determined using the following formula.
[0094]
[0095] Among them, R gain It is the red channel value of the specified color block, G gain It is the green channel value of the specified color block, B gain R is the blue channel value of the specified color block, and G and B are the red channel value, green channel value and blue channel value of the specified color block, respectively.
[0096] In some embodiments, color patch 22 in the 24-color chart is selected as the designated color patch. For example, if the red, green and blue channel values of color patch 22 are 45, 90 and 180 respectively, then the white balance parameter is [2, 1, 0.5].
[0097] In the above embodiments, white balance processing is performed by selecting a specified color block from the color blocks of the color chart image, which is simple and convenient.
[0098] In one embodiment, a target color correction matrix corresponding to the target color patch is generated based on the weighted fitting result. The target color correction matrix is used to perform color correction processing on the captured target image, including: generating a candidate color correction matrix corresponding to the target color patch based on the weighted fitting result; correcting the white balance color patch value of each color patch in the color patch image based on the candidate color correction matrix, and using the corrected white balance color patch value as the new white balance color patch value, and returning to perform the step of weighted fitting of the white balance color patch value and the standard color patch value of each color patch based on the weight matrix for iterative processing; the candidate color correction matrix corresponds to the white balance color patch value after correction based on the candidate color correction matrix; from the multiple candidate color correction matrices obtained by iterative processing, the candidate color correction matrix corresponding to the white balance color patch value with the highest fitting degree to the standard color patch value is selected; and the target color correction matrix corresponding to the target color patch is determined according to the selected candidate color correction matrix.
[0099] The candidate color correction matrix is generated during the weighted fitting process of the white balance color patch values and the standard color patch values of each color patch based on the weight matrix. In other words, each weighted fitting generates a color correction matrix, i.e., a candidate color correction matrix. It can be understood that to find the candidate color correction matrix corresponding to the white balance color patch value with the highest degree of fit to the standard color patch value, multiple weighted fittings are performed, resulting in multiple candidate color correction matrices.
[0100] Specifically, the electronic device corrects the white balance values of each color block in the color patch image based on the candidate color correction matrix, and uses the corrected white balance values as the new white balance values. That is, the white balance values of each color block in the color patch image are multiplied by the candidate color correction matrix to obtain the corrected white balance values of each color block. Then, the corrected white balance values of each color block are iteratively fitted with the standard color patch values of each color block to obtain multiple candidate color correction matrices. From the multiple candidate color correction matrices obtained by the iterative process, the candidate color correction matrix corresponding to the white balance value with the highest degree of fit to the standard color patch value, that is, the smallest overall color difference, is selected as the target color correction matrix corresponding to the target color patch, and the iterative process stops.
[0101] In some embodiments, when the weighted average of the color difference values between the white balance color block value and the standard color block value of each color block in the color block image corrected by the candidate color correction matrix reaches the color difference threshold, that is, when the overall color difference is the minimum, the iterative processing is stopped, and the candidate color correction matrix corresponding to the white balance color block value is used as the target color correction matrix corresponding to the target color block.
[0102] In some embodiments, when the difference between the white balance color block value of each color block in the color block image corrected by the candidate color correction matrix obtained from two iterations and the weighted average of the color difference values of the standard color block value is less than a preset difference, that is, when the overall color difference is the minimum, the iteration process is stopped, and the candidate color correction matrix obtained from the last iteration process is used as the target color correction matrix.
[0103] In some embodiments, training stops when the number of iterations exceeds a set maximum number. From the multiple candidate color correction matrices obtained by the iteration process, the candidate color correction matrix corresponding to the white balance color block value with the smallest overall color difference from the standard color block value is selected as the target color correction matrix corresponding to the target color block.
[0104] In some embodiments, such as Figure 3 The diagram shown illustrates a weighted fitting process. The following section addresses... Figure 3 Provide a detailed explanation.
[0105] S1. Adjust the white balance of each color block in the color chart image according to its actual value.
[0106] S2. Convert the white balance color block value and the standard color block value of each color block into the color parameter value corresponding to the L*a*b color space respectively; where L represents brightness, a represents the component from green to red, and b represents the component from blue to yellow.
[0107] S3. Based on the weight matrix, perform weighted fitting of the white balance color block value and the standard color block value of each color block.
[0108] S4. When the optimization algorithm is stable, the target color correction matrix is obtained.
[0109] S5. When the optimization algorithm is unstable, the candidate color matrix is obtained.
[0110] In the above embodiments, multiple weighted fittings are performed based on the weight matrix to obtain multiple candidate color correction matrices. The target color correction matrix is selected from the multiple candidate color correction matrices. Therefore, when the target color correction matrix is used to correct the color of the image, the accuracy of color correction can be improved.
[0111] In one embodiment, a weighted fitting is performed on the white balance color block value and the standard color block value of each color block based on a weight matrix, including: calculating the color difference between the white balance color block value and the standard color block value of the same color block to obtain the color difference value corresponding to the color block; calculating the weighted average of the color difference values corresponding to each color block according to the weight matrix; generating a candidate color correction matrix corresponding to the target color block based on the weighted fitting result, including: determining the corresponding candidate color correction matrix according to the weighted average; selecting the candidate color correction matrix corresponding to the white balance color block value with the highest fitting degree to the standard color block value from multiple candidate color correction matrices obtained by iterative processing, including: selecting the candidate color correction matrix corresponding to the minimum weighted average from multiple candidate color correction matrices obtained by iterative processing.
[0112] Specifically, the electronic device calculates the color difference between the white balance color patch value and the standard color patch value for the same color patch. Based on a weight matrix, the electronic device performs a weighted average summation of the color difference values for each color patch, obtaining a weighted average. That is, when performing the weighted average summation, non-target color patches with smaller color distances from the target color patch have a larger weight in the weighted average summation. Conversely, non-target color patches with larger color distances from the target color patch have a smaller weight in the weighted average summation. The electronic device iteratively processes the weighted average summation to obtain multiple candidate color correction matrices. When the weighted average of the color difference values between the white balance color patch value and the standard color patch value for each color patch in the color patch image corrected by the candidate color correction matrix reaches its minimum, the candidate color correction matrix corresponding to the minimum weighted average summation is selected.
[0113] In the above embodiments, the color correction matrix with the smallest weighted average color difference of each color block is selected as the candidate color correction matrix corresponding to the target color block, which is both simple and accurate.
[0114] In one embodiment, there are multiple target color blocks; the method further includes: for each pixel in the target image, calculating the distance between the pixel and each of the multiple target color blocks; using the target color correction matrix corresponding to the target color block closest to the pixel as the color correction matrix of the pixel; and performing color correction on the pixel using the color correction matrix of the pixel.
[0115] Specifically, when there are multiple target color patches, there are also multiple target color correction matrices corresponding to each target color patch; that is, one target color patch corresponds to one target color correction matrix. When performing color correction on a target image, the electronic device determines the color distance between each pixel in the target image and each target color patch. The target color correction matrix corresponding to the target color patch with the smallest color distance to the pixel (i.e., the target color patch most similar in color to the pixel) is used as the pixel's color correction matrix. The electronic device performs color correction on the pixels using the pixel's color correction matrix; in other words, it performs color correction on the target image.
[0116] It's understandable that a target image contains multiple pixels of different colors. When the same color correction matrix is used to correct multiple pixels, the degree of color restoration for each pixel varies, resulting in a discrepancy between the corrected pixel color and the true color. Therefore, selecting the target color correction matrix corresponding to the target color block with the smallest color distance from the pixel and using it to correct the pixel achieves higher accuracy in pixel color restoration.
[0117] In the above embodiments, the target color correction matrix corresponding to the target color block that is most similar to the color of the pixel is selected for correction, so that the color restoration accuracy of the pixel is higher.
[0118] In one embodiment, there are multiple color chart images; these multiple color chart images are images captured under different standard light sources; the same target color patch in the color chart images acquired under different standard light sources corresponds to different target color correction matrices; the target image is acquired under ambient light; the method further includes: determining the color temperature of the ambient light source and each standard light source respectively to obtain multiple standard light source color temperatures and ambient light source color temperatures; determining interpolation weights based on the multiple standard light source color temperatures and ambient light source color temperatures; and performing weighted calculations on the target color correction matrices corresponding to the target color patch under different standard light sources based on the interpolation weights to obtain the comprehensive color correction matrix corresponding to the target color patch.
[0119] Specifically, the electronic device determines different target color correction matrices corresponding to the same target color patch under different standard light sources, and determines the color temperature under different standard light sources and the color temperature under ambient light. The electronic device determines the interpolation weights based on the color temperatures of multiple standard light sources, the ambient light color temperature, and the interpolation weight formula. When acquiring a target image under ambient light, the target color correction matrices corresponding to the target color patch under different standard light sources are weighted according to the interpolation weights to obtain the comprehensive color correction matrix corresponding to the target color patch. In some embodiments, the color patch value of a specified color patch under the light source is first determined, and then the white balance parameters are determined based on the color patch value of the specified color patch, and the white balance parameters are converted into color temperature.
[0120] In some embodiments, under standard laboratory lighting conditions, two light sources with a certain color temperature difference are selected as standard light sources, such as A-light (2800K) and D65 light (6500K), and color patch 22 from the 24-color chart is selected as the designated color patch. The color temperature (CCT) of A-light is obtained by calculating the color patch value of color patch 22 using the following formula. 2800k Color temperature CCT of D65 light 6500k .
[0121] CCT=-449n3+3525n2-6823.3*n+5520.33
[0122]
[0123] Where cct is the color temperature, and x and y are the color values of the specified color patch in the CIE xyY color space (chromaticity).
[0124] In some embodiments, when acquiring a target image under ambient light, the interpolation weight α is calculated using the following interpolation weight formula.
[0125]
[0126] Among them, CCT env It is the color temperature under ambient light.
[0127] In some embodiments, the target color patches are color patches 13 (red), 14 (green), and 15 (blue) from a 24-color chart. When acquiring the target image under ambient light, the target color correction matrix corresponding to the target color patches under different standard light sources is calculated using the following interpolation formula to obtain the comprehensive color correction matrix corresponding to the target color patches. It should be noted that the same target color patch corresponds to different target color correction matrices under different standard light sources; that is, when there are three standard light sources, the same target color patch corresponds to three different target color correction matrices.
[0128] CCM 13-env =α*CCM 13-2800k +(1-α)*CCM 13-6500k
[0129] CCM 14-env =α*CCM 14-2800k +(1-α)*CCM 14-6500k
[0130] CCM 15-env =α*CCM 15-2800k +(1-α)*CCM 15-6500k
[0131] Among them, CCM 13-env This is the color correction matrix corresponding to color swatch #13 under ambient light.
[0132] CCM 13-2800k It is the color correction matrix corresponding to color patch 13 under standard light source A (2800K);
[0133] CCM 13-6500k It is the color correction matrix corresponding to color patch #13 under standard light source D65 light (6500K);
[0134] CCM 14-env This is the color correction matrix corresponding to color swatch #14 under ambient light.
[0135] CCM 14-2800k It is the color correction matrix corresponding to color patch 14 under standard light source A (2800K);
[0136] CCM 14-6500k It is the color correction matrix corresponding to color patch 14 under standard light source D65 light (6500K);
[0137] CCM 15-env This is the color correction matrix corresponding to color swatch #15 under ambient light.
[0138] CCM 15-2800k It is the color correction matrix corresponding to color patch 15 under standard light source A (2800K);
[0139] CCM 15-6500k It is the color correction matrix corresponding to color patch 15 under standard light source D65 light (6500K).
[0140] In the above embodiments, when color correction is performed on the target image acquired under ambient light, a comprehensive color correction matrix is obtained by weighting the different color correction matrices of the target color blocks under different standard light sources. The comprehensive color correction matrix is then used to correct the color of the target image, making the color of the corrected target image closer to the true color of the target image.
[0141] In one embodiment, the method further includes: determining white balance parameters corresponding to multiple color chart images respectively; performing weighted calculations on each white balance parameter according to interpolation weights to obtain target white balance parameters; and performing color correction processing on the target image based on the comprehensive color correction matrix and the target white balance parameters.
[0142] The target white balance parameter is the white balance parameter corresponding to the ambient light source. It can be understood that white balance affects color reproduction. Therefore, when performing color correction on a target image, it is necessary to determine the white balance parameter under the ambient light source.
[0143] Specifically, white balance parameters under different standard light sources and under ambient light sources are determined. These parameters are then weighted according to interpolation weights to obtain the target white balance parameters. Finally, based on the comprehensive color correction matrix and the target white balance parameters, color correction processing is performed on the target image. That is, each pixel in the target image is sequentially multiplied by the target white balance parameters and the comprehensive color correction matrix to obtain the color-corrected target image.
[0144] It is understood that the color temperature under ambient light is determined by the color patch value of a specified color patch. For details on how to determine the white balance parameters based on the color patch value, please refer to the above embodiment; this embodiment will not repeat the details here.
[0145] In some embodiments, the target color blocks are color blocks No. 13 (red), No. 14 (green), and No. 15 (blue) in a 24-color chart. The target white balance parameters are obtained by weighting each white balance parameter using the following interpolation formula.
[0146] ccmean 13-env =α*ccmean 13-2800k+ (1-α)*ccmean 13-6500k
[0147] ccmean 14-env =α*ccmean 14-2800k +(1-α)*ccmean 14-6500k
[0148] ccmean 15-env =α*ccmean 15-2800k +(1-α)*ccmean 15-6500k
[0149] Where, ccmean 13-env These are the white balance parameters for color swatch #13 under ambient light.
[0150] ccmean 13-2800k These are the white balance parameters for color patch #13 under standard light source A (2800K);
[0151] ccmean 13-6500k These are the white balance parameters for color patch #13 under standard light source D65 light (6500K);
[0152] ccmean 14-env These are the white balance parameters for color swatch #14 under ambient light.
[0153] ccmean 14-2800k These are the white balance parameters for color patch #14 under standard light source A (2800K);
[0154] ccmean 14-6500k These are the white balance parameters for color patch #14 under standard light source D65 light (6500K);
[0155] ccmean 15-env These are the white balance parameters for color swatch #15 under ambient light.
[0156] ccmean 15-2800kThese are the white balance parameters for color patch #15 under standard light source A (2800K);
[0157] ccmean 15-6500k These are the white balance parameters for color patch #15 under standard light source D65 light (6500K).
[0158] In the above embodiments, when color correction is performed on the target image acquired under ambient light, the target white balance parameters are obtained by weighting the white balance parameters under different standard light sources. The target image is then color corrected using the comprehensive color correction matrix and the target white balance parameters, resulting in higher accuracy and fidelity of the corrected color.
[0159] It should be understood that although the steps in the flowcharts of the embodiments described above are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the embodiments described above may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages of other steps.
[0160] Based on the same inventive concept, this application also provides a color correction apparatus for implementing the color correction method described above. The solution provided by this apparatus is similar to the implementation described in the above method; therefore, the specific limitations in one or more color correction apparatus embodiments provided below can be found in the limitations of the color correction method described above, and will not be repeated here.
[0161] In one embodiment, such as Figure 4 As shown, a color correction device is provided, including: a white balance adjustment module 401, a determination module 402, and a weighted fitting module 403, wherein:
[0162] The white balance adjustment module 401 is used to adjust the white balance of each color block in the color chart image to obtain the white balance color block value corresponding to each color block.
[0163] The determining module 402 is used to determine the color distance between the target color block and the non-target color block based on the white balance color block values corresponding to the target color block and the non-target color block in each color block, and obtain a distance matrix; and determine a weight matrix based on the distance matrix.
[0164] The weighted fitting module 403 is used to perform weighted fitting on the white balance color block value and the standard color block value of each color block based on the weight matrix; the standard color block value is the standard printing value of each color block in the color card; and to generate a target color correction matrix corresponding to the target color block based on the weighted fitting result; the target color correction matrix is used to perform color correction processing on the acquired target image.
[0165] In one embodiment, the white balance adjustment module 401 is used to select a specified color block for white balance adjustment from the color blocks in the color card image; determine the white balance parameter corresponding to the color card image based on the color block value of the specified color block in the color card image; and adjust the white balance of the actual color block value of each color block in the color card image based on the white balance parameter corresponding to the color card image.
[0166] In one embodiment, the weighted fitting module 403 is used to generate a candidate color correction matrix corresponding to the target color block based on the weighted fitting result; correct the white balance color block value of each color block in the color block image based on the candidate color correction matrix, and use the corrected white balance color block value as the new white balance color block value, and return to perform the step of weighted fitting of the white balance color block value and the standard color block value of each color block based on the weight matrix for iterative processing; the candidate color correction matrix corresponds to the white balance color block value after correction based on the candidate color correction matrix; from the multiple candidate color correction matrices obtained by iterative processing, the candidate color correction matrix corresponding to the white balance color block value with the highest degree of fitting to the standard color block value is selected; and the target color correction matrix corresponding to the target color block is determined according to the selected candidate color correction matrix.
[0167] In one embodiment, the weighted fitting module 403 includes:
[0168] The calculation unit 403a is used to calculate the color difference between the white balance color block value and the standard color block value of the same color block, and obtain the color difference value corresponding to the color block; and calculate the weighted average value of the color difference value corresponding to each color block according to the weight matrix.
[0169] The determination unit 403b is used to determine the corresponding candidate color correction matrix based on the weighted average value.
[0170] Selection unit 403c is used to select a candidate color correction matrix corresponding to the minimum weighted average value from multiple candidate color correction matrices obtained by iterative processing.
[0171] In one embodiment, the weighted fitting module 403 is used to calculate the distance between each pixel in the target image and each of the multiple target color patches; and to use the target color correction matrix corresponding to the target color patch closest to the pixel as the color correction matrix of the pixel.
[0172] The color of each pixel is corrected using a color correction matrix.
[0173] In one embodiment, the weighted fitting module 403 is used to determine the color temperature of the ambient light source and each standard light source respectively, to obtain multiple standard light source color temperatures and ambient light source color temperatures; to determine interpolation weights based on the multiple standard light source color temperatures and ambient light source color temperatures; and to perform weighted calculations on the target color correction matrix corresponding to the target color block under different standard light sources based on the interpolation weights, to obtain the comprehensive color correction matrix corresponding to the target color block.
[0174] In one embodiment, the weighted fitting module 403 is used to determine the white balance parameters corresponding to the multiple color chart images respectively; to perform weighted calculation on each white balance parameter according to the interpolation weight to obtain the target white balance parameter; and to perform color correction processing on the target image based on the comprehensive color correction matrix and the target white balance parameter.
[0175] Each module in the aforementioned color correction device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in the processor of the electronic device in hardware form or independent of it, or stored in the memory of the electronic device in software form, so that the processor can call and execute the corresponding operations of each module.
[0176] In one embodiment, an electronic device is provided, which may be a server, and its internal structure diagram may be as follows: Figure 6 As shown, this electronic device includes a processor, memory, and a network interface connected via a system bus. The processor provides computing and control capabilities. The memory includes a non-volatile storage medium and internal memory. The non-volatile storage medium stores an operating system, computer programs, and a database. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage medium. The database stores color correction data. The network interface communicates with external terminals via a network connection. When the computer program is executed by the processor, it implements a color correction method.
[0177] In one embodiment, an electronic device is provided, which may be a terminal, and its internal structure diagram may be as follows: Figure 7As shown, the electronic device includes a processor, memory, and a communication interface connected via a system bus. The processor provides computing and control capabilities. The memory includes a non-volatile storage medium and internal memory. The non-volatile storage medium stores the operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage medium. The communication interface is used for wired or wireless communication with external terminals; wireless communication can be achieved through Wi-Fi, mobile cellular networks, NFC (Near Field Communication), or other technologies. When executed by the processor, the computer program implements a color correction method.
[0178] Those skilled in the art will understand that Figure 7 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the electronic device to which the present application is applied. The specific electronic device may include more or fewer components than shown in the figure, or combine certain components, or have different component arrangements.
[0179] In one embodiment, an electronic device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps in the above-described method embodiments.
[0180] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed by a processor, implements the steps in the above method embodiments.
[0181] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, etc., and are not limited to these.
[0182] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0183] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.
Claims
1. A color correction method, characterized in that, The method includes: White balance adjustment is performed on the actual color block values of each color block in the color chart image to obtain the white balance color block values corresponding to each color block; Based on the white balance color block values corresponding to the target color block and the non-target color block in each color block, the color distance between the target color block and the non-target color block is determined, and a distance matrix is obtained; A weight matrix is determined based on the distance matrix; the magnitude of the weights in the weight matrix is negatively correlated with the magnitude of the color distances in the distance matrix. Calculate the color difference between the white balance color block value and the standard color block value for the same color block to obtain the color difference value corresponding to the color block; calculate the weighted average of the color difference values corresponding to each color block according to the weight matrix; the standard color block value is the standard printing value of each color block in the color chart; The corresponding candidate color correction matrix is determined based on the weighted average value; the white balance color block values of each color block in the color block image are corrected based on the candidate color correction matrix, and the corrected white balance color block values are used as the new white balance color block values. The process of calculating the color difference between the white balance color block value and the standard color block value of the same color block is then performed to obtain the color difference value corresponding to the color block; the step of calculating the weighted average value of the color difference value corresponding to each color block based on the weight matrix is iteratively processed; the candidate color correction matrix corresponds to the white balance color block values after correction based on the candidate color correction matrix; From the multiple candidate color correction matrices obtained by iterative processing, a candidate color correction matrix corresponding to the minimum weighted average value is selected; based on the selected candidate color correction matrix, the target color correction matrix corresponding to the target color patch is determined; the target color correction matrix is used to perform color correction processing on the acquired target image.
2. The method according to claim 1, characterized in that, The step of adjusting the white balance of the actual color block values of each color block in the color chart image to obtain the white balance color block value corresponding to each color block includes: Select a specific color patch from the color patch of the color chart image for white balance adjustment; Based on the color patch value of the specified color patch in the color chart image, determine the white balance parameters corresponding to the color chart image; Based on the white balance parameters corresponding to the color chart image, the actual color values of each color block in the color chart image are adjusted for white balance.
3. The method according to claim 1, characterized in that, The target color blocks are multiple; the method further includes: For each pixel in the target image, calculate the distance between the pixel and each of the multiple target color patches; The target color correction matrix corresponding to the target color block closest to the pixel is used as the color correction matrix of the pixel. The pixel is color corrected using the pixel color correction matrix.
4. The method according to claim 3, characterized in that, The color chart images are multiple; these multiple color chart images are images captured under different standard light sources; the same target color patch in the color chart images captured under different standard light sources corresponds to different target color correction matrices; the target image is captured under ambient light; the method further includes: The color temperatures of the ambient light source and each of the standard light sources are determined respectively to obtain multiple standard light source color temperatures and ambient light source color temperatures; The interpolation weights are determined based on the color temperatures of the multiple standard light sources and the ambient light source. The target color correction matrix corresponding to the target color block under different standard light sources is calculated by weighting the interpolation weights to obtain the comprehensive color correction matrix corresponding to the target color block.
5. The method according to claim 4, characterized in that, The method further includes: Determine the white balance parameters corresponding to the multiple color chart images respectively; The target white balance parameters are obtained by weighting each of the white balance parameters according to the interpolation weights. Based on the comprehensive color correction matrix and the target white balance parameters, the target image is subjected to color correction processing.
6. The method according to claim 1, characterized in that, The method further includes: When the optimization algorithm is unstable, the candidate color correction matrix is obtained; When the optimization algorithm is stable, the target color correction matrix is obtained.
7. The method according to claim 1, characterized in that, The step of determining the color distance between the target color block and the non-target color block based on the white balance color block values corresponding to the target color block and the non-target color block in each color block, and obtaining a distance matrix, includes: The white balance value corresponding to the target color block and the white balance value corresponding to the non-target color block are converted into specific color parameters in a specific color space. Based on the specific color parameters corresponding to the target color block and the specific color parameters corresponding to the non-target color block, the color distance between the target color block and the non-target color block is calculated to obtain a distance matrix.
8. A color correction device, characterized in that, The device includes: The white balance adjustment module is used to adjust the white balance of each color block in the color chart image to obtain the white balance color block value corresponding to each color block. The determination module is used to determine the color distance between the target color block and the non-target color block based on the white balance color block values corresponding to the target color block and the non-target color block in each color block, thereby obtaining a distance matrix; and to determine a weight matrix based on the distance matrix; the magnitude of the weight in the weight matrix is negatively correlated with the magnitude of the color distance in the distance matrix. The weighted fitting module is used to calculate the color difference between the white balance color block value and the standard color block value of the same color block, thereby obtaining the color difference value corresponding to the color block; calculate the weighted average of the color difference values corresponding to each color block according to the weight matrix; the standard color block value is the standard printing value of each color block in the color chart; determine the corresponding candidate color correction matrix according to the weighted average; correct the white balance color block value of each color block in the color block image based on the candidate color correction matrix, and use the corrected white balance color block value as the new white balance color block value, and return to the process of calculating the white balance color block value and the standard color block value of the same color block. The color difference between values is used to obtain the color difference value corresponding to the color block; the step of calculating the weighted average of the color difference values corresponding to each color block according to the weight matrix is carried out iteratively; the candidate color correction matrix corresponds to the white balance color block value after correction based on the candidate color correction matrix; from the multiple candidate color correction matrices obtained by the iterative process, the candidate color correction matrix corresponding to the minimum weighted average is selected; according to the selected candidate color correction matrix, the target color correction matrix corresponding to the target color block is determined; the target color correction matrix is used to perform color correction processing on the acquired target image.
9. An electronic device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 7.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Image white balance processing method and device, storage medium and terminal
CN113301318A
Color correction method based on color card
CN113923429A