Skin color transfer method, apparatus, and electronic device
By employing Lab color space conversion and color matrix correction, the problem of uneven image brightness in skin color transfer was solved, achieving higher accuracy and stability in skin color transfer.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SHENZHEN SHULIAN TIANXIA INTELLIGENT TECH CO LTD
- Filing Date
- 2022-09-30
- Publication Date
- 2026-05-29
AI Technical Summary
In existing skin color transfer techniques, uneven image brightness leads to poor transfer results and poor skin color transfer performance.
By employing Lab color space conversion and color matrix correction, the skin color regions of the source image and the reference image are segmented, converted to Lab color space, and the color matrix is calculated and color correction is performed to obtain the corrected skin color migration image.
It improves the accuracy and stability of skin color transfer, solves the problem of unreasonable image brightness distribution, and enhances the skin color transfer effect.
Smart Images

Figure CN115601225B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of image processing technology, and in particular to a skin color transfer method, apparatus, and electronic device. Background Technology
[0002] With the popularity of beauty filters, more and more users want to use these tools to enhance the appearance of people in photos or videos, specifically by beautifying areas of the skin such as the face, neck, and arms. Common beauty enhancement methods include skin tone transfer.
[0003] Currently, skin color transfer is usually performed using histogram matching. For example, image segmentation is performed on the source image and reference image, and histogram matching is performed on the segmented images according to the brightness level to obtain the transfer result image.
[0004] However, when using this method for skin color transfer, the lack of overall brightness distribution information can lead to uneven brightness in the transferred image, resulting in poor skin color transfer performance. Summary of the Invention
[0005] This application provides a skin color transfer method, apparatus, and electronic device to solve the problems of unreasonable image brightness distribution and poor transfer effect after skin color transfer, thereby improving the accuracy and stability of skin color transfer.
[0006] In a first aspect, this application provides a skin color migration method, the method comprising:
[0007] Acquire the source image and the reference image;
[0008] The source image and the reference image are segmented to obtain the skin color region of the source image and the skin color region of the reference image;
[0009] The skin color regions of the source image and the reference image are converted to Lab color space respectively to obtain the skin color regions of the source image and the reference image in Lab color space.
[0010] Based on skin color conversion rules, preliminary skin color transfer is performed on the skin color region of the source image in the Lab color space to obtain a preliminary skin color transfer image.
[0011] Calculate the color matrix based on the pixel values of the skin region of the source image and the pixel values of the skin region of the reference image in the Lab color space.
[0012] Based on the color matrix, the initial skin color transfer image is color-corrected to obtain the corrected skin color transfer image.
[0013] In some embodiments, after obtaining the skin tone regions of the source image and the reference image in the Lab color space, the method further includes:
[0014] Obtain the convergence regions of pixel values of the skin region of the source image in the a and b channels of the Lab color space, respectively; and obtain the convergence regions of pixel values of the skin region of the reference image in the a and b channels of the Lab color space, respectively.
[0015] Calculate the average pixel values of the skin region of the source image in the a and b channels of the Lab color space, respectively, and calculate the average pixel values of the skin region of the reference image in the a and b channels of the Lab color space, respectively.
[0016] In some embodiments, based on skin color conversion rules, preliminary skin color transfer is performed on the skin color regions of the source image in the Lab color space to obtain a preliminary skin color transferred image, including:
[0017] Iterate through every pixel in the skin color region of the source image;
[0018] If a pixel meets the skin color transfer condition, then the pixel is initially transferred based on the skin color conversion rule to obtain the initial skin color transfer pixel value corresponding to the pixel, so as to obtain the initial skin color transfer image.
[0019] The skin color migration conditions include the pixel value of the a channel in the Lab color space being within the convergence region of the a channel in the Lab color space for the skin color area of the reference image, or the pixel value of the b channel in the Lab color space being within the convergence region of the b channel in the Lab color space for the skin color area of the reference image.
[0020] In some embodiments, skin color conversion rules include:
[0021]
[0022] Wherein, l′, a′, and b′ are the pixel values of the pixels after initial skin color transfer in the L, a, and b channels of the Lab color space, respectively; l, a, and b are the pixel values of the skin color region of the source image in the L, a, and b channels of the Lab color space, respectively; Rsa1 and Rsb1 are the proportions of skin color pixels in the a and b channels of the source image within the same pixel range, respectively; Rta1 and Rtb1 are the proportions of skin color pixels in the a and b channels of the reference image within the same pixel range, respectively; and Ta...m 、Tb m Sa represents the average pixel value of the skin-colored region of the reference image in the a and b channels of the Lab color space. m Sb m These are the average values of the pixel values of the skin-colored region of the source image in the a and b channels of the Lab color space.
[0023] In some embodiments, the method further includes:
[0024] Calculating the proportion of skin-colored pixels in the source image's skin-colored region in the a-channel and b-channel of the Lab color space, and the proportion of skin-colored pixels in the reference image's skin-colored region in the a-channel and b-channel of the Lab color space, specifically includes:
[0025]
[0026]
[0027]
[0028]
[0029] Wherein, Rsa1 and Rsb1 represent the proportions of skin-tone pixels in the a and b channels of the Lab color space within the same pixel range of the source image and the reference image, respectively. m Sb m SaB and SbB are the average pixel values of the skin-colored region in the source image in the a and b channels of the Lab color space, respectively. SaB and SbB are the pixel values at the left endpoints of the convergence regions of the skin-colored region in the source image in the a and b channels of the Lab color space, respectively. m 、Tb mTaB and TbB are the average pixel values of the skin-colored region of the reference image in the a-channel and b-channel of the Lab color space, respectively. TaB and TbB are the pixel values at the left endpoints of the convergence regions of the skin-colored region of the reference image in the a-channel and b-channel of the Lab color space, respectively. Rta1 and Rtb1 are the proportions of skin-colored pixels in the a-channel and b-channel of the reference image in the same pixel range in the source image and the reference image, respectively. SaE and SbE are the pixel values at the right endpoints of the convergence regions of the skin-colored region of the source image in the a-channel and b-channel of the Lab color space, respectively. TbE is the pixel value at the right endpoint of the convergence region of the skin-colored region of the reference image in the b-channel of the Lab color space.
[0030] In some embodiments, a color matrix is calculated based on the pixel values of the skin-tone regions of the source image and the pixel values of the skin-tone regions of the reference image in the Lab color space, including:
[0031] Functions for constructing color matrices;
[0032] The color matrix is calculated by substituting the pixel values of each pixel in the skin region of the source image in the Lab color space with the pixel values of each pixel in the skin region of the reference image in the Lab color space into the color matrix function.
[0033] The color matrix function includes:
[0034]
[0035] in, T represents the pixel value of the skin-colored region of the reference image in the Lab color space. L T a T b These represent the pixel values of the skin-tone region of the reference image in the L, a, and b channels of the Lab color space, respectively, where M is the color matrix. S represents the pixel value of the skin-colored region of the source image in the Lab color space. L S a S b These are the pixel values of the skin-colored region of the source image in the L channel, a channel, and b channel of the Lab color space, respectively.
[0036] In some embodiments, the color matrix M is:
[0037]
[0038] Among them, a11+a12+a13=1, a21+a22+a23=1, a31+a32+a33=1.
[0039] In some embodiments, based on a color matrix, color correction is performed on the initial skin color transfer image to obtain a corrected skin color transfer image, including:
[0040] Based on the color matrix, color correction is performed on each pixel of the initial skin color transfer image to obtain the pixel value of each pixel in the RGB color space after correction, so as to obtain the corrected skin color transfer image.
[0041] Specifically, based on the color matrix, color correction is performed on each pixel of the initial skin color transfer image, including:
[0042]
[0043] in, Let R, G, and B be the pixel values of the corrected skin color transfer image in the RGB color space, respectively, representing the R, G, and B channels of the corrected skin color transfer image in the RGB color space. M is the color matrix. S represents the pixel values of the initial skin color transfer image in the RGB color space. T r S T g S T b These represent the pixel values of the R, G, and B channels of the initial skin color transfer image in the RGB color space.
[0044] Secondly, embodiments of this application provide a skin color transfer device, comprising:
[0045] The image acquisition module is used to acquire source images and reference images;
[0046] The image segmentation module is used to segment the source image and the reference image to obtain the skin color region of the source image and the skin color region of the reference image.
[0047] The color space conversion module is used to convert the skin color region of the source image and the skin color region of the reference image to Lab color space, respectively, to obtain the skin color region of the source image and the skin color region of the reference image in Lab color space.
[0048] The skin color transfer module is used to perform preliminary skin color transfer on the skin color region of the source image in the Lab color space based on skin color conversion rules, so as to obtain a preliminary skin color transfer image.
[0049] The matrix calculation module is used to calculate the color matrix based on the pixel values of the skin region of the source image and the pixel values of the skin region of the reference image in the Lab color space.
[0050] The color correction module is used to perform color correction on the initial skin color transfer image based on the color matrix to obtain the corrected skin color transfer image.
[0051] Thirdly, embodiments of this application provide an electronic device, including:
[0052] At least one processor, and
[0053] A memory that is communicatively connected to at least one processor, wherein,
[0054] The memory stores instructions that can be executed by at least one processor to enable the at least one processor to perform the method provided in the first aspect above.
[0055] Fourthly, embodiments of this application provide a non-volatile computer-readable storage medium storing computer-executable instructions for causing an electronic device to perform the method provided in the first aspect above.
[0056] The beneficial effects of this application's embodiments are as follows: Unlike existing technologies, this application provides a skin color transfer method, which includes: acquiring a source image and a reference image; segmenting the source image and the reference image to obtain skin color regions in the source image and reference image; performing Lab color space conversion on the skin color regions in the source image and the reference image respectively to obtain skin color regions in the source image and reference image under Lab color space; performing preliminary skin color transfer on the skin color regions in the source image under Lab color space based on skin color conversion rules to obtain a preliminary skin color transfer image; calculating a color matrix based on the pixel values of the skin color regions in the source image and the reference image under Lab color space; and performing color correction on the preliminary skin color transfer image based on the color matrix to obtain a corrected skin color transfer image.
[0057] By using skin color conversion rules, preliminary skin color transfer is performed on the skin color region of the source image in the Lab color space. Based on the color matrix, the preliminary skin color transfer image is color corrected to obtain the corrected skin color transfer image. This application can solve the problems of unreasonable brightness distribution and poor transfer effect after skin color transfer, and improve the accuracy and stability of skin color transfer. Attached Figure Description
[0058] One or more embodiments are illustrated by way of example with reference numerals in the accompanying drawings. These illustrations do not constitute a limitation on the embodiments. Elements with the same reference numerals in the drawings are denoted as similar elements. Unless otherwise stated, the figures in the drawings are not to be limited by scale.
[0059] Figure 1 This is a schematic diagram illustrating the application environment of a skin color migration method provided in an embodiment of this application;
[0060] Figure 2 This is a schematic flowchart of a skin color migration method provided in an embodiment of this application;
[0061] Figure 3 This is a schematic diagram of a skin-colored region provided in an embodiment of this application;
[0062] Figure 4 This is a schematic diagram of a process for calculating the convergence region of a pixel and the average value of a pixel, provided in an embodiment of this application.
[0063] Figure 5 This is a schematic diagram of a process for calculating the proportion of skin color pixels in the a and b channels of the Lab color space, as provided in an embodiment of this application.
[0064] Figure 6 yes Figure 2 Detailed flowchart of step S204 in the process;
[0065] Figure 7 yes Figure 2 Detailed flowchart of step S205 in the process;
[0066] Figure 8 This is a schematic diagram of a reference image, a source image, and a corrected skin color transfer image provided in an embodiment of this application;
[0067] Figure 9 yes Figure 2 A detailed flowchart of step S206 in the process;
[0068] Figure 10 This is a schematic diagram of the structure of a skin color transfer device provided in an embodiment of this application;
[0069] Figure 11 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0070] The present application will now be described in detail with reference to specific embodiments. These embodiments will help those skilled in the art to further understand the present application, but do not limit the present application in any way. It should be noted that those skilled in the art can make several modifications and improvements without departing from the concept of the present application. These all fall within the protection scope of the present application.
[0071] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0072] It should be noted that, unless there is a conflict, the various features in the embodiments of this application can be combined with each other, all of which are within the protection scope of this application. Furthermore, although functional modules are divided in the device schematic diagram and a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in a different order than the module division in the device or the order in the flowchart. In addition, the terms "first," "second," and "third" used herein do not limit the data or execution order, but only distinguish identical or similar items with essentially the same function and effect.
[0073] Unless otherwise defined, all technical and scientific terms used in this specification have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used in this specification is for the purpose of describing particular embodiments only and is not intended to limit the scope of this application. The term "and / or" as used in this specification includes any and all combinations of one or more of the associated listed items.
[0074] Furthermore, the technical features involved in the various embodiments of this application described below can be combined with each other as long as they do not conflict with each other.
[0075] Please see Figure 1 , Figure 1 This is a schematic diagram illustrating the application environment of a skin color migration method provided in an embodiment of this application;
[0076] like Figure 1 As shown, the application environment 100 includes a terminal 10 and a server 20, which communicate with each other via wired or wireless communication.
[0077] The terminal 10 can be a smartphone, tablet, laptop, desktop computer, smart speaker, smartwatch, etc., but is not limited to these. The terminal 10 may include a client, which can be a video client, browser client, online shopping client, instant messaging client, etc. This application does not limit the type of client.
[0078] Terminal 10 and server 20 can be connected directly or indirectly via wired or wireless communication, which is not limited herein. Terminal 10 can receive the corrected skin color transfer image sent by server 20 and display the corrected skin color transfer image on a visual interface. Terminal 10 can acquire a source image through an image acquisition device in response to a skin color transfer command triggered by a user. Terminal 10 can also store a reference image library and select an image from the reference image library as a reference image in response to a skin color transfer command triggered by a user. The source image includes, but is not limited to, a face image, a full-body image, etc. The reference image and the source image include the same area covered by human skin. The image acquisition device can be built into terminal 10 or externally connected to terminal 10, which is not limited herein.
[0079] Terminal 10 can send the skin color transfer instruction, the acquired source image, and the reference image selected from the reference image library to server 20, and receive the corrected skin color transfer image returned by server 20, and then display the corrected skin color transfer image on the visualization interface.
[0080] It is understood that terminal 10 can refer to one of multiple terminals, and this application embodiment only uses terminal 10 as an example. Those skilled in the art will know that the number of terminals can be more or less. For example, there may be only one terminal, or there may be dozens or hundreds of terminals, or more. This application embodiment does not limit the number of terminals or the type of device.
[0081] Among them, server 20 can be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery network (CDN), and big data and artificial intelligence platforms.
[0082] The server 20 and the terminal 10 can be connected directly or indirectly via wired or wireless communication, which is not limited herein. The server 20 can receive skin color migration instructions, source images, and reference images sent by the terminal 10, and perform skin color migration on the source image according to the skin color migration instructions to obtain a corrected skin color migration image, and then send the corrected skin color migration image to the terminal 10.
[0083] It is understood that the number of servers 20 described above may be more or fewer, and this application embodiment does not limit this. Of course, servers 20 may also include other functional servers to provide more comprehensive and diversified services.
[0084] The technical solution of this application can be applied to various scenarios of skin color transfer. Specifically, the technical solution of this application can be used in the scenario of image processing to perform skin color transfer on human images.
[0085] Currently, skin color transfer is usually performed using histogram matching. This involves segmenting the source and reference images to obtain skin color regions in the source and reference images, respectively. The skin color regions in the source and reference images are then divided into multiple sub-regions based on different brightness levels. Histogram matching is then performed between each sub-region in the source image and the sub-region in the reference image with the same brightness level to obtain the transferred image.
[0086] However, this method can easily lead to uneven brightness in the transferred image and unreasonable skin color transfer because the proportion of shadow and / or highlight areas in the source image differs significantly from that in the reference image.
[0087] In view of this, embodiments of this application provide a skin color transfer method, apparatus, and electronic device to solve the problems of unreasonable image brightness distribution and poor transfer effect after skin color transfer, thereby improving the accuracy and stability of skin color transfer.
[0088] Example 1
[0089] Please see Figure 2 , Figure 2 This is a schematic flowchart of a skin color migration method provided in an embodiment of this application;
[0090] This method can be applied to various electronic devices or servers, and the execution subject of this method is one or at least two processors of the electronic device or server.
[0091] like Figure 2 As shown, the skin color transfer method includes:
[0092] Step S201: Acquire the source image and the reference image;
[0093] Specifically, the source image can be a user's image, i.e., the image that needs to be skin color transferred, and the reference image can be a model's image, i.e., an image that provides a skin color template. Skin color transfer refers to transferring the skin color of the reference image to the source image. Ideally, the source image and the reference image will have the same skin color after the transfer. The source image and the reference image can be a face image or a human image that includes the skin color region of the human body.
[0094] In some embodiments, an image of the user can be captured as a source image by an image acquisition device built into the terminal, such as a camera, or a corresponding image can be selected as a source image from a local image library; an image can be captured by a camera as a reference image, a corresponding image can be selected from a local image library as a reference image, or an image of a model can be downloaded from a server as a reference image and stored in the reference image dataset of the terminal.
[0095] Step S202: Segment the source image and the reference image to obtain the skin color region of the source image and the skin color region of the reference image;
[0096] For details, please refer to Figure 3 , Figure 3 This is a schematic diagram of a skin-colored region provided in an embodiment of this application;
[0097] like Figure 3 As shown, the image on the left is the source image, and the image on the right is the source image after segmentation. The segmented source image includes skin-colored regions.
[0098] Specifically, skin color regions refer to the areas covered by skin in an image. The methods for segmenting the source image and the reference image to obtain the skin color regions are similar. Taking the source image as an example, the source image is input into a pre-trained human body analysis model to obtain the skin color regions of the source image.
[0099] Specifically, this human body analysis model is used to segment skin color regions in both the source and reference images. The training method for this human body analysis model includes:
[0100] Obtain a training set, which includes several human figure instance images with known human body part categories;
[0101] Construct a neural network model;
[0102] The training set is input into the neural network model. When the loss function of the neural network model converges, training stops and the trained neural network model is output. This trained neural network model is the human body analysis model.
[0103] Specifically, the training set includes the LookinPerson (LIP) dataset, which contains 19 categories of human body parts and clothing labels and 16 keypoint pose labels, comprising over 50,000 human instance images cropped from the COCO dataset. The LIP dataset contains a total of 20 attribute categories including background: background, hat, hair, gloves, sunglasses, top, coat, scarf, skirt, socks, pants, dress, jumpsuit, face, left arm, right arm, left leg, right leg, left shoe, and right shoe.
[0104] Specifically, the neural network model can be a DeeplabV3+ model, comprising multiple sequentially connected feature extraction convolutional layers, ASPP modules, and softmax layers. Each feature extraction convolutional layer is followed by an activation function layer and a normalization layer. The loss function of this neural network model can be the cross-entropy loss function. Understandably, this human body analysis model can determine the category label corresponding to each pixel in an image and segment different categories of regions by classifying pixels belonging to the same category.
[0105] In this embodiment, a loss function is used for backpropagation to bring the human body analysis model to convergence. Convergence of the human body analysis model includes minimizing the loss and / or allowing the loss to fluctuate within a certain range and / or reaching a certain number of training iterations. For example, the Adam algorithm is used to optimize the model parameters, with 500 iterations, an initial learning rate of 0.001, and a weight decay of 0.0005. Every 50 iterations, the learning rate is decayed to 1 / 10 of its original value. The human body analysis model is trained until convergence, and then the human body analysis model is saved.
[0106] In some embodiments, a segmentation algorithm can also be used to segment the source image and the reference image to obtain the skin color region of the source image and the skin color region of the reference image. The segmentation algorithm includes, but is not limited to, deep learning-based human body analysis methods, color space-based image segmentation algorithms, deep learning-based image segmentation algorithms (e.g., using a pre-trained convolutional neural network to segment the image, which can adopt UNet, SegNet, or other structures), and feature point detection-based image segmentation algorithms (e.g., first detecting facial feature points in the image, and then connecting the facial feature points in a preset order to form a closed region, i.e., the skin color region).
[0107] Step S203: Perform Lab color space conversion on the skin color region of the source image and the skin color region of the reference image respectively to obtain the skin color region of the source image and the skin color region of the reference image in Lab color space.
[0108] Specifically, the skin color regions of the source image and the reference image output by the human body analysis model belong to the sRGB color space. They need to be converted from sRGB to Lab color space to isolate the luminance values for subsequent luminance correction. The Lab color space consists of one luminance channel and two color channels. L represents the luminance value, a represents the component from green to red, with a value range of (-128 to 127), where 127 is red, and b represents the component from blue to yellow, also with a value range of (-128 to 127), where 127 is yellow.
[0109] Specifically, to convert the skin tone regions of the source image and the reference image from the sRGB color space to the Lab color space, it is necessary to first convert from the sRGB color space to the RGB color space, then from the RGB color space to the XYZ color space, and finally from the XYZ color space to the Lab color space.
[0110] In some embodiments, the conversion formulas for the skin tone regions of the source image and the reference image from sRGB color space to RGB color space are as follows:
[0111]
[0112]
[0113] Where r, g, and b are the pixel values of the r, g, and b channels of a pixel in the sRGB color space, respectively; R, G, and B are the pixel values of the r, g, and b channels of a pixel in the RGB color space, respectively; and gamma(x) is the gamma transformation function.
[0114] In some embodiments, the conversion formulas for the skin tone regions of the source image and the reference image from RGB color space to XYZ color space are as follows:
[0115]
[0116] Where X, Y, and Z are the x, y, and z coordinates of a pixel in the XYZ color space, respectively, and R, G, and B are the r, g, and b channel pixel values of a pixel in the RGB color space, respectively.
[0117] In some embodiments, the conversion formulas for the skin color regions of the source image and the reference image from XYZ space to Lab color space are as follows:
[0118]
[0119] Where l, a, and b are the pixel values of the L, a, and b channels of the pixel in the Lab color space, respectively, and X, Y, and Z are the coordinate values of the pixel on the x, y, and z axes in the XYZ color space, respectively. n =0.95047, Y n =1.0, Z n =1.08883,
[0120]
[0121] The function f(t) is used to calculate the above formula. The function value.
[0122] Specifically, will Substituting into the function f(t) yields The function value will Substituting into the function f(t) yields The function value will Substituting into the function f(t) yields The function values are then substituted into the aforementioned conversion formula from XYZ space to Lab color space to obtain pixel values l, a, and b.
[0123] Please refer to the following: Figure 4 , Figure 4 This is a schematic diagram of a process for calculating the convergence region of a pixel and the average value of a pixel, provided in an embodiment of this application.
[0124] like Figure 4 As shown, the process for calculating the convergence region of a pixel and the average pixel value includes:
[0125] Step S401: Obtain the convergence regions of the pixel values of the skin region of the source image in the a and b channels of the Lab color space, respectively; and refer to the convergence regions of the pixel values of the skin region of the reference image in the a and b channels of the Lab color space, respectively.
[0126] Specifically, the convergence region of the pixel values of the skin region in the source image in the a channel of the Lab color space can be represented as [SaB, SaE], where SaB is the minimum pixel value of the skin region in the source image in the a channel of the Lab color space, and SaE is the maximum pixel value of the skin region in the source image in the a channel of the Lab color space; the convergence region of the pixel values of the skin region in the source image in the b channel of the Lab color space can be represented as [, SbE], where SbB is the minimum pixel value of the skin region in the source image in the b channel of the Lab color space, and SbE is the maximum pixel value of the skin region in the source image in the b channel of the Lab color space.
[0127] Specifically, the convergence region of the pixel values of the skin region of the image in the a channel of the Lab color space can be represented as [TaB, TaE], where TaB is the minimum pixel value of the skin region of the image in the a channel of the Lab color space, and TaE is the maximum pixel value of the skin region of the image in the b channel of the Lab color space; the convergence region of the pixel values of the skin region of the image in the b channel of the Lab color space can be represented as [, TbE], where TbB is the minimum pixel value of the skin region of the image in the b channel of the Lab color space, and TbE is the maximum pixel value of the skin region of the image in the b channel of the Lab color space.
[0128] Step S402: Calculate the average pixel value of the skin region of the source image in the a channel and b channel of the Lab color space, respectively, and calculate the average pixel value of the skin region of the reference image in the a channel and b channel of the Lab color space, respectively.
[0129] Specifically, in the a channel of the Lab color space, the pixel values of each pixel in the skin color region of the source image are summed. The sum of the pixel values is then divided by the number of pixels in the skin color region to obtain the average value. This average value is the average pixel value of the skin color region of the source image in the a channel of the Lab color space.
[0130] Similarly, in the b channel of the Lab color space, the pixel values of each pixel in the skin region of the source image are summed, and the sum of the pixel values is divided by the number of pixels in the skin region to obtain the average value. This average value is the average value of the pixel values of the skin region of the source image in the b channel of the Lab color space.
[0131] Step S204: Based on the skin color conversion rules, perform preliminary skin color transfer on the skin color region of the source image in the Lab color space to obtain a preliminary skin color transfer image;
[0132] Specifically, the skin color conversion rules include:
[0133]
[0134] Among them, l ′ a ′ b ′ Rsa1 and Rsb1 represent the pixel values of the skin region in the source image within the same pixel range in the Lab color space, respectively, along with the proportions of skin pixels in the source image and the reference image within the same pixel range. Rta1 and Rtb1 represent the proportions of skin pixels in the source image and the reference image within the same pixel range, along with the proportions of skin pixels in the reference image and the reference image within the same pixel range. m 、Tb m Sa represents the average pixel value of the skin-tone region of the reference image in the Lab color space, specifically the a and b channels. m Sb m These are the average pixel values of the skin-colored region of the source image in the a and b channels of the Lab color space.
[0135] It is understandable that by performing preliminary skin color transfer on each pixel of the skin color region of the source image in the Lab color space, that is, by using the skin color transfer rule to perform preliminary skin color transfer on each pixel of the skin color region of the source image in the Lab color space, the pixel value of each pixel after preliminary skin color transfer can be obtained, and thus a preliminary skin color transfer image can be obtained.
[0136] Please see Figure 5 , Figure 5 This is a schematic diagram of a process for calculating the proportion of skin color pixels in the a and b channels of the Lab color space, as provided in an embodiment of this application.
[0137] like Figure 5 As shown, the process for calculating the proportion of skin-tone pixels in the a and b channels of the Lab color space includes:
[0138] Step S501: Calculate the proportion of skin pixels in the source image's skin region in the a and b channels of the Lab color space, respectively, and refer to the proportion of skin pixels in the reference image's skin region in the a and b channels of the Lab color space, specifically including:
[0139]
[0140]
[0141]
[0142]
[0143] Where Rsa1 and Rsb1 represent the proportions of skin-tone pixels in the source image and reference image, respectively, within the same pixel range, in the a and b channels of the Lab color space. m Sb m SaB and SbB are the average pixel values of the skin region in the source image in the a and b channels of the Lab color space, respectively. SaB and SbB are the pixel values of the left endpoints of the convergence regions of the skin region in the source image in the a and b channels of the Lab color space, respectively. m 、Tb m TaB and TbB are the average pixel values of the skin region in the reference image in the a and b channels of the Lab color space, respectively. TaB and TbB are the pixel values at the left endpoints of the convergence regions of the skin region in the reference image in the a and b channels of the Lab color space, respectively. Rta1 and Rtb1 are the proportions of skin pixels in the a and b channels of the reference image in the same pixel range, respectively. SaE and SbE are the pixel values at the right endpoints of the convergence regions of the skin region in the reference image in the a and b channels of the Lab color space, respectively. TbE is the pixel value at the right endpoint of the convergence region of the skin region in the reference image in the b channel of the Lab color space.
[0144] It should be noted that the proportion of skin color pixels refers to the proportion of skin color in each channel of the source image and the reference image at the normalized scale. The normalized scale means that the source image and the reference image are at the same scale, that is, the source image and the reference image are in the same pixel range, so that the source image and the reference image can be compared within the same pixel range. For example, if the pixel range of the a channel of the source image is (54, 180), and the pixel range of the a channel of the reference image is (12, 170), then at the same scale, the pixel range of the two is (12, 180).
[0145] It can be understood that the proportion of skin-colored pixels in the source image or reference image in the a and b channels of the Lab color space refers to the proportion of the number of pixels in the a channel of the Lab color space that match the skin-colored range to the total number of pixels in the source image or reference image.
[0146] For details, please refer to Figure 6 , Figure 6 yes Figure 2 Detailed flowchart of step S204 in the process;
[0147] like Figure 6 As shown, step S204 includes:
[0148] Step S2041: Traverse every pixel of the skin color region in the source image;
[0149] Specifically, each pixel in the skin color region of the source image is identified sequentially, and it is determined whether it meets the skin color transfer conditions.
[0150] Step S2042: If a pixel meets the skin color transfer condition, perform preliminary skin color transfer on the pixel based on the skin color conversion rule to obtain the preliminary skin color transfer pixel value corresponding to the pixel, so as to obtain a preliminary skin color transfer image.
[0151] Specifically, skin color migration conditions include the pixel value of the a channel in the Lab color space being within the convergence region of the a channel in the Lab color space for the skin color area of the reference image, or the pixel value of the b channel in the Lab color space being within the convergence region of the b channel in the Lab color space for the skin color area of the reference image.
[0152] For example: Suppose the current pixel is N(l,a,b), where l is the pixel value of the L channel of the pixel in the Lab color space, a is the pixel value of the pixel in the a channel of the Lab color space, and b is the pixel value of the pixel in the b channel of the Lab color space.
[0153] If the current pixel N(l,a,b) satisfies the skin color transfer condition, i.e., a∈[TaB,TaE] or b∈[TbB,TbE], that is, the pixel value of the a channel in the Lab color space is within the convergence region of the pixel in the skin color region of the reference image in the a channel of the Lab color space, or the pixel value of the b channel in the Lab color space is within the convergence region of the pixel in the skin color region of the reference image in the b channel of the Lab color space, then substitute the pixel values l, a, and b of the L, a, and b channels of the pixel N(l,a,b) in the Lab color space into the formula corresponding to the skin color conversion rule to perform pixel value conversion, and obtain the preliminary skin color transfer pixel value N(l′,a′,b′) corresponding to the pixel N(l,a,b). Perform preliminary skin color transfer on all pixels in the skin color region that satisfy the skin color transfer condition to obtain a preliminary skin color transfer image.
[0154] It is understandable that if the current pixel N(l,a,b) does not meet the skin color transfer condition, then there is no need to substitute its pixel values in each channel of the Lab color space into the formula corresponding to the skin color conversion rule, that is, no pixel value conversion is performed.
[0155] In this embodiment, by acquiring a source image and a reference image, segmenting the source image and the reference image to obtain the skin color region of the source image and the skin color region of the reference image, and then performing Lab color space conversion on the skin color region of the source image and the skin color region of the reference image respectively, the skin color region of the source image and the skin color region of the reference image in Lab color space can be obtained. This can separate the brightness pixel values, and based on the skin color conversion rules, perform preliminary skin color migration on the skin color region of the source image in Lab color space to obtain a preliminary skin color migration image, which can effectively reduce the situation where the skin color migration effect is poor due to unreasonable brightness distribution.
[0156] Step S205: Calculate the color matrix based on the pixel values of the skin region of the source image and the pixel values of the skin region of the reference image in the Lab color space;
[0157] For details, please refer to Figure 7 , Figure 7 yes Figure 2 A detailed flowchart of step S205 in the process;
[0158] like Figure 7 As shown, step S205 includes:
[0159] Step S2051: Construct the color matrix function;
[0160] Specifically, the color matrix function includes:
[0161]
[0162] in, To refer to the pixel values of the skin-tone region of the image in the Lab color space, T L T a T b These represent the pixel values of the skin-tone region of the reference image in the L, a, and b channels of the Lab color space, respectively, where M is the color matrix. S represents the pixel value of the skin-colored region in the source image in the Lab color space. L S a S b These are the pixel values of the skin-colored region of the source image in the L, a, and b channels of the Lab color space.
[0163] The color matrix M is:
[0164]
[0165] Among them, a11+a12+a13=1, a21+a22+a23=1, a31+a32+a33=1.
[0166] Step S2052: Substitute the pixel value of each pixel in the skin region of the source image in the Lab color space and the pixel value of each pixel in the skin region of the reference image in the Lab color space into the color matrix function to calculate the color matrix;
[0167] Specifically, the pixel values S of each pixel in the skin tone region of the source image in the L, a, and b channels of the Lab color space are... L S a S b The pixel values T of each pixel in the skin area of the reference image in the L, a, and b channels of the Lab color space. L T a T bThe parameters are then substituted into the color matrix function and iteratively optimized to obtain the optimal parameters of the color matrix. For example, the optimal parameters can be obtained using iterative methods such as the Jacobi iteration method or the Gauss-Seidel iteration method. Alternatively, the OpenCV library can be used to input the relevant parameters of the aforementioned color matrix function to obtain the optimal parameters of the color matrix M. In these optimal parameters, a11, a22, and a33 approach 1 infinitely, and a12, a13, a21, a23, a31, and a32 approach 0 infinitely, and a11... The constraints are: a12+a13=1, a21+a22+a23=1, a31+a32+a33=1. For example, a11=0.99998, a12=0.00001, a13=0.00001, a21=0.0001, a22=0.9996, a23=0.0003, a31=0.00002, a32=0.00001, a33=0.99997, etc.
[0168] Step S206: Based on the color matrix, perform color correction on the preliminary skin color transfer image to obtain the corrected skin color transfer image.
[0169] Specifically, based on the color matrix, color correction is performed on each pixel of the initial skin color transfer image to obtain the corrected pixel value of each pixel, thereby obtaining the corrected skin color transfer image.
[0170] Please refer to the following for details. Figure 8 and Figure 9 , Figure 8 This is a schematic diagram of a reference image, a source image, and a corrected skin color transfer image provided in an embodiment of this application;
[0171] Figure 9 yes Figure 2 A detailed flowchart of step S206 in the process;
[0172] like Figure 8 As shown, the source image is the image that needs to be skin color transfer, such as a user's image; the reference image is an image that provides a skin color template, such as a model's image. The skin color of the reference image is different from that of the source image, and the corrected skin color transfer image has a similar skin color to the reference image.
[0173] Specifically, the goal of skin color transfer is to transfer the skin color from a reference image to a source image. Ideally, the transferred source image and the reference image will have the same skin color. After performing image segmentation and Lab color space conversion, preliminary skin color transfer, and color correction on the source and reference images, a corrected skin color transfer image is obtained. This corrected skin color transfer image is the source image with a similar skin color to the reference image. It should be noted that the specific implementation methods for image segmentation and Lab color space conversion, preliminary skin color transfer, and color correction have been explained in detail above and will not be repeated here.
[0174] like Figure 9 As shown, step S206 includes:
[0175] Step S2061: Based on the color matrix, perform color correction on each pixel of the initial skin color transfer image to obtain the pixel value of each pixel in the RGB color space after correction, so as to obtain the corrected skin color transfer image.
[0176] Specifically, color correction can be performed on each pixel of the initial skin color transfer image using the following formula:
[0177]
[0178] in, Let R, G, and B be the pixel values of the corrected skin color transfer image in the RGB color space, respectively, representing the R, G, and B channels of the corrected skin color transfer image in the RGB color space. M is the color matrix. S represents the pixel values of the initial skin color transfer image in the RGB color space. T r S T g S T b These represent the pixel values of the R, G, and B channels of the initial skin color transfer image in the RGB color space.
[0179] It is understandable that the pixel value of each corrected pixel obtained by the above formula belongs to the RGB color space, and the corrected skin color transfer image composed of each corrected pixel also belongs to the RGB color space.
[0180] In some embodiments, the conversion formula for converting the initial skin color transfer image from Lab color space to XYZ color space is as follows:
[0181]
[0182] Where X, Y, and Z are the x, y, and z coordinates of the pixels in the initial skin color transfer image in the XYZ space, respectively; and l, a, and b are the L, a, and b channel pixel values of the pixels in the initial skin color transfer image in the Lab color space, respectively. n =0.95047, Y n =1.0, Z n =1.08883,
[0183]
[0184] Wherein, function f -1 (t) is used to calculate The function value of f-11116+16-1200.
[0185] Specifically, will Substitute into function f -1 (t) The function value will Substitute into function f -1 (t) The function value of 16+1500 is obtained by substituting t=1116+16-1200 into the function f-1. The function value is then substituted into the above conversion formula from Lab color space to XYZ space to obtain the coordinate values X, Y, and Z.
[0186] In some embodiments, the conversion formula for converting the initial skin color transfer image from XYZ space to RGB color space is as follows:
[0187]
[0188] Among them, S T r S T g S T b , respectively, are the pixel values of the r, g, and b channels of the initial skin color transfer image in the RGB color space; X, Y, and Z are the coordinate values of the pixels of the initial skin color transfer image on the x, y, and z axes in the XYZ color space, respectively.
[0189]
[0190] In this embodiment, a color matrix is calculated based on the pixel values of the skin color region of the source image and the pixel values of the skin color region of the reference image in the Lab color space. Based on the color matrix, the initial skin color transfer image is color-corrected to obtain a corrected skin color transfer image. This embodiment enables the skin color of the color-corrected initial skin color transfer image to match the skin color of the reference image more closely, thereby improving the stability of skin color transfer.
[0191] In this application embodiment, a skin color transfer method is provided. The method includes: acquiring a source image and a reference image, segmenting the source image and the reference image to obtain skin color regions of the source image and the reference image, performing Lab color space conversion on the skin color regions of the source image and the reference image respectively, and performing preliminary skin color transfer on the skin color regions of the source image in Lab color space based on skin color conversion rules to obtain a preliminary skin color transfer image. Further, a color matrix is calculated based on the pixel values of the skin color regions of the source image and the reference image in Lab color space, and color correction is performed on the preliminary skin color transfer image based on the color matrix to obtain a corrected skin color transfer image. This application can solve the problems of unreasonable brightness distribution and poor transfer effect after skin color transfer, making the skin color of the corrected skin color transfer image more matched with the skin color of the reference image, and improving the accuracy and stability of skin color transfer.
[0192] Example 2
[0193] Please see Figure 10 , Figure 10 This is a schematic diagram of the structure of a skin color transfer device provided in an embodiment of this application;
[0194] This device can be applied to various electronic devices or servers, such as one or at least two processors in an electronic device or server.
[0195] like Figure 10 As shown, the skin color transfer device 101 includes:
[0196] Image acquisition module 1011 is used to acquire source image and reference image;
[0197] The image segmentation module 1012 is used to segment the source image and the reference image to obtain the skin color region of the source image and the skin color region of the reference image.
[0198] The space conversion module 1013 is used to perform Lab color space conversion on the skin color area of the source image and the skin color area of the reference image respectively, so as to obtain the skin color area of the source image and the skin color area of the reference image in Lab color space.
[0199] Skin color transfer module 1014 is used to perform preliminary skin color transfer on the skin color region of the source image in Lab color space based on skin color conversion rules to obtain a preliminary skin color transfer image.
[0200] The matrix calculation module 1015 is used to calculate the color matrix based on the pixel values of the skin region of the source image and the pixel values of the skin region of the reference image in the Lab color space.
[0201] Color correction module 1016 is used to perform color correction on the initial skin color transfer image based on the color matrix to obtain the corrected skin color transfer image.
[0202] In the embodiments of this application, the skin color transfer device can also be constructed from hardware devices. For example, the skin color transfer device can be constructed from one or more chips, and the chips can work together to complete the skin color transfer method described in the above embodiments. Furthermore, the skin color transfer device can also be constructed from various logic devices, such as general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), microcontrollers, ARM (Acorn RISC Machine) or other programmable logic devices, discrete gate or transistor logic, discrete hardware components, or any combination of these components.
[0203] The skin color migration device in this application embodiment can be a device, or a component, integrated circuit, or chip in a terminal. The device can be a mobile electronic device or a non-mobile electronic device. For example, mobile electronic devices can be mobile phones, tablets, laptops, PDAs, in-vehicle electronic devices, wearable devices, ultra-mobile personal computers (UMPCs), netbooks, or personal digital assistants (PDAs), etc., while non-mobile electronic devices can be servers, network-attached storage (NAS), personal computers (PCs), televisions (TVs), ATMs, or self-service machines, etc. This application embodiment does not impose specific limitations.
[0204] The skin color migration device in this application embodiment can be a device with an operating system. This operating system can be Android, iOS, or other possible operating systems; this application embodiment does not specifically limit the specific operating system used.
[0205] The skin color transfer device provided in this application embodiment can achieve... Figure 2 To avoid repetition, the various processes involved will not be described in detail here.
[0206] It should be noted that the skin color transfer device described above can execute the skin color transfer method provided in the above embodiments of this application, and has the corresponding functional modules and beneficial effects for executing the method. Technical details not described in detail in the skin color transfer device embodiments can be found in the skin color transfer method provided in the above embodiments.
[0207] In this embodiment, a skin color transfer device is provided, comprising: an image acquisition module for acquiring a source image and a reference image; an image segmentation module for segmenting the source image and the reference image to obtain skin color regions of the source image and the reference image; a space conversion module for performing Lab color space conversion on the skin color regions of the source image and the reference image respectively to obtain skin color regions of the source image and the reference image in Lab color space; a skin color transfer module for performing preliminary skin color transfer on the skin color regions of the source image in Lab color space based on skin color conversion rules to obtain a preliminary skin color transfer image; a matrix calculation module for calculating a color matrix based on the pixel values of the pixels of the skin color regions of the source image and the pixels of the skin color regions of the reference image in Lab color space; and a color correction module for performing color correction on the preliminary skin color transfer image based on the color matrix to obtain a corrected skin color transfer image.
[0208] By acquiring a source image and a reference image, segmenting the source image and the reference image to obtain the skin color region of the source image and the skin color region of the reference image, respectively, performing Lab color space conversion on the skin color regions of the source image and the reference image to obtain the skin color regions of the source image and the reference image in Lab color space, and performing preliminary skin color transfer on the skin color region of the source image in Lab color space based on skin color conversion rules, and performing color correction on the preliminary skin color transfer image based on the color matrix to obtain the corrected skin color transfer image. This application can solve the problems of unreasonable brightness distribution and poor transfer effect after skin color transfer, and improve the accuracy and stability of skin color transfer.
[0209] Example 3
[0210] Please see Figure 11 , Figure 11 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application;
[0211] like Figure 11 As shown, the electronic device 110 includes one or more processors 111 and a memory 112. Wherein, Figure 11 Take a processor 111 as an example.
[0212] Processor 111 and memory 112 can be connected via a bus or other means. Figure 11 Taking the example of a connection between China and Israel via a bus.
[0213] The processor 111 provides computing and control capabilities to control the electronic device 110 to perform corresponding tasks, such as controlling the electronic device 110 to perform the skin color migration method in any of the above method embodiments, including: acquiring a source image and a reference image; segmenting the source image and the reference image to obtain skin color regions of the source image and skin color regions of the reference image; performing Lab color space conversion on the skin color regions of the source image and the reference image respectively to obtain skin color regions of the source image and the reference image in Lab color space; performing preliminary skin color migration on the skin color regions of the source image in Lab color space based on skin color conversion rules to obtain a preliminary skin color migration image; calculating a color matrix based on the pixel values of the pixels of the skin color regions of the source image and the pixels of the skin color regions of the reference image in Lab color space; and performing color correction on the preliminary skin color migration image based on the color matrix to obtain a corrected skin color migration image.
[0214] By acquiring a source image and a reference image, segmenting the source image and the reference image to obtain the skin color region of the source image and the skin color region of the reference image, respectively, performing Lab color space conversion on the skin color regions of the source image and the reference image to obtain the skin color regions of the source image and the reference image in Lab color space, and performing preliminary skin color transfer on the skin color region of the source image in Lab color space based on skin color conversion rules, and performing color correction on the preliminary skin color transfer image based on the color matrix to obtain the corrected skin color transfer image. This application can solve the problems of unreasonable brightness distribution and poor transfer effect after skin color transfer, and improve the accuracy and stability of skin color transfer.
[0215] Processor 111 can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), a hardware chip, or any combination thereof; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a programmable logic device (PLD), or a combination thereof. The aforementioned PLD can be a complex programmable logic device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL), or any combination thereof.
[0216] Memory 112, as a non-transitory computer-readable storage medium, can be used to store non-transitory software programs, non-transitory computer-executable programs, and modules, such as the skin color migration method or the program instructions / modules corresponding to the skin color migration method in the embodiments of this application. Processor 111 can implement the skin color migration method in any of the following method embodiments by running the non-transitory software programs, instructions, and modules stored in memory 112. Specifically, memory 112 may include volatile memory (VM), such as random access memory (RAM); memory 112 may also include non-volatile memory (NVM), such as read-only memory (ROM), flash memory, hard disk drive (HDD), solid-state drive (SSD), or other non-transitory solid-state storage devices; memory 112 may also include combinations of the above types of memory.
[0217] Memory 112 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other non-volatile solid-state storage device. In some embodiments, memory 112 may optionally include memory remotely located relative to processor 111, and these remote memories may be connected to processor 111 via a network. Examples of such networks include, but are not limited to, the Internet, intranets, local area networks, mobile communication networks, and combinations thereof.
[0218] One or more modules are stored in memory 112. When executed by one or more processors 111, they perform the skin color migration method in any of the above method embodiments, for example, the method described above. Figure 2 The steps shown can also be implemented. Figure 10 The functions of each module or unit.
[0219] In this embodiment, the electronic device 110 may also have wired or wireless network interfaces, keyboards, and input / output interfaces for input and output. The electronic device 110 may also include other components for implementing device functions, which will not be described in detail here.
[0220] The electronic devices described in this application exist in various forms, and perform the above-described... Figure 2 The steps shown can also be implemented. Figure 10 When considering the functions of each unit, including but not limited to: mobile terminals, electronic watches, fixed terminals, wearable devices, etc.
[0221] This application also provides a computer-readable storage medium, such as a memory including program code, which can be executed by a processor to complete the skin color migration method in the above embodiments. For example, the computer-readable storage medium may be a read-only memory (ROM), a random access memory (RAM), a compact disc read-only memory (CDROM), magnetic tape, floppy disk, and optical data storage device, etc.
[0222] This application also provides a computer program product comprising one or more lines of program code stored in a computer-readable storage medium. A processor of an electronic device reads the program code from the computer-readable storage medium and executes the program code to complete the method steps of the skin color migration method provided in the above embodiments.
[0223] Those skilled in the art will understand that all or part of the steps of the above embodiments can be implemented by hardware, or by a program or program code related to hardware. The program can be stored in a computer-readable storage medium, such as a read-only memory, a disk, or an optical disk.
[0224] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented using software and a general-purpose hardware platform, or of course, using hardware. Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The program can be stored in a computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. The storage medium can be a magnetic disk, optical disk, read-only memory (ROM), or random access memory (RAM), etc.
[0225] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and not to limit them; under the concept of this application, the technical features of the above embodiments or different embodiments can also be combined, the steps can be implemented in any order, and there are many other variations as described above in different aspects of this application, which are not provided in detail for the sake of brevity; although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the foregoing embodiments, or make equivalent substitutions for some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of this application.
Claims
1. A skin color transfer method, characterized in that, The method includes: Acquire the source image and the reference image; The source image and the reference image are segmented to obtain the skin color region of the source image and the skin color region of the reference image; The skin color regions of the source image and the reference image are respectively converted to Lab color space to obtain the skin color regions of the source image and the reference image in Lab color space. Obtain the convergence regions of the pixel values of the skin region of the source image in the a and b channels of the Lab color space, respectively; and obtain the convergence regions of the pixel values of the skin region of the reference image in the a and b channels of the Lab color space, respectively. Based on the skin color conversion rules, a preliminary skin color transfer is performed on the skin color region of the source image in the Lab color space to obtain a preliminary skin color transfer image. Calculate the color matrix based on the pixel values of the skin color region of the source image and the pixel values of the skin color region of the reference image in the Lab color space; Based on the color matrix, the initial skin color transfer image is color corrected to obtain the corrected skin color transfer image; The process of performing preliminary skin color transfer on the skin color region of the source image in the Lab color space based on skin color conversion rules to obtain a preliminary skin color transfer image includes: Iterate through every pixel in the skin color region of the source image; If the pixel meets the skin color migration condition, then the pixel is subjected to preliminary skin color migration based on the skin color conversion rule to obtain the preliminary skin color migration pixel value corresponding to the pixel, so as to obtain a preliminary skin color migration image; The skin color migration condition includes the pixel value of the a channel of the pixel in the Lab color space being within the convergence region of the a channel of the pixel in the skin color region of the reference image in the Lab color space, or the pixel value of the b channel of the pixel in the Lab color space being within the convergence region of the b channel of the pixel in the skin color region of the reference image in the Lab color space.
2. The method according to claim 1, characterized in that, The method further includes: Calculate the average pixel values of the skin-colored region of the source image in the a-channel and b-channel of the Lab color space, respectively, and calculate the average pixel values of the skin-colored region of the reference image in the a-channel and b-channel of the Lab color space, respectively.
3. The method according to claim 2, characterized in that, The skin color conversion rules include: in, , , These represent the pixel values of the L, a, and b channels in the Lab color space after the initial skin tone transfer. , , These are the pixel values of the skin-colored region of the source image in the L channel, a channel, and b channel of the Lab color space, respectively. , The proportions of skin-tone pixels in the source image and the reference image within the same pixel range, representing the proportions of skin-tone pixels in the a and b channels of the Lab color space. , The proportions of skin-tone pixels in the a and b channels of the Lab color space for the source image and the reference image, respectively, within the same pixel range. 、 These are the average pixel values of the skin-colored region of the reference image in the a and b channels of the Lab color space. 、 These are the average values of the pixel values of the skin-colored region of the source image in the a and b channels of the Lab color space.
4. The method according to claim 3, characterized in that, The method further includes: Calculating the proportion of skin-colored pixels in the source image's skin-colored region in the a-channel and b-channel of the Lab color space, and the proportion of skin-colored pixels in the reference image's skin-colored region in the a-channel and b-channel of the Lab color space, specifically includes: in, , The proportions of skin-tone pixels in the source image and the reference image within the same pixel range, representing the proportions of skin-tone pixels in the a and b channels of the Lab color space. These are the average pixel values of the skin-colored region of the source image in the a-channel and b-channel of the Lab color space, respectively. , These are the pixel values of the left endpoints of the convergence regions of the skin-colored region in the source image's a and b channels in the Lab color space. , These are the average pixel values of the skin-colored region of the reference image in the a and b channels of the Lab color space. , These are the pixel values at the left endpoints of the convergence regions of the skin-colored region in the reference image's a and b channels in the Lab color space. 、 The proportions of skin-tone pixels in the a and b channels of the Lab color space for the source image and the reference image, respectively, within the same pixel range. These are the pixel values at the right endpoints of the convergence regions of the skin-colored region in the source image's a and b channels in the Lab color space. The pixel value is the right endpoint of the convergence region of the b channel in the Lab color space for the skin color region of the reference image.
5. The method according to claim 1, characterized in that, The step of calculating the color matrix based on the pixel values of the skin-tone region of the source image and the pixel values of the skin-tone region of the reference image in the Lab color space includes: Functions for constructing color matrices; The color matrix is calculated by substituting the pixel value of each pixel in the skin region of the source image in the Lab color space and the pixel value of each pixel in the skin region of the reference image in the Lab color space into the color matrix function. The color matrix function includes: in, The pixel value of the skin-colored region of the reference image in the Lab color space. , , These represent the pixel values of the skin-tone region of the reference image in the L, a, and b channels of the Lab color space, respectively, where M is the color matrix. The pixel value of the skin-colored region in the source image in the Lab color space. , , These are the pixel values of the skin-colored region of the source image in the L channel, a channel, and b channel of the Lab color space, respectively.
6. The method according to claim 5, characterized in that, The color matrix M is: M= Among them, a11+a12+a13=1, a21+a22+a23=1, a31+a32+a33=1.
7. The method according to any one of claims 1-6, characterized in that, The step of performing color correction on the preliminary skin color transfer image based on the color matrix to obtain a corrected skin color transfer image includes: Based on the color matrix, each pixel of the initial skin color transfer image is color corrected to obtain the pixel value of each pixel in the RGB color space after correction, so as to obtain the corrected skin color transfer image. Specifically, based on the color matrix, color correction is performed on each pixel of the preliminary skin color transfer image, including: in, The pixel values of the corrected skin color transfer image in the RGB color space. G, B, and R represent the pixel values of the corrected skin color transfer image in the RGB color space, respectively, where M is the color matrix. The pixel values of the initial skin color transfer image in the RGB color space. , , These represent the pixel values of the R, G, and B channels of the initial skin color transfer image in the RGB color space.
8. A skin color transfer device, characterized in that, The device includes: The image acquisition module is used to acquire source images and reference images; An image segmentation module is used to segment the source image and the reference image to obtain the skin color region of the source image and the skin color region of the reference image; The color space conversion module is used to perform Lab color space conversion on the skin color region of the source image and the skin color region of the reference image respectively, to obtain the skin color region of the source image and the skin color region of the reference image in Lab color space; and to obtain the convergence regions of the pixel values of the skin color region of the source image in the a channel and b channel of Lab color space, respectively, and the convergence regions of the pixel values of the skin color region of the reference image in the a channel and b channel of Lab color space, respectively. The skin color transfer module is used to perform preliminary skin color transfer on the skin color region of the source image in the Lab color space based on skin color conversion rules, so as to obtain a preliminary skin color transfer image. The matrix calculation module is used to calculate a color matrix based on the pixel values of the skin color region of the source image and the pixel values of the skin color region of the reference image in the Lab color space. The color correction module is used to perform color correction on the preliminary skin color transfer image based on the color matrix to obtain the corrected skin color transfer image. The skin color transfer module is specifically used to traverse each pixel of the skin color region of the source image; If the pixel meets the skin color migration condition, then the pixel is subjected to preliminary skin color migration based on the skin color conversion rule to obtain the preliminary skin color migration pixel value corresponding to the pixel, so as to obtain a preliminary skin color migration image; The skin color migration condition includes the pixel value of the a channel of the pixel in the Lab color space being within the convergence region of the a channel of the pixel in the skin color region of the reference image in the Lab color space, or the pixel value of the b channel of the pixel in the Lab color space being within the convergence region of the b channel of the pixel in the skin color region of the reference image in the Lab color space.
9. An electronic device, characterized in that, include: At least one processor, and The memory communicatively connected to the at least one processor, wherein, The memory stores instructions that can be executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1-7.