Method for automatically modifying non-uniform hair color of hair in figure image
By using pre-trained segmentation networks and adversarial generation network models, the hair areas in the character images are automatically identified and processed, and the problem of uneven hair color is solved, achieving efficient and natural image processing effects.
Patent Information
- Application Number
- CN202411664247.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-20
- Publication Date
- 2025-03-11
AI Technical Summary
The prior art requires manual operation when dealing with the problem of uneven hair color in character images, which is time-consuming and difficult to achieve natural and harmonious visual effects.
The pre-trained segmented network model and adversarial generation network model are used to automatically identify and process the hair region, and the mean color of the root and end of the hair region is extracted, and the result diagram of the unified color is generated.
It realizes automatic processing of uneven hair color problems in character images, improves the appearance quality of the image, reduces the workload of post-processing, and the results generated are natural and beautiful.
Smart Images

Figure CN119599928A_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the technical field of hair color modification, and in particular to a method for automatically modifying uneven hair color of a person's image. Background Art
[0002] In the field of portrait image editing, the beautification of the hair area occupies a pivotal position. With the evolution of aesthetic trends in modern society, more and more individuals tend to choose hair dye colors that are different from their natural hair color. However, as time goes by, the growth of new hair roots causes a color gap between the dyed hair part and the original hair color. This color difference is particularly noticeable in photographic works, affecting the overall aesthetics. In the post-processing of portrait images, professional editors will adopt specific technical means to achieve uniform hair color processing for such color difference problems.
[0003] Traditional artificial hair color homogenization involves complex steps such as area selection and color adjustment. This process is not only time-consuming and labor-intensive, but the processing results are often difficult to achieve a natural and harmonious visual effect, and may even appear to have too many artificial traces. In view of this, it is particularly urgent to develop an automated algorithm to identify the phenomenon of uneven hair color and automatically beautify and modify it. This automated method aims to improve the appearance quality of portrait images, while reducing the workload of post-processing and improving efficiency, in order to achieve an image effect that is both natural and beautiful. Summary of the invention
[0004] In view of this, the purpose of the present invention is to provide a method for automatically modifying uneven hair color of a person's image, which can process a person's image and address the problem of uneven hair color of the person in the image, so that the processed image is natural and beautiful.
[0005] According to one aspect of the present invention, a method for automatically modifying uneven hair color of a person's image is provided, the method comprising:
[0006] Obtaining character image data that needs to be processed;
[0007] The image data is input into a pre-trained segmentation network model; the image data is used as the input of the segmentation network model, and the segmentation network model outputs a hair region mask, a hair root region mask, and a hair tail region mask corresponding to the image data based on the input image data;
[0008] Extract the mean color of the hair color based on the hair root area mask and the hair tail area mask, and grayscale the hair area image based on the hair area mask;
[0009] The hair color mean color and the grayscale processed hair area image are input into a pre-trained adversarial generative network model, and a result image of unified hair color is output based on the hair color mean color as a guided auxiliary model.
[0010] In the above technical solution, it is mainly used to process the hair area in the character image and perform color uniform processing on it. First, it is necessary to obtain the character image data to be processed. These data can be static pictures or video frames, which will serve as the basis for subsequent processing. The acquired image data is input into a pre-trained segmentation network model. This model can identify and segment different areas in the image, such as the hair area, the hair root area and the hair tail area. The segmentation model can adopt a PyTorch image segmentation model, etc., which will not be repeated here. The segmentation network model outputs masks corresponding to the hair area, the hair root area and the hair tail area based on the input image data. These masks are binary images that identify the location of each area. Based on the hair root area mask and the hair tail area mask, the mean color of the hair is extracted. This step is to determine the dominant color of the hair for use in subsequent steps. The hair area image is grayed. Graying is the process of converting a color image into a grayscale image, which can remove the image of the original image hair color and retain the original image hair texture information. The mean hair color and the grayscaled hair area image are used as input to a pre-trained Generative Adversarial Network (GAN) model. This model can generate a uniform hair color result image based on the input color information and mask area. The model will repaint the grayscale hair area based on the provided mean hair color color to make the color of the entire hair area uniform. The entire solution utilizes the segmentation technology and generation technology in deep learning to achieve automated hair color processing through a pre-trained model. This method can be used to improve or change a person's hair color, and solve the problem of new hair of the original color growing out of the roots of the hair after dyeing, and the problem of hair color discontinuity after taking a photo.
[0011] In some embodiments, the average hair color is extracted based on the hair root area mask and the hair tail area mask, specifically:
[0012] Based on the hair root area mask, find the coordinates of all pixel points belonging to the hair root area; according to the coordinate points, extract the corresponding color value, and calculate the mean color in the hair root area, which is used as the mean color of the hair color;
[0013] and / or,
[0014] Based on the hair tail area mask, find the coordinates of all pixel points belonging to the hair tail area; according to the coordinate points, extract the corresponding color values, and calculate the mean color in the hair tail area, which is used as the mean color of the hair color.
[0015] In the above technical solution, the color information of the hair root area and the hair tail area is extracted from the character image, and the mean color of these areas is calculated for subsequent hair color processing. First, the mask of the hair root area is used to determine the coordinates of the pixel points belonging to the hair root area in the image. This can be achieved by performing a bitwise AND operation on the mask and the original image, so that only the pixel points in the hair root area are retained. Then, according to these coordinate points, the corresponding color values are extracted. This usually involves traversing these coordinate points and obtaining the color information of each point from the original image. Finally, the mean color in the hair root area is calculated. This can be achieved by adding all the extracted color values and then dividing them by the total number of pixels in the hair root area. The mean color can be used as the hair color mean color for subsequent hair color processing. Similar to the processing of the hair root area, the mask of the hair tail area is first used to determine the coordinates of the pixel points belonging to the hair tail area in the image. Then, the corresponding color values are extracted according to these coordinate points. Finally, the mean color in the hair tail area is calculated, which is also achieved by adding all the extracted color values and then dividing them by the total number of pixels in the hair tail area. The color mean can be calculated by traversing all pixels in a specific area, accumulating the color value of each pixel (such as the value in RGB or HSV color space), and then dividing it by the total number of pixels in the area. This method ensures that the color value obtained represents the overall trend of the color in the area. Once the mean color of the root area or the tail area of the hair is obtained, this information can be used as input to a deep learning model to assist the model in generating a result map of uniform hair color. In deep learning, this mean color can be used as conditional information to guide the model to generate a hair color that matches the actual hair color. Using a pre-trained Generative Adversarial Network (GAN) model, the hair color mean color and the hair area image can be used as input, and the model will learn how to generate a result map of uniform hair color based on this information. This model is usually trained on a large amount of data to learn how to generate realistic hair color from the input information in order to generate uniform and realistic hair color.
[0016] In some embodiments, the result graph output by the adversarial generative network model includes:
[0017] A result map of unifying the hair color with the average color of the hair roots, and / or a result map of unifying the hair color with the average color of the hair ends.
[0018] In the above technical solution, the model outputs a result image of uniform hair color based on the mean color of the input. In GAN, the generator network is responsible for generating images based on the input, while the discriminator network evaluates the authenticity of the generated images. In this process, the generator network will continue to learn how to generate more realistic images until the discriminator cannot distinguish between the generated images and the real images. The output result image is a result image of uniform hair color with the mean color of the hair roots or the mean color of the hair ends. This means that no matter how the hair color in the original image changes, the output image will appear as a uniform color. This is achieved through the color mapping and generation technology learned by the GAN model, and it can generate two different result images based on the different colors of the hair roots and hair ends, providing more selectivity and flexibility.
[0019] In some embodiments, the training data sets of the segmentation network model and the adversarial generative network model are constructed in the following manner:
[0020] Collect a portrait image dataset containing uniform hair color and uneven hair color, the dataset includes portrait images and true labels corresponding to the portrait images;
[0021] in,
[0022] The data volume of the portrait image data of the person with uniform hair color and the data volume of the portrait image data of the person with uneven hair color each account for 50%;
[0023] The real label includes: hair area mask, hair root area mask and hair tail area mask; for portrait image data with uneven hair color, the hair root and hair tail are divided into different areas according to their colors; for portrait image data with uniform hair color, only the hair mask is marked.
[0024] In the above technical solution, a portrait image dataset containing uniform hair color and uneven hair color is collected. This dataset contains portrait images and their corresponding true labels, namely, hair region mask, hair root region mask, and hair tail region mask. The amount of portrait image data with uniform hair color and the amount of portrait image data with uneven hair color in the dataset each account for 50% to ensure that the model can learn the features of different hair color conditions. For portrait image data with uneven hair color, it is necessary to partition according to the color of the hair root and hair tail, and annotate the corresponding mask. Partition annotation can help the model more accurately identify the areas of the hair root and hair tail, because these two areas may have significant differences in color and texture. The color of the hair root and hair tail is often different, especially in hair dyeing or gradient color design. Partition annotation allows the model to perform more natural coloring processing for these different areas. By learning the different features of the hair root and hair tail, the model can better generalize to different hairstyles and color changes, and improve performance on diverse data. When generating a result map of uniform hair color, partition annotation helps the model create a smoother color transition between the hair root and hair tail to avoid abrupt color differences. By partitioning and labeling the roots and ends of hair according to color, the model can better learn the color features of different areas, thereby reducing the impact on other areas (such as eyelashes, armpits, eyebrows, etc.) when generating new colors. The roots and ends of hair require different details. Partition labeling enables the model to optimize these details and improve the quality of the final image. For portrait image data with uniform hair color, only the hair mask needs to be labeled. The portrait images with uniform and uneven hair color each account for half of the dataset. Such a balanced distribution helps the model learn the hair features in different situations and improve the generalization ability of the model. Through adversarial training, the spatial consistency between category labels can be strengthened, the probability of large-area categories can be improved, the category boundaries can be sharpened, and the incorrectly predicted category labels can be deleted in a small range. Since the model training takes into account both uniform and uneven hair color, the model can have a good processing effect on hair of different hair colors in practical applications, enhancing the robustness of the model. Through precise labeling and adversarial training, the generated result image is more realistic and can be better integrated into the original image, improving the user experience. Through this training dataset, segmentation network models and adversarial generative network models that can handle different hair color situations can be trained. These models can provide high-quality hair color generation effects in practical applications.
[0025] In some embodiments, the adversarial generative network model adopts adversarial loss and mean square error loss functions.
[0026] In the above technical solution, on the one hand, the result is made to tend to the real color hair image by generating adversarial loss (GAN Loss), and on the other hand, the mean square error loss (L2 Loss) supervises the model to color the portrait hair according to the guided hair mean color. The combination of adversarial loss and mean square error loss function (L2 Loss) in the adversarial generative network (GAN) model has the following advantages: adversarial loss helps the generator learn to generate high-quality images that are difficult to distinguish between true and false, while L2 Loss focuses on pixel-level accuracy. The combination of the two can balance the overall quality and details of the image. In hair color processing, adversarial loss may cause instability during training, while the addition of L2 Loss can help the model converge more stably. L2 Loss assumes that the error follows a Gaussian distribution and is more sensitive to outliers, while adversarial loss, as a nonlinear loss, can provide a certain robustness to outliers. L2 Loss can converge faster than MAE (mean absolute error), which is an advantage for training efficiency.
[0027] According to another aspect of the present invention, there is provided a device for automatically modifying uneven hair color of a person's image, based on the above-mentioned method for automatically modifying uneven hair color of a person's image; comprising the following modules connected in sequence:
[0028] Acquisition module: used to acquire the character image data that needs to be processed;
[0029] Segmentation module: used to input the image data into a pre-trained segmentation network model; the image data is used as the input of the segmentation network model, and the segmentation network model outputs a hair area mask, a hair root area mask, and a hair tail area mask corresponding to the image data based on the input image data;
[0030] Preprocessing module: used to extract the mean color of hair color based on the hair root area mask and the hair tail area mask, and grayscale the hair area image based on the hair area mask;
[0031] The processing module is used to input the hair color mean color and the grayscale processed hair area image into a pre-trained adversarial generative network model, and output a result image of unified hair color based on the hair color mean color as a guiding auxiliary model.
[0032] In the above technical scheme, in order to better use the above method, the present application proposes a device for automatically modifying uneven hair color of a person's image. Each module corresponds to each step of the above method. The specific principles have been described above and will not be repeated here.
[0033] According to another aspect of the present invention, there is provided a device for automatically modifying uneven hair color of a person's image, comprising:
[0034] at least one processor and a memory communicatively coupled to the at least one processor;
[0035] The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can perform the above method.
[0036] In the above technical solution, in order to better run and process the method, the above method is stored in a memory, and the stored method is executed by a processor. It should be noted that the principle and effect of each step have been described above and will not be described in detail here.
[0037] According to another aspect of the present invention, a computer-readable storage medium is provided, storing a computer program, wherein the computer program implements the above method when executed by a processor.
[0038] In the above technical solution, in order to better run and use the method, the above method is stored in a computer-readable storage medium, and the above method is implemented by a processor. It should be noted that the principle and effect of each step have been described above and will not be described in detail here. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0040] Figure 1 It is a flow chart of an embodiment of a method for automatically modifying uneven hair color of a person's image according to the present invention;
[0041] Figure 2 It is a schematic flow chart of the recognition part of an embodiment of a method for automatically modifying uneven hair color of a person's image according to the present invention;
[0042] Figure 3 It is a schematic diagram of the processing part of an embodiment of a method for automatically modifying uneven hair color of a person's image according to the present invention;
[0043] Figure 4 is a schematic diagram for comparing the results of an embodiment of a method for automatically modifying uneven hair color of a person's image according to the present invention;
[0044] Figure 5 The present invention is a schematic structural diagram of an embodiment of a device for automatically modifying uneven hair color of a person's image. DETAILED DESCRIPTION
[0045] The present invention will be further described in detail below in conjunction with the accompanying drawings and examples. It is particularly noted that the following examples are only used to illustrate the present invention, but are not intended to limit the scope of the present invention. Similarly, the following examples are only partial embodiments of the present invention rather than all embodiments, and all other embodiments obtained by those of ordinary skill in the art without creative work are within the scope of protection of the present invention.
[0046] The present invention provides a method for automatically modifying uneven hair color in a person image, aiming to modify uneven hair color in a person image. The method specifically targets the problem of inconsistent hair color in a person image, and realizes uniform adjustment of hair color through intelligent processing technology. The image processed by the method not only has natural and harmonious colors, but also has significantly improved overall aesthetics, bringing a more refined and professional visual effect to the user.
[0047] Embodiment 1
[0048] See also Figure 1 , a method for automatically modifying uneven hair color of a person's image, the method comprising:
[0049] S1, obtaining the character image data to be processed;
[0050] S2, inputting the image data into a pre-trained segmentation network model; the image data is used as the input of the segmentation network model, and the segmentation network model outputs a hair region mask, a hair root region mask, and a hair tail region mask corresponding to the image data based on the input image data;
[0051] S3, extracting the mean color of the hair color based on the hair root region mask and the hair tail region mask, and graying the hair region image based on the hair region mask;
[0052] S4. The hair color mean color and the grayscale processed hair area image are input into a pre-trained adversarial generative network model, and a result image of unified hair color is output based on the hair color mean color as a guided auxiliary model.
[0053] In this embodiment, it is mainly used to process the hair area in the character image and perform color uniform processing on it. First, it is necessary to obtain the character image data to be processed. These data can be static pictures or video frames, which will serve as the basis for subsequent processing. The acquired image data is input into a pre-trained segmentation network model. This model can identify and segment different areas in the image, such as the hair area, the hair root area and the hair tail area. The segmentation model can adopt a PyTorch image segmentation model, etc., which will not be repeated here. The segmentation network model outputs masks corresponding to the hair area, the hair root area and the hair tail area based on the input image data. These masks are binary images that identify the location of each area. Based on the hair root area mask and the hair tail area mask, the mean color of the hair is extracted. This step is to determine the dominant color of the hair for use in subsequent steps. The hair area image is grayed. Graying is the process of converting a color image into a grayscale image, which can remove the image of the original image hair color and retain the original image hair texture information. The mean hair color and the grayscaled hair area image are used as input to a pre-trained Generative Adversarial Network (GAN) model. This model can generate a uniform hair color result image based on the input color information and mask area. The model will repaint the grayscale hair area based on the provided mean hair color color to make the color of the entire hair area uniform. The entire solution utilizes the segmentation technology and generation technology in deep learning to achieve automated hair color processing through a pre-trained model. This method can be used to improve or change a person's hair color, and solve the problem of new hair of the original color growing out of the roots of the hair after dyeing, and the problem of hair color discontinuity after taking a photo.
[0054] In this embodiment, the average hair color is extracted based on the hair root area mask and the hair tail area mask, specifically:
[0055] Based on the hair root area mask, find the coordinates of all pixel points belonging to the hair root area; according to the coordinate points, extract the corresponding color value, and calculate the mean color in the hair root area, which is used as the mean color of the hair color;
[0056] and / or,
[0057] Based on the hair tail area mask, find the coordinates of all pixel points belonging to the hair tail area; according to the coordinate points, extract the corresponding color values, and calculate the mean color in the hair tail area, which is used as the mean color of the hair color.
[0058] In this embodiment, color information of the hair root region and the hair tail region is extracted from the character image, and the mean color of these regions is calculated for subsequent hair color processing. First, the mask of the hair root region is used to determine the coordinates of the pixels belonging to the hair root region in the image. This can be achieved by performing a bitwise AND operation on the mask and the original image, so that only the pixels in the hair root region are retained. Then, according to these coordinate points, the corresponding color values are extracted. This usually involves traversing these coordinate points and obtaining the color information of each point from the original image. Finally, the mean color in the hair root region is calculated. This can be achieved by adding all the extracted color values and then dividing them by the total number of pixels in the hair root region. The mean color can be used as the hair color mean color for subsequent hair color processing. Similar to the processing of the hair root region, the mask of the hair tail region is first used to determine the coordinates of the pixels belonging to the hair tail region in the image. Then, the corresponding color values are extracted according to these coordinate points. Finally, the mean color in the hair tail region is calculated, which is also achieved by adding all the extracted color values and then dividing them by the total number of pixels in the hair tail region. The color mean can be calculated by traversing all pixels in a specific area, accumulating the color value of each pixel (such as the value in RGB or HSV color space), and then dividing it by the total number of pixels in the area. This method ensures that the color value obtained represents the overall trend of the color in the area. Once the mean color of the root area or the tail area of the hair is obtained, this information can be used as input to a deep learning model to assist the model in generating a result map of uniform hair color. In deep learning, this mean color can be used as conditional information to guide the model to generate a hair color that matches the actual hair color. Using a pre-trained Generative Adversarial Network (GAN) model, the hair color mean color and the hair area image can be used as input, and the model will learn how to generate a result map of uniform hair color based on this information. This model is usually trained on a large amount of data to learn how to generate realistic hair color from the input information in order to generate uniform and realistic hair color.
[0059] In this embodiment, the result graph output by the adversarial generative network model includes: a result graph of unifying the hair color with the mean color of the hair root, and / or a result graph of unifying the hair color with the mean color of the hair tail. The model outputs a result graph of unified hair color based on the input mean color. In GAN, the generator network is responsible for generating images based on the input, while the discriminator network evaluates the authenticity of the generated image. In this process, the generator network will continue to learn how to generate more realistic images until the discriminator cannot distinguish between the generated image and the real image. The output result graph is a result graph of unifying the hair color with the mean color of the hair root or the mean color of the hair tail. This means that no matter how the hair color in the original image changes, the output image will be displayed as a unified color, which is achieved through the color mapping and generation technology learned by the GAN model, and can generate two different result graphs based on the different colors of the hair root and the hair tail, providing more selectivity and flexibility.
[0060] In this embodiment, the training data sets of the segmentation network model and the adversarial generative network model are constructed in the following manner:
[0061] Collect a portrait image dataset containing uniform hair color and uneven hair color, the dataset includes portrait images and true labels corresponding to the portrait images;
[0062] in,
[0063] The data volume of the portrait image data of the person with uniform hair color and the data volume of the portrait image data of the person with uneven hair color each account for 50%;
[0064] The real label includes: hair area mask, hair root area mask and hair tail area mask; for portrait image data with uneven hair color, the hair root and hair tail are divided into different areas according to their colors; for portrait image data with uniform hair color, only the hair mask is marked.
[0065] In this embodiment, a portrait image dataset containing uniform hair color and uneven hair color is collected. This dataset contains portrait images and corresponding true labels, namely, hair region mask, hair root region mask and hair tail region mask. The amount of portrait image data with uniform hair color and the amount of portrait image data with uneven hair color in the dataset each account for 50% to ensure that the model can learn the features under different hair color conditions. For portrait image data with uneven hair color, it is necessary to partition according to the color of the hair root and hair tail, and annotate the corresponding mask. Partition annotation can help the model more accurately identify the areas of the hair root and hair tail, because these two areas may have significant differences in color and texture. The color of the hair root and hair tail is often different, especially in hair dyeing or gradient color design. Partition annotation allows the model to perform more natural coloring processing for these different areas. By learning the different features of the hair root and hair tail, the model can better generalize to different hairstyles and color changes, and improve performance on diverse data. When generating a result map of uniform hair color, partition annotation helps the model create a smoother color transition between the hair root and hair tail to avoid abrupt color differences. By partitioning and labeling the roots and ends of hair according to color, the model can better learn the color features of different areas, thereby reducing the impact on other areas (such as eyelashes, armpits, eyebrows, etc.) when generating new colors. The roots and ends of hair require different details. Partition labeling enables the model to optimize these details and improve the quality of the final image. For portrait image data with uniform hair color, only the hair mask needs to be labeled. The portrait images with uniform and uneven hair color each account for half of the dataset. Such a balanced distribution helps the model learn the hair features in different situations and improve the generalization ability of the model. Through adversarial training, the spatial consistency between category labels can be strengthened, the probability of large-area categories can be improved, the category boundaries can be sharpened, and the incorrectly predicted category labels can be deleted in a small range. Since the model training takes into account both uniform and uneven hair color, the model can have a good processing effect on hair of different hair colors in practical applications, enhancing the robustness of the model. Through precise labeling and adversarial training, the generated result image is more realistic and can be better integrated into the original image, improving the user experience. Through this training dataset, segmentation network models and adversarial generative network models that can handle different hair color situations can be trained. These models can provide high-quality hair color generation effects in practical applications.
[0066] In this embodiment, the adversarial generative network model adopts adversarial loss and mean square error loss function. On the one hand, the result is made to tend to the real color hair image by generating adversarial loss (GAN Loss), and on the other hand, the mean square error loss (L2 Loss) supervises the model to color the portrait hair according to the guided hair mean color. The combination of adversarial loss and mean square error loss function (L2 Loss) in the adversarial generative network (GAN) model has the following advantages: adversarial loss helps the generator learn to generate high-quality images that are difficult to distinguish between true and false, while L2 Loss focuses on pixel-level accuracy. The combination of the two can balance the overall quality and details of the image. In hair color processing, adversarial loss may cause instability during training, and the addition of L2 Loss can help the model converge more stably. L2 Loss assumes that the error follows a Gaussian distribution and is more sensitive to outliers, while adversarial loss, as a nonlinear loss, can provide a certain robustness to outliers. L2 Loss can converge faster than MAE (mean absolute error), which is an advantage for training efficiency.
[0067] In order to better explain the example of the present invention, the whole process will be further described as follows:
[0068] This case proposes an automatic beautification method for uneven hair color in human images. The method can process human images and deal with the problem of uneven hair color in the images, making the processed images natural and beautiful. The method includes two parts: recognition part and processing part. The networks mentioned below are all convolutional neural networks.
[0069] 1. Identification
[0070] See also Figure 2 , the recognition module recognizes the hair area of the person in the image, as well as the hair root area and hair tail area. If the hair color is uneven after dyeing, the root and hair tail areas are distinguished according to the color; if the hair color is uniform, the root mask, hair tail mask, and hair mask are the same. The recognition module needs to annotate a batch of data, half of which is data with uniform hair color and half is data with uneven hair color. The data with uniform hair color only needs to be annotated with the hair mask, and the data with uneven hair color needs to be annotated with three masks. The recognition module uses a segmentation network for training, and the training method is consistent with the common segmentation network training method, which will not be repeated here.
[0071] 2. Processing
[0072] See also Figure 3 ,The processing module is a module for recoloring the portrait hair.
[0073] 1) The input of the hair color uniformity network is the image of the hair area extracted from the portrait image according to the hair mask of the recognition module, and then converted to a grayscale image to remove the original hair color information. In addition, a hair mean color information needs to be input as a guide;
[0074] 2) When training the model, the training data is an image with uniform hair color, and the mean hair color is the mean color in the hair mask; when the model is actually used for inference, the input is an image with uneven hair color, and the mean hair color is the mean color in the hair root mask or the mean color in the hair tail mask, so as to obtain the results in both the hair root direction and the hair tail direction; please refer to Figure 4 In this figure, (a) is the original image. It can be seen that the uneven hair color caused by the length of time after hair dyeing causes a discontinuity in the hair color in the photo. As can be seen from the figure, the hair roots are the black color of the newly grown black hair, and the hair ends are the color of the dyed hair. (b) is the result of the hair color being unified to the root color. The model unified the hair color based on the black color at the root. (c) is the result of the hair color being unified to the hair ends. The model unified the hair color based on the dyed color at the hair ends. And from the output results, the processed area is only limited to the hair area, and areas such as eyebrows and eyelashes are not affected.
[0075] 3) The way to train the network is, on the one hand, to make the result tend to the real color hair image through generative adversarial loss (GAN loss), and on the other hand, to supervise the model through mean square error loss (L2 loss) to color the portrait hair according to the guided mean hair color.
[0076] This solution has the following two advantages:
[0077] 1. Natural and beautiful effect: This solution can intelligently optimize the uneven hair color of portraits, making them present a more harmonious and natural visual effect, thereby significantly enhancing the visual appeal of the character image.
[0078] 2. Improve efficiency: This solution greatly simplifies the traditional cumbersome manual hair beautification process by automatically processing images with uneven hair color, greatly improves the speed and efficiency of post-processing, and perfectly meets the needs of large-scale image processing.
[0079] Embodiment 2
[0080] See also Figure 5 , a device for automatically modifying uneven hair color of a person's image, based on the above-mentioned method for automatically modifying uneven hair color of a person's image; comprising the following modules connected in sequence:
[0081] Acquisition module: used to acquire the character image data that needs to be processed;
[0082] Segmentation module: used to input the image data into a pre-trained segmentation network model; the image data is used as the input of the segmentation network model, and the segmentation network model outputs a hair area mask, a hair root area mask, and a hair tail area mask corresponding to the image data based on the input image data;
[0083] Preprocessing module: used to extract the mean color of hair color based on the hair root area mask and the hair tail area mask, and grayscale the hair area image based on the hair area mask;
[0084] The processing module is used to input the hair color mean color and the grayscale processed hair area image into a pre-trained adversarial generative network model, and output a result image of unified hair color based on the hair color mean color as a guiding auxiliary model.
[0085] In this embodiment, in order to better use the method described in one of the embodiments, the present application proposes a device for automatically modifying uneven hair color of a person's image. Each module corresponds to each step of the method described in one of the embodiments. The specific principles have been described above and will not be repeated here.
[0086] Embodiment 3
[0087] A device for automatically modifying uneven hair color of a person's image, comprising:
[0088] at least one processor and a memory communicatively coupled to the at least one processor;
[0089] The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the method described in one of the embodiments.
[0090] In this embodiment, in order to better run and process the method described in one of the embodiments, the method described in one of the embodiments is stored in a memory, and a processor is used to execute the stored method. It should be noted that the principle and effect of each step have been described above and will not be described in detail here.
[0091] Embodiment 4
[0092] A computer-readable storage medium stores a computer program, wherein when the computer program is executed by a processor, the method described in one of the embodiments is implemented.
[0093] In the above technical solution, in order to better run and use the method described in one of the embodiments, the above method is stored in a computer-readable storage medium, and a processor is used to implement the method described in one of the embodiments. It should be noted that the principle and effect of each step have been described above and will not be described in detail here.
[0094] The above descriptions are only some embodiments of the present invention, and are not intended to limit the protection scope of the present invention. Any equivalent device or equivalent process transformation made using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.
Claims
1. A method for automatically modifying uneven hair color of a person's image, characterized in that the method include: Obtaining character image data that needs to be processed; Inputting the image data into a pre-trained segmentation network model; The image data is used as the input of the segmentation network model. The segmentation network model outputs a hair region mask, a hair root region mask, and a hair tail region mask corresponding to the image data based on the input image data. Extract the mean color of the hair color based on the hair root area mask and the hair tail area mask, and grayscale the hair area image based on the hair area mask; The hair color mean color and the grayscale processed hair area image are input into a pre-trained adversarial generative network model, and a result image of unified hair color is output based on the hair color mean color as a guided auxiliary model.
2. The method for automatically modifying uneven hair color of a person's image as claimed in claim 1, characterized in that: The average hair color is extracted based on the hair root area mask and the hair tail area mask, specifically: Based on the hair root area mask, find the coordinates of all pixel points belonging to the hair root area; according to the coordinate points, extract the corresponding color value, and calculate the mean color in the hair root area, which is used as the mean color of the hair color; and / or, Based on the hair tail area mask, find the coordinates of all pixel points belonging to the hair tail area; according to the coordinate points, extract the corresponding color values, and calculate the mean color in the hair tail area, which is used as the mean color of the hair color.
3. A method for automatically modifying uneven hair color of a person's image as claimed in claim 2, characterized in that: The result graph output by the adversarial generation network model includes: A result map of unifying the hair color with the average color of the hair roots, and / or a result map of unifying the hair color with the average color of the hair ends.
4. The method for automatically modifying uneven hair color of a person's image as claimed in claim 1, characterized in that: The training data sets of the segmentation network model and the adversarial generation network model are constructed in the following manner: Collect a portrait image dataset containing uniform hair color and uneven hair color, the dataset includes portrait images and true labels corresponding to the portrait images; in, The data volume of the portrait image data of the person with uniform hair color and the data volume of the portrait image data of the person with uneven hair color each account for 50%; The real label includes: hair area mask, hair root area mask and hair tail area mask; for portrait image data with uneven hair color, the hair root and hair tail are divided into different areas according to their colors; for portrait image data with uniform hair color, only the hair mask is marked.
5. The method for automatically modifying uneven hair color of a person's image as claimed in claim 1, characterized in that: The adversarial generative network model adopts adversarial loss and mean square error loss functions.
6. A device for automatically modifying uneven hair color of a person's image, characterized in that: A method for automatically modifying uneven hair color of a person's image based on any one of claims 1 to 5; comprising the following modules connected in sequence: Acquisition module: used to acquire the character image data that needs to be processed; Segmentation module: used to input the image data into a pre-trained segmentation network model; the image data is used as the input of the segmentation network model, and the segmentation network model outputs a hair area mask, a hair root area mask, and a hair tail area mask corresponding to the image data based on the input image data; Preprocessing module; It is used to extract the mean color of hair color based on the hair root area mask and the hair tail area mask, and grayscale the hair area image based on the hair area mask; The processing module is used to input the hair color mean color and the grayscale processed hair area image into a pre-trained adversarial generative network model, and output a result image of unified hair color based on the hair color mean color as a guiding auxiliary model.
7. A device for automatically modifying uneven hair color of a person's image, characterized in that: include: at least one processor and a memory communicatively coupled to the at least one processor; The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the method as claimed in any one of claims 1 to 5.
8. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 5 is implemented.