Image processing method and apparatus, and device and medium
By obtaining the object information and hairstyle generation model of the target object, determining the area to be processed and performing fusion processing, the problem of poor hairstyle replacement effect in existing software is solved, and realistic hairstyle replacement effects and improved user experience are achieved.
Patent Information
- Application Number
- PCT/CN2025/084436
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2024-03-25
- Filing Date
- 2025-03-24
- Publication Date
- 2025-10-02
AI Technical Summary
Existing software performs poorly in the hairstyle change function, provides a poor user experience, and is unable to reasonably and reliably determine the area to be processed, resulting in unnatural hairstyle changes.
By obtaining the object information and target hairstyle of the target object, determining the area to be processed, and using the hairstyle generation model to generate the target image, the object information and the hairstyle generation model are combined for fusion processing to ensure the rationality and realistic effect of the hairstyle replacement.
It improves the rationality and realism of hairstyle changes, enhances user experience, avoids undesirable phenomena such as hair growing on hats and hair covering the face, and ensures that the hairstyle change effect is realistic.
Smart Images

Figure CN2025084436_02102025_PF_FP_ABST
Abstract
Description
Image processing method, device, equipment and medium
[0001] CROSS-REFERENCE TO RELATED APPLICATIONS
[0002] This application claims priority to Chinese invention patent application number 202410345972.8, entitled “Image processing method, device, equipment and medium” and filed on March 25, 2024, and the entire application is incorporated herein by reference. Technical Field
[0003] The present disclosure relates to the field of computer technology, and in particular to an image processing method, apparatus, device, and medium. Background Art
[0004] The photo editing function has been widely used in various application scenarios such as image editing software, photo taking software, video live streaming platforms, etc. Users can adjust the image according to their needs, for example, change the hairstyle. Summary of the Invention
[0005] The present disclosure provides an image processing method, apparatus, device, and medium.
[0006] An embodiment of the present disclosure provides an image processing method, comprising: obtaining a first image to be processed and determining a target hairstyle required for a target object in the first image; obtaining object information of the target object and, based on the object information and the target hairstyle, determining an area to be processed corresponding to the target object; obtaining a target image based on the first image, the area to be processed, and the target hairstyle; wherein the target image is an image containing a target object having the target hairstyle.
[0007] Optionally, determining the target hairstyle required for the target object in the first image includes: upon receiving hairstyle prompt information, determining the target hairstyle required for the target object in the first image based on the hairstyle prompt information; and / or, upon triggering a target option among a plurality of preset hairstyle options, determining the target hairstyle required for the target object in the first image based on the hairstyle corresponding to the target option.
[0008] Optionally, determining the area to be processed corresponding to the target object based on the object information and the target hairstyle includes: obtaining a hair expansion mask image of the target object based on the object information and the target hairstyle, so as to identify the area to be processed corresponding to the target object through the hair expansion mask image; wherein the area to be processed is larger than the original hair area of the target object.
[0009] Optionally, obtaining a target image based on the first image, the area to be processed and the target hairstyle includes: obtaining hairstyle prompt information corresponding to the target hairstyle to obtain target prompt information based on the hairstyle prompt information; generating a second image based on the first image, the mask image corresponding to the area to be processed and the target prompt information using a hairstyle generation model corresponding to the target hairstyle; and performing fusion processing based on the mask image corresponding to the area to be processed, the first image and the second image to obtain a target image.
[0010] Optionally, obtaining target prompt information based on the hairstyle prompt information includes: adjusting the hairstyle prompt information based on the object information to obtain adjusted hairstyle prompt information; wherein the object information includes information of the original hair area of the target object and information of the hair-associated area of the target object; obtaining preset general prompt information; and obtaining target prompt information based on the adjusted hairstyle prompt information and the general prompt information.
[0011] Optionally, the object information includes the object category to which the target object belongs, and the adjusting the hairstyle prompt information based on the object information to obtain the adjusted hairstyle prompt information includes: when detecting that the hairstyle prompt information contains a target prompt word, modifying the target prompt word; wherein the object category corresponding to the target prompt word is inconsistent with the object category to which the target object belongs; and determining a supplementary prompt word based on the object information, and adding the supplementary prompt word to the hairstyle prompt information.
[0012] Optionally, the mask image corresponding to the area to be processed, the first image and the second image are fused to obtain a target image, including: correcting the second image based on the first image to obtain a corrected second image; and / or obtaining designated key point information of the target object in the first image, and correcting the target object in the second image based on the designated key point information; and fusing the mask image corresponding to the area to be processed, the first image and the corrected second image to obtain a target image.
[0013] Optionally, the mask image corresponding to the area to be processed, the first image and the corrected second image are fused to obtain a target image, including: generating a third image based on the mask image corresponding to the area to be processed, the corrected second image and the target prompt information using a hairstyle generation model corresponding to the target hairstyle; and fusing the first image and the third image based on the mask image corresponding to the area to be processed to obtain a target image.
[0014] Optionally, the target image includes a first area and a second area; wherein, the position of the first area in the target image is determined based on the position of the area to be processed in the first image, and the second area is the area in the target image other than the first area; the pixel value of the first area is determined based on the pixels corresponding to the area to be processed in the second image, and the pixel value of the second area is determined based on the pixels of the area in the first image other than the area to be processed.
[0015] An embodiment of the present disclosure also provides an image processing device, including: a target hairstyle determination module, used to obtain a first image to be processed and determine a target hairstyle required for a target object in the first image; a to-be-processed area determination module, used to obtain object information of the target object and, based on the object information and the target hairstyle, determine a to-be-processed area corresponding to the target object; a target image acquisition module, used to obtain a target image based on the first image, the to-be-processed area and the target hairstyle; wherein the target image is an image containing a target object having the target hairstyle.
[0016] An embodiment of the present disclosure also provides an electronic device, which includes: a processor; a memory for storing executable instructions of the processor; the processor is used to read the executable instructions from the memory and execute the instructions to implement the image processing method provided by the embodiment of the present disclosure.
[0017] An embodiment of the present disclosure further provides a computer-readable storage medium, wherein the storage medium stores a computer program, and the computer program is used to execute the image processing method provided by the embodiment of the present disclosure.
[0018] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present disclosure, nor are they intended to limit the scope of the present disclosure. Other features of the present disclosure will become readily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the present disclosure.
[0020] In order to more clearly illustrate the embodiments of the present disclosure or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0021] FIG1 is a schematic flow chart of an image processing method provided by an embodiment of the present disclosure;
[0022] FIG2 is a schematic diagram of a flow chart of an image processing method provided by an embodiment of the present disclosure;
[0023] FIG3 is a schematic structural diagram of an image processing device provided by an embodiment of the present disclosure;
[0024] FIG4 is a schematic structural diagram of an electronic device provided by an embodiment of the present disclosure. DETAILED DESCRIPTION
[0025] In order to more clearly understand the above-mentioned objectives, features and advantages of the present disclosure, the scheme of the present disclosure will be further described below. It should be noted that the embodiments of the present disclosure and the features therein can be combined with each other in the absence of conflict.
[0026] In the following description, many specific details are set forth to facilitate a full understanding of the present disclosure, but the present disclosure may also be implemented in other ways different from those described herein; it is obvious that the embodiments in the specification are only part of the embodiments of the present disclosure, rather than all of the embodiments.
[0027] As mentioned above, the photo editing function has been widely used. However, the inventors have found through research that there are currently few software programs that have the function of changing hairstyles. Even if some software programs provide this function, the hairstyle changing effect is not good and the user experience is poor.
[0028] The present disclosure first provides an image processing method. FIG1 is a flow chart of an image processing method provided by the present disclosure. The method can be performed by an image processing device, wherein the device can be implemented using software and / or hardware and can generally be integrated into an electronic device. As shown in FIG1 , the method mainly includes the following steps S102 to S106:
[0029] Step S102: Acquire a first image to be processed, and determine a target hairstyle required by a target object in the first image.
[0030] The first image is an image containing a target object. The disclosed embodiments do not restrict the type of target object. For example, the target object can be a person, or a doll or animal with hair. In practical applications, the first image can include only the head of the target object, or the entire body or upper body of the target object, without limitation. Furthermore, if the first image contains multiple target objects, the target objects can be all objects contained in the first image, or user-specified objects, without limitation.
[0031] When determining the target hairstyle required for the target object in the first image, the target hairstyle can be determined based on the required hairstyle information input by the user, or multiple hairstyle options can be provided to the user, and the target hairstyle can be determined based on the hairstyle selected by the user from the multiple hairstyle options. The target object in the first image can also be subjected to feature analysis, and a target hairstyle suitable for the target object can be recommended based on the feature analysis results. No restrictions are imposed here.
[0032] Step S104: acquiring object information of the target object, and determining the area to be processed corresponding to the target object based on the object information and the target hairstyle.
[0033] Object information refers to information related to the target object and can include characteristic information such as the target object's hair, as well as information about items related to the target object, such as a hat. For example, the object information includes information about the target object's original hair region and information about the target object's hair-related region. The target object's hair-related region can be an area that partially overlaps with and / or is adjacent to the hair region, such as a facial region or a target article region associated with hair. The target article region refers to the region of the target article. The target article can be specified as needed, such as a hat or other article that affects hairstyle changes. If the target object does not have the target article, the target article region is not identified, or the object information indicates that the target article region does not exist. The aforementioned region information can specifically be location information of the region. In practical applications, semantic analysis can be performed on the first image, and the object information can be presented using the semantic analysis results (such as a semantic map). In the semantic map, different regions are represented using different pixel values, while all pixels in the same region have the same pixel value. On this basis, the object information may further include the object category to which the target object belongs. The object category can be flexibly set according to needs. For example, taking the target object as a person as an example, it can be classified based on the characteristics of different people, such as facial features, etc. The classification method of the person can be flexibly set according to needs. Taking the target object as a doll as an example, it can be classified according to the type of doll (such as a humanoid doll, an animal doll with hair), etc., and there is no restriction here.
[0034] The disclosed embodiments fully consider the influence of the target object's object information on the hairstyle transformation. For example, when determining the area to be processed, the original hair area of the target object indicated by the object information, the hair-related area indicated by the object information, the object type to which the target object belongs indicated by the object information, and other object information are fully considered, and then combined with the relevant information of the target hairstyle (such as the description information of the target hairstyle), so as to reasonably and reliably determine the area to be processed, thereby ensuring the rationality of the subsequent generated image and avoiding the undesirable phenomena in the related technology, such as hair generated on the hat, generated hair covering the face, and partial hair missing.
[0035] Step S106 , obtaining a target image based on the first image, the area to be processed, and the target hairstyle; wherein the target image is an image containing a target object with the target hairstyle.
[0036] In practical applications, a hairstyle generation model corresponding to the target hairstyle can be obtained. Based on the first image, the area to be processed, and the target hairstyle, the hairstyle generation model can be used to efficiently and conveniently obtain an image of the target object having the target hairstyle. The disclosed embodiments do not limit the hairstyle generation model. For example, the hairstyle generation model can be implemented using a diffusion model. In practical applications, different hairstyles can correspond to different hairstyle generation models. Specifically, corresponding hairstyle generation models can be pre-trained for multiple hairstyles. For example, based on a general diffusion model, the diffusion model can be adjusted using LoRA technology (also known as LoRA fine-tuning technology) to obtain hairstyle generation models corresponding to various hairstyles.
[0037] The above-mentioned image processing method provided by the embodiment of the present disclosure does not directly perform a simple hairstyle transformation based on the target hairstyle, but fully considers the influence of object information on the hairstyle transformation effect, and reasonably and reliably determines the target object's to-be-processed area in combination with the object information of the target object in the first image and the target hairstyle required by the target object, thereby obtaining an image containing the target object with the target hairstyle based on the first image, and the above-mentioned method can effectively ensure the rationality of the hairstyle transformation based on the first image, thereby ensuring the hairstyle replacement effect, and can better improve the user experience.
[0038] In some embodiments, the step of determining the target hairstyle required for the target object in the first image in step S102 may be performed with reference to (1) and / or (2) below:
[0039] (1) Upon receiving the hairstyle prompt information, determining a target hairstyle for the target object in the first image based on the hairstyle prompt information. The hairstyle prompt information may be descriptive information of the desired target hairstyle input by the user, and may include one or more descriptive words, such as straight hair, black hair, long hair, smooth hair, etc., which may be set by the user as needed. Based on the hairstyle prompt information, the target hairstyle for the target object in the first image may be determined.
[0040] (2) When a target option among the preset multiple hairstyle options is triggered, a target hairstyle required for the target object in the first image is determined based on the hairstyle corresponding to the target option. In practical applications, multiple optional hairstyle options may be provided to the user in advance, such as hairstyle A, hairstyle B, hairstyle C, etc., and the hairstyle options may be annotated with relevant hairstyle description information or example images, so that the user can select the desired target hairstyle according to their needs.
[0041] In actual applications, the target hairstyle can be determined by the above (1) or (2) as needed. The above (1) and (2) can also be combined. For example, the user can first select a target option from the provided hairstyle options, and then input hairstyle prompt information as needed, so as to make personalized adjustments based on the hairstyle corresponding to the target option. In other words, the target hairstyle required by the target object in the first image can be comprehensively determined based on the hairstyle prompt information input by the user and the hairstyle corresponding to the target option triggered by the user. The above are all exemplary descriptions. The target hairstyle can be flexibly determined by selecting an appropriate method according to needs, and there is no limitation here.
[0042] To reasonably determine the area to be processed, the step of determining the area to be processed corresponding to the target object based on the object information and the target hairstyle in step S104 may specifically include: obtaining a hair dilation mask image of the target object based on the object information and the target hairstyle, thereby identifying the area to be processed corresponding to the target object using the hair dilation mask image, wherein the area to be processed is larger than the original hair area of the target object. To ensure the rationality and reliability of image processing, embodiments of the present disclosure may perform dilation processing on the original hair area based on the object information (such as information about the original hair area of the target object, information about the hair-related area of the target object, and the object category to which the target object belongs) and the target hairstyle, thereby determining an area to be processed that is larger than the original hair area. The hair dilation mask image can be used to clearly identify the area to be processed. For example, the pixel values of the to-be-processed area in the hair expansion mask image are all first values, and the pixel values of the to-be-processed area in the hair expansion mask image are all second values, and the first value is different from the second value. For example, the first value and the second value can be selected from values such as 0 and 1. This not only can clearly identify the to-be-processed area, but also makes it easier for the hairstyle generation model to perform image generation processing based on the hair expansion mask image, and also makes it easier to perform subsequent fusion processing on the first image and the model-generated image based on the hair expansion mask image.
[0043] That is, through the above method, the area to be processed can be reasonably determined by integrating information such as object information and relevant information of the target hairstyle. The area to be processed can clearly indicate the area that the hairstyle generation model needs to focus on, such as generating hair corresponding to the target hairstyle in this area, to ensure the generation effect of the hairstyle generation model; in addition, based on the area to be processed, the first image and the image (second image) output by the hairstyle generation model can be fused to further ensure the presentation effect of the final target image, such as making the difference between the final target image and the original first image mainly reflected in the different hairstyle, and the other contents of the target image except the hair-related area (that is, the area in the target image corresponding to the area to be processed) are still consistent with the first image, thereby presenting the user with a realistic image effect of only changing the hairstyle.
[0044] In order to efficiently and reliably obtain a target image with a better hairstyle change effect, in some embodiments, the above step S106, i.e., the step of obtaining the target image based on the first image, the area to be processed, and the target hairstyle, can be performed with reference to the following steps A to C:
[0045] Step A: Obtain hairstyle prompt information corresponding to the target hairstyle, and obtain target prompt information based on the hairstyle prompt information. In actual applications, the hairstyle prompt information can be directly used as the target prompt information, or the hairstyle prompt information can be adjusted or supplemented to obtain more reasonable or comprehensive target prompt information.
[0046] In step B, a second image is generated using a hairstyle generation model corresponding to the target hairstyle based on the first image, the mask corresponding to the area to be processed, and the target prompt information. The mask corresponding to the area to be processed is the aforementioned hair expansion mask. In practical applications, the hairstyle generation model corresponding to the target hairstyle can be preloaded, and the first image, the mask corresponding to the area to be processed, and the target prompt information are used as input information for the hairstyle generation model. The hairstyle generation model then generates an image based on this input information to obtain the second image.
[0047] In step C, the target image is obtained by fusing the mask image corresponding to the area to be processed, the first image, and the second image. It is understood that the second image is a new image generated by the hairstyle generation model, and that the second image may differ from the first image in areas other than the hair region. By performing step C, the resulting target image can be rendered with good quality.
[0048] Exemplarily, the target image includes a first region and a second region; wherein the position of the first region in the target image is determined based on the position of the region to be processed in the first image, which can be simply understood as the first region being the region in the target image corresponding to the region to be processed. The pixel values of the first region are determined based on the pixels corresponding to the region to be processed in the second image, and the pixels corresponding to the region to be processed in the second image are also the pixels in the region corresponding to the region to be processed in the second image. In a specific implementation, the pixel values of the first region can be consistent with the pixel values corresponding to the region to be processed in the second image. If correction or other processing is required for the second image, the pixel values of the first region can be consistent with the pixel values corresponding to the region to be processed in the corrected second image.
[0049] The second area is an area in the target image other than the first area, and the pixel value of the second area is determined based on the pixels of the area in the first image other than the area to be processed. For example, the pixel value of the second area can be consistent with the pixel value of the area in the first image other than the area to be processed.
[0050] In summary, it can be understood that the above-mentioned fusion processing method is to synthesize the corresponding area of the area to be processed in the second image (or the corrected second image) with the area in the first image other than the area to be processed to obtain the target image. It can also be simply understood as replacing the area to be processed in the first image with the corresponding area in the second image (or the corrected second image), thereby ensuring that the final target image presents only the hairstyle change effect to the user without changing other content in the first image.
[0051] The present disclosure provides some implementation examples of obtaining target prompt information based on hairstyle prompt information in step A above, which can be performed with reference to the following steps 1 and 2:
[0052] Step 1: Adjust the hairstyle prompt information based on the object information to obtain the adjusted hairstyle prompt information. The disclosed embodiment fully considers that the acquired hairstyle prompt information may not be accurate or complete. In order to ensure the reliability of the ultimately obtained prompt information, the hairstyle prompt information can be adjusted.
[0053] Considering the possibility that the hairstyle hint information input by the user may not match the target object in the first image, for example, if the object category represented by the hairstyle hint information is inconsistent with the object category of the target object, the hairstyle hint information can be modified. In some specific implementation examples, the object information includes the object category to which the target object belongs. Based on this, if the hairstyle hint information is detected to contain a target hint word, the target hint word is modified; wherein the object category corresponding to the target hint word is inconsistent with the object category to which the target object belongs. The target hint word is modified to ensure that the modified hint word is consistent with the object category to which the target object belongs. In practical applications, some descriptive words often have a corresponding relationship with object categories. For example, "beautiful" and "handsome" often describe different object categories. In practical applications, corresponding hint word libraries can be set for different object categories. If the hairstyle hint information contains a target hint word that is inconsistent with the object category to which the target object belongs, the target hint word is modified, such as by searching for a desired hint word in the hint word library corresponding to the object category to which the target object belongs and replacing the target hint word with the found hint word. The desired hint word can be a word with similar semantics to the target hint word.
[0054] In some specific implementation examples, supplementary prompt words can be determined based on the object information and added to the hairstyle prompt information. For example, the object category of the target object indicated by the object information can be directly used as the supplementary prompt word, or descriptive information related to the target object, such as the hair-related area of the target object, can be used as the supplementary prompt word. This allows the hairstyle generation model to more accurately and reasonably generate images based on the expanded hairstyle prompt information.
[0055] Step 2: Obtain target prompt information based on the adjusted hairstyle prompt information.
[0056] In some specific implementation examples, the adjusted hairstyle prompt information may be directly used as the target prompt information.
[0057] In other specific implementation examples, preset general prompt information can be obtained, and then target prompt information can be obtained based on the adjusted hairstyle prompt information and the general prompt information. In actual applications, general prompt information (i.e., general prompt words) can be pre-set. Regardless of the target hairstyle or the target object, the general prompt information can be combined with the hairstyle prompt information as the target prompt information. In other words, the general prompt information is applicable to any hairstyle or object category. In some specific implementations, the general prompt information includes positive prompt information and negative prompt information. The positive prompt information includes feature descriptors that the image is expected to have, and the negative prompt information includes feature descriptors that the image is not expected to have. For example, the positive prompt information can include prompt words such as "high quality", "clear", and "real", and the negative prompt information can include "low quality", "fuzzy", and "incomplete". The target prompt words obtained in the above manner can further ensure the image generation effect of the hairstyle generation model.
[0058] Furthermore, the embodiment of the present disclosure provides an implementation example of the above step C, that is, performing fusion processing based on the mask image corresponding to the area to be processed, the first image, and the second image to obtain a target image, which can be performed with reference to the following steps C1 and C2:
[0059] Step C1: Correct the second image based on the first image to obtain a corrected second image. Since the second image is generated by the hairstyle generation model, it may deviate from the desired image. To ensure the quality of the final target image, the present embodiment can correct the second image. For example, step C1 can be performed with reference to 1) and / or 2) below:
[0060] 1) Based on the color information of the first image, the color of the second image is corrected. Considering that there may be a certain color deviation between the second image and the first image, the color of the second image can be corrected so that the color of the corrected second image matches the color of the first image. Exemplarily, this can be achieved using an image style transfer algorithm using RGB channels. For example, the color of the second image can be corrected based on the overall mean variance of the first image.
[0061] 2) Obtain the designated key point information of the target object in the first image, and perform correction processing on the target object in the second image based on the designated key point information. The designated key point information can specify the key points to be obtained as needed, such as obtaining key points of limbs such as shoulders and hands. Considering that there may be a certain position deviation between the target object in the second image output by the model and the target object in the first image, by using the designated key point information to correct the target object in the second image, it is possible to effectively ensure the consistency of the facial features and other parts of the target object in the corrected second image with those in the first image, thereby avoiding undesirable problems such as facial deformation.
[0062] In actual applications, the above 1), 2), or a combination of 1) and 2) can be flexibly selected to correct and optimize the second image. It should be noted that the above is only an exemplary correction processing method. In actual applications, other correction processing methods can also be used, such as correcting the eyes and eyebrows of the second image based on the eyes, eyebrows and other areas in the first image. It can be simply understood as pasting the eyes and eyebrows in the first image back to the second image, thereby ensuring that the eyes and eyebrows in the second image are completely consistent with the first image.
[0063] Step C2: performing fusion processing based on the mask image corresponding to the area to be processed, the first image and the corrected second image to obtain a target image.
[0064] In some implementation examples, the first image and the corrected second image can be directly fused based on the mask image corresponding to the area to be processed to obtain a target image. The specific fusion processing method can refer to the aforementioned related content and will not be repeated here.
[0065] In order to further improve the generation effect of the target image, in some specific implementation examples, step C2 can be performed with reference to the following steps C2.1 and C2.2:
[0066] In step C2.1, a third image is generated using the hairstyle generation model corresponding to the target hairstyle based on the mask image corresponding to the area to be processed, the corrected second image, and the target prompt information. Specifically, the hairstyle generation model corresponding to the target hairstyle can be used again to generate a third image based on the mask image corresponding to the area to be processed, the corrected second image, and the target prompt information. The third image is typically superior to the corrected second image and can effectively repair flaws in the corrected second image. In practical applications, the hairstyle generation model required to generate the second image and the hairstyle generation model required to generate the third image can be the same model, but with different control parameters (such as step size and control strength). This operation can further enhance the image generation performance of the model.
[0067] In step C2.2, the first and third images are fused based on the mask corresponding to the unprocessed region to produce a target image. For example, the unprocessed region in the first image is replaced with the corresponding region in the third image. This ensures that the resulting target image presents only the hairstyle change effect to the user, without altering other content in the first image.
[0068] Based on the above, the embodiment of the present disclosure provides a flowchart of an image processing method as shown in FIG2 , which mainly includes the following steps S202 to S216:
[0069] Step S202: obtaining a first image to be processed and obtaining hairstyle prompt information.
[0070] Step S204: determining a target hairstyle required for the target object in the first image based on the hairstyle prompt information.
[0071] Step S206: semantically analyze the first image to obtain object information of the target object based on the semantic analysis result. The object information may include the original hair area of the target object, information about the hair-related area of the target object, and the object category to which the target object belongs.
[0072] Step S208: Acquire a hair expansion mask image of the target object based on the object information and the target hairstyle.
[0073] In step S210, target prompt information is obtained based on the object information and the hairstyle prompt information, and a second image is generated based on the first image, the dilated mask image, and the target prompt information using a hairstyle generation model corresponding to the target hairstyle.
[0074] Step S212, performing correction processing on the second image based on the first image to obtain a corrected second image;
[0075] Step S214 , based on the mask image corresponding to the area to be processed, the corrected second image, and the target prompt information, a hairstyle generation model corresponding to the target hairstyle is used to generate a third image.
[0076] Step S216 , based on the mask image corresponding to the area to be processed, the first image and the third image are fused to obtain a target image.
[0077] The specific implementation methods of the above steps can refer to the aforementioned related content and will not be repeated here. Through the above method, the rationality of the hairstyle change based on the first image can be effectively guaranteed, and the hairstyle replacement effect of the final target image can be fully guaranteed, so that the target image presents a realistic effect of only changing the hairstyle, which can better improve the user experience.
[0078] Corresponding to the aforementioned image processing method, FIG3 is a schematic structural diagram of an image processing device provided by an embodiment of the present disclosure. The device can be implemented by software and / or hardware and can generally be integrated into an electronic device. As shown in FIG3 , the image processing device includes:
[0079] A target hairstyle determination module 302 is configured to obtain a first image to be processed and determine a target hairstyle required for a target object in the first image;
[0080] The to-be-processed area determination module 304 is configured to obtain object information of the target object and determine the to-be-processed area corresponding to the target object based on the object information and the target hairstyle;
[0081] The target image obtaining module 306 is configured to obtain a target image based on the first image, the area to be processed, and the target hairstyle; wherein the target image is an image containing a target object with a target hairstyle.
[0082] The above-mentioned image processing device provided by the embodiment of the present disclosure does not directly perform a simple hairstyle change based on the target hairstyle, but fully considers the influence of object information on the hairstyle change effect, and reasonably and reliably determines the target object's to-be-processed area in combination with the object information of the target object in the first image and the target hairstyle required by the target object, thereby obtaining an image containing the target object with the target hairstyle based on the first image, the to-be-processed area and the target hairstyle. The above-mentioned method can effectively ensure the rationality of the hairstyle change based on the first image, thereby ensuring the hairstyle replacement effect, and can better improve the user experience.
[0083] In some embodiments, the target hairstyle determination module 302 is specifically used to: determine the target hairstyle required for the target object in the first image based on the hairstyle prompt information when hairstyle prompt information is received; and / or determine the target hairstyle required for the target object in the first image based on the hairstyle corresponding to the target option when a target option among multiple preset hairstyle options is triggered.
[0084] In some embodiments, the module 304 for determining the area to be processed is specifically configured to obtain a hair expansion mask image of the target object based on the object information and the target hairstyle, so as to identify the area to be processed corresponding to the target object through the hair expansion mask image; wherein the area to be processed is larger than the original hair area of the target object.
[0085] In some embodiments, the target image acquisition module 306 is specifically used to: obtain hairstyle prompt information corresponding to the target hairstyle, so as to obtain target prompt information based on the hairstyle prompt information; generate a second image based on the first image, the mask image corresponding to the area to be processed, and the target prompt information using the hairstyle generation model corresponding to the target hairstyle; and perform fusion processing based on the mask image corresponding to the area to be processed, the first image, and the second image to obtain a target image.
[0086] In some embodiments, the target image acquisition module 306 is specifically used to: adjust the hairstyle prompt information based on the object information to obtain adjusted hairstyle prompt information, wherein the object information includes information about the original hair area of the target object and information about the hair-related area of the target object; obtain preset general prompt information; and obtain target prompt information based on the adjusted hairstyle prompt information and the general prompt information.
[0087] In some embodiments, the object information includes the object category to which the target object belongs, and the target image acquisition module 306 is specifically used to: modify the target prompt word when it is detected that the hairstyle prompt information contains a target prompt word; wherein the object category corresponding to the target prompt word is inconsistent with the object category to which the target object belongs; determine a supplementary prompt word based on the object information, and add the supplementary prompt word to the hairstyle prompt information.
[0088] In some embodiments, the target image acquisition module 306 is specifically used to: correct the color of the second image based on the color information of the first image; and / or obtain the specified key point information of the target object in the first image, and correct the target object in the second image based on the specified key point information; perform fusion processing based on the mask image corresponding to the area to be processed, the first image and the corrected second image to obtain the target image.
[0089] In some embodiments, the target image acquisition module 306 is specifically used to: generate a third image based on the mask image corresponding to the area to be processed, the corrected second image and the target prompt information, using the hairstyle generation model corresponding to the target hairstyle; and fuse the first image and the third image based on the mask image corresponding to the area to be processed to obtain the target image.
[0090] In some embodiments, the target image includes a first area and a second area; wherein the position of the first area in the target image is determined based on the position of the area to be processed in the first image, and the second area is the area in the target image other than the first area; the pixel value of the first area is determined based on the pixel corresponding to the area to be processed in the second image, and the pixel value of the second area is determined based on the pixel of the area in the first image other than the area to be processed.
[0091] The image processing device provided by the embodiments of the present disclosure can execute the image processing method provided by any embodiment of the present disclosure, and has the corresponding functional modules and beneficial effects of the execution method.
[0092] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the above-described device embodiment can refer to the corresponding process in the method embodiment, and will not be repeated here.
[0093] An embodiment of the present disclosure provides an electronic device, which includes: a storage device storing a computer program; and a processing device configured to execute the computer program in the storage device to implement the steps of any one of the methods in the present disclosure.
[0094] Reference is now made to FIG4 , which illustrates a schematic diagram of the structure of an electronic device 400 suitable for implementing embodiments of the present disclosure. Terminal devices in embodiments of the present disclosure may include, but are not limited to, mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), in-vehicle terminals (e.g., in-vehicle navigation terminals), and fixed terminals such as digital TVs and desktop computers. The electronic device illustrated in FIG4 is merely an example and should not limit the functionality or scope of use of embodiments of the present disclosure.
[0095] As shown in Figure 4, electronic device 400 may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 401, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 402 or a program loaded from a storage device 408 into a random access memory (RAM) 403. Various programs and data required for the operation of electronic device 400 are also stored in RAM 403. Processing device 401, ROM 402, and RAM 403 are connected to each other via a bus 404. An input / output (I / O) interface 405 is also connected to bus 404.
[0096] Typically, the following devices may be connected to the I / O interface 405: an input device 406 including, for example, a touch screen, a touchpad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 407 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 408 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 409. The communication device 409 may allow the electronic device 400 to communicate with other devices wirelessly or by wire to exchange data. Although FIG4 shows the electronic device 400 with various devices, it should be understood that not all of the devices shown are required to be implemented or present. More or fewer devices may alternatively be implemented or present.
[0097] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a non-transitory computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication device 409, or installed from the storage device 408, or installed from the ROM 402. When the computer program is executed by the processing device 401, the above-mentioned functions defined in the method of the embodiment of the present disclosure are performed.
[0098] In addition to the above-mentioned methods and devices, the embodiments of the present disclosure may also be a computer program product, which includes computer program instructions, which, when executed by a processor, cause the processor to perform the image processing method provided by the embodiments of the present disclosure. The computer program product may be written in any combination of one or more programming languages to write program codes for performing the operations of the embodiments of the present disclosure, the programming languages including object-oriented programming languages such as Java, C++, etc., and also conventional procedural programming languages such as "C" language or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as a separate software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server.
[0099] In addition, the embodiment of the present disclosure may also be a computer-readable storage medium having computer program instructions stored thereon. When the computer program instructions are executed by a processor, the processor is enabled to execute the image processing method provided by the embodiment of the present disclosure.
[0100] The computer-readable storage medium can adopt any combination of one or more readable media. The readable medium can be a readable signal medium or a readable storage medium. The readable storage medium can, for example, include but is not limited to a system, device or component of electricity, magnetism, light, electromagnetic, infrared, or semiconductor, or any combination thereof. More specific examples (non-exhaustive list) of readable storage media include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof.
[0101] The embodiment of the present disclosure further provides a computer program product, including a computer program / instruction, which implements the image processing method in the embodiment of the present disclosure when executed by a processor.
[0102] It is understandable that before using the technical solutions disclosed in the various embodiments of this disclosure, the type, scope of use, usage scenarios, etc. of the personal information involved in this disclosure should be informed to the user and the user's authorization should be obtained in an appropriate manner in accordance with relevant laws and regulations.
[0103] For example, in response to a user's active request, a prompt message is sent to the user to clearly inform the user that the operation requested will require the acquisition and use of the user's personal information. This allows the user to independently choose whether to provide personal information to the electronic device, application, server, storage medium, or other software or hardware that performs the operations of the disclosed technical solution based on the prompt message.
[0104] As an optional but non-limiting implementation, in response to receiving a user's active request, the prompt information may be sent to the user in the form of a pop-up window, in which the prompt information may be presented in text form. Furthermore, the pop-up window may also contain a selection control for the user to select "agree" or "disagree" to provide personal information to the electronic device.
[0105] It is understandable that the above notification and user authorization process are merely illustrative and do not constitute a limitation on the implementation of the present disclosure. Other methods that comply with relevant laws and regulations may also be applied to the implementation of the present disclosure.
[0106] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of other identical elements in the process, method, article, or device comprising the element.
[0107] The foregoing description is intended only to provide specific embodiments of the present disclosure, intended to enable those skilled in the art to understand and implement the present disclosure. 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 the present disclosure. Therefore, the present disclosure is not intended to be limited to the embodiments described herein, but rather to be construed in the broadest manner consistent with the principles and novel features disclosed herein.
Claims
1. An image processing method, wherein the method comprises: Acquire a first image to be processed, and determine a target hairstyle required for a target object in the first image; Acquiring object information of the target object, and determining a to-be-processed area corresponding to the target object based on the object information and the target hairstyle; A target image is obtained based on the first image, the area to be processed, and the target hairstyle; wherein the target image is an image containing a target object having the target hairstyle.
2. The method according to claim 1, wherein determining a target hairstyle required for the target object in the first image comprises: Upon receiving the hairstyle prompt information, determining a target hairstyle required for the target object in the first image based on the hairstyle prompt information; and / or, When a target option among the preset multiple hairstyle options is triggered, a target hairstyle required for the target object in the first image is determined based on the hairstyle corresponding to the target option.
3. The method according to claim 1, wherein determining the area to be processed corresponding to the target object based on the object information and the target hairstyle comprises: Based on the object information and the target hairstyle, a hair expansion mask image of the target object is obtained, so as to identify a to-be-processed area corresponding to the target object through the hair expansion mask image; wherein the to-be-processed area is larger than an original hair area of the target object.
4. The method according to claim 1, wherein obtaining a target image based on the first image, the area to be processed, and the target hairstyle comprises: Acquiring hairstyle prompt information corresponding to the target hairstyle, so as to obtain target prompt information based on the hairstyle prompt information; generating a second image based on the first image, the mask image corresponding to the area to be processed, and the target prompt information, and utilizing a hairstyle generation model corresponding to the target hairstyle; A target image is obtained by performing fusion processing based on the mask image corresponding to the area to be processed, the first image, and the second image.
5. The method according to claim 4, wherein obtaining target prompt information based on the hairstyle prompt information comprises: Adjusting the hairstyle prompt information based on the object information to obtain adjusted hairstyle prompt information, wherein the object information includes information about the original hair area of the target object and information about the hair-related area of the target object; Get the preset general prompt information; Target prompt information is obtained based on the adjusted hairstyle prompt information and the general prompt information.
6. The method according to claim 5, wherein the object information includes an object category to which the target object belongs, and adjusting the hairstyle prompt information based on the object information to obtain the adjusted hairstyle prompt information comprises: When detecting that the hairstyle prompt information includes a target prompt word, modifying the target prompt word; wherein the object category corresponding to the target prompt word is inconsistent with the object category to which the target object belongs; A supplementary prompt word is determined based on the object information, and the supplementary prompt word is added to the hairstyle prompt information.
7. The method according to claim 4, wherein the step of fusing the mask image corresponding to the area to be processed, the first image, and the second image to obtain a target image comprises: performing color correction processing on the second image based on color information of the first image; and / or, obtaining designated key point information of the target object in the first image, and performing correction processing on the target object in the second image based on the designated key point information; A target image is obtained by performing fusion processing based on the mask image corresponding to the area to be processed, the first image and the corrected second image.
8. The method according to claim 7, wherein the step of fusing the mask image corresponding to the area to be processed, the first image, and the corrected second image to obtain a target image comprises: Generate a third image based on the mask image corresponding to the area to be processed, the corrected second image, and the target prompt information, using a hairstyle generation model corresponding to the target hairstyle; Based on the mask image corresponding to the area to be processed, the first image and the third image are fused to obtain a target image.
9. The method according to claim 4, wherein the target image includes a first area and a second area; wherein The position of the first region in the target image is determined based on the position of the to-be-processed region in the first image, and the second region is a region in the target image excluding the first region; The pixel values of the first area are determined based on pixels corresponding to the area to be processed in the second image, and the pixel values of the second area are determined based on pixels of an area other than the area to be processed in the first image.
10. An image processing device, wherein the device comprises: a target hairstyle determination module, configured to acquire a first image to be processed and determine a target hairstyle required for a target object in the first image; a module for determining an area to be processed, configured to obtain object information of the target object and determine an area to be processed corresponding to the target object based on the object information and the target hairstyle; The target image acquisition module is configured to obtain a target image based on the first image, the area to be processed, and the target hairstyle; wherein the target image is an image containing a target object having the target hairstyle.
11. An electronic device, wherein the electronic device comprises: a storage device having a computer program stored thereon; A processing device, configured to execute the computer program in the storage device to implement the steps of the image processing method according to any one of claims 1 to 9.
12. A computer-readable storage medium, wherein the storage medium stores a computer program, wherein the computer program is used to execute the image processing method according to any one of claims 1 to 9.
Citation Information
Patent Citations
Method and device for changing hair style of character, equipment and storage medium
CN112819921A
Special effect display method and device, electronic equipment and storage medium
CN114881845A
Special effect graph generation method and device, equipment and storage medium
CN115063335A
Image processing method and device and electronic equipment
CN116229054A