Color correction matrix adjustment method and device, and storage medium
By mapping the color correction matrix from RGB space to YUV space for coordinate transformation, the problem that the color correction matrix cannot be accurately corrected in the existing technology is solved, and an accurate and controllable color correction effect is achieved.
Patent Information
- Application Number
- CN202010705620.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-07-21
- Publication Date
- 2024-09-17
- Estimated Expiration
- 2040-07-21
AI Technical Summary
Existing color correction matrices cannot be accurately corrected or cannot achieve predetermined effects, especially because the difference in response curves of different image sensors is nonlinear, resulting in poor correction results.
Obtain the initial color correction matrix of the RGB color space based on the standard color card, map it to the YUV color space for coordinate transformation, including saturation adjustment and chroma rotation, and finally map the transformed matrix back to the RGB color space to obtain the final color correction matrix.
It achieves accurate and predictable color correction effects, avoids the problem of adjusting one item that affects other items, and ensures the accuracy and controllability of the correction effect.
Smart Images

Figure CN111861922B
Abstract
Description
Technical Field
[0001] The embodiments of the present invention relate to the field of image processing technology, and in particular to a method and device for adjusting a color correction matrix, and a storage medium. Background Art
[0002] The scene color captured by the camera is closely related to the spectral response of the sensor. Different image sensors will capture different colors in the same shooting scene, and they are different from the human eye. Therefore, color correction is required to restore the true color.
[0003] At present, the traditional color correction method is to use the color correction matrix CCM (color correction matrix) for calibration, that is, to use a 3x3 matrix to multiply the red, green, blue RGB (red, green, blue) channels of each pixel for color correction. In essence, it is a linear transformation of each sensor response curve.
[0004] Since the differences between different response curves are nonlinear, the color correction matrix often cannot be accurately corrected or cannot correct to the intended effect. Summary of the invention
[0005] The embodiments of the present invention provide a method and device for adjusting a color correction matrix, and a storage medium, so as to at least solve the problem in the related art that the color correction matrix often cannot be accurately corrected or cannot correct to a predetermined effect.
[0006] According to one embodiment of the present invention, a method for adjusting a color correction matrix is provided, comprising: obtaining an initial color correction matrix based on an RGB color space based on a standard color card; mapping the initial color correction matrix based on the RGB color space to a transformation matrix based on a YUV color space; performing a coordinate transformation on the transformation matrix in the YUV color space, wherein the coordinate transformation comprises at least one of the following: a coordinate transformation for adjusting image saturation, a coordinate transformation for performing image chromaticity rotation; and mapping the transformation matrix based on the YUV color space after the coordinate transformation to a final color correction matrix based on the RGB color space.
[0007] In at least one exemplary embodiment, obtaining an initial color correction matrix based on an RGB color space based on a standard color card includes: obtaining a color card standard image corresponding to the standard color card; performing a first type of preprocessing on a target color block of the standard color card in the color card standard image to obtain a color card target image, wherein the first type of preprocessing includes at least one of the following: saturation adjustment, color adjustment, and inverse gamma transformation; and determining the initial color correction matrix based on the RGB color space according to the color card standard image and the color card target image.
[0008] In at least one exemplary embodiment, obtaining a color card standard image corresponding to the standard color card includes: acquiring a color card image of the standard color card; performing a second type of preprocessing on the acquired color card image to obtain the color card standard image, wherein the second type of preprocessing includes at least one of the following: black level correction, bayer domain interpolation, and white balance correction.
[0009] In at least one exemplary embodiment, determining the initial color correction matrix based on the RGB color space according to the color card standard image and the color card target image includes: determining an original color matrix CO based on the RGB color space formed by original values of RGB channels of each color block in the color card standard image, and a target color matrix CT based on the RGB color space formed by original values of RGB channels of each color block in the color card target image; determining the initial color correction matrix CCM based on the RGB color space according to the original color matrix CO based on the RGB color space and the target color matrix CT based on the RGB color space, wherein the CCM satisfies the following conditions: the least squares error between CCM×CO and CT is the smallest, and a i1 +a i2 +a i3 =1, where a ij is the matrix of i rows and j columns of the CCM.
[0010] In at least one exemplary embodiment, mapping the initial color correction matrix based on the RGB color space to a transformation matrix based on the YUV color space includes: multiplying the initial color correction matrix CCM based on the RGB color space by a first mapping matrix on the left and a second mapping matrix on the right to obtain the transformation matrix T based on the YUV color space. O , wherein the first mapping matrix is an RGB to YUV conversion matrix rgb2yuv, the second mapping matrix is a YUV to RGB conversion matrix yuv2rgb, and the second mapping matrix is an inverse matrix of the first mapping matrix.
[0011] In at least one exemplary embodiment, performing coordinate transformation on the transformation matrix in the YUV color space for adjusting the image saturation comprises: transforming the transformation matrix T based on the YUV color space O The scaling transformation matrix S is multiplied on the left to obtain the transformation matrix T = S0·T0 after the coordinate transformation, where: s1 and s2 are the saturation changes in the u direction and v direction respectively.
[0012] In at least one exemplary embodiment, performing coordinate transformation on the transformation matrix in the YUV color space for image chromaticity rotation includes: transforming the transformation matrix T based on the YUV color space O The rotation transformation matrix R0 is multiplied on the left to obtain the transformation matrix T=R0·T0 after the coordinate transformation, where: θ is the spatial rotation angle along the y-axis.
[0013] In at least one exemplary embodiment, performing coordinate transformation for adjusting image saturation and coordinate transformation for image chromaticity rotation on the transformation matrix in the YUV color space includes: performing coordinate transformation on the transformation matrix T based on the YUV color space O First, multiply the scaling transformation matrix S on the left, and then multiply the rotation transformation matrix R0 on the left to obtain the transformation matrix T = R0·S0·T0 after the coordinate transformation, where: s1 and s2 are the saturation changes in the u direction and v direction respectively. θ is the spatial rotation angle along the y-axis.
[0014] In at least one exemplary embodiment, mapping the transformation matrix based on the YUV color space after the coordinate transformation to a final color correction matrix based on the RGB color space includes: multiplying the transformation matrix T based on the YUV color space after the coordinate transformation by a second mapping matrix on the left and a first mapping matrix on the right to obtain a final color correction matrix CCM based on the RGB color space. final , wherein the first mapping matrix is an RGB to YUV conversion matrix rgb2yuv, the second mapping matrix is a YUV to RGB conversion matrix yuv2rgb, and the second mapping matrix is an inverse matrix of the first mapping matrix.
[0015] According to another embodiment of the present invention, a device for adjusting a color correction matrix is provided, comprising: an acquisition module, configured to acquire an initial color correction matrix based on an RGB color space based on a standard color card; a first space mapping module, configured to map the initial color correction matrix based on the RGB color space into a transformation matrix based on a YUV color space; a coordinate transformation module, configured to perform coordinate transformation on the transformation matrix in the YUV color space, wherein the coordinate transformation comprises at least one of the following: a coordinate transformation for adjusting image saturation, a coordinate transformation for performing image chromaticity rotation; and a second space mapping module, configured to map the transformation matrix based on the YUV color space after the coordinate transformation into a final color correction matrix based on the RGB color space.
[0016] In at least one exemplary embodiment, the acquisition module includes: an acquisition unit, configured to acquire a color card standard image corresponding to the standard color card; a preprocessing unit, configured to perform a first type of preprocessing on a target color block of the standard color card in the color card standard image to obtain a color card target image, wherein the first type of preprocessing includes at least one of the following: saturation adjustment, color adjustment, and inverse gamma transformation; a determination unit, configured to determine the initial color correction matrix based on the RGB color space according to the color card standard image and the color card target image.
[0017] According to yet another embodiment of the present invention, a computer-readable storage medium is provided, in which a computer program is stored, wherein the computer program is configured to execute the steps of any one of the above method embodiments when run.
[0018] According to yet another embodiment of the present invention, there is provided an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
[0019] Through the present invention, the color correction matrix is mapped from RGB to YUV space and then the coordinates are transformed to achieve the adjustment of saturation and chromaticity, and finally mapped back to the RGB color space, so that the adjustment items are accurately adjusted without affecting the non-adjustment items, and an accurate and predictable correction effect is guaranteed. Therefore, the problem that the color correction matrix often cannot be accurately corrected or cannot correct to a predetermined effect can be solved. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] Figure 1 is a hardware structure block diagram of a computer according to an embodiment of the present invention;
[0021] Figure 2 is a flow chart of a method for adjusting a color correction matrix according to an embodiment of the present invention;
[0022] Figure 3 is a structural block diagram of a device for adjusting a color correction matrix according to an embodiment of the present invention;
[0023] Figure 4 is a detailed structural block diagram of a device for adjusting a color correction matrix according to an embodiment of the present invention;
[0024] Figure 5 is a detailed flow chart of a method for adjusting a color correction matrix according to an embodiment of the present invention. DETAILED DESCRIPTION
[0025] In order to obtain a more accurate and more satisfactory color correction matrix, the color of the standard color card can be collected under the standard light source to increase the dimension of the color correction matrix. Finally, the least squares method can be used to obtain a CCM matrix with a smaller error. In addition, the CCM matrix that has been initially corrected can be interpolated with the unit matrix to achieve saturation adjustment.
[0026] However, if only the accurate CCM correction of the standard color card (for example, 24 color cards) under the standard light source is performed, due to the dimensional limitation of the 3x3 linear transformation, increasing the dimension during the calculation process will only improve the final accuracy to a limited extent, and accurate color correction is not necessarily the color correction effect that the user really wants. If the color correction is adjusted according to the user's requirements, the CCM is directly interpolated with the unit matrix, which will lead to the problem of over-correction of chromaticity when the saturation is increased, resulting in a significant change in chromaticity when the saturation is changed.
[0027] In order to solve the problem that the color correction matrix often cannot be accurately corrected or cannot correct to the predetermined effect, and also to solve the problem that the adjustment of one adjustment item will affect the adjustment of other adjustment items when the color correction matrix is adjusted, the embodiment of the present invention further corrects the preliminary color correction matrix, and can make the color better meet the user's requirements through adjustment. At the same time, it can distinguish the adjustment items to avoid problems such as changing the chroma when changing the saturation.
[0028] Hereinafter, embodiments of the present invention will be described in detail with reference to the accompanying drawings and in combination with the embodiments.
[0029] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.
[0030] The method embodiments provided in the embodiments of the present application can be executed in a computing device for implementing image processing. Taking running on a computer as an example, Figure 1 is a hardware structure block diagram of a computer according to an embodiment of the present invention. Figure 1 As shown, the computer may include one or more ( Figure 1 Only one is shown in the figure) a processor 102 (the processor 102 may include but is not limited to a central processing unit CPU, a microprocessor MCU or a programmable logic device FPGA and the like) and a memory 104 for storing data, wherein the above-mentioned computer may also include a transmission device 106 and an input / output device 108 for communication functions. It can be understood by those skilled in the art that Figure 1 The structure shown is only for illustration and does not limit the structure of the above-mentioned computer. Figure 1 More or fewer components as shown, or with Figure 1Different configurations are shown.
[0031] The memory 104 can be used to store computer programs, for example, software programs and modules of application software, such as the computer program corresponding to the adjustment method of the color correction matrix in the embodiment of the present invention. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, that is, to implement the above method. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include a memory remotely arranged relative to the processor 102, and these remote memories may be connected to the mobile terminal via a network. Examples of the above network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0032] In this embodiment, a method for adjusting a color correction matrix running on a computing device is provided. Figure 2 is a flow chart of a method for adjusting a color correction matrix according to an embodiment of the present invention. Figure 2 As shown, the process includes the following steps:
[0033] Step S202, obtaining an initial color correction matrix based on the RGB color space based on a standard color card;
[0034] Step S204, mapping the initial color correction matrix based on the RGB color space into a transformation matrix based on the YUV color space;
[0035] Step S206, performing coordinate transformation on the transformation matrix in the YUV color space, wherein the coordinate transformation includes at least one of the following: a coordinate transformation for adjusting image saturation, and a coordinate transformation for performing image chromaticity rotation;
[0036] Step S208: Mapping the transformation matrix based on the YUV color space after the coordinate transformation into a final color correction matrix based on the RGB color space.
[0037] According to the above steps, the saturation and chromaticity are adjusted by mapping the color correction matrix from RGB to YUV space and then performing coordinate transformation, and finally mapping it back to the RGB color space, so that the adjustment items can be accurately adjusted without affecting the non-adjustment items, ensuring an accurate and predictable correction effect. Therefore, the problem that the color correction matrix often cannot be accurately corrected or cannot correct to the predetermined effect can be solved.
[0038] The execution subject of the above steps may be a computing device such as a computer, but is not limited thereto.
[0039] In at least one exemplary embodiment, step S202 may include:
[0040] Step S2021, obtaining a color card standard image corresponding to the standard color card. In practical applications, considering that there are multiple color temperatures in reality, a color card standard image corresponding to the standard color card under different standard color temperature light sources may be obtained;
[0041] Step S2022, performing a first type of preprocessing on the target color block of the standard color card in the color card standard image to obtain a color card target image, wherein the first type of preprocessing includes at least one of the following: saturation adjustment, color adjustment, and inverse gamma transformation. Through this step, adjustments can be made in the target image selection stage (for example, preprocessing can be performed according to preset conditions, or specific preprocessing operations can be performed according to subjective needs of users), thereby performing preliminary adjustments and interventions on the initial color correction matrix;
[0042] Step S2023: determining the initial color correction matrix based on the RGB color space according to the color card standard image and the color card target image.
[0043] In at least one exemplary embodiment, step S2021 may include:
[0044] Step S2021-1, collecting a color card image of the standard color card (which may be a color card image corresponding to the standard color card under different standard color temperature light sources);
[0045] Step S2021-2, performing a second type of preprocessing on the collected color card image to obtain the color card standard image, wherein the second type of preprocessing includes at least one of the following: black level correction, bayer domain interpolation, and white balance correction.
[0046] In at least one exemplary embodiment, step S2023 may include:
[0047] Step S2023-1, determining an original color matrix CO based on the RGB color space formed by the original values of the RGB channels of each color block in the color card standard image, and a target color matrix CT based on the RGB color space formed by the original values of the RGB channels of each color block in the color card target image;
[0048] Step S2023-2, determining the initial color correction matrix CCM based on the RGB color space according to the original color matrix CO based on the RGB color space and the target color matrix CT based on the RGB color space, wherein the CCM satisfies the following conditions: the least squares error between CCM×CO and CT is the smallest, and a i1 +ai2 +a i3 =1, where a ij is the matrix of i rows and j columns of the CCM.
[0049] In at least one exemplary embodiment, step S204 may include:
[0050] Step S2041, the initial color correction matrix CCM based on the RGB color space is multiplied by the first mapping matrix on the left and the second mapping matrix on the right to obtain the transformation matrix T based on the YUV color space O , wherein the first mapping matrix is an RGB to YUV conversion matrix rgb2yuv, the second mapping matrix is a YUV to RGB conversion matrix yuv2rgb, and the second mapping matrix is an inverse matrix of the first mapping matrix.
[0051] In at least one exemplary embodiment, in step S206, the process of performing coordinate transformation on the transformation matrix in the YUV color space for adjusting the image saturation may include: transforming the transformation matrix T based on the YUV color space O The scaling transformation matrix S is multiplied on the left to obtain the transformation matrix T = S0·T0 after the coordinate transformation, where: s1 and s2 are the saturation changes in the u direction and v direction respectively.
[0052] In at least one exemplary embodiment, in step S206, the process of performing coordinate transformation on the transformation matrix in the YUV color space for image chromaticity rotation may include: transforming the transformation matrix T based on the YUV color space O The rotation transformation matrix R0 is multiplied on the left to obtain the transformation matrix T=R0·T0 after the coordinate transformation, where: θ is the spatial rotation angle along the y-axis.
[0053] In at least one exemplary embodiment, in step S206, the process of performing coordinate transformation for adjusting image saturation and coordinate transformation for image chromaticity rotation on the transformation matrix in the YUV color space may include: performing coordinate transformation on the transformation matrix T based on the YUV color space O First, multiply the scaling transformation matrix S on the left, and then multiply the rotation transformation matrix R0 on the left to obtain the transformation matrix T = R0·S0·T0 after the coordinate transformation, where: s1 and s2 are the saturation changes in the u direction and v direction respectively. θ is the spatial rotation angle along the y-axis.
[0054] In at least one exemplary embodiment, step S208 may include:
[0055] Step S2081, the transformation matrix T based on the YUV color space after the coordinate transformation is multiplied by the second mapping matrix on the left and the first mapping matrix on the right to obtain a final color correction matrix CCM based on the RGB color space final , wherein the first mapping matrix is an RGB to YUV conversion matrix rgb2yuv, the second mapping matrix is a YUV to RGB conversion matrix yuv2rgb, and the second mapping matrix is an inverse matrix of the first mapping matrix.
[0056] In at least one exemplary embodiment, after step S208, the method may further include:
[0057] Color correction is performed on the image captured by the camera according to the final color correction matrix.
[0058] After color correction is performed on the image captured by the camera, the color-corrected image may be displayed on a screen or sent to a server.
[0059] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, a magnetic disk, or an optical disk), and includes a number of instructions for enabling a terminal device (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present invention.
[0060] In this embodiment, a color correction matrix adjustment device is also provided, which is used to implement the above-mentioned embodiments and preferred implementation modes, and the descriptions that have been made will not be repeated. As used below, the term "module" can implement a combination of software and / or hardware of a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.
[0061] Figure 3 is a structural block diagram of a device for adjusting a color correction matrix according to an embodiment of the present invention. Figure 3 As shown, the device comprises:
[0062] An acquisition module 32 is configured to acquire an initial color correction matrix based on an RGB color space based on a standard color card;
[0063] A first space mapping module 34 is configured to map the initial color correction matrix based on the RGB color space into a transformation matrix based on the YUV color space;
[0064] A coordinate transformation module 36, configured to perform coordinate transformation on the transformation matrix in the YUV color space, wherein the coordinate transformation includes at least one of the following: a coordinate transformation for adjusting image saturation, and a coordinate transformation for performing image chromaticity rotation;
[0065] The second space mapping module 38 is configured to map the transformation matrix based on the YUV color space after the coordinate transformation into a final color correction matrix based on the RGB color space.
[0066] Figure 4 Detailed structural diagram of a device for adjusting a color correction matrix according to an embodiment of the present invention. Figure 4 As shown, the acquisition module 32 includes:
[0067] An acquisition unit 322 is configured to acquire a color card standard image corresponding to the standard color card. In practical applications, considering that there are multiple color temperatures in reality, the color card standard image corresponding to the standard color card under different standard color temperature light sources can be acquired;
[0068] The preprocessing unit 324 is configured to perform a first type of preprocessing on the target color block of the standard color card in the color card standard image to obtain a color card target image, wherein the first type of preprocessing includes at least one of the following: saturation adjustment, color adjustment, and inverse gamma transformation. Through this process, adjustments can be made at the target image selection stage (for example, preprocessing can be performed according to preset conditions, or specific preprocessing operations can be performed according to subjective needs of users), thereby performing preliminary adjustments and interventions on the initial color correction matrix;
[0069] The determination unit 326 is configured to determine the initial color correction matrix based on the RGB color space according to the color card standard image and the color card target image.
[0070] In at least one exemplary embodiment, the acquisition unit 322 may be configured to perform the following operations:
[0071] Collecting a color card image of the standard color card (which may be a color card image corresponding to the standard color card under different standard color temperature light sources);
[0072] The collected color card image is subjected to a second type of preprocessing to obtain the color card standard image, wherein the second type of preprocessing includes at least one of the following: black level correction, bayer domain interpolation, and white balance correction.
[0073] In at least one exemplary embodiment, the determining unit 326 may be configured to perform the following operations:
[0074] Determine an original color matrix CO based on the RGB color space formed by the original values of the RGB channels of each color block in the color card standard image, and a target color matrix CT based on the RGB color space formed by the original values of the RGB channels of each color block in the color card target image;
[0075] The initial color correction matrix CCM based on the RGB color space is determined according to the original color matrix CO based on the RGB color space and the target color matrix CT based on the RGB color space, wherein the CCM satisfies the following conditions: the least squares error between CCM×CO and CT is the smallest, and a i1 +a i2 +a i3 =1, where a ij is the matrix of i rows and j columns of the CCM.
[0076] In at least one exemplary embodiment, the first spatial mapping module 34 may be configured to perform the following operations:
[0077] The initial color correction matrix CCM based on the RGB color space is multiplied by the first mapping matrix on the left and the second mapping matrix on the right to obtain the transformation matrix T based on the YUV color space. O , wherein the first mapping matrix is an RGB to YUV conversion matrix rgb2yuv, the second mapping matrix is a YUV to RGB conversion matrix yuv2rgb, and the second mapping matrix is an inverse matrix of the first mapping matrix.
[0078] In at least one exemplary embodiment, the coordinate transformation module 36 may be configured to perform a coordinate transformation on the transformation matrix in the YUV color space for adjusting the image saturation in the following manner:
[0079] The transformation matrix T based on the YUV color space O The scaling transformation matrix S is multiplied on the left to obtain the transformation matrix T = S0·T0 after the coordinate transformation, where: s1 and s2 are the saturation changes in the u direction and v direction respectively.
[0080] In at least one exemplary embodiment, the coordinate transformation module 36 may be configured to perform a coordinate transformation process for performing image chromaticity rotation on the transformation matrix in the YUV color space in the following manner:
[0081] The transformation matrix T based on the YUV color spaceO The rotation transformation matrix R0 is multiplied on the left to obtain the transformation matrix T=R0·T0 after the coordinate transformation, where: θ is the spatial rotation angle along the y-axis.
[0082] In at least one exemplary embodiment, the coordinate transformation module 36 may be configured to perform a coordinate transformation for adjusting image saturation and a coordinate transformation for performing image chromaticity rotation on the transformation matrix in the YUV color space in the following manner:
[0083] The transformation matrix T based on the YUV color space O First, multiply the scaling transformation matrix S on the left, and then multiply the rotation transformation matrix R0 on the left to obtain the transformation matrix T = R0·S0·T0 after the coordinate transformation, where: s1 and s2 are the saturation changes in the u direction and v direction respectively. θ is the spatial rotation angle along the y-axis.
[0084] In at least one exemplary embodiment, the second spatial mapping module 38 may be configured to perform the following operations:
[0085] The transformation matrix T based on the YUV color space after the coordinate transformation is multiplied by the second mapping matrix on the left and the first mapping matrix on the right to obtain the final color correction matrix CCM based on the RGB color space final , wherein the first mapping matrix is an RGB to YUV conversion matrix rgb2yuv, the second mapping matrix is a YUV to RGB conversion matrix yuv2rgb, and the second mapping matrix is an inverse matrix of the first mapping matrix.
[0086] In at least one exemplary embodiment, the apparatus may further include:
[0087] The correction processing module is configured to perform color correction on the image captured by the camera according to the final color correction matrix.
[0088] The device may also include:
[0089] The control module is configured to display the color-corrected image on a screen or send it to a server after color correction is performed on the image captured by the camera.
[0090] It should be noted that the above modules can be implemented by software or hardware. For the latter, it can be implemented in the following ways, but not limited to: the above modules are all located in the same processor; or the above modules are located in different processors in any combination.
[0091] An embodiment of the present invention further provides a computer-readable storage medium, in which a computer program is stored, wherein the computer program is configured to execute the steps of any of the above method embodiments when running.
[0092] In this embodiment, the computer-readable storage medium may be configured to store a computer program for performing the following steps:
[0093] Step S1, obtaining an initial color correction matrix based on an RGB color space based on a standard color card;
[0094] Step S2, mapping the initial color correction matrix based on the RGB color space into a transformation matrix based on the YUV color space;
[0095] Step S3, performing coordinate transformation on the transformation matrix in the YUV color space, wherein the coordinate transformation includes at least one of the following: a coordinate transformation for adjusting image saturation, and a coordinate transformation for performing image chromaticity rotation;
[0096] Step S4, mapping the transformation matrix based on the YUV color space after the coordinate transformation into a final color correction matrix based on the RGB color space.
[0097] In an exemplary embodiment, the computer-readable storage medium may include, but is not limited to, various media that can store computer programs, such as a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk.
[0098] An embodiment of the present invention further provides an electronic device, including a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
[0099] In an exemplary embodiment, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.
[0100] In an exemplary embodiment, the processor may be configured to perform the following steps via a computer program:
[0101] Step S1, obtaining an initial color correction matrix based on an RGB color space based on a standard color card;
[0102] Step S2, mapping the initial color correction matrix based on the RGB color space into a transformation matrix based on the YUV color space;
[0103] Step S3, performing coordinate transformation on the transformation matrix in the YUV color space, wherein the coordinate transformation includes at least one of the following: a coordinate transformation for adjusting image saturation, and a coordinate transformation for performing image chromaticity rotation;
[0104] Step S4, mapping the transformation matrix based on the YUV color space after the coordinate transformation into a final color correction matrix based on the RGB color space.
[0105] For specific examples in this embodiment, reference may be made to the examples described in the above embodiments and exemplary implementation modes, and this embodiment will not be described in detail herein.
[0106] The following is a solution for determining and adjusting an accurate color correction matrix based on a 24-color card according to an embodiment of the present invention, so as to better solve the problem that accurate adjustment is required after accurate color calibration.
[0107] Figure 5 is a detailed flow chart of a method for adjusting a color correction matrix according to an embodiment of the present invention. Figure 5 As shown, the method comprises the following steps:
[0108] Step S501, the camera collects color card images of standard 24 color cards under a variety of standard light sources with different color temperatures, where the standard light source can be A light source, TL84 light source, D50 light source, D65 light source, D75 light source. The collected color card images are preprocessed (corresponding to the second type of preprocessing), including black level correction, bayer interpolation and manual white balance correction. To keep consistent with the ISP process, the original image is obtained.
[0109] Step S502, pre-process the target color card standard image, directly adjust the saturation and chroma and perform inverse gamma processing (corresponding to the first type of pre-processing) on the standard image as needed to obtain the target image. Specifically, Photoshop can be used to adjust the target color block, increase the saturation as needed, change some colors, etc. In the ISP process, the gamma to be used can also be used to perform an inverse gamma transformation operation on the target color card.
[0110] Step S503, the RBG channel values of each color block of the color card in the processed original image are counted, and a 3x24-dimensional color card matrix is formed according to the standard value to form a source matrix; the RGB channel values of each color block of the color card in the processed target image are counted, and a 3x24-dimensional color card matrix is formed according to the reference value to form a target matrix.
[0111] Among them, the original values of the RGB channels of each color block of the original image are counted, and a total of 24 color blocks are formed into a 3x24 original color matrix CO as follows:
[0112]
[0113] Among them, the target values of the RGB channels of each color block of the target image after statistical processing, a total of 24 color blocks, form a 3x24 target color matrix CT as follows:
[0114]
[0115] Step S504: based on the source matrix and the target matrix, gray block constraint items are added, and an initial color correction matrix CCM is obtained by least square fitting.
[0116] Specifically, let the color correction matrix CCM be a 3x3 matrix
[0117]
[0118] Use the least squares method to find the least squares error between CCM·CO and CT that is the smallest and satisfies:
[0119] a i1 +a i2 +a i3 =1, where a ij is the CCM matrix with i rows and j columns of CCM.
[0120] Step S505, the CCM obtained above is adjusted as needed. In order to avoid the mutual influence of chroma, saturation and brightness when adjusting the color, the color space needs to be mapped to the YUV space for processing. Specifically, the initial color correction matrix CCM can be linearly transformed according to the RGB2YUV matrix used in the ISP system, so that it can be expressed as a YUV3x3 transformation matrix in the YUV domain.
[0121] Specifically, the CCM is multiplied by the rgb2yuv matrix used by isp later on the left, and multiplied by its yuv2rgb matrix, i.e. the rgb2yuv inverse matrix, on the right. The resulting YUV transformation matrix
[0122]
[0123] Step S506, next, coordinate transformation is performed on the space. Saturation is increased as needed, space scaling transformation is performed on the YUV space in the UV direction, and the YUV transformation matrix is multiplied by the scaling matrix on the left; chromaticity rotation is performed as needed, space rotation transformation is performed on the YUV space along the Y axis, and the YUV transformation matrix is multiplied by the rotation matrix on the left.
[0124] Specifically, when the image saturation needs to be increased, the transformation matrix T O Left multiply the scaling transformation matrix S:
[0125]
[0126] Among them, s1 and s2 are the saturation changes in the u direction and v direction respectively. When > 1, the saturation is increased. According to the commonly used yuv matrix, s1 will mainly increase the saturation in the blue direction, and s2 will mainly increase the saturation in the red direction. Generally, s1 and s2 should be increased.
[0127] Specifically, when the chromaticity rotation of the image is required, the transformation matrix T O Left multiply the rotation transformation matrix R0:
[0128]
[0129] When θ is positive, the chromaticity increases, and vice versa.
[0130] Step S507, using the inverse matrix of RGB2YUV, the transformed YUV transformation matrix is linearly transformed into a new CCM, that is, the left-multiplied transformation matrix T=R0·S0·T0 is transformed back to the CCM of the RGB space.
[0131] Specifically, multiply the transformation matrix T by the yuv2rgb matrix on the left and the rgb2yuv matrix on the right to get the final CCM final .
[0132] In the specific implementation, since the coordinate transformation matrix is left-multiplied on the transformation matrix T0, the right-multiplied spatial transformation matrices of the two spatial transformations can cancel each other out and do not need to be multiplied.
[0133] In the solution provided by the embodiment of the present invention, certain preliminary adjustments are implemented in the target map selection stage. In addition, the ccm is adjusted by using color space conversion and space coordinate transformation. Through this solution, ccm can be further adjusted, and the influence range of the adjustment is better controlled by using space conversion. In addition, adjustments are made in the target map selection stage, referring to the needs of users.
[0134] Obviously, those skilled in the art should understand that the above modules or steps of the present invention can be implemented by a general computing device, they can be concentrated on a single computing device, or distributed on a network composed of multiple computing devices, they can be implemented by a program code executable by a computing device, so that they can be stored in a storage device and executed by the computing device, and in some cases, the steps shown or described can be executed in a different order than here, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. Thus, the present invention is not limited to any specific combination of hardware and software.
[0135] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A method for adjusting a color correction matrix, characterized in that: include: Obtaining an initial color correction matrix based on the RGB color space based on a standard color card; Mapping the initial color correction matrix based on the RGB color space into a transformation matrix based on the YUV color space; Performing coordinate transformation on the transformation matrix in the YUV color space, wherein the coordinate transformation includes at least one of the following: a coordinate transformation for adjusting image saturation, and a coordinate transformation for performing image chromaticity rotation; Mapping the transformation matrix based on the YUV color space after the coordinate transformation into a final color correction matrix based on the RGB color space; The initial color correction matrix based on the RGB color space is mapped to a transformation matrix based on the YUV color space, including: multiplying the initial color correction matrix CCM based on the RGB color space by a first mapping matrix on the left and a second mapping matrix on the right to obtain the transformation matrix based on the YUV color space. , wherein the first mapping matrix is an RGB to YUV conversion matrix rgb2yuv, the second mapping matrix is a YUV to RGB conversion matrix yuv2rgb, and the second mapping matrix is an inverse matrix of the first mapping matrix; The coordinate transformation for adjusting the image saturation and the coordinate transformation for rotating the image chromaticity of the transformation matrix in the YUV color space include: First multiply the scaling transformation matrix S0 by the left, then multiply the rotation transformation matrix by the left , get the transformation matrix after the coordinate transformation ,in, , , are the saturation changes in the u direction and the v direction respectively, , is the spatial rotation angle along the y-axis.
2. The method according to claim 1, characterized in that The step of obtaining an initial color correction matrix based on the RGB color space based on the standard color card includes: Obtaining a color card standard image corresponding to the standard color card; Performing a first type of preprocessing on the target color block of the standard color card in the color card standard image to obtain a color card target image, wherein the first type of preprocessing includes at least one of the following: saturation adjustment, color adjustment, and inverse gamma transformation, and the first type of preprocessing is selected according to a preset condition; The initial color correction matrix based on the RGB color space is determined according to the color card standard image and the color card target image.
3. The method according to claim 2, characterized in that Acquiring a color card standard image corresponding to the standard color card includes: Acquiring a color card image of the standard color card; The collected color card image is subjected to a second type of preprocessing to obtain the color card standard image, wherein the second type of preprocessing includes at least one of the following: black level correction, bayer domain interpolation, and white balance correction.
4. The method according to claim 2, characterized in that: Determining the initial color correction matrix based on the RGB color space according to the color card standard image and the color card target image includes: Determine an original color matrix CO based on the RGB color space formed by the original values of the RGB channels of each color block in the color card standard image, and a target color matrix CT based on the RGB color space formed by the original values of the RGB channels of each color block in the color card target image; The initial color correction matrix CCM based on the RGB color space is determined according to the original color matrix CO based on the RGB color space and the target color matrix CT based on the RGB color space, wherein the CCM satisfies the following conditions: The least squares error with the CT is the smallest, and ,in is the matrix of i rows and j columns of the CCM.
5. The method according to claim 1, characterized in that Performing coordinate transformation on the transformation matrix in the YUV color space for adjusting the image saturation includes: The transformation matrix based on the YUV color space Multiply the scaling transformation matrix S0 on the left to obtain the transformation matrix after the coordinate transformation ,in, , , They are the saturation changes in the u direction and the v direction respectively.
6. The method according to claim 1, characterized in that Performing coordinate transformation of the transformation matrix in the YUV color space for image chromaticity rotation includes: The transformation matrix based on the YUV color space Left multiply the rotation transformation matrix , get the transformation matrix after the coordinate transformation ,in, , is the spatial rotation angle along the y-axis.
7. The method according to claim 1, characterized in that Mapping the transformation matrix based on the YUV color space after the coordinate transformation into a final color correction matrix based on the RGB color space includes: The transformation matrix T based on the YUV color space after the coordinate transformation is multiplied by the second mapping matrix on the left and the first mapping matrix on the right to obtain a final color correction matrix based on the RGB color space. , wherein the first mapping matrix is an RGB to YUV conversion matrix rgb2yuv, the second mapping matrix is a YUV to RGB conversion matrix yuv2rgb, and the second mapping matrix is an inverse matrix of the first mapping matrix.
8. A color correction matrix adjustment device, characterized in that: include: An acquisition module is configured to acquire an initial color correction matrix based on an RGB color space based on a standard color card; A first space mapping module is configured to map the initial color correction matrix based on the RGB color space into a transformation matrix based on the YUV color space; A coordinate transformation module, configured to perform coordinate transformation on the transformation matrix in the YUV color space, wherein the coordinate transformation includes at least one of the following: a coordinate transformation for adjusting image saturation, and a coordinate transformation for performing image chromaticity rotation; A second space mapping module is configured to map the transformation matrix based on the YUV color space after the coordinate transformation into a final color correction matrix based on the RGB color space; The first space mapping module is configured to map the initial color correction matrix based on the RGB color space into a transformation matrix based on the YUV color space in the following manner: multiplying the initial color correction matrix CCM based on the RGB color space by a first mapping matrix on the left and a second mapping matrix on the right to obtain the transformation matrix based on the YUV color space: , wherein the first mapping matrix is an RGB to YUV conversion matrix rgb2yuv, the second mapping matrix is a YUV to RGB conversion matrix yuv2rgb, and the second mapping matrix is an inverse matrix of the first mapping matrix; The coordinate transformation module is configured to perform coordinate transformation for adjusting image saturation and coordinate transformation for image chromaticity rotation on the transformation matrix in the YUV color space in the following manner: First multiply the scaling transformation matrix S0 by the left, then multiply the rotation transformation matrix by the left , get the transformation matrix after the coordinate transformation ,in, , , are the saturation changes in the u direction and the v direction respectively, , is the spatial rotation angle along the y-axis.
9. The device according to claim 8, characterized in that The acquisition module comprises: An acquisition unit, configured to acquire a color card standard image corresponding to the standard color card; A preprocessing unit, configured to perform a first type of preprocessing on the target color block of the standard color card in the color card standard image to obtain a color card target image, wherein the first type of preprocessing includes at least one of the following: saturation adjustment, color adjustment, and inverse gamma transformation; A determination unit is configured to determine the initial color correction matrix based on the RGB color space according to the color card standard image and the color card target image.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, wherein the computer program is configured to execute the method according to any one of claims 1 to 7 when executed.
