An image color transfer method, system, and computer medium

By combining the KNN regression model and the Reinhard algorithm in the Lab color space, the shortcomings of existing image color transfer algorithms in color-rich and grayscale images are addressed, achieving a more natural color transfer effect.

CN115147259BActive Publication Date: 2026-11-17SUN YAT SEN UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210225721.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-03-07
Publication Date
2026-11-17
Estimated Expiration
2042-03-07

AI Technical Summary

Technical Problem

Existing image color transfer algorithms do not perform well when processing images with rich colors. In particular, the Reinhard algorithm cannot be directly applied to grayscale images, and the Welsh algorithm is inefficient and depends on brightness features. The transfer effect of existing methods is not ideal.

Method used

An image color transfer method based on the K-nearest neighbor regression model is adopted. By converting the source image and the target image to the Lab color space, a KNN regression model is established, color transfer is performed using local features, and the results are optimized by combining the Reinhard algorithm.

Benefits of technology

It improves the image transfer effect, solves the shortcomings of existing algorithms in local color detail processing, and achieves a more natural color transfer effect.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115147259B_ABST
    Figure CN115147259B_ABST
Patent Text Reader

Abstract

This invention provides an image color transfer method, system, and computer medium. The method utilizes local features of an image to transfer colors. This algorithm can transfer local color details in an image, improving the image transfer effect to a certain extent. This solves the problem that the above algorithms only use global color statistics as features, ignoring local information, resulting in unsatisfactory transfer effects when the color tones of the source and target images are very different. Simultaneously, it combines global statistical features with local pixel features. It can first perform K-nearest neighbor-based color transfer on the source image, and then perform a Reinhard color transfer operation on the resulting image; or first perform Reinhard color transfer on the source image, and then perform a K-nearest neighbor-based color transfer operation on the resulting image. This solves the problem of potentially unnatural color transitions between adjacent pixels.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of digital image processing, and more specifically, to an image color transfer method, system, and computer medium. Background Technology

[0002] In digital image processing technology, image color transfer technology can meet user needs, enabling images to achieve the colors desired by the user. Image color transfer technology involves learning the overall tone and color of a target image through a certain method, without altering the content information expressed in the source image, and then applying that tone and color to the source image, so that the source image has similar color information to the target image. Image color transfer technology can modify the color information of an image to meet the different color needs of different users.

[0003] The Reinhard algorithm utilizes the incoordination of the three channels in the Lab color space to modify the values ​​of these three channels in both the source and target images, making their mean and variance equal, thus achieving color transfer between images. The algorithm is easy to implement and runs quickly and efficiently. However, when processing images with rich colors, the L, a, and b channels amplify the chromaticity difference, leading to unsatisfactory results. The Reinhard algorithm can only be applied to color image-to-color image conversions. If one image is grayscale, the limitation of grayscale images having only one luminance channel prevents the Reinhard algorithm from being directly applied to grayscale images.

[0004] Welsh proposed a color transfer algorithm between grayscale and color images. The main operation of this algorithm is to match the brightness and texture information of the grayscale and color images, transferring the entire color from the source image to the target image, thus achieving colorization of the grayscale image. However, this algorithm spends a significant amount of time finding the optimal matching point for each pixel, reducing its efficiency. Furthermore, this algorithm only utilizes brightness features during the matching process; therefore, the quality of the transfer depends on the consistency and similarity of the brightness and color features between the source and target images.

[0005] Existing technology discloses a color transfer method that integrates global and superpixel segmentation. First, the source image and target image are segmented using gradient descent simple linear iterative clustering. Then, for each superpixel in the source image, the most similar superpixel is searched in the target image. Color transfer is then performed between the matched superpixel pairs. Finally, the problem of incorrect color transfer and unnatural brightness transition caused by mismatches due to over-segmentation is eliminated. First, a fuzzy matrix is ​​introduced in the first matching transfer process. Then, the global statistical information of the initial transfer result is used to perform a second color transfer on the source image to obtain a more natural color transfer effect. However, this scheme is relatively cumbersome and the transfer effect is not ideal. Summary of the Invention

[0006] The primary objective of this invention is to provide an image color transfer method that improves the image transfer effect to a certain extent.

[0007] A further object of the present invention is to provide an image color transfer system.

[0008] A third objective of this invention is to provide a computer medium.

[0009] To solve the above-mentioned technical problems, the technical solution of the present invention is as follows:

[0010] An image color transfer method includes the following steps:

[0011] S1: Convert the RGB color space of the source image S and the target image T to the Lab color space using a color space transformation matrix;

[0012] S2: Establish datasets based on the transformed source image S and target image T respectively;

[0013] S3: Establish a first KNN regression model and a second KNN regression model, and train the first KNN regression model and the second KNN regression model respectively using the dataset to obtain the trained first KNN regression model that maps from channel L to channel a and the second KNN regression model that maps from channel L to channel b.

[0014] S4: Using the trained first KNN regression model and second KNN regression model, predict the values ​​of channel a and channel b mapped by channel L in the source image S, respectively, to obtain the mapped image;

[0015] S5: Convert the mapped image back to the RGB color space to obtain the result image, thus realizing the transfer of the color of the target image T to the source image S.

[0016] Preferably, in step S2, datasets are established based on the converted source image S and target image T, specifically as follows:

[0017] The dataset includes a training set and a prediction set. The training set consists of an N×N rectangular block in channel L of the target image T and the values ​​of channel a and channel b corresponding to the center point of the N×N rectangular block. The prediction set of the model consists of an N×N rectangular block in channel L of the source image S.

[0018] Preferably, the first KNN regression model and the second KNN regression model are specifically as follows:

[0019] In channel L of the target image T, for each N×N rectangular block, find K blocks that are closest in numerical distance to the N×N rectangular block. The closer the numerical distance, the more similar the information in channel L of the two rectangular blocks. In order to make the influence of the rectangular blocks with closer numerical distance on the selected rectangular block greater than the influence of the rectangular blocks with farther numerical distance, the inverse of the numerical distance is used for weighting. The first KNN regression model maps from channel L to channel a and the second KNN regression model maps from channel L to channel b.

[0020] Preferably, the numerical distance is measured using Manhattan distance.

[0021] Preferably, the N×N rectangular block is a 3×3 rectangular block.

[0022] Preferably, before converting the source image S from the RGB color space to the Lab color space in step S1, the method further includes the following step:

[0023] The Reinhard color transfer algorithm is used to perform a Reinhard color transfer operation on the source image S, where the source image S is a color image.

[0024] Preferably, after obtaining the result image in step S5, the method further includes the following step:

[0025] The Reinhard color transfer algorithm is used to perform a Reinhard color transfer operation on the resulting image.

[0026] An image color transfer system, comprising:

[0027] A color space conversion module is used to convert the RGB color space of the source image S and the target image T to the Lab color space using a color space conversion matrix.

[0028] A dataset creation module is used to create datasets based on the converted source image S and target image T respectively.

[0029] The regression model module is used to establish a first KNN regression model and a second KNN regression model. The first KNN regression model and the second KNN regression model are trained using the dataset to obtain the trained first KNN regression model that maps from channel L to channel a and the second KNN regression model that maps from channel L to channel b.

[0030] The prediction module is used to predict the values ​​of channel a and channel b mapped by channel L in the source image S using the trained first KNN regression model and second KNN regression model, respectively, to obtain the mapped image;

[0031] The output module is used to convert the mapped image back to the RGB color space to obtain the result image, thereby realizing the transfer of the color of the target image T to the source image S.

[0032] Preferably, in the regression model module, the first KNN regression model and the second KNN regression model are specifically:

[0033] In channel L of the target image T, for each N×N rectangular block, find K blocks that are closest in numerical distance to the N×N rectangular block. The closer the numerical distance, the more similar the information in channel L of the two rectangular blocks. In order to make the influence of the rectangular blocks with closer numerical distance on the selected rectangular block greater than the influence of the rectangular blocks with farther numerical distance, the inverse of the numerical distance is used for weighting. The first KNN regression model maps from channel L to channel a and the second KNN regression model maps from channel L to channel b.

[0034] A computer medium storing a computer program, which, when executed by a processor, implements the image color transfer method described above.

[0035] Compared with the prior art, the beneficial effects of the technical solution of the present invention are:

[0036] This patent application proposes a color transfer algorithm based on the K-nearest neighbor regression model. This algorithm utilizes local features of the image to transfer colors, enabling the transfer of local color details and improving the image transfer effect. This addresses the problem of previous algorithms that only used global color statistics as features while ignoring local information, resulting in unsatisfactory transfer effects when the color tones of the source and target images are significantly different. Attached Figure Description

[0037] Figure 1 This is a schematic diagram of the method flow in Example 1.

[0038] Figure 2This is a schematic diagram of the method flow in Example 2.

[0039] Figure 3 This is a schematic diagram of the method flow in Example 3.

[0040] Figure 4 As one embodiment of the present invention, Figure 4 (a) is the source image during the color transfer process. Figure 4 (b) is the target image during the color transfer process. Figure 4 (c) shows the transfer results of the Reinhard algorithm. Figure 4 (d) is the transfer result of the KNN algorithm.

[0041] Figure 5 To Figure 4 Continuation of the embodiments, Figure 5 (a) shows the transfer results of the KNN-2 algorithm. Figure 5 (b) shows the transfer results of the KNN-3 algorithm.

[0042] Figure 6 The source image is provided for one embodiment of the present invention.

[0043] Figure 7 According to Figure 6 A comparative diagram showing the results of applying different color transfer algorithms to the provided source images. Figure 7 (a) is the target image during the color transfer process. Figure 7 (b) shows the transfer result of the Reinhard algorithm. Figure 7 (c) shows the transfer results of the Welsh algorithm. Figure 7 (d) shows the transfer result of the KNN-1 algorithm. Figure 7 (e) is the transfer result of the KNN-2 algorithm. Figure 7 (f) is the transfer result of the KNN-3 algorithm.

[0044] Figure 8 According to Figure 6 A comparative diagram showing the results of applying different color transfer algorithms to the provided source images. Figure 8 (a) is the target image during the color transfer process. Figure 8 (b) shows the transfer result of the Reinhard algorithm. Figure 8 (c) shows the transfer results of the Welsh algorithm. Figure 8 (d) shows the transfer result of the KNN-1 algorithm. Figure 8 (e) is the transfer result of the KNN-2 algorithm. Figure 8 (f) is the transfer result of the KNN-3 algorithm.

[0045] Figure 9 According to Figure 6A comparative diagram showing the results of applying different color transfer algorithms to the provided source images. Figure 9 (a) is the target image during the color transfer process. Figure 9 (b) shows the transfer result of the Reinhard algorithm. Figure 9 (c) shows the transfer results of the Welsh algorithm. Figure 9 (d) shows the transfer result of the KNN-1 algorithm. Figure 9 (e) is the transfer result of the KNN-2 algorithm. Figure 9 (f) is the transfer result of the KNN-3 algorithm.

[0046] Figure 10 According to Figure 6 A comparative diagram showing the results of applying different color transfer algorithms to the provided source images. Figure 10 (a) is the target image during the color transfer process. Figure 10 (b) shows the transfer result of the Reinhard algorithm.

[0047] Figure 10 (c) shows the transfer results of the Welsh algorithm. Figure 10 (d) shows the transfer result of the KNN-1 algorithm. Figure 10 (e) is the transfer result of the KNN-2 algorithm. Figure 10 (f) is the transfer result of the KNN-3 algorithm.

[0048] Figure 11 A target image provided for one embodiment of the present invention.

[0049] Figure 12 According to Figure 11 A comparative diagram showing the results of applying different color transfer algorithms to the provided source images. Figure 12 (a) is the source image during the color transfer process. Figure 12 (b) shows the transfer result of the Reinhard algorithm.

[0050] Figure 12 (c) shows the transfer results of the Welsh algorithm. Figure 12 (d) shows the transfer result of the KNN-1 algorithm. Figure 12 (e) is the transfer result of the KNN-2 algorithm. Figure 12 (f) is the transfer result of the KNN-3 algorithm.

[0051] Figure 13 A target image provided for one embodiment of the present invention.

[0052] Figure 14 According to Figure 13 A comparative diagram showing the results of applying different color transfer algorithms to the provided source images. Figure 14(a) is the source image during the color transfer process. Figure 14 (b) shows the transfer result of the Reinhard algorithm. Figure 14 (c) shows the transfer results of the Welsh algorithm. Figure 14 (d) shows the transfer result of the KNN-1 algorithm. Figure 14 (e) is the transfer result of the KNN-2 algorithm. Figure 14 (f) is the transfer result of the KNN-3 algorithm.

[0053] Figure 15 This is a schematic diagram of one embodiment of the present invention. Figure 15 (a) is the source image during the color transfer process. Figure 15 (b) is the target image during the color transfer process. Figure 15 (c) shows the transfer results of the Reinhard algorithm. Figure 15 (d) shows the transfer result of the KNN algorithm. Figure 15 (e) is the transfer result of the KNN-2 algorithm.

[0054] Figure 16 This is a schematic diagram of one embodiment of the present invention. Figure 16 (a) is the source image during the color transfer process. Figure 16 (b) is the target image during the color transfer process. Figure 16 (c) shows the transfer results of the Reinhard algorithm. Figure 16 (d) shows the transfer result of the KNN algorithm. Figure 16 (e) is the transfer result of the KNN-2 algorithm. Detailed Implementation

[0055] The accompanying drawings are for illustrative purposes only and should not be construed as limiting the scope of this patent.

[0056] To better illustrate this embodiment, some parts in the accompanying drawings may be omitted, enlarged, or reduced, and do not represent the actual product dimensions;

[0057] It will be understood by those skilled in the art that certain well-known structures and their descriptions may be omitted in the accompanying drawings.

[0058] The technical solution of the present invention will be further described below with reference to the accompanying drawings and embodiments.

[0059] Example 1

[0060] This embodiment provides an image color transfer method, such as... Figure 1 As shown, it includes the following steps:

[0061] S1: Convert the RGB color space of the source image S and the target image T to the Lab color space using a color space transformation matrix;

[0062] S2: Establish datasets based on the transformed source image S and target image T respectively;

[0063] S3: Establish a first KNN regression model and a second KNN regression model, and train the first KNN regression model and the second KNN regression model respectively using the dataset to obtain the trained first KNN regression model that maps from channel L to channel a and the second KNN regression model that maps from channel L to channel b.

[0064] S4: Using the trained first KNN regression model and second KNN regression model, predict the values ​​of channel a and channel b mapped by channel L in the source image S, respectively, to obtain the mapped image;

[0065] S5: Convert the mapped image back to the RGB color space to obtain the result image, thus realizing the transfer of the color of the target image T to the source image S.

[0066] In step S2, datasets are established based on the transformed source image S and target image T, specifically as follows:

[0067] The dataset includes a training set and a prediction set. The training set consists of an N×N rectangular block in channel L of the target image T and the values ​​of channel a and channel b corresponding to the center point of the N×N rectangular block. The prediction set of the model consists of an N×N rectangular block in channel L of the source image S.

[0068] The first KNN regression model and the second KNN regression model are as follows:

[0069] In channel L of the target image T, for each N×N rectangular block, find K blocks that are closest in numerical distance to the N×N rectangular block. The closer the numerical distance, the more similar the information in channel L of the two rectangular blocks. In order to make the influence of the rectangular blocks with closer numerical distance on the selected rectangular block greater than the influence of the rectangular blocks with farther numerical distance, the inverse of the numerical distance is used for weighting. The first KNN regression model maps from channel L to channel a and the second KNN regression model maps from channel L to channel b.

[0070] The numerical distance is measured using Manhattan distance.

[0071] The N×N rectangular block is specifically a 3×3 rectangular block.

[0072] Example 2

[0073] This embodiment, based on embodiment 1, after obtaining the result image in step S5, is as follows: Figure 3 It also includes the following steps:

[0074] The Reinhard color transfer algorithm is used to perform a Reinhard color transfer operation on the resulting image.

[0075] Example 3

[0076] This embodiment, based on embodiment 1, modifies the source image S before converting its RGB color space to the Lab color space in step S1, as follows: Figure 2 It also includes the following steps:

[0077] The Reinhard color transfer algorithm is used to perform a Reinhard color transfer operation on the source image S, where the source image S is a color image.

[0078] Example 4

[0079] This embodiment provides specific implementations of the image color transfer methods proposed in Embodiments 1, 2, and 3.

[0080] Figure 4 This is an embodiment of the image color transfer algorithm provided in Example 1. Color transfer processing is performed on the following two images, and the results are compared with the color transfer results of Reinhard et al. For example... Figure 4 As shown, the source image Figure 4 (a) shows a lawn and houses, target image. Figure 4 (b) shows red trees at dusk; the target image needs to be... Figure 4 (b) Color transfer to the source image Figure 4 (a) Above, Figure 4 (c) is the result image obtained using the Reinhard color transfer algorithm. Figure 4 (d) is the result image obtained using the image color transfer algorithm proposed in Example 1.

[0081] Analyzing the transfer effect images obtained by the two algorithms above, it can be found that since the color transfer algorithm proposed by Reinhard et al. uses the overall statistical value of the target image's color as a feature for transfer, when the overall color tone of the target image is reddish, the sky in the final transferred effect image is also reddish, and the overall color of the image is also reddish. However, the image color transfer algorithm proposed in Example 1 uses the KNN algorithm to establish mappings from channel L to channels a and b in the Lab space using local data of the target image. Then, it directly uses the trained mappings in the Lab space of the source image, taking the value of channel L as the independent variable, and obtains the values ​​of channels a and b corresponding to the color tone. Through the KNN algorithm, it can be seen that the color transfer algorithm based on the K-nearest neighbor regression model differs from the color transfer algorithm proposed by Reinhard et al. It utilizes the local features of pixels for transfer, so the overall color tone of the final transferred effect image is yellow. However, since the color transfer algorithm based on the K-nearest neighbor regression model only uses local information for transfer, it may cause unnatural over-coloring of adjacent pixels, such as... Figure 4 As shown in (d), the white clouds in the sky are directly separated from the yellow sky, which looks a bit abrupt.

[0082] To address the issues of the two algorithms mentioned above, global statistical features are combined with local pixel features. This can be achieved by first performing K-nearest neighbor-based color transfer on the source image, followed by a Reinhard color transfer operation on the resulting image. Alternatively, Reinhard color transfer can be performed on the source image first, followed by a K-nearest neighbor-based color transfer operation on the resulting image. The source and target images are still used for illustration, as shown below. Figure 5 As shown, for ease of description, in the following text, the image color transfer proposed in Example 1 is represented by the KNN-1 algorithm, the image color transfer method proposed in Example 2 is represented by KNN-2, which is to first use the color transfer algorithm based on the K-nearest neighbor regression model and then use the Reinhard color transfer algorithm, and the image color transfer method proposed in Example 3 is represented by KNN-3, which is to first perform the Reinhard color transfer operation and then use the color transfer algorithm based on the K-nearest neighbor regression model.

[0083] Analyze and observe the resulting images obtained by the four algorithms, such as Figure 5 It can be observed that the image obtained by the KNN-2 algorithm is not significantly different from the image obtained by the KNN-1 algorithm. The image still presents an overall yellow tone. However, the image obtained by the KNN-3 algorithm shows a clear blue tone in the sky, which is more similar to the twilight sky in the target image. However, there are still seemingly discontinuous pixel blocks in the sky.

[0084] Color is the effect of light reflected from an object, and its perception is based on human visual perception. Color is the most perceptible feature of an image because it is one of the most expressive features, directly attracting the eye and influencing emotions, affecting both psychological and physiological aspects. Many psychologists believe that vision is the primary sense, and color has the greatest impact on vision. A painting can reflect the artist's emotional state at the time, and color preferences can indicate personality traits. In character portrayal, the shared meanings of color perception are used to express character traits; the colors of facial makeup in Sichuan opera also reflect the character's qualities. These all fall within the psychological scope of color.

[0085] like Figure 7 As shown, the target image here Figure 7 (a) is a photograph of the sea level before a storm, with alternating white and dark blue clouds in the sky. The overall structure of the photograph is similar to the source image. Figure 6 The structure is similar.

[0086] Observing the migration results images 7 obtained by the five algorithms, we can see that in the image obtained by the Reinhard algorithm, the wheat ears still retain green pixels, and blue pixels can be faintly seen in the sky; the overall color tone of the image obtained by the KNN-1 algorithm is light gray; the image obtained by the KNN-2 algorithm is more inclined to dark gray; the image obtained by Welsh has a color tone between the two; and the overall color tone of the image obtained by the KNN-3 algorithm is more inclined to dark blue. Visually, the image obtained by the KNN-3 algorithm is more similar to the overall tone of the target image.

[0087] like Figure 8 As shown in (a), the target image here is a photograph of a blue hydrangea. Observe. Figure 8 It can be observed that in the image produced by the Reinhard algorithm, there is a clear boundary between the green wheat field and the blue sky, resulting in an unnatural transition. In contrast, the foreground and background of the images produced by the other four algorithms blend very naturally. Regarding the wheat ears, the Reinhard algorithm's image retains a green tint, while the wheat ears from the other four algorithms appear as varying degrees of blue. Visually, the KNN-1 algorithm's image is brighter, the KNN-3 algorithm's image is less bright, and the Welsh algorithm's image is brighter than the KNN-2 algorithm, falling somewhere between the KNN-1 and KNN-3 algorithms. It is difficult to judge the relative merits of the KNN-2 and Welsh algorithms with the naked eye.

[0088] In a comparative analysis of the experimental results on the transfer of purple emotional color, such as Figure 9 As shown in (a), the target image is a photograph of a purple flower field. Observe. Figure 9 It can be observed that the Reinhard algorithm still suffers from noticeable boundaries and unnatural transitions in the resulting image. The KNN-1 algorithm produces an overall light purple color tone. The KNN-2 and KNN-3 algorithms, which combine Reinhard, produce images with a deeper overall color tone. The KNN-3 algorithm's image has higher saturation, while the Welsh algorithm's color brightness falls between that of KNN-1 and KNN-2. Visually, the image obtained by the KNN-2 algorithm is more similar in overall tone to the target image.

[0089] Next, we will compare and analyze the experimental results of yellow emotional color transfer, such as... Figure 10 As shown, the target image selected here is an image of a yellow lemon. Figure 10 It can be observed that in the image obtained by the Reinhard algorithm, the wheat ears still retain a large number of green pixels, while the wheat ears of the other four algorithms appear as varying degrees of orange-yellow. The image obtained by the KNN-1 algorithm has the lightest color and the highest brightness, followed by the Welsh algorithm, KNN-3 algorithm, and KNN-2 algorithm. Compared with the image obtained by the KNN-3 algorithm, the image obtained by the KNN-2 algorithm is more orange-red. Visually, the image obtained by the KNN-2 algorithm is more similar to the overall tone of the target image.

[0090] Every painter has their own distinctive artistic style, manifested in the colors, brushstrokes, and composition used in their work. This makes their paintings highly recognizable, allowing viewers to instantly identify the artist. For example, Van Gogh favored high-brightness, high-purity colors in his paintings, often using bright yellow to symbolize light and hope. A painter's brushstrokes can express their emotions and summarize their inner feelings. Van Gogh's brushstrokes, short and elongated, connected continuously, create a sense of flow, a release of his nature and an expression of life. Similar to Western oil painting, traditional Chinese painting also reflects the artist's creative state of mind. The works of Zhang Daqian, a renowned Chinese ink wash painter, exhibit different styles at different times, evolving from "fresh and elegant" to "magnificent and majestic," and finally to "deep and profound," enhancing the emotional impact of his paintings. Building upon ink wash painting, Zhang Daqian incorporated Western painting techniques, creating a splashed-color technique that retains the characteristics of traditional Chinese painting, resulting in a harmonious interplay of ink and color.

[0091] "The Starry Night" is one of Van Gogh's most famous masterpieces, such as Figure 11As shown, the painting primarily uses a deep blue sky and the yellow glow of the stars as its base colors to depict a sleeping village, giving a sense of tranquility and peace. In the experiment presented in this section, examples such as... Figure 12 (a) shows a sunset image as the source image. The overall tone of this image is pinkish-purple, which is quite different from the overall tone of "Starry Night." Figure 12 As shown, in the image obtained by the Reinhard algorithm, the sky's hue changes from pinkish-purple to blue, but the sunset glow still appears reddish-orange. In contrast, the other four algorithms not only change the sky to blue, but also transform the sunset glow into the yellow glow of the stars in "The Starry Night," corresponding to the Reinhard algorithm. However, the image obtained by the Welsh algorithm is darker in color compared to the other three. Therefore, visually, the images obtained by the KNN-1, KNN-2, and KNN-3 algorithms are more similar and closer to the overall hue of the target image than the Reinhard and Welsh algorithms.

[0092] Mount Emei was a recurring theme in the paintings of Zhang Daqian throughout his life, and "The Hall of Reception at Mount Emei" was created during his final ascent of the mountain, recording his observations, experiences, and thoughts from his travelogue. The painting uses a predominantly blue-green color scheme, employing vibrant hues such as vermilion and malachite green to embellish the work, showcasing the lush greenery and majestic grandeur of Mount Emei. Figure 9 As shown.

[0093] To use image color transfer technology to transfer the color tone of the "Emei Jieyin Hall", the following image was selected: Figure 14 (a) uses a real-life natural landscape painting as the source image, in which the mountains are grayish-black and the trees are light green. Figure 14 As shown, in the image obtained by the Reinhard algorithm, the rocks in the image are still grayish-black, which differs from the overall color tone of the target image. Visually, the images obtained by the Welsh, KNN-1, KNN-2, and KNN-3 algorithms are quite similar, all approximating the color tone of the target image, thus giving the images a more distinctive ink-wash painting style.

[0094] Color transfer based on grayscale images is also known as grayscale image colorization. Since grayscale images have only one luminance channel, the color transfer algorithm proposed by Reinhard et al. cannot be directly applied to grayscale images. Subsequently, Welsh et al. proposed a color transfer algorithm based on grayscale images. The color transfer algorithm based on the K-nearest neighbor regression model proposed in this paper is not limited to color transfer between color images but is also applicable to grayscale images. This is because the K-nearest neighbor regression model-based color transfer algorithm only needs to use the value of channel L in the source image to predict the values ​​of channel a and channel b during the transfer process. Since the channel L value of a grayscale image exists in the Lab space, the colorization process of a grayscale image can be completed.

[0095] Since the color transfer algorithm proposed by Reinhard et al. is ineffective on grayscale images, when combining the color transfer algorithm based on the K-nearest neighbor regression model with the color transfer algorithm proposed by Reinhard et al., the color transfer operation based on the K-nearest neighbor regression model must be performed first, and then the color transfer operation of Reinhard et al. (i.e., the KNN-2 algorithm) must be applied to the resulting image. The experimental results will then be analyzed using grayscale natural landscape images and grayscale cartoon characters.

[0096] In this experiment, a grayscale image of a real-life tree was selected as the source image, such as... Figure 15 As shown in (a), the trees in the image are dark gray, and the sky is white. To restore the grayscale source image to green, select as shown in (a). Figure 15 (b) shows another colored forest image as the target image. As shown in the figure, the result image obtained by the KNN-1 algorithm is quite different in color from the result images obtained by the other two algorithms. The overall color tone is dark green, and the transferred color is darker. However, the result image obtained by the KNN-2 algorithm is closer to the color of the target image than that of the Welsh algorithm. The color of the sky does not show a yellow tone like that of the Welsh algorithm, and is closer to the color of the real sky.

[0097] Colorizing grayscale images is a relatively mainstream problem. In the animation field, color transfer technology can automatically colorize cartoon characters, making them more vivid and interesting, and improving their expressiveness. In the experiments in this section, we selected... Figure 16(a) shows the source image and (b) shows the target image for colorizing a grayscale cartoon character. The overall color tone of the target image is pinkish-purple. In the result images of the three algorithms, similar to the results in the previous section, the result image obtained by the KNN-1 algorithm is more purple than the result images obtained by the other two algorithms. The result images obtained by the KNN-2 algorithm and the Welsh algorithm are closer to the color of the target image, but the result image obtained by the KNN-2 algorithm is brighter.

[0098] Example 5

[0099] This embodiment provides an image color transfer system, including:

[0100] A color space conversion module is used to convert the RGB color space of the source image S and the target image T to the Lab color space using a color space conversion matrix.

[0101] A dataset creation module is used to create datasets based on the converted source image S and target image T respectively.

[0102] The regression model module is used to establish a first KNN regression model and a second KNN regression model. The first KNN regression model and the second KNN regression model are trained using the dataset to obtain the trained first KNN regression model that maps from channel L to channel a and the second KNN regression model that maps from channel L to channel b.

[0103] The prediction module is used to predict the values ​​of channel a and channel b mapped by channel L in the source image S using the trained first KNN regression model and second KNN regression model, respectively, to obtain the mapped image;

[0104] The output module is used to convert the mapped image back to the RGB color space to obtain the result image, thereby realizing the transfer of the color of the target image T to the source image S.

[0105] Example 6

[0106] This embodiment provides a computer medium storing a computer program. When the computer program is executed by a processor, it implements the image color transfer method described in embodiments 1 to 3.

[0107] The same or similar labels correspond to the same or similar parts;

[0108] The terms used to describe positional relationships in the accompanying drawings are for illustrative purposes only and should not be construed as limiting this patent.

[0109] Obviously, the above embodiments of the present invention are merely examples for clearly illustrating the present invention, and are not intended to limit the implementation of the present invention. Those skilled in the art can make other variations or modifications based on the above description. It is neither necessary nor possible to exhaustively describe all embodiments here. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention should be included within the scope of protection of the claims of the present invention.

Claims

1. A method of image color migration, characterized by, Includes the following steps: S1: Convert the RGB color space of the source image S and the target image T to the Lab color space using a color space transformation matrix; S2: Establish datasets based on the transformed source image S and target image T respectively; S3: Establish a first KNN regression model and a second KNN regression model, and train the first KNN regression model and the second KNN regression model respectively using the dataset to obtain the trained first KNN regression model that maps from channel L to channel a and the second KNN regression model that maps from channel L to channel b. S4: Using the trained first KNN regression model and second KNN regression model, predict the values ​​of channel a and channel b mapped to channel L in the source image S, respectively, to obtain the mapped image; S5: Convert the mapped image back to the RGB color space to obtain the result image, thereby transferring the color of the target image T to the source image S; Before converting the source image S from the RGB color space to the Lab color space in step S1, the following steps are also included: The Reinhard color transfer algorithm is used to perform a Reinhard color transfer operation on the source image S, where the source image S is a color image.

2. The image color migration method of claim 1, wherein, In step S2, datasets are established based on the transformed source image S and target image T, specifically as follows: The dataset includes a training set and a prediction set. The training set consists of an N×N rectangular block in channel L of the target image T and the values ​​of channel a and channel b corresponding to the center point of the N×N rectangular block. The prediction set of the first KNN regression model and the second KNN regression model consists of an N×N rectangular block in channel L of the source image S.

3. The image color migration method of claim 2, wherein, The first KNN regression model and the second KNN regression model are as follows: In channel L of the target image T, for each N×N rectangular block, find K blocks that are closest in numerical distance to the N×N rectangular block. The closer the numerical distance, the more similar the information in channel L of the two rectangular blocks. Use the reciprocal of the numerical distance for weighting to realize the first KNN regression model mapping from channel L to channel a and the second KNN regression model mapping from channel L to channel b.

4. The image color migration method of claim 3, wherein, The numerical distance is measured using Manhattan distance.

5. The image color migration method of claim 4, wherein, The N×N rectangular block is specifically a 3×3 rectangular block.

6. The image color migration method of any of claims 1 to 5, wherein, After obtaining the result image in step S5, the following steps are also included: The Reinhard color transfer algorithm is used to perform a Reinhard color transfer operation on the resulting image.

7. An image color migration system characterized by, The system is used to implement the image color transfer method of claim 1, including: A color space conversion module is used to convert the RGB color space of the source image S and the target image T to the Lab color space using a color space conversion matrix. A dataset creation module is used to create datasets based on the converted source image S and target image T respectively. The regression model module is used to establish a first KNN regression model and a second KNN regression model. The first KNN regression model and the second KNN regression model are trained using the dataset to obtain the trained first KNN regression model that maps from channel L to channel a and the second KNN regression model that maps from channel L to channel b. The prediction module is used to predict the values ​​of channel a and channel b mapped by channel L in the source image S using the trained first KNN regression model and second KNN regression model, respectively, to obtain the mapped image; The output module is used to convert the mapped image back to the RGB color space to obtain the result image, thereby realizing the transfer of the color of the target image T to the source image S.

8. The image color transfer system according to claim 7, characterized in that, In the regression model module, the first KNN regression model and the second KNN regression model are specifically as follows: In channel L of the target image T, for each N×N rectangular block, find K blocks that are closest in numerical distance to the N×N rectangular block. The closer the numerical distance, the more similar the information in channel L of the two rectangular blocks. In order to make the influence of the rectangular blocks with closer numerical distance on the selected rectangular block greater than the influence of the rectangular blocks with farther numerical distance, the reciprocal of the numerical distance is used for weighting to realize the first KNN regression model mapping from channel L to channel a and the second KNN regression model mapping from channel L to channel b.

9. A computer medium, characterized in that, The computer medium stores a computer program, which, when executed by a processor, implements the image color transfer method according to any one of claims 1 to 6.