Human face image hair rendering method, device, electronic device and medium

By performing linear transformation and HSV color space processing on the RGB color values ​​of the hair area, the problem of hair rendering distortion in the existing technology is solved, and a more natural and accurate hair rendering effect is achieved.

CN112614060BActive Publication Date: 2024-10-18SHENZHEN SHULIAN TIANXIA INTELLIGENT TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202011433458.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-12-09
Publication Date
2024-10-18
Estimated Expiration
2040-12-09

AI Technical Summary

Technical Problem

In application scenarios where existing hairdressing technology requires high quality portrait images, semantic segmentation technology is difficult to achieve natural and accurate hair rendering, and can easily lead to hair rendering distortion.

Method used

By obtaining the hair area in the image to be processed, use the preset linear transformation relationship to correct the RGB color values, convert them into HSV format, and adjust the target color values ​​​​combined with the reference color values ​​to ensure that the distinction between color values ​​and brightness values ​​is large, thereby Natural color transformation and rendering in HSV color space.

Benefits of technology

Preserve the color value changes of pixels to the maximum extent, achieve a more natural rendering effect, avoid hair rendering distortion, and improve the accuracy and effect of hairdressing processing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112614060B_ABST
    Figure CN112614060B_ABST
Patent Text Reader

Abstract

The present application discloses a method, device, electronic device and medium for rendering hair in a face image. The method includes: obtaining a hair region in an image to be processed, wherein the first color value of each pixel is in RGB format; performing correction processing on each channel component in the first color value according to a preset linear transformation relationship to obtain a corrected first color value; the difference between the first color value of the corrected target pixel and the brightness value of the target pixel is greater than the difference between the first color value of the target pixel and the brightness value of the target pixel before correction, and the target pixel is any pixel in the hair region; converting the corrected first color value into HSV format to obtain the second color value of each pixel; obtaining a reference color value in HSV format; obtaining the target color value of each pixel in RGB format according to the reference color value and the second color value; rendering the hair region using the target color value of each pixel to obtain a rendered image.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer vision technology, and in particular to a method, device, electronic equipment and medium for rendering hair in a facial image. Background Art

[0002] With the popularity of beauty enhancement, more and more users hope to use beauty enhancement tools to enhance the image or video quality of people. Especially in the field of mobile phones or live broadcasts, the demand for beauty enhancement is becoming more and more prominent. Common beauty enhancements include face slimming and hairdressing.

[0003] Take hairdressing as an example. In many application scenarios that require high quality portrait images, the accuracy requirements for portrait segmentation are getting higher and higher. The semantic segmentation technology generally used is mainly to find the approximate pixel points of the object in the image, focusing on finding different object instances, and realizing the semantic understanding of the image content information. On this basis, the color parameters of the hair area are adjusted to achieve poor hairdressing effects, and hair rendering distortion is prone to occur. Summary of the invention

[0004] The present application provides a method, device, electronic device and medium for rendering hair of a facial image.

[0005] In a first aspect, a method for rendering hair in a facial image is provided, comprising:

[0006] Acquire a hair region in the image to be processed, wherein the first color value of each pixel point in the hair region is in RGB format;

[0007] According to a preset linear transformation relationship, correction processing is performed on each channel component in the first color value to obtain a corrected first color value; the difference between the first color value of the target pixel after correction and the brightness value of the target pixel is greater than the difference between the first color value of the target pixel and the brightness value of the target pixel before correction, and the target pixel is any pixel in the hair area;

[0008] Convert the corrected first color value into HSV format to obtain the second color value of each pixel;

[0009] Obtain a reference color value in HSV format; obtain a target color value of each pixel according to the reference color value and the second color value, wherein the target color value is in RGB format;

[0010] The hair area is rendered using the target color value of each pixel to obtain a rendered image.

[0011] In a second aspect, a facial image hair rendering device is provided, comprising:

[0012] An acquisition module, used for acquiring a hair region in the image to be processed, wherein the first color value of each pixel point in the hair region is in RGB format;

[0013] a correction module, configured to perform correction processing on each channel component in the first color value according to a preset linear transformation relationship to obtain a corrected first color value; the difference between the first color value of the target pixel after correction and the brightness value of the target pixel is greater than the difference between the first color value of the target pixel and the brightness value of the target pixel before correction, and the target pixel is any pixel in the hair area;

[0014] A conversion module, used for converting the corrected first color value into an HSV format to obtain a second color value of each pixel;

[0015] Rendering module, used to:

[0016] Obtain a reference color value in HSV format; obtain a target color value of each pixel according to the reference color value and the second color value, wherein the target color value is in RGB format;

[0017] The hair area is rendered using the target color value of each pixel to obtain a rendered image.

[0018] According to a third aspect, an electronic device is provided, comprising a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor executes the steps of the first aspect and any possible implementation thereof.

[0019] In a fourth aspect, a computer storage medium is provided, wherein the computer storage medium stores one or more instructions, wherein the one or more instructions are suitable for being loaded by a processor and executing the steps of the above-mentioned first aspect and any possible implementation thereof.

[0020] The embodiment of the present application obtains a hair area in an image to be processed, wherein the first color value of each pixel in the hair area is in RGB format, firstly performs correction processing on each channel component in the first color value according to a preset linear transformation relationship to obtain a corrected first color value, wherein the difference between the first color value of a target pixel after correction and the brightness value of the target pixel is greater than the difference between the first color value of the target pixel before correction and the brightness value of the target pixel, wherein the target pixel is any pixel in the hair area, and then converts the corrected first color value into HSV format to obtain a second color value of each pixel, and then obtains the HSV format. The reference color value of the formula is obtained, and the target color value in RGB format of each pixel is obtained according to the reference color value and the second color value. The target color value of each pixel is used to render the hair area to obtain a rendered image; the three color channels of R, G, and B of the pixels in the hair area can be linearly transformed respectively, and then merged in the HSV color space. Compared with the general direct replacement of pixel color values, this method first corrects each channel component, which can maximize the retention of the color value change of each pixel, so that the color value and the brightness value are greatly distinguished, so that the color value can be better transformed in the HSV color space, while the brightness value is retained, making the rendering effect more natural. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the background technology, the drawings required for use in the embodiments of the present application or the background technology will be described below.

[0022] Figure 1 A schematic diagram of a flow chart of a method for rendering hair in a facial image provided by an embodiment of the present application;

[0023] Figure 2 A flowchart of another method for rendering hair in a facial image provided by an embodiment of the present application;

[0024] Figure 3 A schematic diagram of a hair binary mask label provided in an embodiment of the present application;

[0025] Figure 4 A schematic diagram of the structure of a preset hair segmentation model provided in an embodiment of the present application;

[0026] Figure 5 A schematic diagram of the structure of a facial image hair rendering device provided in an embodiment of the present application;

[0027] Figure 6 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0028] In order to enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be described clearly and completely below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without creative work are within the scope of protection of the present application.

[0029] The terms "first", "second", etc. in the specification and claims of this application and the above-mentioned drawings are used to distinguish different objects, rather than to describe a specific order. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not limited to the listed steps or units, but optionally includes steps or units that are not listed, or optionally includes other steps or units inherent to these processes, methods, products or devices.

[0030] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.

[0031] The embodiments of the present application are described below in conjunction with the drawings in the embodiments of the present application.

[0032] See also Figure 1 , Figure 1 1 is a flow chart of a method for rendering hair in a facial image provided by an embodiment of the present application. The method may include:

[0033] 101. Acquire a hair region in an image to be processed, wherein a first color value of each pixel point in the hair region is in RGB format.

[0034] The execution subject of the embodiment of the present application may be a facial image hair rendering device, which may be an electronic device. In a specific implementation, the electronic device may be a terminal, which may also be referred to as a terminal device, including but not limited to other portable devices such as mobile phones, laptop computers, or tablet computers with touch-sensitive surfaces (e.g., touch screen displays and / or touch pads). It should also be understood that in some embodiments, the device is not a portable communication device, but a desktop computer with a touch-sensitive surface (e.g., touch screen displays and / or touch pads).

[0035] The above-mentioned image to be processed is an image containing a hair area, which can be a face and hair image, that is, an image containing a face and a hair area. The above-mentioned image to be processed can be an image taken by a camera device, or a composite image, etc., and the embodiment of the present application does not limit this.

[0036] The RGB color mode involved in the embodiments of the present application is a color standard in the industry. Various colors are obtained by changing the three color channels of red (R), green (G), and blue (B) and superimposing them on each other. RGB represents the colors of the three channels of red, green, and blue. An image is composed of pixels, and the pixel value (also called color value) of each pixel of the three-channel image represents the above RGB. The above-mentioned image to be processed can be an image using the RGB color mode, in which the color value of each pixel is in RGB format, including the first color value of each pixel in the above-mentioned hair area is in RGB format.

[0037] In an optional implementation, the step of obtaining the hair region in the image to be processed may include:

[0038] 11. Obtain the above-mentioned image to be processed;

[0039] 12. Process the image to be processed based on a preset hair segmentation model to obtain a hair region in the image to be processed.

[0040] Specifically, the image to be processed may be segmented to extract the hair region in the image to be processed.

[0041] Image segmentation is a crucial preprocessing for image recognition and computer vision. In the embodiment of the present application, the hair region is first accurately segmented to accurately recognize and process the hair region.

[0042] In the embodiment of the present application, a preset hair segmentation model can be used to process the above-mentioned image to be processed. The above-mentioned preset hair segmentation model can be a neural network model obtained through training and learning. The preset hair segmentation model can be used to analyze and process the input image to be processed, and predict the probability that each pixel in the image to be processed belongs to a different region, so as to classify each pixel, realize image segmentation, and obtain the hair region in the image to be processed. For the preset hair segmentation model, please refer to the specific description in the subsequent embodiments, which will not be repeated here.

[0043] Optionally, in the embodiment of the present application, a hair segmentation model can be selected as needed to extract the hair area in the image to be processed. A threshold-based segmentation method, a region-based segmentation method, an edge-based segmentation method, etc. can be used, and there is no limitation here.

[0044] After obtaining the hair region in the image to be processed, step 102 may be performed.

[0045] 102. Perform correction processing on each channel component in the first color value according to a preset linear transformation relationship to obtain a corrected first color value; a difference between the first color value of the target pixel after correction and the brightness value of the target pixel is greater than a difference between the first color value of the target pixel and the brightness value of the target pixel before correction, and the target pixel is any pixel in the hair region.

[0046] The facial image hair rendering method in the embodiment of the present application can replace the hair color, that is, replace the color value of the hair area, and does not change the brightness value of the hair area, because changing the brightness value will cause distortion of the hair rendering.

[0047] In order to more accurately distinguish the color values ​​and brightness values ​​of the pixels in the hair area, before replacing the hair color, the first color values ​​of each pixel in the hair area are corrected so that the color values ​​and brightness values ​​of the pixels in the hair area are more different after the correction, which facilitates more accurate rendering of the color values ​​of the pixels.

[0048] In one implementation, the above step 102 may include:

[0049] Obtain each channel component in the first color value, as well as the mean and variance of each channel component;

[0050] The corrected first color value is obtained by calculation according to the preset adjustment coefficient, each channel component, and the mean and variance of each channel component.

[0051] In the RGB color mode, each pixel has three channels: R, G, and B. A pixel has a corresponding color component in each channel. The color value can be corrected by adjusting the components of each channel of the pixel.

[0052] Specifically, assuming that the channel component of a pixel in any channel is expressed as I(x, y), where (x, y) is the coordinate of the pixel, the mean of the channel component is P, and the variance is σ, the mean P of the above channel component is the mean of the channel components of all pixels in the channel, and the variance σ of the above channel component is the variance of the channel components of all pixels in the channel; the following formula can be used for the above correction processing:

[0053]

[0054] I min =PD·σ;

[0055] Among them, I minis an intermediate parameter, D is the above preset adjustment coefficient, D can be a constant such as 3, and can be set as needed; I′(x, y) is the corrected channel component.

[0056] By using the above formula, the three channel components R, G, and B in each pixel in the hair area can be corrected and then merged to obtain the corrected color value of each pixel, that is, the corrected first color value. Specifically, the above formula can be used to correct any channel component of any channel in the hair area. In the color value correction of the embodiment of the present application, the above formula can be used to correct each pixel in the hair area and each channel component of the above pixel, and the corrected channel component corresponding to each channel component can be calculated, which is equivalent to replacing each original channel component with the corresponding corrected channel component, so that the three corrected channel components of each pixel can be combined into the new color value (first color value) of the pixel, that is, the corrected first color value of each pixel is obtained. Here is a specific introduction to the correction of the R channel component: for example, for the hair area a, firstly, the mean P1 and variance σ1 of the R channel components corresponding to all the pixels in the hair area a can be calculated. For a pixel point M in the hair area a, its coordinates in the image are (x1, y1), and the pixel point M in the R, G, and B channel components can be expressed as I1(x1, y1), I2(x1, y1), and I3(x1, y1), respectively; and then it can be calculated by the above formula:

[0057] By I 1min =P1-D·σ1, and obtain the intermediate parameter I 1min ;

[0058] Then through

[0059] The R channel component I′1(x1, y1) of the pixel M after correction can be obtained. Similarly, the G channel component I′2(x1, y1) and the B channel component I′3(x1, y1) of the pixel M after correction can be obtained, that is, the three channel components of R, G, and B of the pixel M after correction are obtained, which constitute the first color value of the pixel M after correction. The same correction process can be performed on each pixel in the hair area a, which will not be repeated here.

[0060] The brightness value of the color value in RGB format is determined by the three values ​​of R, G, and B. There is no way to extract the brightness value in the RGB color space separately. It can be understood that the color value and the brightness value are mixed together. In this case, adjusting the brightness requires adjusting the overall color value. Generally, the image can be mapped from RGB to HSV color space, and then the brightness is adjusted by modifying the V value of the pixel point, and then mapped back from HSV to RGB color space to adjust the image brightness. Through the above correction processing, there is no need to convert to HSV space. The brightness of the above hair area can be adjusted in RGB format to prevent the hair area from being too dark or too bright as a whole, so as to better perform subsequent color rendering processing and achieve better display effects.

[0061] 103. Convert the corrected first color value into an HSV format to obtain a second color value of each pixel.

[0062] In the embodiment of the present application, the color value of the pixel point in the hair area in RGB format is converted into HSV format for hair color replacement. HSV is a color space created based on the intuitive characteristics of color, also known as the Hexcone Model. The color parameters in this model are hue (H), saturation (S), and brightness (V), that is, the color value of the pixel point can include hue value, saturation value, and brightness value.

[0063] The brightness value of the color value in RGB format is determined by the three values ​​of R, G, and B. There is no way to extract the brightness value in the RGB color space separately. It can be understood that the color value and the brightness value are mixed together. However, when the color space can be converted to HSV through the above formula, its brightness value only needs a V value to represent it, so it can better distinguish the color value and brightness value of the pixel.

[0064] The conversion of the color value of the pixel point from the RGB format to the color value of the HSV format may adopt a preset mapping relationship, that is, the mapping relationship between the corrected first color value and the color value in the HSV format may be preset.

[0065] In one implementation, the above step 103 may include:

[0066] Determine a mapping relationship between the modified first color value and the HSV format color value according to a size relationship between the channel values ​​in the modified first color value;

[0067] According to the mapping relationship between the modified first color value and the HSV format color value, the HSV format color value corresponding to the modified first color value is calculated as the second color value.

[0068] Specifically, in order to better extract the pixel color values ​​of the hair area to be rendered, the color space of the image to be processed is converted from the RGB color space to the HSV color space in the embodiment of the present application. Let (r, g, b) be the color value of a pixel in a hair area, where r, g, and b are the red, green, and blue channel components of the color value of the pixel, respectively; let max be equal to the maximum of r, g, and b of the pixel, and let min be equal to the minimum of r, g, and b of the pixel; the color value of the pixel in the HSV color space can be expressed as (h, s, v), where h, s, and v values ​​represent the hue value, saturation value, and brightness value of the pixel, respectively; to find the (h, s, v) value in the HSV color space, the conversion formula can be as follows:

[0069]

[0070]

[0071] v = max;

[0072] Specifically, the h, s, and v values ​​corresponding to any pixel in the hair area can be calculated using the r, g, and b values ​​of the pixel. The corresponding h, s, and v values ​​of each pixel in the hair area are calculated using the above formula to obtain the second color value of each pixel in the HSV format.

[0073] For example, let (r1, g1, b1) be the color value of a pixel in a hair area. If g1 is the largest and b1 is the smallest among r1, g1, and b1, then max = g1, min = b1, and max is not 0. The corresponding calculation formula can be:

[0074]

[0075]

[0076] v1=max=g1;

[0077] The above formula can be used to calculate h1, s1, and v1, so as to obtain the second color value (h1, s1, v1) in the HSV color space corresponding to the pixel.

[0078] After the second color value is converted into the HSV format through the above steps, step 104 may be performed.

[0079] 104. Obtain a reference color value in HSV format; obtain a target color value of each pixel according to the reference color value and the second color value, wherein the target color value is in RGB format.

[0080] The reference color value can be set as needed, that is, the color value of the hair area after adjustment. The reference color value and the second color value are both in HSV format, so as to adjust the second color value, and convert the obtained color value into RGB format again.

[0081] Optionally, the user may select a reference color value in RGB format, which may be converted into a reference color value in HSV format according to the same method as in step 103 above, and then processed.

[0082] In one implementation, the above step 104 may include:

[0083] The hue value and saturation value in the second color value are respectively set to the hue value and saturation value in the reference color value to obtain a third color value;

[0084] According to the third color value and the preset rendering mapping relationship, the target color value of each pixel is obtained by calculation.

[0085] Specifically, according to the reference color value to be rendered, in the HSV color space, the lightness value of the second color value is retained, and the hue value and saturation value in the second color value are respectively set to the hue value and saturation value in the reference color value, and then the conversion is performed. Furthermore, the third color value and the preset rendering mapping relationship may be preset. In an optional implementation, the rendering mapping relationship includes the following calculation formula:

[0086]

[0087]

[0088] p=v*(1-s),

[0089] q=v*(1-f*s),

[0090] t=v*(1-(1-f)*s),

[0091]

[0092] In the embodiment of the present application, the color value (h, s, v) of a pixel point in the HSV color space and the corresponding color value (r, g, b) in the RGB space can be calculated to determine the above parameters p, q, f, and t. It can be seen from the above formula that a reference parameter hi can be calculated through the h value of the pixel point, and then the corresponding p, q, f, and t values ​​can be calculated. The above p, q, f, and t are intermediate variables, which are constructed according to the relationship between the three values ​​of h, s, and v. For example, for a known second color value of a pixel point (h1, s1, v1), the hi value can be first calculated by the above formula and recorded as hi1:

[0093]

[0094] According to h1 and the above hi1, the f value can be calculated and recorded as f1:

[0095]

[0096] Based on v1, s1, and f1, we can calculate the p, q, and t values, which are denoted as p1, q1, and t1 respectively:

[0097] p1=v1*(1-s1),

[0098] q1=v1*(1-f1*s1),

[0099] t = v1*(1-(1-f1)*s1);

[0100] Based on the above formula, the corresponding r, g, and b values ​​(referred to as r2, g2, and b2) can be determined according to the different hi1 values. For example, if hi1 = 0, then (r2, g2, b2) = (v1, t1, p1); if hi1 = 2, then (r2, g2, b2) = (p1, v1, t1), thereby obtaining the target color value of the pixel in RGB format.

[0101] By converting the second color value of each pixel point in the hair area according to the above mapping relationship, the target color value of each pixel point can be obtained.

[0102] 105. Render the hair area using the target color value of each pixel to obtain a rendered image.

[0103] After calculating the target color value of each pixel, the hair area can be rendered, that is, the color value of each pixel is adjusted to the corresponding target color value to obtain a rendered image. The hair area of ​​the rendered image can display the color of the selected reference color value, achieving the effect of replacing the hair color.

[0104] For example, assuming that the hair is pure black and the first color value of the pixel in the hair area is R=G=B=0, then you can first convert it to the HSV color space, that is, calculate the second color value of the corresponding pixel H=S=V=0; assuming that you want to replace the hair color with red (R=255, G=0, B=0), then you can first convert the red to the corresponding HSV format, and then retain the V value, H, and S values ​​of the original black hair in the second color value and modify them to the H and S values ​​of the red hair to obtain the recombined HSV value, and then convert the recombined HSV value back to the RGB color space to get the effect after the hair area is changed in color.

[0105] Optionally, after the above step 105, the method further includes:

[0106] The pixels in the hair area are sharpened.

[0107] The sharpening process of the image in the embodiment of the present application can quickly focus on the blurred edge of the hair area, improve the clarity or focal length of the hair area in the image, and make the color more vivid. The sharpening process can be completed by spatial differentiation. For example, the following formula can be used to sharpen the pixels in the hair area:

[0108]

[0109]

[0110] The above formula can be understood as, for any pixel in the image to be sharpened, the grayscale difference between the pixel 1 and the upper, lower, left and right pixels is calculated. For example, for the image to be sharpened, pixel 1 is the center point, and the grayscales of the upper, lower, left and right pixels 2, 3, 4, and 5 adjacent to pixel 1 are compared respectively, that is, (2(grayscale value)-1(grayscale value))+(3(grayscale value)-1(grayscale value))+(4(grayscale value)-1(grayscale value))+(5(grayscale value)-1(grayscale value)) is the sum of the grayscale differences. The sum of grayscale differences To represent the difference between the central pixel 1 and the surrounding pixels. Then use the sum of the grayscale differences to modify the grayscale of the central point, that is, add the original grayscale value f(x, y) of the pixel 1 to the sum of the grayscale differences. Obtain the sharpened grayscale value G(x,y) of the pixel 1. Perform the above processing on each pixel in the above manner, modify the grayscale value, and achieve sharpening of the entire image, so as to enhance the grayscale jump part, quickly focus on the blurred edge of the hair area, and improve the clarity and focal length of the hair area in the image. If the pixel a does not have four adjacent pixels, the grayscale value of the corresponding adjacent pixel can be 0, or the pixel a may not be sharpened and the original grayscale value may be retained.

[0111] In the embodiment of the present application, other sharpening methods may be selected or other processing adjustments may be performed on the rendered image as needed to achieve different display effects, which is not limited here.

[0112] The embodiment of the present application obtains a hair area in an image to be processed, wherein the first color value of each pixel in the hair area is in RGB format, firstly performs correction processing on each channel component in the first color value according to a preset linear transformation relationship to obtain a corrected first color value, wherein the difference between the first color value of a target pixel after correction and the brightness value of the target pixel is greater than the difference between the first color value of the target pixel before correction and the brightness value of the target pixel, wherein the target pixel is any pixel in the hair area, and then converts the corrected first color value into HSV format to obtain a second color value of each pixel, and then obtains the HSV format. The reference color value of the formula is obtained, and the target color value in RGB format of each pixel is obtained according to the reference color value and the second color value. The target color value of each pixel is used to render the hair area to obtain a rendered image; the three color channels of R, G, and B of the pixels in the hair area can be linearly transformed respectively, and then merged in the HSV color space. Compared with the general direct replacement of pixel color values, this method first corrects each channel component, which can maximize the retention of the color value change of each pixel, so that the color value and the brightness value are greatly distinguished, so that the color value can be better transformed in the HSV color space, while the brightness value is retained, making the rendering effect more natural.

[0113] See also Figure 2 , Figure 2 is a flow chart of a preset hair segmentation model training method provided in an embodiment of the present application. Figure 2 As shown, the method may specifically include:

[0114] 201. Obtain sample image data, where the sample image data includes different types of face and hair sample images and annotated sample images corresponding to the face and hair sample images, wherein the annotated sample images have annotated hair areas and background areas.

[0115] Specifically, in the embodiment of the present application, a network model can be pre-established and trained to obtain the above-mentioned preset hair segmentation model to perform the following steps: Figure 1 The method for rendering hair in a facial image in the illustrated embodiment.

[0116] Different types of face and hair sample images and corresponding labeled sample images can be used as sample data to train a preset convolutional neural network.

[0117] In the above labeled sample image, binary labels can be used to mark the hair area and background area. Figure 3 A schematic diagram of a hair binary mask label is shown in Figure 3 As shown,

[0118] The left side is an example of a face and hair sample image, and the right side is the annotated sample image corresponding to the face and hair sample image. In the annotated sample image, the white area represents the hair area, where the color value of the pixel is 1, and the black area represents the background area, where the color value of the pixel is 0.

[0119] 202. Use the sample image data and a preset loss function to train a preset convolutional neural network to obtain the preset hair segmentation model; the preset loss function includes a global loss function and a local loss function, the global loss function is used to calculate the overall difference between the prediction result of the preset convolutional neural network and the hair area of ​​the annotated sample image, and the local loss function is used to calculate the difference between the prediction result and each pixel in the hair area of ​​the annotated sample image.

[0120] In an optional embodiment, in order to improve the processing efficiency of the model, the format and size of the images input into the model can be unified. For example, the images input into the model are all 256*256 pixels and the format is RGB. Therefore, before the face and hair sample images are input into the model, the face and hair sample images and the labeled sample images can be subjected to the same preprocessing, such as image scaling and / or format conversion, to obtain RGB format images with a size of 256*256*3.

[0121] The preset hair segmentation model constructed in the embodiment of the present application may include a coding module and a decoding module, and the coding module is connected to the decoding module;

[0122] The encoding module may include a basic convolution layer, a depthwise separable convolution layer, a normalization layer, and an activation function layer, and the activation function layer may use a Relu activation function. The decoding module may include an upsampling layer, a depthwise separable deconvolution layer, a deconvolution layer, and an inverse activation function layer.

[0123] See also Figure 4 A schematic diagram of the structure of a preset hair segmentation model is shown in FIG. Figure 4 As shown, the preset hair segmentation model includes a first convolution unit a, a first depthwise separable convolution unit b, a second depthwise separable convolution unit c, a third depthwise separable convolution unit d, a second convolution unit e, a third convolution unit f, a first deconvolution unit g, a second deconvolution unit h, a first depthwise separable deconvolution unit i, a second depthwise separable deconvolution unit j, and a deconvolution processing unit k, which are sequentially connected;

[0124] Among them, each convolution unit includes two convolution processing layers and a downsampling layer, and each convolution processing layer includes a convolution layer Conv and a corresponding normalization layer BN and an activation function layer relu;

[0125] Each depth-wise separable convolutional unit consists of two depth-wise separable convolutional layers and one downsampling layer;

[0126] Each deconvolution unit includes two deconvolution processing layers and an upsampling layer. Each deconvolution processing layer includes a deconvolution layer and a corresponding normalization layer BN and an activation function layer relu.

[0127] Each depth-separable deconvolution unit includes two depth-separable deconvolution layers and one upsampling layer; the above-mentioned deconvolution processing unit k includes two of the above-mentioned deconvolution processing layers.

[0128] The above units a, b, c, d, e, and f belong to the encoding module, and units g, h, i, j, and k belong to the decoding module. The convolution layer is combined with the corresponding downsampling layer to convert the image to a smaller size to more accurately extract image features. The deconvolution layer is combined with the corresponding upsampling layer to convert the image back to a larger size, and finally obtain the original image size. The normalization layer is used to control the distribution of the input value of any neuron in each layer of the neural network to a standard normal distribution. In fact, it is to force the distribution results that may become more and more biased in general training to be pulled back to a more standard distribution, so that the gradient becomes larger and the gradient disappearance problem is avoided. Moreover, the larger gradient means that the learning convergence speed is fast, which can greatly speed up the training speed. The activation function layer introduces nonlinear factors, so that the neural network can arbitrarily approximate any nonlinear function, which is convenient for the training of nonlinear models.

[0129] During the training process, the encoding module is mainly used to obtain the feature map of the face and hair sample image. The essence of the encoding module is to perform a convolution operation on the face and hair sample image. After each convolution kernel operation, a feature map will be obtained. Therefore, the number of feature maps can be obtained as many as the number of convolution kernels. The essence of the feature map is the result of the convolution operation.

[0130] For the decoding module, when the encoding module obtains a smaller feature map (such as 8*8 size), deconvolution and upsampling operations are used to convert the feature map into a larger feature map (such as 16*16 size). This process first extracts feature information based on the deconvolution operation. Whether it is convolution or deconvolution, it is for extracting image features. The upsampling in the embodiment of the present application can use the interpolation method to achieve the effect of image magnification, that is, based on the original image pixels, a suitable interpolation algorithm is used to insert new elements between the pixels, so as to convert the 8*8 size feature map into 16*16. In the above decoding module, probability prediction can be performed based on the feature map to determine the hair area. When the final feature map (such as 256*256 size) is obtained, the data of the feature map is 0-1 distributed, indicating the probability value at a specific pixel position, that is, the probability that each pixel of the human face hair sample image belongs to the hair area or the background area, which can be used as a basis for judging whether the pixel belongs to the hair area. Each pixel is classified to determine all the pixels belonging to the hair area, and the hair area can be determined. The data in each layer of the model is obtained by continuously superimposing the input data through convolution operations.

[0131] Correspondingly, when the preset hair segmentation model is used to perform hair segmentation on an image, Figure 1 Step 12 in the illustrated embodiment may specifically include:

[0132] Analyze the image to be processed by the encoding module to obtain a feature map corresponding to the image to be processed;

[0133] The decoding module obtains the category prediction probability of each pixel in the image to be processed according to the feature map corresponding to the image to be processed, and obtains the hair area in the image to be processed according to the category prediction probability of each pixel in the image to be processed, wherein the category prediction probability includes the probability that the pixel belongs to the hair area and the probability that the pixel does not belong to the hair area.

[0134] Based on the above-mentioned category prediction probability, the pixel points in the image to be processed can be classified as hair area or non-hair area, and the image area where the pixel points belonging to the hair area are located can be extracted, so that the hair area in the image to be processed can be determined and segmented. Specifically, the face hair image to be processed is input into a preset hair segmentation model, and can be output as a binary image. In this binary image, the area with a pixel value of 1 is the hair area, and the area with a pixel value of 0 is the non-hair area.

[0135] During the training process, the network loss is calculated according to the preset loss function, and the parameters of the convolutional neural network are iterated and updated using the preset loss function to obtain the above-mentioned preset hair segmentation model.

[0136] In the design of the preset loss function in the embodiment of the present application, the preset loss function is composed of two parts, including the global loss function and the local loss function, wherein the global loss function calculates the overall difference between the prediction result of the preset convolutional neural network and the hair area of ​​the labeled sample image, and the local loss function calculates the difference between the prediction result and each pixel in the hair area of ​​the labeled sample image. By considering the overall hair loss through the global loss function and considering the relationship between the individual pixel values ​​of the hair strands through the local loss function, the training result of the model can be made more accurate.

[0137] In one implementation, the calculation formula of the preset loss function may be as follows:

[0138]

[0139] Among them, diceloss and softmaxloss represent the global loss function and the local loss function respectively, α and β represent different weight parameters, ranging from [0,1]; Y represents the correct label (ground truth) or true label of each pixel in the sample, and P represents the prediction result; |·| represents the sum of matrix elements, |Y∩P| represents the number of common elements of Y and P, and is actually calculated by taking the sum of the pixel-by-pixel products of the two, for example:

[0140]

[0141] The above Y i,j Represents the true label of the pixel at position (i, j). i,j The prediction result of the pixel at position (i, j) is expressed as follows. In the preset hair segmentation model training method in the embodiment of the present application, the preset loss function includes two parts: a global loss function and a local loss function. The global loss function part calculates the difference between the prediction result set and the true label set, and measures the overall hair area loss, while the second part of the local loss function part is the pixel category loss, which can be understood as judging whether the pixel is a pixel in the hair area. By minimizing the loss function for model training, more image details can be learned during training, which can make the model training results more accurate, that is, more accurate hair segmentation processing can be achieved.

[0142] Based on the description of the above-mentioned human face image hair rendering method embodiment, the present application embodiment also discloses a human face image hair rendering device. Figure 5 , the facial image hair rendering device 500 comprises:

[0143] An acquisition module 510 is used to acquire a hair region in the image to be processed, wherein the first color value of each pixel point in the hair region is in RGB format;

[0144] a correction module 520, configured to perform correction processing on each channel component in the first color value according to a preset linear transformation relationship to obtain a corrected first color value; the difference between the first color value of the target pixel after correction and the brightness value of the target pixel is greater than the difference between the first color value of the target pixel and the brightness value of the target pixel before correction, and the target pixel is any pixel in the hair region;

[0145] A conversion module 530, configured to convert the corrected first color value into an HSV format to obtain a second color value of each pixel;

[0146] The rendering module 540 is used to:

[0147] Obtain a reference color value in HSV format; obtain a target color value of each pixel according to the reference color value and the second color value, wherein the target color value is in RGB format;

[0148] The hair area is rendered using the target color value of each pixel to obtain a rendered image.

[0149] According to one embodiment of the present application, Figure 1 and Figure 2 Each step involved in the method shown can be performed by Figure 5 The operations performed by various modules in the facial image hair rendering device 500 are not described in detail here.

[0150] The facial image hair rendering device 500 in the embodiment of the present application can obtain a hair area in the image to be processed, wherein the first color value of each pixel in the hair area is in RGB format, firstly perform correction processing on each channel component in the first color value according to a preset linear transformation relationship to obtain a corrected first color value, wherein the difference between the first color value of the target pixel after correction and the brightness value of the target pixel is greater than the difference between the first color value of the target pixel before correction and the brightness value of the target pixel, wherein the target pixel is any pixel in the hair area, and then convert the corrected first color value into HSV format to obtain a second color value of each pixel. Then, the reference color value in HSV format is obtained, and the target color value in RGB format of each pixel is obtained according to the reference color value and the second color value. The target color value of each pixel is used to render the hair area to obtain a rendered image. The three color channels of R, G, and B of the pixels in the hair area can be linearly transformed respectively, and then fused in the HSV color space. Compared with the general direct replacement of pixel color values, this method first corrects each channel component, which can maximize the retention of the color value changes of each pixel, so that the color value and the brightness value are greatly distinguished, so that the color value can be better transformed in the HSV color space, while the brightness value is retained, making the rendering effect more natural.

[0151] Based on the description of the above method embodiment and device embodiment, the present application embodiment also provides an electronic device. Figure 6 The electronic device 600 at least includes a processor 601, an input device 602, an output device 603, and a computer storage medium 604. The processor 601, the input device 602, the output device 603, and the computer storage medium 604 in the electronic device may be connected via a bus or other means.

[0152] The computer storage medium 604 can be stored in the memory of the electronic device. The computer storage medium 604 is used to store a computer program. The computer program includes program instructions. The processor 601 is used to execute the program instructions stored in the computer storage medium 604. The processor 601 (or CPU (Central Processing Unit)) is the computing core and control core of the electronic device, which is suitable for implementing one or more instructions, and is specifically suitable for loading and executing one or more instructions to implement the corresponding method flow or corresponding function; in one embodiment, the processor 601 of the embodiment of the present application can be used to perform a series of processing, including such as Figure 1 or Figure 2 The various steps involved in the method shown, etc.

[0153] The embodiment of the present application also provides a computer storage medium (Memory), which is a memory device in an electronic device for storing programs and data. It is understandable that the computer storage medium here can include both built-in storage media in electronic devices and, of course, extended storage media supported by electronic devices. The computer storage medium provides a storage space that stores the operating system of the electronic device. In addition, one or more instructions suitable for being loaded and executed by the processor 401 are also stored in the storage space, and these instructions can be one or more computer programs (including program codes). It should be noted that the computer storage medium here can be a high-speed RAM memory, or a non-volatile memory (non-volatile memory), such as at least one disk storage; optionally, it can also be at least one computer storage medium located away from the aforementioned processor.

[0154] In one embodiment, one or more instructions stored in a computer storage medium may be loaded and executed by a processor to implement the corresponding steps in the above embodiment; in a specific implementation, one or more instructions in a computer storage medium may be loaded and executed by a processor. Figure 1 and / or Figure 2 Any steps in the method will not be repeated here.

[0155] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the above-described devices and modules can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.

[0156] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the division of the module is only a logical function division, and there may be other division methods in actual implementation, for example, multiple modules or components can be combined or integrated into another system, or some features can be ignored or not executed. The mutual coupling, direct coupling, or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or modules, which can be electrical, mechanical or other forms.

[0157] The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical modules, that is, they may be located in one place or distributed on multiple network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0158] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function according to the embodiment of the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions can be stored in a computer-readable storage medium or transmitted through the computer-readable storage medium. The computer instructions can be transmitted from a website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (digital subscriber line, DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that contains one or more available media integrations. The available medium may be a read-only memory (ROM), or a random access memory (RAM), or a magnetic medium, such as a floppy disk, a hard disk, a tape, a magnetic disk, or an optical medium, such as a digital versatile disc (DVD), or a semiconductor medium, such as a solid state disk (SSD), etc.

Claims

1. A method for rendering hair in a facial image, characterized in that: include: Acquire a hair region in the image to be processed, wherein the first color value of each pixel point in the hair region is in RGB format; According to a preset linear transformation relationship, each channel component in the first color value is corrected to obtain a corrected first color value; The difference between the first color value of the target pixel after correction and the brightness value of the target pixel is greater than the difference between the first color value of the target pixel and the brightness value of the target pixel before correction, and the target pixel is any pixel in the hair area; Convert the corrected first color value into HSV format to obtain the second color value of each pixel; Obtain a reference color value in HSV format; obtain a target color value of each pixel according to the reference color value and the second color value, wherein the target color value is in RGB format; Rendering the hair area using the target color value of each pixel to obtain a rendered image; The step of performing correction processing on each channel component in the first color value according to a preset linear transformation relationship to obtain the corrected first color value comprises: obtaining each channel component in the first color value, and the mean and variance of each channel component; and calculating and obtaining the corrected first color value according to a preset adjustment coefficient, each channel component, and the mean and variance of each channel component; The method of obtaining the target color value of each pixel point according to the reference color value and the second color value includes: setting the hue value and saturation value in the second color value to the hue value and saturation value in the reference color value, respectively, to obtain a third color value; and calculating the target color value of each pixel point according to the third color value and a preset rendering mapping relationship.

2. The method for rendering hair in a facial image according to claim 1, characterized in that: The converting the corrected first color value into an HSV format to obtain the second color value of each pixel point includes: Determine a mapping relationship between the corrected first color value and the HSV format color value according to a size relationship between the channel values ​​in the corrected first color value; According to the mapping relationship between the modified first color value and the HSV format color value, the HSV format color value corresponding to the modified first color value is calculated as the second color value.

3. The method for rendering hair in a facial image according to claim 1 or 2, characterized in that: The step of obtaining the hair region in the image to be processed comprises: Acquire the image to be processed; Processing the image to be processed based on a preset hair segmentation model to obtain a hair region in the image to be processed; The preset hair segmentation model is trained by the following method: Acquire sample image data, the sample image data including different types of human face and hair sample images and annotated sample images corresponding to the human face and hair sample images, wherein the annotated sample images have annotated hair areas and background areas; The preset convolutional neural network is trained using the sample image data and a preset loss function to obtain the preset hair segmentation model; the preset loss function includes a global loss function and a local loss function, the global loss function is used to calculate the overall difference between the prediction result of the preset convolutional neural network and the hair area of ​​the labeled sample image, and the local loss function is used to calculate the difference between the prediction result and each pixel in the hair area of ​​the labeled sample image.

4. The method for rendering hair of a facial image according to claim 3, characterized in that: The preset hair segmentation model includes a coding module and a decoding module, and the coding module is connected to the decoding module; the processing of the image to be processed based on the preset hair segmentation model to obtain the hair area in the image to be processed includes: Analyze the image to be processed by the encoding module to obtain a feature map corresponding to the image to be processed; The decoding module obtains the category prediction probability of each pixel in the image to be processed according to the feature map corresponding to the image to be processed, and obtains the hair area in the image to be processed according to the category prediction probability of each pixel in the image to be processed, wherein the category prediction probability includes the probability that the pixel belongs to the hair area and the probability that the pixel does not belong to the hair area.

5. The method for rendering hair of a facial image according to claim 1, characterized in that: After rendering the hair area using the target color value of each pixel point, the method further includes: Sharpening is performed on the pixels in the hair area.

6. A facial image hair rendering device, characterized in that: include: An acquisition module, used for acquiring a hair region in the image to be processed, wherein the first color value of each pixel point in the hair region is in RGB format; A correction module, used for performing correction processing on each channel component in the first color value according to a preset linear transformation relationship to obtain a corrected first color value; The difference between the first color value of the target pixel after correction and the brightness value of the target pixel is greater than the difference between the first color value of the target pixel and the brightness value of the target pixel before correction, and the target pixel is any pixel in the hair area; A conversion module, used for converting the corrected first color value into an HSV format to obtain a second color value of each pixel; Rendering module, used to: Obtain a reference color value in HSV format; obtain a target color value of each pixel according to the reference color value and the second color value, wherein the target color value is in RGB format; Rendering the hair area using the target color value of each pixel to obtain a rendered image; The correction module is specifically used to: obtain each channel component in the first color value, and the mean and variance of each channel component; calculate and obtain the corrected first color value according to a preset adjustment coefficient, each channel component, and the mean and variance of each channel component; The rendering module is specifically used to: set the hue value and saturation value in the second color value to the hue value and saturation value in the reference color value respectively, to obtain a third color value; The target color value of each pixel is obtained by calculation according to the third color value and a preset rendering mapping relationship.

7. An electronic device, characterized in that: The method comprises a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor executes the steps of hair rendering of a facial image as claimed in any one of claims 1 to 5.

8. A computer-readable storage medium, characterized in that: A computer program is stored, and when the computer program is executed by a processor, the processor executes the steps of the facial image hair rendering method according to any one of claims 1 to 5.

Citation Information

Patent Citations

  • Three-dimensional object color adjusting method and device, computer equipment and computer readable storage medium

    CN108876931A

  • Object color recognition method and device, electronic equipment and storage medium

    CN111476849A