Image processing method, apparatus, device, and medium

CN117710220BActive Publication Date: 2026-10-30BEIJING ZITIAO NETWORK TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211056881.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-08-31
Publication Date
2026-10-30
Estimated Expiration
2042-08-31

AI Technical Summary

Technical Problem

然而,发明人经研究发现,现有的发色变换技术大多难以精确地分割原始图像中的头发区域,主要体现在无法精确处理头发边缘,导致头发变色效果不佳

Benefits of technology

[0015]本公开实施例还提供了一种电子设备,所述电子设备包括:处理器;用于存储所述处理器可执行指令的存储器;所述处理器,用于从所述存储器中读取所述可执行指令,并执行所述指令以实现如本公开实施例提供的图像处理方法。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117710220B_ABST
    Figure CN117710220B_ABST
Patent Text Reader

Abstract

The present disclosure relates to an image processing method, device, equipment and medium, wherein the method comprises: obtaining a first transformed image corresponding to an original image; wherein the first transformed image is an image after performing transformation processing on the hair color of a target object in the original image; performing filtering processing on the first transformed image according to the original image to obtain a second transformed image; wherein the gradient information of the second transformed image corresponds to the gradient information of the original image; generating a final transformed image according to the first transformed image and the second transformed image; wherein the hair body of the target object in the final transformed image is obtained based on the hair body of the target object in the first transformed image, and the hair edge of the target object in the final transformed image is obtained based on the hair edge of the target object in the second transformed image. The hair region of the final transformed image obtained by the present disclosure can achieve a good hair color transformation effect.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the field of image processing technology, and in particular to an image processing method, apparatus, device and medium. Background Technology

[0002] Facial effects have been widely used in various applications such as image editing software, photo-taking software, and live video streaming platforms. Users can change the appearance of their faces according to their needs, and changing hair color is one such user request. However, the inventors discovered through research that most existing hair color changing technologies struggle to accurately segment the hair area in the original image, mainly due to the inability to precisely process hair edges, resulting in poor hair color changing effects. Summary of the Invention

[0003] In order to solve the above-mentioned technical problems, or at least partially solve the above-mentioned technical problems, this disclosure provides an image processing method, apparatus, device and medium.

[0004] This disclosure provides an image processing method, the method comprising: obtaining a first transformation image corresponding to an original image; wherein the first transformation image is an image after transforming the hair color of a target object in the original image; filtering the first transformation image according to the original image to obtain a second transformation image; generating a final transformation image according to the first transformation image and the second transformation image; wherein the main body of the hair of the target object in the final transformation image is obtained based on the main body of the hair of the target object in the first transformation image, and the hair edge of the target object in the final transformation image is obtained based on the hair edge of the target object in the second transformation image.

[0005] Optionally, the gradient information of the second transformed graph corresponds to the gradient information of the original graph;

[0006] Optionally, the step of filtering the first transformed image based on the original image to obtain the second transformed image includes: using the original image as the guiding image of the guided filtering algorithm, and using the guided filtering algorithm to filter the first transformed image based on the guiding image to obtain the second transformed image.

[0007] Optionally, the step of generating a final transformation image based on the first transformation image and the second transformation image includes: obtaining a hair body mask image of the target object in the first transformation image; fusing the first transformation image and the second transformation image based on the hair body mask image to obtain a third transformation image; wherein, the pixels corresponding to the hair body of the target object in the third transformation image are the pixels corresponding to the hair body of the target object in the first transformation image, and the pixels corresponding to the hair edges and non-hair regions of the target object in the third transformation image are the pixels corresponding to the hair edges and non-hair regions of the target object in the second transformation image; fusing the third transformation image and the first transformation image to obtain the final transformation image.

[0008] Optionally, the step of obtaining the hair body mask of the target object in the first transformed image includes: obtaining the original hair mask corresponding to the target object in the original image; and performing erosion processing on the original hair mask to obtain the hair body mask of the target object in the first transformed image.

[0009] Optionally, the step of fusing the third transformation image and the first transformation image to obtain the final transformation image includes: obtaining a complete hair mask image of the target object in the third transformation image; fusing the third transformation image and the first transformation image based on the complete hair mask image to obtain the final transformation image; wherein, the pixels corresponding to the complete hair of the target object in the final transformation image are the pixels corresponding to the complete hair of the target object in the third transformation image, and the pixels corresponding to the remaining areas in the final transformation image other than the complete hair are the pixels corresponding to the remaining areas in the first transformation image other than the complete hair.

[0010] Optionally, the step of obtaining the complete hair mask of the target object in the third transformed image includes: obtaining the original hair mask corresponding to the target object in the original image; and performing dilation processing on the original hair mask to obtain the complete hair mask of the target object in the third transformed image.

[0011] Optionally, the step of obtaining the first transformation image corresponding to the original image includes: inputting the original image into the hair color initial transformation model to obtain the first transformation image corresponding to the original image output by the hair color initial transformation model.

[0012] Optionally, the method further includes: replacing the original image with the final transformed image and displaying the final transformed image on the terminal interface.

[0013] Optionally, the method further includes: training a preset neural network model based on the original image and the final transformation image corresponding to the original image, and using the neural network model at the end of training as the final hair color transformation model; wherein, the final hair color transformation model is used to perform hair color transformation processing on the person in the target image and output the final transformation image of the target image.

[0014] This disclosure also provides an image processing apparatus, comprising: a first transformation map acquisition module, configured to acquire a first transformation map corresponding to an original image; wherein the first transformation map is an image after transforming the hair color of a target object in the original image; a second transformation map generation module, configured to filter the first transformation map according to the original image to obtain a second transformation map; and a final transformation map generation module, configured to generate a final transformation map according to the first transformation map and the second transformation map; wherein the main body of the hair of the target object in the final transformation map is obtained based on the main body of the hair of the target object in the first transformation map, and the hair edge of the target object in the final transformation map is obtained based on the hair edge of the target object in the second transformation map.

[0015] This disclosure also provides an electronic device, the electronic device comprising: a processor; a memory for storing executable instructions of the processor; the processor being configured to read the executable instructions from the memory and execute the instructions to implement the image processing method provided in this disclosure.

[0016] This disclosure also provides a computer-readable storage medium storing a computer program for performing the image processing method provided in this disclosure.

[0017] The technical solution provided in this disclosure involves a first transformed image where the hair body color differs from the original image's hair body color, but the hair texture remains essentially unchanged. That is, the textures of the hair body in the first transformed image and the original image are essentially the same. The hair body in the final transformed image is based on the first transformed image, thus allowing the hair texture to be as consistent as possible with the original image's texture while maintaining the hair color change in the final transformed image. Furthermore, since the second transformed image is obtained by filtering the first transformed image based on the original image, the second transformed image achieves better edge-preserving smoothing, and the hair edges are similar to the hair edges in the original image. The hair edges in the final transformed image are based on the hair edges in the second transformed image, so the hair edges in the final transformed image can be as similar as possible to the hair edges in the original image while maintaining the hair color change, effectively avoiding the problem of potentially inaccurate hair edges in the first transformed image. In summary, in this disclosure, the hair region (hair body and hair edges) in the final transformed image can achieve a better hair color transformation effect.

[0018] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of this disclosure, nor is it intended to limit the scope of this disclosure. Other features of this disclosure will become readily apparent from the following description. Attached Figure Description

[0019] The accompanying drawings, which are incorporated in and form a part of this specification, illustrate embodiments consistent with this disclosure and, together with the description, serve to explain the principles of this disclosure.

[0020] To more clearly illustrate the technical solutions in the embodiments of this disclosure or the prior art, the accompanying drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0021] Figure 1 This is a schematic flowchart of an image processing method provided in an embodiment of the present disclosure;

[0022] Figure 2 This is a schematic diagram of a hair color transformation process provided in an embodiment of the present disclosure;

[0023] Figure 3 This is a schematic flowchart of an image processing method provided in an embodiment of the present disclosure;

[0024] Figure 4 This is a schematic diagram of the structure of an image processing apparatus provided in an embodiment of the present disclosure;

[0025] Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this disclosure. Detailed Implementation

[0026] To better understand the above-mentioned objectives, features, and advantages of this disclosure, the solutions disclosed herein will be further described below. It should be noted that, unless otherwise specified, the embodiments and features described herein can be combined with each other.

[0027] Numerous specific details are set forth in the following description in order to provide a full understanding of this disclosure, but this disclosure may also be implemented in other ways different from those described herein; obviously, the embodiments in the specification are only some, and not all, of the embodiments of this disclosure.

[0028] The inventors discovered that the hair segmentation models used in related hair color transformation technologies cannot accurately segment hair regions. Hair edges, such as scattered strands, are easily missed during segmentation and not included in the segmented hair area. This results in the missed hair edges not being color-changed and still displaying their original color. For example, when changing a person's black hair to blonde, the resulting hair color transformation image might show the hair area as predominantly blonde, but the hair edges remaining black. Furthermore, these technologies typically first segment the hair, color-change the segmented hair areas, and then directly paste the color-changed hair areas back onto the original image. This makes it difficult to accurately fit the hair edges, and the final hair color transformation image will still show the original hair color. For example, if the original hair is black, some black edges will still appear at the hair edges in the color transformation image.

[0029] The aforementioned deficiencies in the color-changing technology of related technologies are the result of the applicant's practical experience and careful research. Therefore, the discovery process of the aforementioned deficiencies and the solutions proposed by the applicant in the embodiments of this application below should be considered as contributions made by the applicant to this application.

[0030] To address the issue of inaccurate hair edge processing in related technologies, resulting in poor hair color-changing effects, this disclosure provides an image processing method, apparatus, device, and medium, which are described in detail below:

[0031] Figure 1 This is a flowchart illustrating an image processing method provided in an embodiment of the present disclosure. The method can be executed by an image processing device, which can be implemented in software and / or hardware, and is generally integrated into an electronic device. Figure 1 As shown, the method mainly includes the following steps S102 to S106:

[0032] Step S102: Obtain the first transformed image corresponding to the original image; wherein, the first transformed image is the image after transforming the hair color of the target object in the original image.

[0033] The original image is an image containing at least one object. This embodiment of the disclosure does not limit the type of object; for example, the object can be a person. In practical applications, the original image may only contain the facial features of the object (such as a person's face), or it may contain the object's full body or half-body. The target object can be all objects contained in the original image, or it can be an object specified by the user; there are no limitations here. The aforementioned first transformed image is the image obtained by initially processing the hair color of the target object in the original image. Any technique capable of hair color transformation can be used to obtain the first transformed image corresponding to the original image; there are no limitations here. It should also be noted that the first transformed image only changes the color of the hair area and does not adjust other features such as hair texture, nor does it change non-hair areas; that is, non-hair areas are protected, and only hair color transformation is performed.

[0034] However, hair edges (i.e., the boundary between hair and non-hair areas) are mostly irregular. As mentioned earlier, due to the difficulty in accurately processing hair edges, the first transformed image obtained after transforming the hair color of the target object in the original image still suffers from the aforementioned problem of hair edges not changing color. Compared with the related technologies that directly present the first transformed image to the user, the embodiments of this disclosure further optimize the first transformed image, as detailed in steps S104 to S106 below.

[0035] Step S104: Filter the first transformed image based on the original image to obtain the second transformed image. In practical applications, the first transformed image can be filtered based on specified information from the original image, such as the gradient information of the original image, to obtain the second transformed image, where the gradient information of the second transformed image corresponds to the gradient information of the original image. In some examples, the gradient information of the second transformed image corresponds to the gradient information of the original image, indicating that the gradient information of the second transformed image is similar to the gradient information of the original image. Specifically, the similarity between the gradient information of the second transformed image and the gradient information of the original image is greater than a preset similarity threshold.

[0036] If the hair region segmentation is inaccurate, the hair edges after color transformation may not have undergone the color change, resulting in a sense of discontinuity at the hair edges. However, in the original image, the color of the entire hair region is uniform, and this discontinuity is minimal. To improve this issue, the overall gradient of the second transformation image obtained through the above steps is similar to the overall gradient of the original image, preserving the hair region color as shown in the first transformation image. This method helps to make the hair edges in the second transformation image as close as possible to the hair edges in the original image, eliminating the sense of discontinuity at the hair edges to some extent, and also preserving edge details relatively well.

[0037] In some specific implementation examples, the original image can be used as the guide image (also called the guide graph) for the guided filtering algorithm. The guided filtering algorithm then filters the first transformed image based on the guide image to obtain the second transformed image. By using the original image as the guide image for the guided filtering algorithm and the first transformed image as the input image, it is possible to ensure that the overall gradient of the guided filtering algorithm is as similar as possible to the first transformed image, while achieving a smooth edge-preserving effect.

[0038] Step S106: Generate a final transformation map based on the first transformation map and the second transformation map; wherein, the main body of the hair of the target object in the final transformation map is obtained based on the main body of the hair of the target object in the first transformation map, and the hair edge of the target object in the final transformation map is obtained based on the hair edge of the target object in the second transformation map.

[0039] In practical applications, the first and second transformation images can be fused to obtain the final transformation image. In the technical solution provided by this disclosure, the hair body of the first transformation image differs in color from the hair body of the original image, but the hair texture remains essentially unchanged; that is, the textures of the hair body in the first and original images are basically consistent. Since the hair body of the final transformation image is based on the hair body of the first transformation image, the hair texture can be made as consistent as possible with the hair texture of the original image while changing the hair color in the final transformation image. Furthermore, because the gradient information of the second transformation image obtained by filtering the first transformation image of the original image corresponds to the gradient information of the original image, the second transformation image can achieve a better edge-preserving smoothing effect, and the hair edges are also similar to the hair edges of the original image. The hair edges of the final transformation image are based on the hair edges of the second transformation image, so the hair edges can be made as similar as possible to the hair edges of the original image while changing the hair color in the final transformation image, effectively avoiding the problem of potentially inaccurate hair edges in the first transformation image. In summary, in this disclosure embodiment, the hair region (hair body and hair edges) of the final transformation image can achieve a better hair color transformation effect.

[0040] To quickly and easily obtain a relatively good first transformed image in the initial stage, in some specific implementation examples, the original image can be input into a color-changing initial transformation model to obtain the first transformed image corresponding to the original image output by the color-changing initial transformation model. In some implementations, the color-changing initial transformation model can be a neural network model. This disclosure does not limit the specific implementation of the color-changing initial transformation model; any model with color-changing functionality in related technologies can be used as the color-changing initial transformation model. For example, the color-changing initial transformation model can be a CycleGAN (Cycle Generative Adversarial Network) model, which is a GAN network model that implements image style transfer functionality. It can achieve transformation of specified features. This disclosure does not limit the network structure of the CycleGAN model; the model network structure and training method can be implemented with reference to related technologies. The CycleGAN model can quickly and effectively perform preliminary color-changing processing on the original image. However, the inventors discovered through research that the CycleGAN model still cannot accurately process the hair edges when performing hair color transformation, and the aforementioned hair color transformation effect provided in this embodiment is still unsatisfactory. If the first transformation image is directly provided to the user, it will affect the user experience. Therefore, this embodiment will further perform post-optimization processing based on the first transformation image to obtain a final transformation image in which both the hair body and the hair edges have good color transformation effects.

[0041] After obtaining the first transformed image, this embodiment of the present disclosure can filter the first transformed image according to the original image to obtain a second transformed image with edge-preserving smoothing effect. Based on obtaining the second transformed image, this embodiment of the present disclosure can further generate a final transformed image according to the first transformed image and the second transformed image. For example, steps A to C can be performed as follows:

[0042] Step A: Obtain the main hair mask of the target object in the first transformation image.

[0043] The hair subject mask, also known as the hair subject mask, can be used to distinguish between the main hair region and non-main hair regions. For example, in the hair subject mask, the pixel values ​​corresponding to the main hair region are all 1, and the pixel values ​​corresponding to the non-main hair region are all 0. This is just an example. By setting pixel values ​​such as 0 / 1 for the main hair region and non-main hair region in the hair subject mask, the main hair region and non-main hair region can be clearly distinguished. The specific implementation of the mask can be found in related technologies and will not be elaborated here. The embodiments of this disclosure fully consider that the hair edge of the target object in the first transformed image may not be precise, but the main hair of the target object in the first transformed image is basically the same as the main hair of the target object in the original image except for the color. Therefore, in step A, only the hair subject mask is obtained to make full use of the main hair of the target object in the first transformed image while still preserving the original hair texture.

[0044] For ease of understanding, step A above can be implemented by referring to steps A1 and A2 below:

[0045] Step A1: Obtain the original hair mask corresponding to the target object in the original image. The original hair mask is mainly used to distinguish between the hair region and non-hair region of the target object in the original image. In practical applications, hair segmentation models from relevant technologies can be used to segment the hair in the original image to obtain the original hair mask. The specific hair region segmentation method can refer to relevant technologies and is not limited here. It should be noted that most existing hair segmentation methods are not accurate, so the original hair mask obtained in step A1 may also be inaccurate, that is, the hair edges may not be precise.

[0046] Step A2: Erosion processing is performed on the original hair mask to obtain the main hair mask of the target object in the first transformed image.

[0047] Since the hair edges in the original hair mask are not precise, by eroding the original hair mask, the hair area corresponding to the original hair mask is "shrunk" and the hair edges are removed, so that the main hair mask of the target object in the first transformation image can be obtained, that is, only the main hair of the target object in the first transformation image is retained.

[0048] Step B: Based on the hair subject mask, the first transformation map and the second transformation map are fused to obtain the third transformation map; wherein, the pixels corresponding to the hair subject of the target object in the third transformation map are the pixels corresponding to the hair subject of the target object in the first transformation map, and the pixels corresponding to the hair edges and non-hair areas of the target object in the third transformation map are the pixels corresponding to the hair edges and non-hair areas of the target object in the second transformation map.

[0049] It's understandable that the texture of the hair in the first transformed image and the original image are basically the same. The gradient information of the second transformed image is similar to that of the original image. The second transformed image can achieve a good edge-preserving smoothing effect based on the hair color transformation. Therefore, the third transformed image obtained through the above method can simultaneously have a good hair body rendering effect and hair edge rendering effect based on the hair color transformation, and avoid the situation where the hair edges are not colored in the first transformed image. In other words, the third transformed image can largely eliminate the uncolored hair edges in the first transformed image, and the phenomenon of hair edges not being colored in the first transformed image will basically no longer appear. For ease of understanding, taking the transformation of black hair to blonde hair as an example, the third transformed image will basically not have the problems of black hair strands and black edges remaining due to inaccurate hair edge processing.

[0050] Step C: Merge the third transformation diagram and the first transformation diagram to obtain the final transformation diagram.

[0051] It is understandable that although the third transformation image has a better hair color transformation effect, the pixels corresponding to the non-hair regions are the same as those in the second transformation image, meaning they are still affected by guided filtering and have some differences from the non-hair regions in the first transformation image. Typically, hair transformation processing needs to keep the non-hair regions unchanged and only change the hair color. Therefore, based on the good hair color transformation effect of the third transformation image, the third and first transformation images can be merged. The final transformation image can retain a good hair color transformation effect and the original non-hair regions. In other words, the complete hair in the third transformation image can be pasted back onto the first transformation image, optimizing the hair color transformation effect of the first transformation image while keeping the non-hair regions unchanged. In some specific implementation examples, step C above can be implemented with reference to steps C1 to C2 below:

[0052] Step C1: Obtain the complete hair mask of the target object in the third transformation image.

[0053] A complete hair mask is also called a complete hair mask. A complete hair mask can be used to distinguish between hair regions and non-hair main body regions. The hair region is the complete hair region, including the hair body and hair edges. By obtaining the complete hair mask of the target object in the third transformation image, the complete hair region in the third transformation image can be directly used to achieve a better hair color transformation effect. In some specific implementation examples, the complete hair mask can be obtained by referring to the following steps (1) to (2).

[0054] (1) Obtain the original hair mask corresponding to the target object in the original image. As mentioned earlier, most existing hair segmentation methods are not accurate, so the original hair mask obtained in step (1) may also be inaccurate, that is, the hair edges may not be precise.

[0055] (2) Dilate the original hair mask to obtain the complete hair mask of the target object in the third transformation image.

[0056] Since the hair edges in the original hair mask are not precise, the original hair mask is dilated to "enlarge" the corresponding hair area, thus including any hair areas that might not be covered in the original mask, resulting in a complete hair mask. In practical applications, the degree of dilation in the collision processing is lower than a preset threshold, meaning that only a slight dilation of the original hair mask is needed.

[0057] Step C2: Based on the complete hair mask, the third transformation image and the first transformation image are fused to obtain the final transformation image. In the final transformation image, the pixels corresponding to the complete hair of the target object are the same as those corresponding to the complete hair of the target object in the third transformation image. The pixels corresponding to the remaining areas (excluding the complete hair) in the final transformation image are the same as those corresponding to the remaining areas (excluding the complete hair) in the first transformation image. The pixels corresponding to the complete hair and the pixels corresponding to the remaining areas (excluding the complete hair) can be distinguished based on the complete hair mask.

[0058] By using the above methods, the final transformation image can achieve a good hair color transformation effect while keeping the non-hair areas unchanged.

[0059] Based on the foregoing, this disclosure also provides the following embodiments: Figure 2 The diagram shown is a schematic of a hair color transformation process, for ease of understanding. Figure 2 For further understanding, please refer to, for example, Figure 3 The flowchart of an image processing method shown mainly includes the following steps S302 to S310:

[0060] Step S302: Input the original image into the CycleGAN model to obtain the first transformed image corresponding to the original image output by the CycleGAN model; wherein, the first transformed image is the image after transforming the hair color of the target object in the original image.

[0061] Step S304: The original image is used as the guide image for the guided filtering algorithm. The guided filtering algorithm is used to filter the first transformed image based on the guide image to obtain the second transformed image.

[0062] Step S306: Obtain the main hair mask of the target object in the first transformation image.

[0063] Step S308: Based on the hair body mask, the first transformation image and the second transformation image are fused to obtain the third transformation image; wherein, the pixels corresponding to the hair body of the target object in the third transformation image are the pixels corresponding to the hair body of the target object in the first transformation image, and the pixels corresponding to the hair edges and non-hair areas of the target object in the third transformation image are the pixels corresponding to the hair edges and non-hair areas of the target object in the second transformation image.

[0064] Step S310: Obtain the complete hair mask of the target object in the third transformation image;

[0065] Step S312: Based on the complete hair mask, the third transformation image and the first transformation image are fused to obtain the final transformation image; wherein, the pixels corresponding to the complete hair of the target object in the final transformation image are the pixels corresponding to the complete hair of the target object in the third transformation image, and the pixels corresponding to the remaining areas in the final transformation image other than the complete hair are the pixels corresponding to the remaining areas in the first transformation image other than the complete hair.

[0066] The specific implementation methods of the above steps provided in this disclosure can all refer to the foregoing related content. Initially, a preliminary and reliable hair color transformation result (first transformation image) can be obtained using the CycleGAN model. Later, a guided filtering algorithm is used to generate a smooth second transformation image. The first and second transformation images are fused based on the hair body mask image. The resulting third transformation image can retain the hair body texture in the first transformation image and the hair edges in the second transformation image. Therefore, the hair area in the third transformation image is similar to the original hair in terms of hair texture and hair edges, based on the hair color change, and can present a better hair color transformation effect. On this basis, the complete hair in the third transformation image is "pasted back" onto the first transformation image. The final transformation image can present a better hair color transformation effect, effectively solve the problem of hair edges not changing color, and can continue to keep the non-hair areas unchanged.

[0067] After obtaining the final transformed graph, this disclosure further provides two application examples of the final transformed graph:

[0068] Application Example 1: Replace the original image with the final transformed image and display the final transformed image on the terminal interface. In this example, in various applications such as video editing software, photo-taking software, and live video streaming platforms, the original image is initially captured. Then, according to user settings, the hair color in the original image is transformed to a user-specified color. After obtaining the final transformed image based on the aforementioned image processing method, it can be directly displayed on the terminal interface.

[0069] Application Example 2: A preset neural network model is trained based on the original image and the corresponding final transformation image of the original image, and the neural network model at the end of training is used as the final hair color transformation model; wherein, the final hair color transformation model is used to perform hair color transformation processing on the person in the target image and output the final transformation image of the target image.

[0070] That is, the generated final transformed graph can be compared with the original... Figure 1 These images are used as sample images for training the model. This model can directly transform the hair color of the original image and effectively handle the hair region. The final hair color transformation model can be widely used in various applications such as video editing software, photo software, and live video platforms. This allows applications that require hair color transformation to directly use the final hair color transformation model to obtain a final transformed image with good hair color transformation effect throughout the entire hair region (the main body of the hair and the hair edges), improving problems such as the hair color edges not changing color, making it more convenient and faster.

[0071] In summary, the image processing method provided in this disclosure can effectively improve the hair color transformation effect.

[0072] Corresponding to the aforementioned image processing method, Figure 4 This is a schematic diagram of the structure of an image processing apparatus provided in an embodiment of the present disclosure. The apparatus can be implemented by software and / or hardware, and is generally integrated into an electronic device, such as... Figure 4 As shown, it includes:

[0073] The first transformation image acquisition module 402 is used to acquire the first transformation image corresponding to the original image; wherein, the first transformation image is the image after transforming the hair color of the target object in the original image;

[0074] The second transformation graph generation module 404 is used to filter the first transformation graph based on the original graph to obtain the second transformation graph.

[0075] The final transformation image generation module 406 is used to generate a final transformation image based on the first transformation image and the second transformation image; wherein, the main body of the hair of the target object in the final transformation image is obtained based on the main body of the hair of the target object in the first transformation image, and the hair edge of the target object in the final transformation image is obtained based on the hair edge of the target object in the second transformation image.

[0076] The apparatus provided in this embodiment of the present disclosure has a different color for the main hair component in the first transformed image compared to the main hair component in the original image, but the hair texture remains essentially unchanged. That is, the textures of the main hair components in the first transformed image and the original image are essentially the same. The main hair component in the final transformed image is obtained based on the main hair component in the first transformed image. Therefore, the hair texture can be made as consistent as possible with the hair texture of the original image while the hair color in the final transformed image is changed. Furthermore, since the second transformed image is obtained by filtering the first transformed image based on the original image, the second transformed image can achieve a better edge-preserving smoothing effect, and the hair edges are also similar to the hair edges in the original image. The hair edges in the final transformed image are obtained based on the hair edges in the second transformed image. Therefore, the hair edges in the final transformed image can be made as similar as possible to the hair edges in the original image while the hair color in the final transformed image is changed, effectively avoiding the problem of potentially inaccurate hair edges in the first transformed image. In summary, in this embodiment of the present disclosure, the hair region (main hair component and hair edges) in the final transformed image can achieve a better hair color transformation effect.

[0077] In some implementations, the gradient information of the second transformed graph corresponds to the gradient information of the original graph.

[0078] In some implementations, the second transformation graph generation module 404 is specifically used to: use the original graph as the guide graph for the guided filtering algorithm, and use the guided filtering algorithm to filter the first transformation graph based on the guide graph to obtain the second transformation graph.

[0079] In some implementations, the final transformation image generation module 406 is specifically used to: obtain a hair body mask image of the target object in the first transformation image; fuse the first transformation image and the second transformation image based on the hair body mask image to obtain a third transformation image; wherein, the pixels corresponding to the hair body of the target object in the third transformation image are the pixels corresponding to the hair body of the target object in the first transformation image, and the pixels corresponding to the hair edges and non-hair regions of the target object in the third transformation image are the pixels corresponding to the hair edges and non-hair regions of the target object in the second transformation image; and fuse the third transformation image and the first transformation image to obtain the final transformation image.

[0080] In some implementations, the final transformation image generation module 406 is specifically used to: obtain the original hair mask image corresponding to the target object in the original image; and perform erosion processing on the original hair mask image to obtain the hair body mask image of the target object in the first transformation image.

[0081] In some implementations, the final transformation image generation module 406 is specifically used to: obtain a complete hair mask image of the target object in the third transformation image; and fuse the third transformation image and the first transformation image based on the complete hair mask image to obtain a final transformation image; wherein, the pixels corresponding to the complete hair of the target object in the final transformation image are the pixels corresponding to the complete hair of the target object in the third transformation image, and the pixels corresponding to the remaining areas in the final transformation image other than the complete hair are the pixels corresponding to the remaining areas in the first transformation image other than the complete hair.

[0082] In some implementations, the final transformation image generation module 406 is specifically used to: obtain the original hair mask image corresponding to the target object in the original image; and perform dilation processing on the original hair mask image to obtain the complete hair mask image of the target object in the third transformation image.

[0083] In some implementations, the first transformation image acquisition module 402 is specifically used to: input the original image into the hair color initial transformation model to obtain the first transformation image corresponding to the original image output by the hair color initial transformation model.

[0084] In some embodiments, the apparatus further includes an interface presentation module for replacing the original image with the final transformed image and presenting the final transformed image on a terminal interface.

[0085] In some embodiments, the device further includes a model training module for training a preset neural network model based on the original image and the final transformation image corresponding to the original image, and using the neural network model at the end of training as the final hair color transformation model; wherein the final hair color transformation model is used to perform hair color transformation processing on the person in the target image and output the final transformation image of the target image.

[0086] The image processing apparatus provided in this disclosure can execute the image processing method provided in any embodiment of this disclosure, and has the corresponding functional modules and beneficial effects for executing the method.

[0087] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working process of the above-described device embodiments can be referred to the corresponding process in the method embodiments, and will not be repeated here.

[0088] This disclosure provides an electronic device, which includes: a processor; a memory for storing processor-executable instructions; and a processor for reading executable instructions from the memory and executing the instructions to implement the above-described image processing method.

[0089] Figure 5This is a schematic diagram of the structure of an electronic device provided in an embodiment of this disclosure. Figure 5 As shown, the electronic device 500 includes one or more processors 501 and memory 502.

[0090] The processor 501 may be a central processing unit (CPU) or other form of processing unit with data processing capabilities and / or instruction execution capabilities, and may control other components in the electronic device 500 to perform desired functions.

[0091] The memory 502 may include one or more computer program products, which may include various forms of computer-readable storage media, such as volatile memory and / or non-volatile memory. The volatile memory may include, for example, random access memory (RAM) and / or cache memory. The non-volatile memory may include, for example, read-only memory (ROM), hard disk, flash memory, etc. One or more computer program instructions may be stored on the computer-readable storage medium, and the processor 501 may execute the program instructions to implement the image processing method of the embodiments of this disclosure described above and / or other desired functions. Various contents such as input signals, signal components, and noise components may also be stored in the computer-readable storage medium.

[0092] In one example, the electronic device 500 may also include an input device 503 and an output device 504, which are interconnected via a bus system and / or other forms of connection mechanism (not shown).

[0093] In addition, the input device 503 may also include, for example, a keyboard, a mouse, etc.

[0094] The output device 504 can output various information to the outside, including determined distance information, direction information, etc. The output device 504 may include, for example, a display, a speaker, a printer, and a communication network and its connected remote output devices, etc.

[0095] Of course, for the sake of simplicity, Figure 5 Only some of the components of the electronic device 500 relevant to this disclosure are shown, omitting components such as buses, input / output interfaces, etc. In addition, the electronic device 500 may include any other suitable components depending on the specific application.

[0096] In addition to the methods and devices described above, embodiments of this disclosure may also be computer program products, including computer program instructions that, when executed by a processor, cause the processor to perform the image processing method provided in the embodiments of this disclosure.

[0097] The computer program product can be written in any combination of one or more programming languages ​​to perform the operations of the embodiments of this disclosure. The programming languages ​​include object-oriented programming languages ​​such as Java and C++, as well as conventional procedural programming languages ​​such as C or similar languages. The program code can be executed entirely on a user's computing device, partially on a user's computing device, as a standalone software package, partially on a user's computing device and partially on a remote computing device, or entirely on a remote computing device or server.

[0098] Furthermore, embodiments of this disclosure may also be computer-readable storage media storing computer program instructions that, when executed by a processor, cause the processor to perform the image processing method provided in embodiments of this disclosure.

[0099] The computer-readable storage medium may be any combination of one or more readable media. A readable medium may be a readable signal medium or a readable storage medium. A readable storage medium may, for example, include, but is not limited to, electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatuses, or devices, or any combination thereof. More specific examples of readable storage media (a non-exhaustive list) include: electrical connections having one or more wires, portable disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.

[0100] This disclosure also provides a computer program product, including a computer program / instructions that, when executed by a processor, implement the image processing method of this disclosure.

[0101] It should be noted that, in this document, relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0102] The above description is merely a specific embodiment of this disclosure, enabling those skilled in the art to understand or implement it. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of this disclosure. Therefore, this disclosure is not to be limited to the embodiments described herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. An image processing method, characterized in that, include: Obtain the first transformed image corresponding to the original image; wherein, the first transformed image is the image after transforming the hair color of the target object in the original image; The first transformed image is filtered based on the original image to obtain a second transformed image; wherein the second transformed image is obtained by filtering the first transformed image based on specified information of the original image, the specified information including gradient information; A final transformation map is generated based on the first transformation map and the second transformation map; wherein, the main body of the hair of the target object in the final transformation map is obtained based on the main body of the hair of the target object in the first transformation map, and the hair edge of the target object in the final transformation map is obtained based on the hair edge of the target object in the second transformation map.

2. The method according to claim 1, characterized in that, The gradient information of the second transformed graph corresponds to the gradient information of the original graph.

3. The method according to claim 1 or 2, characterized in that, The step of filtering the first transformed image based on the original image to obtain the second transformed image includes: The original image is used as the guiding image for the guided filtering algorithm. The guided filtering algorithm is then used to filter the first transformed image based on the guiding image to obtain the second transformed image.

4. The method according to claim 1, characterized in that, The step of generating a final transformation graph based on the first transformation graph and the second transformation graph includes: Obtain the hair body mask of the target object in the first transformation image; The first transformation image and the second transformation image are fused based on the hair body mask image to obtain a third transformation image; wherein, the pixels corresponding to the hair body of the target object in the third transformation image are the pixels corresponding to the hair body of the target object in the first transformation image, and the pixels corresponding to the hair edge and non-hair area of ​​the target object in the third transformation image are the pixels corresponding to the hair edge and non-hair area of ​​the target object in the second transformation image. The third transformation diagram and the first transformation diagram are merged to obtain the final transformation diagram.

5. The method according to claim 4, characterized in that, The step of obtaining the hair body mask image of the target object in the first transformed image includes: Obtain the original hair mask image corresponding to the target object in the original image; The original hair mask image is subjected to erosion processing to obtain the main hair mask image of the target object in the first transformed image.

6. The method according to claim 4, characterized in that, The step of fusing the third transformation graph and the first transformation graph to obtain the final transformation graph includes: Obtain the complete hair mask image of the target object in the third transformation image; The third transformation map and the first transformation map are fused based on the complete hair mask map to obtain the final transformation map; wherein, the pixels corresponding to the complete hair of the target object in the final transformation map are the pixels corresponding to the complete hair of the target object in the third transformation map, and the pixels corresponding to the remaining areas in the final transformation map other than the complete hair are the pixels corresponding to the remaining areas in the first transformation map other than the complete hair.

7. The method according to claim 6, characterized in that, The steps for obtaining the complete hair mask image of the target object in the third transformation image include: Obtain the original hair mask image corresponding to the target object in the original image; The original hair mask image is dilated to obtain the complete hair mask image of the target object in the third transformation image.

8. The method according to claim 1, characterized in that, The steps to obtain the first transformed image corresponding to the original image include: The original image is input into the hair color initial transformation model to obtain the first transformation image corresponding to the original image output by the hair color initial transformation model.

9. The method according to claim 1, characterized in that, The method further includes: The original image is replaced with the final transformed image, and the final transformed image is displayed on the terminal interface.

10. The method according to claim 1, characterized in that, The method further includes: A preset neural network model is trained based on the original image and the corresponding final transformation image of the original image, and the neural network model at the end of training is used as the final transformation model of hair color. The hair color final transformation model is used to perform hair color transformation processing on the person in the target image and output the final transformed image of the target image.

11. An image processing apparatus, characterized in that, include: The first transformation image acquisition module is used to acquire the first transformation image corresponding to the original image; wherein, the first transformation image is an image after transforming the hair color of the target object in the original image; The second transformation graph generation module is used to filter the first transformation graph according to the original graph to obtain a second transformation graph; wherein the second transformation graph is obtained by filtering the first transformation graph according to specified information of the original graph, and the specified information includes gradient information; The final transformation image generation module is used to generate a final transformation image based on the first transformation image and the second transformation image; wherein, the main body of the hair of the target object in the final transformation image is obtained based on the main body of the hair of the target object in the first transformation image, and the hair edge of the target object in the final transformation image is obtained based on the hair edge of the target object in the second transformation image.

12. An electronic device, characterized in that, The electronic device includes: processor; Memory used to store the processor's executable instructions; The processor is configured to read the executable instructions from the memory and execute the instructions to implement the image processing method according to any one of claims 1-10.

13. A computer-readable storage medium, characterized in that, The storage medium stores a computer program for executing the image processing method according to any one of claims 1-10.

Citation Information

Patent Citations

  • Image processing method and relevant equipment

    CN108171677A

  • Special effect adding method and device, electronic equipment and storage medium

    CN112258605A