Image color style migration method and device, computer equipment and storage medium
By calculating the covariance matrix and singular value decomposition of the image, whitening and tinting transformation matrices are constructed, which solves the problem of insufficient color channel correlation in existing color style transfer methods, realizes flexible parameter adjustment and color protection, and improves the naturalness and robustness of color transfer.
Patent Information
- Application Number
- CN202512051444.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-31
- Publication Date
- 2026-04-14
AI Technical Summary
Existing color style transfer methods lack consideration for color channel correlation, have an inaccurate mathematical foundation, are inflexible in parameter adjustment, and have imperfect color protection mechanisms, resulting in unnatural and distorted color conversion.
By calculating the covariance matrices of the source and reference images and performing singular value decomposition, whitening and color transformation matrices are constructed. Combined with color space protection strategies, mathematical rigor and flexible parameter control of the color migration process are achieved.
It effectively captures the correlation between color channels, supports flexible control of brightness and color migration intensity, avoids color distortion, and improves the naturalness and robustness of color migration.
Smart Images

Figure CN121860843A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image processing technology, and in particular to an image color style transfer method, apparatus, computer device, and storage medium. Background Technology
[0002] In image processing and computer vision, color style transfer techniques aim to apply color features from a reference image to a source image while preserving the source image's content structure. Traditional methods mainly include histogram matching, mean-standard deviation matching, neural network-based methods, and the Reinhard color transfer method. While histogram matching is simple to implement, it relies solely on one-dimensional color statistics, ignoring the correlation between color channels, resulting in unnatural color transformations and difficulty in maintaining overall tonal consistency. Mean-standard deviation matching adjusts the mean and standard deviation of each channel through linear transformation, but it assumes that each color channel is independent, failing to capture higher-order statistical features of color distribution and thus having limited effectiveness in handling complex color relationships. Neural network-based methods offer improved performance, but suffer from high computational complexity, reliance on large amounts of training data, slow inference speed, and difficulty in real-time application to video. Although the Reinhard method converts the image to the lαβ color space for mean and standard deviation matching, it still fails to fully consider the covariance information between color channels, resulting in insufficient ability to transfer complex color relationships.
[0003] In addition, existing methods generally lack a rigorous mathematical foundation, making it difficult to provide a flexible parameter control mechanism. They cannot independently adjust the brightness and color migration intensity according to user needs, and often cause color distortion after color space conversion due to improper handling of boundary conditions.
[0004] Therefore, there is an urgent need for a color style transfer method that can fully consider the correlation of color channels, has mathematical rigor, supports flexible parameter adjustment, and has a robust color protection mechanism. Summary of the Invention
[0005] The purpose of this invention is to provide an image color style transfer method, apparatus, computer device, and storage medium, aiming to solve the problems existing in the current color style transfer method, such as insufficient consideration of color channel correlation, imprecise mathematical basis, inflexible parameter adjustment, and imperfect color protection mechanism.
[0006] In a first aspect, embodiments of the present invention provide an image color style transfer method, comprising: Image preprocessing and zero-centering are performed on the source image and the reference image respectively to obtain source image data and reference image data; Based on the source image data and reference image data, the corresponding covariance matrix is calculated respectively, and singular value decomposition is performed on each covariance matrix to obtain the initial orthogonal matrix and initial diagonal matrix corresponding to the source image and reference image respectively. Based on the selected color space mode, the initial diagonal matrix of the source image and the initial diagonal matrix of the reference image are parametrically adjusted to obtain the adjusted diagonal matrix of the source image and the adjusted diagonal matrix of the reference image. A whitening transformation matrix is constructed based on the initial orthogonal matrix and the adjusted diagonal matrix of the source image, and a shading transformation matrix is constructed based on the initial orthogonal matrix and the adjusted diagonal matrix of the reference image. The whitening transformation matrix and the coloring transformation matrix are applied sequentially to the source image data to perform color transformation and image reconstruction, resulting in reconstructed image data. The reconstructed image data is subjected to color space protection and post-processing to output the final color migration result image.
[0007] In a second aspect, embodiments of the present invention provide an image color style transfer apparatus, comprising: The image processing unit is used to perform image preprocessing and zero-centering on the source image and the reference image respectively to obtain source image data and reference image data; An initial matrix unit is used to calculate the corresponding covariance matrix based on the source image data and the reference image data, and to perform singular value decomposition on each covariance matrix to obtain the initial orthogonal matrix and the initial diagonal matrix corresponding to the source image and the reference image, respectively. The adjustment matrix unit is used to parametrically adjust the initial diagonal matrix of the source image and the initial diagonal matrix of the reference image according to the selected color space mode, so as to obtain the adjusted diagonal matrix of the source image and the adjusted diagonal matrix of the reference image. The transformation matrix unit is used to construct a whitening transformation matrix based on the initial orthogonal matrix and the adjusted diagonal matrix of the source image, and to construct a coloring transformation matrix based on the initial orthogonal matrix and the adjusted diagonal matrix of the reference image. The reconstruction unit is used to sequentially apply the whitening transformation matrix and the coloring transformation matrix to the source image data to perform color transformation and image reconstruction, thereby obtaining reconstructed image data. The migration unit is used to perform color space protection and post-processing on the reconstructed image data, and output the final color migration result image.
[0008] Thirdly, embodiments of the present invention provide a computer device including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the image color style transfer method described in the first aspect above.
[0009] Fourthly, embodiments of the present invention provide a computer-readable storage medium storing a computer program that, when executed by a processor, causes the processor to perform the image color style transfer method described in the first aspect.
[0010] The beneficial effects of this invention are as follows: A rigorous mathematical framework is established through covariance matrix and singular value decomposition, which can fully capture and transfer the correlation between color channels, overcoming the unnatural color problem caused by ignoring channel correlation in traditional methods. Simultaneously, it supports parameterized adjustment of singular values, providing users with a flexible mechanism for controlling brightness and color migration intensity, enhancing the method's practicality and adaptability. Furthermore, combined with a color space protection strategy, it effectively avoids color distortion and boundary violations, significantly improving the naturalness and robustness of color migration while maintaining computational efficiency. Attached Figure Description
[0011] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the following description of the embodiments will be briefly introduced. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0012] Figure 1 This is a flowchart illustrating the image color style transfer method provided in an embodiment of the present invention. Figure 2 This is a schematic diagram of a sub-process of step S101 provided in an embodiment of the present invention; Figure 3 This is a schematic diagram of a sub-process of step S102 provided in an embodiment of the present invention; Figure 4 This is a schematic diagram of a sub-process of step S103 provided in an embodiment of the present invention; Figure 5 This is a schematic diagram of a sub-process of step S105 provided in an embodiment of the present invention; Figure 6 This is a schematic diagram of a sub-process of step S106 provided in an embodiment of the present invention; Figure 7 A schematic block diagram of an image color style transfer device provided in an embodiment of the present invention; Figure 8A schematic block diagram of a computer device provided for an embodiment of the present invention. Detailed Implementation
[0013] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0014] It should be understood that, when used in this specification and the appended claims, the terms "comprising" and "including" indicate the presence of the described features, integrals, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components and / or collections thereof.
[0015] It should also be understood that the terminology used in this specification is for the purpose of describing particular embodiments only and is not intended to limit the invention. As used in this specification and the appended claims, the singular forms “a,” “an,” and “the” are intended to include the plural forms unless the context clearly indicates otherwise.
[0016] It should also be further understood that the term "and / or" as used in this specification and the appended claims refers to any combination of one or more of the associated listed items and all possible combinations, and includes such combinations.
[0017] Please see Figure 1 , Figure 1 This is a flowchart illustrating the image color style transfer method provided in an embodiment of the present invention. like Figure 1 As shown, the method includes steps S101-S106.
[0018] S101. Perform image preprocessing and zero-centering on the source image and reference image respectively to obtain source image data and reference image data; Step S101 aims to normalize the source and reference images to a unified standard and eliminate the influence of the mean, which facilitates subsequent statistical modeling.
[0019] In one embodiment, such as Figure 2 As shown, step S101 includes: S201. Convert the source image and reference image to or maintain them in the selected color space, which is either Lab color space or RGB color space; S202. Normalize the source image and the reference image respectively to adjust the pixel value range to a preset range, and scale the reference image. S203. Calculate the mean values of the normalized source image and reference image in each color channel respectively; S204. Subtract the mean of the corresponding channel from each pixel value of the source image and the reference image to complete the zero-centering process and obtain the source image data and the reference image data.
[0020] In the scheme of steps S201-S204, the Lab color space in step S201 is a perceptually uniform color model that separates brightness (L) from color information (a, b), which is more in line with human visual perception and is particularly beneficial for achieving the independent adjustment of brightness and color mentioned later in the claims; while the RGB space is a device-related basic space, and the processing is direct. The normalization processing in step S202 (such as scaling pixel values to the [0,1] range) is to unify image data from different sources and with different dimensions into a standard numerical range, ensuring the numerical stability of subsequent matrix operations. Scaling the reference image (such as to a maximum of 512 pixels) is a common engineering optimization aimed at balancing computational accuracy and efficiency, because the dependence of covariance statistics on a large number of pixels can be approximated by downsampling, thereby significantly reducing the amount of computation without significantly affecting the color distribution statistics. SS203 and S204 together complete the zero-centering. The mean of each channel is calculated as mean = [μR, μG, μB] or [μL, μa, μb], representing the overall hue or brightness level of the image. Then, the mean of the corresponding channel is subtracted from each pixel value: Xcentered = X -mean. This operation removes the global color shift (i.e., DC component) of the image, so that the subsequent covariance matrix Cov = (Xcentered^T * Xcentered) / N can purely reflect the changes of the color channels around their mean and the correlation between these changes. This is a prerequisite for all subsequent distribution-matching transformations to be performed correctly.
[0021] The scheme in steps S201-S204 ensures the consistency of input data in color space, numerical range, and statistical characteristics, laying the foundation for the stable operation of subsequent algorithms. The selectivity of the color space enhances the applicability of the method; normalization avoids numerical overflow and unifies the scale; reference image scaling improves the efficiency of the algorithm, especially suitable for processing high-resolution images or real-time video streams; zero-centering is the key to converting the image from an absolute color value representation to a relative color change representation, making statistical matching of color styles feasible.
[0022] S102. Based on the source image data and the reference image data, calculate the corresponding covariance matrix respectively, and perform singular value decomposition on each covariance matrix to obtain the initial orthogonal matrix and the initial diagonal matrix corresponding to the source image and the reference image respectively. Step S102 aims to calculate the covariance matrix and perform singular value decomposition to extract the principal component orientation and variance features of the image color distribution, providing a mathematical basis for color transformation.
[0023] In one embodiment, such as Figure 3 As shown, step S102 includes: S301. Reshape the source image data and reference image data into corresponding two-dimensional matrices, where each row of the two-dimensional matrix represents the color channel values of a pixel. S302. Calculate the covariance matrix of the source image based on the two-dimensional matrix corresponding to the source image data, and calculate the covariance matrix of the reference image based on the two-dimensional matrix corresponding to the reference image data. S303. Perform singular value decomposition on the covariance matrix of the source image to obtain the initial orthogonal matrix and initial diagonal matrix of the source image; perform singular value decomposition on the covariance matrix of the reference image to obtain the initial orthogonal matrix and initial diagonal matrix of the reference image.
[0024] In steps S301-S303, firstly, the source and reference image data, after zero-centering processing, are reshaped from three-dimensional arrays into two-dimensional matrices, where each row of the two-dimensional matrix represents the color channel value of a pixel. Next, the covariance matrix of the source image is calculated based on its corresponding two-dimensional matrix, and similarly, the covariance matrix of the reference image is calculated based on its corresponding two-dimensional matrix. The calculation of the covariance matrix is essentially a statistic measuring the variance of each color channel and the degree of linear correlation between channels. Finally, singular value decomposition (SVD) is performed on the covariance matrices of the source and reference images, respectively. SVD decomposes each covariance matrix into a product of three matrices: an orthogonal matrix whose column vectors represent the principal component directions of the color space; a diagonal matrix whose singular values on the diagonal represent the variance magnitudes along each principal component direction; and the transpose of another orthogonal matrix. Through this decomposition, the essential geometric structure of the image color distribution can be extracted.
[0025] The scheme in steps S301-S303 is the core mathematical foundation of this embodiment. By using singular value decomposition, the complex color distribution information is decoupled into two parts: direction (orthogonal matrix) and scale (diagonal matrix), which allows for targeted adjustment of the scale (i.e., singular values) of the color distribution, thereby achieving controllable color style transfer.
[0026] S103. Based on the selected color space mode, the initial diagonal matrix of the source image and the initial diagonal matrix of the reference image are parametrically adjusted to obtain the adjusted diagonal matrix of the source image and the adjusted diagonal matrix of the reference image. Step S103 aims to flexibly and parametrically adjust the intensity information (singular values) obtained from the decomposition according to the color space mode (RGB or Lab) selected by the user, which is the key to achieving controllable migration intensity.
[0027] In one embodiment, such as Figure 4 As shown, step S103 includes: S401. Determine the singular value adjustment strategy based on the selected color space mode, and proceed to step S402 or S403. S402. If the color space mode is RGB mode, then adjust the singular values in the initial diagonal matrix of the source image by a power of -0.5, and adjust the singular values in the initial diagonal matrix of the reference image by a power of 0.5; and jump to step S404. S403. If the color space mode is Lab mode, then based on the independent luminance and color parameters, adjust the singular values of the corresponding luminance and color channels in the initial diagonal matrix of the source image and the initial diagonal matrix of the reference image by negative and positive powers, respectively; and proceed to step S404. S404. The singular values adjusted in RGB mode or Lab mode are used to construct new diagonal matrices, and invalid singular values in the new diagonal matrices are set to zero, thereby obtaining the adjusted diagonal matrix of the source image and the adjusted diagonal matrix of the reference image.
[0028] In steps S401-S404, firstly, the corresponding singular value adjustment strategy is determined based on the user-selected color space mode. If RGB mode is selected, the singular values in the initial diagonal matrix of the source image are uniformly exponentially raised to -0.5, and the singular values in the initial diagonal matrix of the reference image are uniformly exponentially raised to 0.5. The significance of this adjustment is to whiten the color distribution of the source image (making its covariance matrix an identity matrix) and restore the color distribution of the reference image. If Lab mode is selected, a more refined separation control strategy is adopted. The Lab color space separates luminance information (L channel) from color information (a and b channels). Therefore, based on independent luminance and color parameters, the singular values of the corresponding luminance and color channels in the initial diagonal matrices of the source and reference images are adjusted by different powers. Typically, the singular values of the source image are adjusted by negative powers (such as negative powers of the luminance and color parameters), and the singular values of the reference image are adjusted by positive powers (such as positive powers of the luminance and color parameters). After the adjustment is completed, the adjusted singular values are reconstructed into a new diagonal matrix, and any invalid singular values (such as infinity) are set to zero. Finally, the adjusted diagonal matrices of the source image and the reference image are obtained.
[0029] Steps S401-S404 introduce adjustable parameters to achieve flexible control over the color migration effect. Especially in Lab mode, users can independently adjust the brightness migration intensity and color migration intensity, meeting the differentiated needs for image brightness preservation or color style enhancement in different application scenarios, significantly improving the method's practicality and user experience.
[0030] S104. Construct a whitening transformation matrix based on the initial orthogonal matrix and the adjusted diagonal matrix of the source image, and construct a coloring transformation matrix based on the initial orthogonal matrix and the adjusted diagonal matrix of the reference image. Step S104 aims to construct a whitening transformation matrix for eliminating color correlation in the source image and a shading transformation matrix for assigning color distribution to the reference image.
[0031] In one embodiment, the whitening transformation matrix is constructed by sequentially multiplying the initial orthogonal matrix of the source image, the adjusted diagonal matrix of the source image, and the transpose of the initial orthogonal matrix of the source image. The shading transformation matrix is constructed by sequentially multiplying the initial orthogonal matrix of the reference image, the adjusted diagonal matrix of the reference image, and the transpose of the initial orthogonal matrix of the reference image.
[0032] In this embodiment, when constructing the whitening transformation matrix, the initial orthogonal matrix of the source image, the adjusted diagonal matrix of the source image, and the transpose of the initial orthogonal matrix of the source image are multiplied sequentially in this order, and the result is the whitening transformation matrix. Similarly, when constructing the shading transformation matrix, the initial orthogonal matrix of the reference image, the adjusted diagonal matrix of the reference image, and the transpose of the initial orthogonal matrix of the reference image are multiplied sequentially to obtain the shading transformation matrix.
[0033] From a mathematical perspective, the construction method in this embodiment originates from the decomposition and recombination of the covariance matrix. Let the covariance matrix of the source image be decomposed using SVD as follows: Then the whitening transformation matrix It can transform source image data into an isotropic distribution. Similarly, let the covariance matrix of the reference image be decomposed into... Then the coloring transformation matrix It can impart color distribution characteristics of the reference image to whitened data. Through this construction, the color transfer process is clearly decomposed into two linear transformation steps: eliminating color correlation in the source image and applying the color style of the target image. It is theoretically rigorous and computationally efficient.
[0034] S105. Apply the whitening transformation matrix and the coloring transformation matrix to the source image data in sequence to perform color transformation and image reconstruction, and obtain the reconstructed image data. Step S105 aims to apply the above transformations sequentially through matrix multiplication to complete color migration and data reconstruction.
[0035] In one embodiment, such as Figure 5 As shown, step S105 includes: S501. Multiply the whitening transformation matrix with the source image data to obtain intermediate transformation data; S502. Multiply the color transformation matrix with the intermediate transformation data to obtain the color-transformed data; S503: Reshape the color-transformed data into a three-dimensional array identical to the source image; S504. Add the mean of the reference image to the three-dimensional array to complete the image reconstruction and obtain the reconstructed image data.
[0036] In steps S501-S505, firstly, step S501 performs matrix multiplication with the constructed whitening transformation matrix and the zero-centered source image data (organized with appropriate dimensions) to obtain intermediate transformation data; step S501 whitens the color distribution of the source image, eliminating the correlation between its color channels. Next, step S502 multiplies the color transformation matrix with the intermediate transformation data obtained in step S501 to obtain the color-transformed data; this step assigns the color style features of the reference image to the source image. Then, step S503 reshapes the color-transformed data into a three-dimensional array structure with the same height, width, and number of channels as the original source image. Finally, step S504 adds the previously calculated mean values of each channel of the reference image to each corresponding channel of this three-dimensional array to restore the absolute position information of the colors, completing image reconstruction and obtaining the reconstructed image data.
[0037] The series of matrix operations and reshaping operations in steps S501-S505 completely realize the mapping from mathematical transformation to image data. By applying whitening transformation first and then chromatic transformation, the logical correctness of the color transfer process is ensured; and the final operation of adding the mean of the reference image makes the transferred image exhibit the overall tonal tendency of the reference image, ensuring the harmony of the visual effect.
[0038] S106. Perform color space protection and post-processing on the reconstructed image data, and output the final color transfer result image; Step S106 aims to perform color space protection and post-processing on the reconstruction results to ensure the color validity and visual naturalness of the output image.
[0039] In one embodiment, such as Figure 6 As shown, step S106 includes: If the color space mode is Lab, then perform the following steps: S601. Limit the brightness channel values of the reconstructed image data to a first preset range, and limit the two chroma channel values of the reconstructed image data to a second preset range. S602. Perform inverse normalization on the reconstructed image data after numerical limiting to restore it to the standard image value range. S603. Convert the denormalized reconstructed image data from Lab color space back to RGB color space; S604. Perform color deviation repair processing on the reconstructed image data converted back to RGB color space to obtain the final color migration result image; If the color space mode is RGB, then perform the following steps: The reconstructed image data is denormalized to restore it to the standard image value range, resulting in the final color migration image.
[0040] In this embodiment, the specific operations of color space protection and post-processing are differentiated according to the color space mode. If the current color space mode is Lab mode, the following steps are executed sequentially: First, the value of the luminance channel (L channel) of the reconstructed image data is limited to a first preset range (e.g., [0,1]), and the values of the two chroma channels (a channel and b channel) are limited to a second preset range (e.g., [0.3,0.7]) to prevent out-of-bounds values from occurring during color space conversion. Second, the reconstructed image data after numerical limiting is denormalized to restore it from the normalized range to the standard image value range (e.g., [0,255]). Then, the denormalized image data is converted from Lab color space back to RGB color space for display or storage. Finally, the image data converted back to RGB color space is subjected to color deviation repair processing, such as correcting anomalies such as blue bias that may be caused by numerical rounding or space conversion, thereby obtaining the final color migration result image.
[0041] If the current color space mode is RGB, the post-processing is relatively simple. The reconstructed image data is directly denormalized to restore it to the standard image value range, and the final color transfer result image can be obtained.
[0042] This embodiment is a crucial step in ensuring the quality of the output image. Especially in Lab mode, targeted numerical limiting and color deviation correction effectively avoid common problems such as color distortion and saturation overflow, ensuring the visual naturalness and harmony of the transfer results and improving the robustness and practicality of the algorithm.
[0043] As can be seen, the scheme in steps S101-S106 establishes a rigorous mathematical framework through covariance matrix and singular value decomposition, which can fully capture and transfer the correlation between color channels, overcoming the unnatural color problem caused by ignoring channel correlation in traditional methods. Simultaneously, it supports parameterized adjustment of singular values, providing users with a flexible mechanism for controlling brightness and color migration intensity, enhancing the method's practicality and adaptability. Furthermore, combined with color space protection strategies, it effectively avoids color distortion and boundary violations, significantly improving the naturalness and robustness of color migration while maintaining computational efficiency.
[0044] This invention also provides an image color style transfer apparatus, which is used to perform any of the aforementioned image color style transfer methods. Specifically, please refer to... Figure 7 , Figure 7This is a schematic block diagram of the image color style transfer device provided in an embodiment of the present invention.
[0045] like Figure 7 As shown, the image color style transfer device 700 includes: an image processing unit 701, an initial matrix unit 702, an adjustment matrix unit 703, a transformation matrix unit 704, a reconstruction unit 705, and a transfer unit 706.
[0046] The image processing unit 701 is used to perform image preprocessing and zero-centering processing on the source image and the reference image respectively to obtain source image data and reference image data; The initial matrix unit 702 is used to calculate the corresponding covariance matrix based on the source image data and the reference image data, and to perform singular value decomposition on each covariance matrix to obtain the initial orthogonal matrix and the initial diagonal matrix corresponding to the source image and the reference image, respectively. The adjustment matrix unit 703 is used to parametrically adjust the initial diagonal matrix of the source image and the initial diagonal matrix of the reference image according to the selected color space mode, so as to obtain the adjusted diagonal matrix of the source image and the adjusted diagonal matrix of the reference image. Transformation matrix unit 704 is used to construct a whitening transformation matrix based on the initial orthogonal matrix and the adjusted diagonal matrix of the source image, and to construct a coloring transformation matrix based on the initial orthogonal matrix and the adjusted diagonal matrix of the reference image. The reconstruction unit 705 is used to apply the whitening transformation matrix and the coloring transformation matrix to the source image data in sequence to perform color transformation and image reconstruction, thereby obtaining reconstructed image data. The migration unit 706 is used to perform color space protection and post-processing on the reconstructed image data and output the final color migration result image.
[0047] This device establishes a rigorous mathematical framework through covariance matrix and singular value decomposition, enabling it to fully capture and transfer the correlation between color channels, overcoming the unnatural color problem caused by neglecting channel correlation in traditional methods. Simultaneously, it supports parameterized adjustment of singular values, providing users with a flexible mechanism for controlling brightness and color transfer intensity, enhancing the method's practicality and adaptability. Furthermore, combined with color space protection strategies, it effectively avoids color distortion and boundary violations, significantly improving the naturalness and robustness of color transfer while maintaining computational efficiency.
[0048] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working process of the above-described apparatus and unit can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0049] The aforementioned image color style transfer device can be implemented as a computer program, which can be used in, for example... Figure 8 It runs on the computer device shown.
[0050] Please see Figure 8 , Figure 8 This is a schematic block diagram of a computer device provided in an embodiment of the present invention. The computer device 800 is a server, which can be a standalone server or a server cluster composed of multiple servers.
[0051] See Figure 8 The computer device 800 includes a processor 802, a memory, and a network interface 805 connected via a system bus 801. The memory may include a non-volatile storage medium 803 and internal memory 804.
[0052] The non-volatile storage medium 803 may store an operating system 8031 and a computer program 8032. When the computer program 8032 is executed, it causes the processor 802 to perform an image color style transfer method.
[0053] The processor 802 provides computing and control capabilities to support the operation of the entire computer device 800.
[0054] The internal memory 804 provides an environment for the execution of the computer program 8032 in the non-volatile storage medium 803. When the computer program 8032 is executed by the processor 802, the processor 802 can perform an image color style transfer method.
[0055] This network interface 805 is used for network communication, such as providing data transmission. Those skilled in the art will understand that... Figure 8 The structure shown is merely a block diagram of a portion of the structure related to the present invention and does not constitute a limitation on the computer device 800 to which the present invention is applied. The specific computer device 800 may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0056] Those skilled in the art will understand that Figure 8 The embodiments of the computer device shown do not constitute a limitation on the specific configuration of the computer device. In other embodiments, the computer device may include more or fewer components than illustrated, or combine certain components, or have different component arrangements. For example, in some embodiments, the computer device may include only memory and a processor. In such embodiments, the structure and function of the memory and processor are different from those shown. Figure 8 The embodiments shown are consistent and will not be repeated here.
[0057] It should be understood that, in this embodiment of the invention, the processor 802 may be a Central Processing Unit (CPU), or it may be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or any conventional processor.
[0058] In another embodiment of the invention, a computer-readable storage medium is provided. This computer-readable storage medium may be a non-volatile computer-readable storage medium. The computer-readable storage medium stores a computer program, wherein the computer program, when executed by a processor, implements the image color style transfer method of the embodiments of the present invention.
[0059] The storage medium is a physical, non-transient storage medium, such as a USB flash drive, portable hard drive, read-only memory (ROM), magnetic disk, or optical disk, or any other physical storage medium capable of storing program code.
[0060] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the devices, apparatuses, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0061] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in the present invention, and these modifications or substitutions should all be covered within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. An image color style transfer method, characterized in that, include: Image preprocessing and zero-centering are performed on the source image and the reference image respectively to obtain source image data and reference image data; Based on the source image data and reference image data, the corresponding covariance matrix is calculated respectively, and singular value decomposition is performed on each covariance matrix to obtain the initial orthogonal matrix and initial diagonal matrix corresponding to the source image and reference image respectively. Based on the selected color space mode, the initial diagonal matrix of the source image and the initial diagonal matrix of the reference image are parametrically adjusted respectively to obtain the adjusted diagonal matrix of the source image and the adjusted diagonal matrix of the reference image. A whitening transformation matrix is constructed based on the initial orthogonal matrix and the adjusted diagonal matrix of the source image, and a shading transformation matrix is constructed based on the initial orthogonal matrix and the adjusted diagonal matrix of the reference image. The whitening transformation matrix and the coloring transformation matrix are applied sequentially to the source image data to perform color transformation and image reconstruction, resulting in reconstructed image data. The reconstructed image data is subjected to color space protection and post-processing to output the final color migration result image.
2. The image color style transfer method according to claim 1, characterized in that, The steps of performing image preprocessing and zero-centering on the source image and reference image respectively to obtain source image data and reference image data include: Convert or maintain the source and reference images to a selected color space, which is either the Lab color space or the RGB color space; The source image and the reference image are normalized to adjust the pixel value range to a preset range, and the reference image is scaled. Calculate the mean values of the source and reference images in each color channel after normalization. The source image and reference image data are obtained by subtracting the mean of the corresponding channel from each pixel value of the source image and reference image to perform zero-centering processing.
3. The image color style transfer method according to claim 1, characterized in that, The steps of calculating the corresponding covariance matrices based on the source image data and reference image data, and performing singular value decomposition on each covariance matrix to obtain the initial orthogonal matrix and initial diagonal matrix corresponding to the source image and reference image respectively, include: The source image data and reference image data are reshaped into corresponding two-dimensional matrices, wherein each row of the two-dimensional matrix represents the color channel values of a pixel. The covariance matrix of the source image is calculated based on the two-dimensional matrix corresponding to the source image data, and the covariance matrix of the reference image is calculated based on the two-dimensional matrix corresponding to the reference image data. Singular value decomposition is performed on the covariance matrix of the source image to obtain the initial orthogonal matrix and the initial diagonal matrix of the source image; singular value decomposition is performed on the covariance matrix of the reference image to obtain the initial orthogonal matrix and the initial diagonal matrix of the reference image.
4. The image color style transfer method according to claim 1, characterized in that, The step of parametrically adjusting the initial diagonal matrix of the source image and the initial diagonal matrix of the reference image according to the selected color space mode to obtain the adjusted diagonal matrix of the source image and the adjusted diagonal matrix of the reference image includes: Determine the singular value adjustment strategy based on the selected color space mode; If the color space mode is RGB mode, then the singular values in the initial diagonal matrix of the source image are adjusted by a power of -0.5, and the singular values in the initial diagonal matrix of the reference image are adjusted by a power of 0.
5. If the color space mode is Lab mode, then based on the independent luminance and color parameters, the singular values of the corresponding luminance and color channels in the initial diagonal matrix of the source image and the initial diagonal matrix of the reference image are adjusted by negative and positive powers, respectively. The singular values adjusted under the RGB mode or the Lab mode are used to construct new diagonal matrices, and invalid singular values in the new diagonal matrices are set to zero, thereby obtaining the adjusted diagonal matrix of the source image and the adjusted diagonal matrix of the reference image.
5. The image color style transfer method according to claim 1, characterized in that, The method for constructing the whitening transformation matrix is as follows: the initial orthogonal matrix of the source image, the adjusted diagonal matrix of the source image, and the transpose of the initial orthogonal matrix of the source image are multiplied sequentially to obtain the whitening transformation matrix; The method for constructing the color transformation matrix is as follows: the initial orthogonal matrix of the reference image, the adjusted diagonal matrix of the reference image, and the transpose of the initial orthogonal matrix of the reference image are multiplied sequentially to obtain the color transformation matrix.
6. The image color style transfer method according to claim 1, characterized in that, The step of sequentially applying the whitening transformation matrix and the coloring transformation matrix to the source image data for color transformation and image reconstruction to obtain reconstructed image data includes: Multiply the whitening transformation matrix by the source image data to obtain intermediate transformation data; Multiply the color transformation matrix by the intermediate transformation data to obtain the color-transformed data; The color-transformed data is reshaped into a three-dimensional array identical to the source image; The mean of the reference image is added to the three-dimensional array to complete the image reconstruction, resulting in reconstructed image data.
7. The image color style transfer method according to claim 1, characterized in that, The steps of performing color space protection and post-processing on the reconstructed image data to output the final color transfer result image include: If the color space mode is Lab mode, then perform the following steps: The luminance channel values of the reconstructed image data are limited within a first preset range, and the two chrominance channel values of the reconstructed image data are limited within a second preset range. The reconstructed image data after numerical limiting is denormalized to restore it to the standard image value range. The reconstructed image data after denormalization is converted from the Lab color space back to the RGB color space; The reconstructed image data converted back to RGB color space is subjected to color deviation repair processing to obtain the final color migration result image; If the color space mode is RGB mode, then perform the following steps: The reconstructed image data is denormalized to restore it to the standard image value range, resulting in the final color migration result image.
8. An image color style transfer device, characterized in that, include: The image processing unit is used to perform image preprocessing and zero-centering on the source image and the reference image respectively to obtain source image data and reference image data; An initial matrix unit is used to calculate the corresponding covariance matrix based on the source image data and the reference image data, and to perform singular value decomposition on each covariance matrix to obtain the initial orthogonal matrix and the initial diagonal matrix corresponding to the source image and the reference image, respectively. The adjustment matrix unit is used to parametrically adjust the initial diagonal matrix of the source image and the initial diagonal matrix of the reference image according to the selected color space mode, so as to obtain the adjusted diagonal matrix of the source image and the adjusted diagonal matrix of the reference image. The transformation matrix unit is used to construct a whitening transformation matrix based on the initial orthogonal matrix and the adjusted diagonal matrix of the source image, and to construct a coloring transformation matrix based on the initial orthogonal matrix and the adjusted diagonal matrix of the reference image. The reconstruction unit is used to sequentially apply the whitening transformation matrix and the coloring transformation matrix to the source image data to perform color transformation and image reconstruction, thereby obtaining reconstructed image data. The migration unit is used to perform color space protection and post-processing on the reconstructed image data, and output the final color migration result image.
9. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the image color style transfer method as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, causes the processor to perform the image color style transfer method as described in any one of claims 1 to 7.
