Image processing method and system and electronic equipment

By generating hair smooth mask images and performing layer fusion calculations, the hair smoothing effect of portrait photos is automatically processed, solving the problems of inefficiency and high cost in the existing technology, and achieving efficient batch processing.

CN120339127APending Publication Date: 2025-07-18HANGZHOU MUXIANG TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510403009.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-01
Publication Date
2025-07-18

AI Technical Summary

Technical Problem

In the prior art, the photo editing process of portrait photos with soft hair effect is inefficient, requires manual operation and is costly, making it difficult to achieve batch processing.

Method used

By generating hair smoothing mask images and using layer fusion calculations, we automatically process the hair smoothing effect of portrait photos, including light and shadow adjustment and hair color dodging, and use the softness ratio value to control the smoothness intensity.

Benefits of technology

It realizes automatic batch processing of hair smoothing effect on portrait photos, improves processing efficiency, reduces labor costs, and maintains high-quality processing effects.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120339127A_ABST
    Figure CN120339127A_ABST
Patent Text Reader

Abstract

The invention provides an image processing method and system and electronic equipment, and relates to the field of image processing, the method uses a hair area image in a to-be-processed portrait image to generate a corresponding hair smoothing mask image, and the adjustment of light and shadow in the hair area and the color fading of broken hair are realized through image layer fusion calculation. And the softening strength of the hair softening effect is controlled by using the softening proportion value, so that automatic batch processing of the hair softening effect of the portrait photo can be realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of image processing, and in particular, to an image processing method, system and electronic device. Background Art

[0002] Currently, in the process of processing portrait photos, the retouching of the smoothness effect of portrait hair is basically achieved through manual retouching. Hair smoothness mainly involves removing rough split ends and adjusting the hair light and shadow to be smooth and natural, making the light and shadow more beautiful. Among them, the elimination of split ends requires manual erasure of each hair strand one by one, with very low efficiency, and the effect of split end elimination cannot be guaranteed. It requires retouching personnel with high professional experience to complete, resulting in high labor costs and making it difficult to batch process the hair smoothness effect of portrait photos. Summary of the Invention

[0003] In view of this, an object of the present invention is to provide an image processing method, system and electronic device. This method uses the hair region image in the to-be-processed portrait image to generate a corresponding hair smoothness mask image, realizes the adjustment of light and shadow in the hair region and the color fading of split hair strands through layer fusion calculation, and uses the smoothness ratio value to control the smoothness intensity of the hair smoothness effect, enabling automatic batch processing of the hair smoothness effect of portrait photos, thereby solving the problem of poor processing efficiency in the prior art.

[0004] In a first aspect, an embodiment of the present invention provides an image processing method for processing the hair smoothness effect of a portrait in a digital image. The method includes:

[0005] Determine the to-be-processed portrait image as the first image, and obtain the hair region included in the first image;

[0006] After cropping the first image based on the position parameters corresponding to the hair region, obtain the second image, and obtain the mask image corresponding to the second image;

[0007] After scaling the second image and the mask image to the same size according to a preset scaling ratio, obtain the second scaled image and the mask scaled image;

[0008] Input the second scaled image and the masked scaled image into the trained hair smoothing mask generation network model, and control the hair smoothing mask generation network model to obtain the pixel fusion value corresponding to the second scaled image and the masked scaled image at the same pixel position, and determine the hair smoothing mask image corresponding to the human hair region based on the convolution result between the pixel fusion value and the inverse soft light value; wherein, the dataset used in the training of the hair smoothing mask generation network model includes multiple groups of original images of the human hair region, masked images of the human hair region, and hair smoothing mask images of the human hair region; the hair smoothing mask image of the human hair region is generated by the inverse soft light value between the original image of the human hair region and its corresponding hair smoothing reference template; the input data of the hair smoothing mask generation network model is the digital image corresponding to the human hair region and its corresponding masked image, and the output data of the hair smoothing mask generation network model is the hair smoothing mask image;

[0009] Obtain the hair smoothing mask image output by the hair smoothing mask generation network model, use the scaling ratio to perform layer fusion on the hair smoothing mask image and the second image to obtain the fused image corresponding to the hair region, and use the smoothing ratio value corresponding to the fused image to merge the fused image into the first image according to the position parameter.

[0010] Optionally, determine the first image as the portrait image to be processed, and obtain the hair region included in the first image, including:

[0011] Obtain the portrait image to be processed, and determine the digital image corresponding to the portrait image to be processed as the first image;

[0012] Determine the hair mask corresponding to the portrait image to be processed, and use the hair mask to determine the hair mask corresponding to the portrait image to be processed;

[0013] After performing region segmentation on the first image based on the hair mask, obtain the hair region included in the first image.

[0014] Optionally, crop the first image based on the position parameter corresponding to the hair region to obtain the second image, and obtain the masked image corresponding to the second image, including:

[0015] Obtain the size parameter corresponding to the digital image, and determine the extension direction of the digital image based on the size parameter;

[0016] Determine the minimum bounding rectangle of the hair region according to the extension direction, and determine the position parameter corresponding to the hair region based on the pixel position of the minimum bounding rectangle in the digital image;

[0017] Determine the image corresponding to the hair region obtained by cropping the first image using the position parameter as the second image, and use the hair mask corresponding to the second image to determine the masked image.

[0018] Optionally, the hair smoothing mask generation network model is constructed based on the Pix2Pix model, and the loss functions used in the hair smoothing mask generation network model are VGG and L2.

[0019] Optionally, the inverse soft light value is calculated through the following formula:

[0020]

[0021] where b is the inverse soft light value; a is the first pixel value corresponding to the original image of the portrait hair area; y is the second pixel value corresponding to the hair smoothing reference template.

[0022] Optionally, after layer blending the hair smoothing mask image and the second image using the scaling ratio, the fused image corresponding to the hair area is obtained, including:

[0023] Restoring the hair smoothing mask image to the same size as the second image based on the scaling ratio;

[0024] Obtaining the first layer corresponding to the hair smoothing mask image after scaling, and obtaining the second layer corresponding to the second image;

[0025] After performing layer blending calculation on the first layer and the second layer, the fused image corresponding to the hair area is obtained.

[0026] Optionally, merging the fused image into the first image according to the position parameter using the softening ratio value corresponding to the fused image, including:

[0027] Based on the pixel position of the minimum bounding rectangle corresponding to the second image, covering the fused image into the first image using the position parameter;

[0028] Obtaining the softening ratio value corresponding to the fused image, and calculating the processing result of the fused image in the first image using the first transparent layer of the fused image, the second transparent layer of the first image, and the softening ratio value.

[0029] Optionally, the processing result is calculated through the following formula:

[0030] D end = D * k+(1 - k)* S;

[0031] where D end is the processing result; k is the softening ratio value; D is the first transparent layer; S is the second transparent layer.

[0032] In a second aspect, the present invention provides an image processing system for processing the hair smoothing effect of a portrait in a digital image; the system includes:

[0033] The first processing module is used to determine the to-be-processed portrait image as the first image and obtain the hair region included in the first image;

[0034] The second processing module is used to crop the first image based on the position parameters corresponding to the hair region to obtain the second image, and obtain the mask image corresponding to the second image;

[0035] The image scaling module is used to scale the second image and the mask image to the same size according to a preset scaling ratio to obtain the second scaled image and the mask scaled image;

[0036] The compliant mask obtaining module is used to input the second scaled image and the mask scaled image into the trained hair compliant mask generation network model, control the hair compliant mask generation network model to obtain the pixel fusion value corresponding to the second scaled image and the mask scaled image at the same pixel position, and determine the hair compliant mask image corresponding to the portrait hair region based on the convolution result between the pixel fusion value and the inverse soft light value; wherein, the dataset used in the training of the hair compliant mask generation network model includes multiple groups of original images of portrait hair regions, mask images of portrait hair regions, and hair compliant mask images of portraits; the hair compliant mask image of the portrait is generated by the inverse soft light value between the original image of the portrait hair region and its corresponding hair compliant reference template; the input data of the hair compliant mask generation network model is the digital image corresponding to the portrait hair region and its corresponding mask image, and the output data of the hair compliant mask generation network model is the hair compliant mask image;

[0037] The image fusion processing module is used to obtain the hair compliant mask image output by the hair compliant mask generation network model, perform layer fusion on the hair compliant mask image and the second image by using the scaling ratio to obtain the fusion image corresponding to the hair region, and merge the fusion image into the first image according to the position parameters by using the compliant ratio value corresponding to the fusion image.

[0038] In a third aspect, an embodiment of the present invention further provides an electronic device, including a processor and a memory, the memory stores computer executable instructions that can be executed by the processor, and the processor executes the computer executable instructions to implement the steps of the image processing method provided in the first aspect.

[0039] In a fourth aspect, an embodiment of the present invention further provides a storage medium, the storage medium stores computer executable instructions, and when the computer executable instructions are called and executed by the processor, the computer executable instructions cause the processor to implement the steps of the image processing method provided in the first aspect.

[0040] An image processing method, system and electronic device provided by an embodiment of the present invention, in the process of processing the hair softening effect of a portrait photo, the method first determines the portrait image to be processed as the first image and obtains the hair region included in the first image; then crops the first image based on the position parameters corresponding to the hair region to obtain the second image, and determines the softening standard image corresponding to the second image; subsequently, scales the second image and the mask image to the same size according to a preset scaling ratio to obtain the second scaled image and the mask scaled image; then inputs the second scaled image and the mask scaled image into the trained hair softening mask generation network model, controls the hair softening mask generation network model to obtain the pixel fusion value corresponding to the second scaled image and the mask scaled image at the same pixel position, and determines the hair softening mask image corresponding to the portrait hair region based on the convolution result between the pixel fusion value and the inverse soft light value; finally, obtains the hair softening mask image output by the hair softening mask generation network model, performs layer fusion on the hair softening mask image and the second image using the scaling ratio to obtain the fusion image corresponding to the hair region, and merges the fusion image into the first image according to the position parameters using the softening ratio value corresponding to the fusion image. This method uses the hair region image in the portrait image to be processed to generate the corresponding hair softening mask image, realizes the adjustment of light and shadow in the hair region and the color reduction of broken hair through layer fusion calculation, and controls the softening intensity of the hair softening effect using the softening ratio value, and can realize the automatic batch processing of the hair softening effect of portrait photos.

[0041] Other features and advantages of the present invention will be described in the following specification, and, in part, will be obvious from the specification, or will be understood by implementing the present invention. The objectives and other advantages of the present invention are achieved and obtained by the structures specifically pointed out in the specification, claims and drawings.

[0042] To make the above objectives, features and advantages of the present invention more obvious and understandable, the following specific preferred embodiments are given, and in conjunction with the accompanying drawings, the detailed description is as follows. BRIEF DESCRIPTION OF THE DRAWINGS

[0043] In order to more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the following will briefly introduce the drawings required for use in the description of the specific embodiments or the prior art. Obviously, the following drawings are some embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.

[0044] Figure 1 It is a flowchart of an image processing method provided by an embodiment of the present invention;

[0045] Figure 2Flowchart of step S101 of an image processing method provided by an embodiment of the present invention;

[0046] Figure 3 Flowchart of step S102 of an image processing method provided by an embodiment of the present invention;

[0047] Figure 4 In step S105 of an image processing method provided by an embodiment of the present invention, flowchart of obtaining a fusion image corresponding to the hair region after layer fusion of the hair smoothing mask image and the second image using a scaling ratio;

[0048] Figure 5 In step S105 of an image processing method provided by an embodiment of the present invention, flowchart of merging the fusion image into the first image according to position parameters using the smoothing ratio value corresponding to the fusion image;

[0049] Figure 6 Flowchart of another image processing method provided by an embodiment of the present invention;

[0050] Figure 7 Schematic diagram of portrait image cropping in an image processing method provided by an embodiment of the present invention;

[0051] Figure 8 Schematic diagram of an image of a portrait dataset involved in an image processing method provided by an embodiment of the present invention;

[0052] Figure 9 Network structure diagram of a hair smoothing mask generation model used in an image processing method provided by an embodiment of the present invention;

[0053] Figure 10 Schematic diagram of the smooth hair effect of a portrait in an image processing method provided by an embodiment of the present invention;

[0054] Figure 11 Schematic diagram of an image processing system provided by an embodiment of the present invention;

[0055] Figure 12 Schematic diagram of the structure of an electronic device provided by an embodiment of the present invention.

[0056] Icon:

[0057] 1110 - First processing module; 1120 - Second processing module; 1130 - Image scaling module; 1140 - Smoothing mask acquisition module; 1150 - Image fusion processing module;

[0058] 101 - Processor; 102 - Memory; 103 - Bus; 104 - Communication interface. Detailed implementation manners

[0059] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the present invention will be clearly and completely described below in conjunction with the embodiments. Obviously, the described embodiments are some, but not all, of the embodiments of the present invention. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.

[0060] Currently, in the process of processing portrait photos, the retouching of the smooth effect of portrait hair is basically achieved through manual retouching. Hair smoothness mainly involves removing rough stray hairs and adjusting the hair light and shadow to be smooth and natural, making the light and shadow more beautiful. Among them, the elimination of stray hairs requires manual erasure of each hair strand one by one, with very low efficiency, and the effect of stray hair elimination cannot be guaranteed. It requires retouching personnel with high professional experience to complete, resulting in high labor costs and making it difficult to batch process the smooth effect of portrait hair. Based on this, the embodiments of the present invention provide an image processing method, system, and electronic device. This method uses the inverse soft light value to generate a hair smooth mask image corresponding to the hair area of the portrait image, adjusts the light and shadow in the hair area and fades the color of the fine hair strands through layer fusion calculation, and controls the smoothness intensity of the hair smooth effect using the smoothness ratio value. This method calculates the mask at a small resolution and scales and maps it to a large high-resolution image. Since the mask does not affect the original image resolution information and image content, it solves the processing effect and speed problems of large high-resolution images (above 5000*5000), facilitating batch processing and automation, and thus solving the problem of poor processing efficiency in the prior art.

[0061] To facilitate the understanding of this embodiment, first, a detailed introduction to an image processing method disclosed in the embodiments of the present invention will be given. This method is used to process the smooth effect of portrait hair in digital images, as Figure 1 shown, this method includes:

[0062] Step S101, determine the portrait image to be processed as the first image, and obtain the hair area included in the first image.

[0063] First, determine the portrait image to be processed as the first image. This image to be processed can come from various sources, such as photos taken by digital cameras, portrait pictures taken by mobile phones, or human pixel materials obtained from the Internet, etc. During the process of obtaining the hair region, relevant image segmentation techniques can be used, such as semantic segmentation methods based on deep learning, to accurately obtain the hair region contained in the first image. For example, a pre-trained convolutional neural network model can be used. This model has been trained on a large number of portrait image datasets and can identify and distinguish hair from other image elements (such as skin, clothing, background, etc.). By inputting the first image into this trained model, the model will output a result marked with the hair region, thus achieving the precise extraction of the hair region.

[0064] Step S102: Crop the first image based on the position parameters corresponding to the hair region to obtain a second image, and obtain the mask image corresponding to the second image.

[0065] During the implementation process of image cropping, the first image can be cropped based on the position parameters corresponding to the hair region to obtain a second image. The position parameters include information such as the coordinate range of the hair region in the first image (such as the upper left corner coordinates and the lower right corner coordinates). Using these parameters, an image cropping algorithm is used to crop out the hair region and an appropriate range around it, obtaining a second image focused on the hair part. The purpose of doing this is to process the hair more intensively and reduce the interference of other irrelevant regions.

[0066] After obtaining the second image, combine it with the corresponding hair region to obtain the corresponding mask image. By obtaining the pixels corresponding to the hair region and assigning them special values, such as 0; at the same time, assigning other values, such as 1, to other regions of the second image; then determining this binary image as the mask image.

[0067] Step S103: After scaling the second image and the mask image to the same size according to a preset scaling ratio, obtain a second scaled image and a mask scaled image.

[0068] The purpose of scaling the second image and the mask image to the same size is to meet the input requirements of the hair smooth mask generation network model. It is worth mentioning that the input data of the hair smooth mask generation network model is a digital image corresponding to the portrait hair region of the same size and its corresponding mask image, and the output data is the hair smooth mask image.

[0069] After scaling according to the scaling ratio to obtain the second scaled image and the mask scaled image, the amount of calculation is reduced to a certain extent, and it is also beneficial to improve the calculation process when using them to obtain the hair smooth mask image.

[0070] In step S104, input the second scaled image and the mask scaled image into the trained hair smoothing mask generation network model, and control the hair smoothing mask generation network model to obtain the pixel fusion value corresponding to the second scaled image and the mask scaled image at the same pixel position, and determine the hair smoothing mask image corresponding to the portrait hair region based on the convolution result between the pixel fusion value and the inverse soft light value.

[0071] Specifically, the dataset used in the training of the hair smoothing mask generation network model includes multiple groups of original images of the portrait hair region, mask images of the portrait hair region, and hair smoothing mask images of the portrait; the hair smoothing mask image of the portrait is generated by the inverse soft light value between the original image of the portrait hair region and its corresponding hair smoothing reference template; the input data of the hair smoothing mask generation network model is the digital image corresponding to the portrait hair region and its corresponding mask image, and the output data of the hair smoothing mask generation network model is the hair smoothing mask image.

[0072] The inverse soft light value is obtained by reverse derivation of the soft light layer blending calculation. For the original image of the portrait hair region, its corresponding hair smoothing reference template can be obtained in advance through manual retouching or other methods. The hair smoothing reference template is the hair smoothing effect image corresponding to the original image of the portrait hair region. After performing soft light calculation on the original image of the portrait hair region and the hair smoothing mask image, the hair smoothing reference template is obtained, and the inverse soft light value is obtained by performing inverse soft light calculation between the original image of the portrait hair region and the hair smoothing reference template for the hair smoothing mask image. The finally obtained hair smoothing mask image can be a grayscale image, and this grayscale image contains the grayscale details of the hair smoothing effect in the hair region. Generally speaking, there are irregular stripe patterns in the hair region of the smoothing mask image, while in the non-hair region, it is a single grayscale value.

[0073] Since the sizes of the second scaled image and the mask scaled image are the same, the above two images can be fused and calculated according to the same pixel position coordinates to obtain the corresponding pixel fusion value, which can be specifically achieved through weighted fusion and logical fusion. In weighted fusion, weights can be set for the pixel values of the second scaled image and the mask scaled image respectively, and the pixel fusion value is the sum of the products of their weights and pixel values. In the logical fusion process, if the pixel value of the mask scaled image at a certain pixel position is 0, indicating that this region is the hair region, then the pixel value of the second scaled image at this pixel position is also 0; if the pixel value of the mask scaled image at a certain pixel position is 1, indicating that this region does not belong to the hair region, then the pixel value of the second scaled image at this pixel position remains unchanged. This method simply determines the pixel fusion value according to the mask image, highlighting the pixel information of the hair region.

[0074] After obtaining the pixel fusion value, the hair smooth mask image is determined through the convolution result between the pixel fusion value and the inverse soft light value. During the convolution calculation process, the cyclic convolution method can be adopted, and combined with the relevant sampling process according to the obtained convolution result, the hair smooth mask image is finally determined.

[0075] Step S105: Obtain the hair smooth mask image output by the hair smooth mask generation network model, use the scaling ratio to perform layer fusion on the hair smooth mask image and the second image to obtain the fusion image corresponding to the hair area, and merge the fusion image into the first image according to the position parameter by using the smooth ratio value corresponding to the fusion image.

[0076] After obtaining the hair smooth mask image output by the hair smooth mask generation network model, restore the hair smooth mask image with a small resolution to the original size of the second image according to the scaling ratio in step S103 and perform layer fusion on it and the second image to obtain the corresponding fusion image. Since the hair smooth mask image will not affect the original image resolution information and image content, it has a high processing speed when processing high-resolution images.

[0077] Subsequently, use the smooth ratio value corresponding to the fusion image to merge the fusion image into the first image according to the position parameter. The smooth ratio value is a parameter determined according to the processing degree and overall effect of the fusion image, and it is used to control the intensity when the fusion image is merged into the first image. According to the previously recorded position parameter of the hair area, accurately place the fusion image back to its original position in the first image to complete the final hair smoothing effect processing.

[0078] Optionally, the step S101 of determining the portrait image to be processed as the first image and obtaining the hair area included in the first image is as Figure 2 shown and includes:

[0079] Step S201: Obtain the portrait image to be processed and determine the digital image corresponding to the portrait image to be processed as the first image.

[0080] The portrait image to be processed can be obtained through various channels. The most common way is to read it from a local storage device (such as a hard disk, SD card, etc.). These images may be taken by a professional camera, a smartphone or other image acquisition devices. In addition, portrait materials can also be downloaded from a network platform (such as a picture sharing website, a social media platform, etc.), or by cooperating with an image database provider, screening out the portrait images to be processed that meet the requirements from the massive image library provided by it.

[0081] Once the portrait image to be processed is obtained, the corresponding digital image needs to be determined as the first image. In a computer system, images are usually stored in digital form, and common image formats include JPEG, PNG, BMP, etc. Regardless of the original format of the image, it needs to be loaded into the computer's memory and converted into a format and data structure suitable for subsequent processing before processing. For example, in many image processing software and programming environments, the image is converted into a matrix form, where the elements of the matrix correspond to the pixel values of the image. In this way, the portrait image to be processed after loading and conversion is determined as the first image, preparing for subsequent processing operations.

[0082] Step S202: Determine the hair mask corresponding to the portrait image to be processed, and use the hair mask to determine the hair mask corresponding to the portrait image to be processed.

[0083] Hair usually has specific color ranges and texture features, and these characteristics can be used to determine the hair mask. First, by analyzing a large amount of portrait image data, the distribution ranges of hair colors in different color spaces (such as RGB, HSV, etc.) are statistically obtained. Then, the color space of the portrait image to be processed is converted, and according to the statistically obtained hair color range, the pixel points that may belong to the hair are screened out in the image. At the same time, combined with the texture features of the hair (such as the slender shape of the hair, parallel arrangement, etc.), texture analysis algorithms (such as gray-level co-occurrence matrix, Gabor filter, etc.) are used to further confirm whether these pixel points truly belong to the hair. In this way, the hair mask can be initially determined.

[0084] After the hair mask is determined, it is necessary to use it to generate a hair mask. The hair mask is a binary image (usually white represents the hair area and black represents the non-hair area), which more clearly identifies the position of the hair in the image. Specifically, the hair mask can be further processed, such as morphological operations (erosion, dilation, etc.) to remove noise and fill holes, making the hair mask more accurate and complete. For example, the erosion operation can remove some small noise points on the edge of the hair mask, and the dilation operation can fill small holes that may exist inside the hair area, thereby obtaining a high-quality hair mask.

[0085] Step S203: After regionally segmenting the first image based on the hair mask, obtain the hair area contained in the first image.

[0086] The principle of region segmentation of the first image based on the hair mask is to use the differences between the hair region and the non-hair region in the mask image to classify the pixel points in the first image into two categories: hair and non-hair. Since the hair mask is a binary image, its pixel values have only two states, 1 and 0 (or black and white), corresponding to the non-hair region and the hair region respectively. When performing region segmentation, the pixel points at the same positions in the first image can be classified according to the values of the pixel points in the hair mask.

[0087] In the specific implementation process, each pixel point of the hair mask image can be traversed, and according to its value (0 or 1), it is determined whether the pixel point at the corresponding position in the first image belongs to the hair region. For example, when the value of a certain pixel point in the hair mask image is 0, the pixel point at the corresponding position in the first image is marked as a pixel in the hair region; when the value is 1, it is marked as a pixel in the non-hair region. After classifying all the pixel points in the first image in this way, the hair region contained in the first image can be obtained. For the convenience of subsequent processing, the hair region can also be extracted to form an independent image data structure, which only contains the pixel information of the hair part, thereby reducing the amount of data and complexity of the processing.

[0088] Optionally, the step S102 of cropping the first image based on the position parameters corresponding to the hair region to obtain the second image and obtaining the compliant standard map corresponding to the second image is as Figure 3 shown, including:

[0089] Step S301, obtaining the size parameters corresponding to the digital image and determining the extension direction of the digital image based on the size parameters.

[0090] First, it is necessary to obtain the size parameters corresponding to the digital image to be processed (i.e., the first image). In a computer, the size of a digital image is usually represented by its width and height, and the unit is generally pixels. These information can be obtained through an image reading function or a related image processing library. For example, after reading an image using the OpenCV library, the height, width, and number of channels of the image can be obtained through the image.shape attribute, where the width and height are the size parameters we need. These size parameters are crucial for subsequent determination of the image extension direction and cropping operations.

[0091] Determine the extension direction of the digital image based on the obtained size parameters. The extension direction mainly determines whether the image extends horizontally (width greater than height) or vertically (height greater than width). It is determined by comparing the width and height values of the image. If the width is greater than the height, the extension direction of the image is horizontal; conversely, if the height is greater than the width, the extension direction is vertical. For example, for an image with a width of 800 pixels and a height of 600 pixels, its extension direction is horizontal. Determining the extension direction helps to more reasonably determine the minimum bounding rectangle of the hair region in the subsequent steps.

[0092] Step S302: Determine the minimum bounding rectangle of the hair region according to the extension direction, and determine the position parameters corresponding to the hair region based on the pixel positions corresponding to the minimum bounding rectangle in the digital image.

[0093] The minimum bounding rectangle refers to the smallest rectangle that can completely enclose a given region (here it is the hair region). In image processing, it is often used to describe the position and range of the target region. For the hair region, finding its minimum bounding rectangle can more accurately locate the hair part and provide a basis for subsequent cropping operations.

[0094] Determine the minimum bounding rectangle of the hair region according to the extension direction determined in step S301. When the extension direction of the image is horizontal, first find the minimum length in the horizontal direction that can completely contain the hair region, and at the same time determine an appropriate height in the vertical direction so that this rectangle can just enclose the hair region. Conversely, when the extension direction is vertical, first find the minimum height in the vertical direction, and then determine an appropriate width in the horizontal direction. Specifically, some geometric algorithms can be used to implement this process. For example, by traversing all the pixel points of the hair region, find the boundary points in the horizontal and vertical directions, so as to determine the four vertex coordinates of the minimum bounding rectangle.

[0095] After determining the minimum bounding rectangle of the hair region, it is necessary to determine the position parameters corresponding to the hair region based on the pixel positions corresponding to this rectangle in the digital image. The pixel positions of the minimum bounding rectangle in the digital image can be represented by the coordinates of its four vertices. By obtaining the coordinate values of these four vertices in the image coordinate system (usually with the upper left corner as the origin, the abscissa represents the horizontal direction, and the ordinate represents the vertical direction), the specific position information of the hair region in the image can be obtained.

[0096] The position parameters corresponding to the hair region mainly include the coordinates (abscissa and ordinate) of the upper left vertex of the minimum bounding rectangle and the width and height of the rectangle. These parameters completely describe the position and range of the hair region in the digital image. For example, if the coordinates of the upper left vertex of the minimum bounding rectangle are (x, y), the width is w, and the height is h, then the position parameters of the hair region can be expressed as (x, y, w, h). These position parameters will be directly used for subsequent image cropping operations.

[0097] Step S303: The image corresponding to the hair region obtained by cropping the first image using the position parameters is determined as the second image, and the mask image is determined using the hair mask corresponding to the second image.

[0098] The principle of cropping the first image using the position parameters determined in step S302 is to extract the corresponding part from the first image according to the position and range of the hair region. In image processing, the cropping operation is usually achieved by specifying the coordinate range of the image region to be retained.

[0099] In the specific implementation process, according to the position parameters (x, y, w, h) of the hair region, corresponding image processing functions or libraries can be used to crop the first image. For example, in the OpenCV library, the cv2.rectangle() function can be used to first mark the minimum bounding rectangle of the hair region, and then the cv2.getRectSubPix() function or directly through array slicing operations to extract the image part corresponding to the hair region from the first image, and this part of the image is determined as the second image. In this way, the cropping operation of the first image based on the position parameters of the hair region is completed, and the second image focusing on the hair part is obtained, providing a more suitable processing object for subsequent hair smoothing effect processing.

[0100] There are various ways to determine the mask image corresponding to the second image. For example, mask generation based on edge detection can be used. Specifically, an edge detection algorithm such as the Canny operator is used. The Canny operator first performs Gaussian filtering on the second image to reduce noise, then calculates the gradient magnitude and direction of the image, then refines the edges through non-maximum suppression, and finally uses a double-threshold algorithm to determine the final edges. The detected edge region is set to a specific value (such as 1), and the remaining regions are set to 0, thereby generating the mask image. The mask image generated in this way can highlight edge information such as the contour of the hair, which helps to focus on the hair region in subsequent processing.

[0101] Another type of method is mask generation based on semantic segmentation. Specifically, a pre-trained semantic segmentation model is utilized. This model can perform semantic understanding on the input second image and identify the hair region. The result output by the model is an image with the same size as the second image, where the pixels in the hair region are marked with a specific class value (e.g., 0), and the other regions are marked with 1. This method can obtain the mask image of the hair region more accurately, especially for the segmentation of the hair region under a complex background with good results.

[0102] Optionally, the hair smooth mask generation network model is constructed based on the Pix2Pix model, and the loss function used by the hair smooth mask generation network model is VGG and L2. Specifically, the hair smooth mask generation network model is constructed based on the Pix2Pix model. The dataset used during the training of the hair smooth mask generation network model includes multiple groups of original images of the human hair region, mask images of the human hair region, and hair smooth mask images of the human. The hair smooth mask image of the human is generated by the inverse soft light value between the original image of the human hair region and its corresponding hair smooth reference template. The input data of the hair smooth mask generation network model is the digital image corresponding to the human hair region and its corresponding mask image, and the output data of the hair smooth mask generation network model is the hair smooth mask image corresponding to the human hair region. The inverse soft light value is calculated through the following formula:

[0103]

[0104] where b is the inverse soft light value; a is the first pixel value corresponding to the original image of the human hair region; y is the second pixel value corresponding to the hair smooth reference template.

[0105] The process of obtaining the hair smooth reference template can be determined based on the type parameter corresponding to the second image. In the process of determining the hair smooth reference template corresponding to the second image according to the type parameter, a hair smooth reference template library containing various combinations of hair features can be established first. Each template in this template library has a clear type parameter label, such as a specific color range, length interval, and hairstyle category. The images in each template can be pre-generated by means of manual refinement, etc.

[0106] Then, similarity calculation is performed. The type parameters of the obtained second image are calculated for similarity with the parameters of each template in the template library. For color parameters, the Euclidean distance can be used to measure the difference between different color features; for length and hairstyle parameters, the classification distance method can be used for comparison. For example, for hairstyles, the distance for the same hairstyle category is 0, and the distance for different hairstyle categories is 1.

[0107] During the process of selecting the hair softness reference template, the template with the highest similarity can be selected as the hair softness reference template corresponding to the second image according to the result of similarity calculation. For example, if it is calculated that the color, length, and hairstyle of the second image have the highest similarity with a "medium-length straight brown hair" template in the template library, then this template is determined as the hair softness reference template for the second image.

[0108] Since the sizes of the second scaled image and the mask scaled image are the same, the above two images can be fused and calculated according to the same pixel position coordinates to obtain the corresponding pixel fusion value, which can be specifically realized through weighted fusion and logical fusion. For weighted fusion, weights can be set for the pixel values of the second scaled image and the mask scaled image respectively, and the pixel fusion value is the sum of the products of their weights and pixel values. During the logical fusion process, if the pixel value of the mask scaled image at a certain pixel position is 0, it means that this area is the hair area, then the pixel value of the second scaled image at this pixel position is also 0; if the pixel value of the mask scaled image at a certain pixel position is 1, it means that this area does not belong to the hair area, then the pixel value of the second scaled image at this pixel position remains unchanged. This method simply determines the pixel fusion value according to the mask image, highlighting the pixel information of the hair area.

[0109] After obtaining the pixel fusion value, the softening mask image is determined through the convolution result between the pixel fusion value and the inverse soft light value. During the convolution calculation process, the method of circular convolution can be used, and combined with the relevant sampling process according to the obtained convolution result, the softening mask image is finally determined. The calculation process can be implemented using relevant convolutional neural networks, which will be described in detail later.

[0110] Optionally, after layer-fusing the hair softening mask image and the second image using the scaling ratio, the fused image corresponding to the hair area is obtained, as Figure 4 shown, including:

[0111] Step S401, restore the hair softening mask image to the same size as the second image based on the scaling ratio.

[0112] In the previous steps, the second image has been scaled according to the need to match the size of the softness standard image to obtain the second scaled image, and at the same time, the mask image has also been scaled to obtain the mask scaled image and then the hair softening mask image has been determined. At this time, the size of the hair softening mask image is the same as that of the second scaled image, but may be different from the size of the original second image. Therefore, the hair softening mask image needs to be restored to the same size as the second image according to the scaling ratio used in the previous steps.

[0113] Step S402, obtain the first layer corresponding to the hair softening mask image after scaling, and obtain the second layer corresponding to the second image.

[0114] After the hair smoothing mask image is scaled, its corresponding first layer is created. Specifically, the scaled hair smoothing mask image can be imported into relevant image processing software, which will automatically take it as a new layer and mark this layer as the first layer. The first layer contains the pixel information of the hair smoothing mask image and related attributes such as transparency and blending mode.

[0115] Similarly, the second image is imported into the image processing software to create a new layer, marked as the second layer. The second layer stores the complete pixel information of the second image, including color, brightness, etc. In the layer panel, it can be seen that the first layer and the second layer are arranged in a certain order, and their order can be adjusted as needed.

[0116] Step S403: After performing layer blending calculation on the first layer and the second layer, a fused image is obtained.

[0117] According to the selected layer blending mode, the pixel values of the first layer and the second layer are calculated accordingly. For each pixel position, the fused pixel value is calculated according to the rules of the blending mode, thereby generating a fused image. During the calculation process, the transparency setting of the first layer can also be considered to further adjust the fusion effect. For example, if the transparency setting of the first layer is 50%, then during the blending calculation, the pixel values of the first layer will be blended with the pixel values of the second layer at a ratio of 50%.

[0118] Optionally, the fused image is merged into the first image according to the position parameter using the smoothing ratio value corresponding to the fused image, as Figure 5 shown, including:

[0119] Step S501: Based on the pixel positions of the minimum bounding rectangle corresponding to the second image, the fused image is covered onto the first image using the position parameter;

[0120] Step S502: Obtain the smoothing ratio value corresponding to the fused image, and calculate the processing result of the fused image in the first image using the first transparent layer of the fused image, the second transparent layer of the first image, and the smoothing ratio value.

[0121] After the fused image is obtained, it needs to be merged into the first image. Since the second image is obtained by cropping the first image, the fused image is restored and pasted back onto the first image based on the pixel positions of the minimum bounding rectangle of the second image, thereby obtaining a preliminary processing of the human hair smoothing effect.

[0122] In the actual scenario, the smoothing effect needs to be controlled, and the control process is achieved through the smoothing ratio value. The final processing result is obtained through the following formula calculation:

[0123] Dend = D * k + (1 - k) * S;

[0124] Wherein, D end is the processing result; k is the softening ratio value; D is the first transparent layer; S is the second transparent layer.

[0125] The following describes the above image processing method with a specific example. As Figure 6 shown in the flowchart of another image processing method, assuming that the user image is S and the final output effect image is D. First, the hair area is obtained after segmenting the hair from the first image S, and the mask image S_mask corresponding to the first image S is obtained. Subsequently, the hair area is cropped. By performing the minimum external rectangle detection on S_mask, the minimum bounding rectangle Rect(x, y, w, h) is obtained, where (x, y, w, h) respectively represent the coordinates of the upper left vertex of the rectangle and the width and height information of the rectangle; the minimum bounding rectangle calculation can directly call the opencv interface minAreaRect(); after cropping the original image S according to Rect, the second image S_hair is obtained, and the mask image S_hairmask corresponding to the second image S_hair is obtained.

[0126] Subsequently, S_hair and S_hairmask are scaled to a size of 512×512 to obtain the scaled images S_hair_s and S_hairmask_s, the scaling ratio coefficient Scale is recorded, and the above scaled images are input into the hair softening model HairSmoothNet to obtain the softening mask image Ds.

[0127] It is worth mentioning that the dataset used in the training process of the hair smoothing model HairSmoothNet is Set{S_hair(i), S_hairmask(i), Ds(i)}, where i = 1, 1,... 10000. Specifically, 10,000 high-definition studio portrait photos are selected, as long as there are different portrait hair regions in the photos. For each original photo S, the hair region is segmented to obtain a hair mask named S_mask; the hair region segmentation can be achieved using any one of the segmentation convolutional neural networks such as Unet / PspNet / BiSeNet, or open-source algorithms such as Segment Anything. Then, the minimum bounding rectangle of S_mask is detected to obtain the minimum bounding rectangle Rect(x, y, w, h), where (x, y, w, h) represent the coordinates of the upper left vertex of the rectangle and the width and height information of the rectangle respectively. Subsequently, the original photo S is cropped according to Rect to obtain the original hair region photo S_hair, and S_mask is cropped according to Rect to obtain the hair region mask S_hairmask corresponding to S_hair, and the hair of S_hair is manually retouched to obtain the rendered image D_tmp of smooth hair. The specific rendered image can be seen in Figure 7 .

[0128] Subsequently, the inverse soft light algorithm is calculated for D_tmp and S_hair. By traversing the RGB component values of each pixel in the image, the inverse soft light value of D_tmp(y) with respect to S_hair is calculated to obtain the mask image Ds of smooth hair. The inverse soft light calculation is derived by reverse deduction from the soft light layer blending calculation, and the calculation formula is as follows:

[0129]

[0130] In the above formula, y corresponds to D_tmp, a corresponds to S_hair, and b corresponds to the result of the inverse soft light calculation. Processing 10,000 data according to the above process finally obtains the dataset Set, and the specific rendered image is as shown in Figure 8 .

[0131] The network structure diagram of the hair smoothing mask generation model HairSmoothNet is as shown in Figure 9 . The network structure corresponding to this model is the hair smoothing mask generation network HairSmooth Net constructed based on the Pix2Pix algorithm. The network input user image is a 512×512 user hair region image S_hair + hair region Mask image S_hairmask, the output is the rendered image Ds of smooth hair, and the dataset is Set constructed in the foregoing content. Figure 12The network shown in [description] uses the Unet structure. The original images S_hair and S_hairmask are input and centralized, then the number of channels is amplified through convolution + Relu, and then max pooling for downsampling is performed after convolution + Relu. Convolution and downsampling are repeated multiple times until the bottom of the Unet. Then, multiple upsampling and convolution operations are performed correspondingly. Each layer is horizontally fused with the upsampling result of the next layer. Finally, the rendering effect diagram is output after several convolutions; the loss function of the generator uses VGG loss and L2 loss, and finally HairSmoothNet is trained.

[0132] After obtaining the smooth mask image Ds using HairSmoothNet, it is used as the smooth mask, scaled back to the size of the original image S_hair according to Scale, and then Ds and S_hair are blended in a soft light layer to obtain the rendering effect diagram D0; subsequently, D0 is restored and pasted back into the original image S according to the coordinate information of Rect(x,y,w,h) to obtain the final rendering effect diagram D.

[0133] In the actual scenario, D and S can also be alpha-blended according to the hair smoothness ratio k to control the final effect degree. The alpha-blending formula used: D end = D * k + (1 - k) * S; where D end is the final processing result of the hair smoothness; k is the smoothness ratio value; D is the first transparent layer; S is the second transparent layer. See specifically Figure 10 the schematic diagram of the smooth effect of the portrait hair shown. After the user inputs a portrait photo and selects the hair smoothness parameter k, the corresponding hair smooth mask can be generated and applied to the original image to obtain the hair smooth effect of the photo.

[0134] The above method can use the idea of the deep learning GAN network to construct a neutral gray hair smooth mask, combine soft light layer blending to achieve light and shadow adjustment in the hair area and color fading of hair fragments, and control the intensity of hair smoothness through parameters, thereby solving the problem of automatic intelligent hair smooth effect in photos. In addition, the above method calculates the mask at a small resolution and then scales and maps it to a large high-resolution image. Since the mask does not affect the original image resolution information and image content, the processing effect and speed problems of large high-resolution images (above 5000*5000) are solved, which is convenient for batch processing and automation.

[0135] Corresponding to the image processing method provided in the foregoing embodiments, an embodiment of the present invention provides an image processing system for processing the smooth effect of portrait hair in digital images, as Figure 11 shown, the system includes:

[0136] The first processing module 1110 is configured to determine the to-be-processed portrait image as a first image and obtain the hair region included in the first image;

[0137] The second processing module 1120 is configured to crop the first image based on the position parameters corresponding to the hair region to obtain a second image, and obtain a mask image corresponding to the second image;

[0138] The image scaling module 1130 is configured to scale the second image and the mask image to the same size according to a preset scaling ratio to obtain a second scaled image and a mask scaled image;

[0139] The hair smoothing mask acquisition module 1140 is configured to input the second scaled image and the mask scaled image into a trained hair smoothing mask generation network model, control the hair smoothing mask generation network model to obtain the pixel fusion value corresponding to the second scaled image and the mask scaled image at the same pixel position, and determine the hair smoothing mask image corresponding to the portrait hair region based on the convolution result between the pixel fusion value and the inverse soft light value; wherein, the dataset used in the training of the hair smoothing mask generation network model includes multiple groups of original images of portrait hair regions, mask images of portrait hair regions, and hair smoothing mask images of portraits; the hair smoothing mask image of the portrait is generated by the inverse soft light value between the original image of the portrait hair region and its corresponding hair smoothing reference template; the input data of the hair smoothing mask generation network model is the digital image corresponding to the portrait hair region and its corresponding mask image, and the output data of the hair smoothing mask generation network model is the hair smoothing mask image;

[0140] The image fusion processing module 1150 is configured to obtain the hair smoothing mask image output by the hair smoothing mask generation network model, perform layer fusion on the hair smoothing mask image and the second image using the scaling ratio to obtain a fusion image corresponding to the hair region, and merge the fusion image into the first image according to the position parameters using the smoothing ratio value corresponding to the fusion image.

[0141] As can be seen from the image processing system mentioned in the above embodiments, the system generates a corresponding smoothing mask image using the hair region image in the to-be-processed portrait image, realizes the adjustment of light and shadow in the hair region and the color fading of fine hair through layer fusion calculation, and controls the smoothing intensity of the hair smoothing effect using the smoothing ratio value, and can realize the automatic batch processing of the hair smoothing effect of portrait photos.

[0142] The image processing system provided by the embodiments of the present invention has the same implementation principle and the same technical effects as those of the foregoing image processing method embodiments. For a brief description, for the parts not mentioned in the system embodiments, reference may be made to the corresponding contents in the foregoing image processing method embodiments.

[0143] This embodiment also provides an electronic device, and the schematic structural diagram of the electronic device is as Figure 12 shown. The device includes a processor 101 and a memory 102. Among them, the memory 102 is used to store one or more computer instructions, and the one or more computer instructions are executed by the processor to implement the steps of the above image processing method.

[0144] Figure 12 The electronic device shown also includes a bus 103 and a communication interface 104, and the processor 101, the communication interface 104, and the memory 102 are connected through the bus 103.

[0145] Among them, the memory 102 may include a high-speed random access memory (RAM, Random Access Memory), and may also include a non-volatile memory, such as at least one disk memory. The bus 103 may be an ISA bus, a PCI bus, an EISA bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. For the sake of convenience of representation, Figure 12 only a bidirectional arrow is used in the figure, but it does not mean that there is only one bus or one type of bus.

[0146] The communication interface 104 is used to connect to at least one user terminal and other network units through a network interface, and send the encapsulated IPv4 packet or IPv4 packet to the user terminal through the network interface.

[0147] The processor 101 may be an integrated circuit chip with the ability to process signals. In the implementation process, each step of the above method can be completed by the integrated logic circuit of the hardware in the processor 101 or the instructions in the form of software. The above-mentioned processor 101 may be a general-purpose processor, including a central processing unit (CPU for short), a network processor (NP for short), etc.; it may also be a digital signal processor (DSP for short), an application specific integrated circuit (ASIC for short), a field-programmable gate array (FPGA for short), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components. It can implement or execute the various methods, steps and logic block diagrams disclosed in the embodiments of the present disclosure. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc. The steps of the method disclosed in combination with the embodiments of the present disclosure can be directly embodied as being executed by a hardware decoding processor, or executed by a combination of hardware and software modules in the decoding processor. The software module may be located in a mature storage medium in the art such as random access memory, flash memory, read-only memory, programmable read-only memory, or electrically erasable programmable memory, register, etc. This storage medium is located in the memory 102, and the processor 101 reads the information in the memory 102 and combines its hardware to complete the steps of the method of the foregoing embodiments.

[0148] An embodiment of the present invention further provides a storage medium, on which a computer program is stored, and when the computer program is run by a processor, it executes the steps of the image processing method in the foregoing embodiments.

[0149] In several embodiments provided in the present application, it should be understood that the disclosed systems, devices, equipment and methods can be implemented in other ways. The system embodiments described above are only illustrative. For example, the division of the units is only a logical function division, and there may be other division methods in actual implementation. For another example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Another point is that the displayed or discussed couplings or direct couplings or communication connections to each other may be through some communication interfaces, and the indirect couplings or communication connections of devices or units may be in electrical, mechanical or other forms.

[0150] The unit described as a separation component may or may not be physically separated. The component displayed as a unit may or may not be a physical unit, that is, it may be located in one place or distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0151] If the above function is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a non-volatile computer-readable storage medium executable by a processor. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art or part of this technical solution can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in various embodiments of the present invention. The foregoing storage medium includes: USB flash drives, mobile hard disks, read-only memories (ROM, Read-Only Memory), random access memories (RAM, Random Access Memory), magnetic disks, or optical disks and other various media that can store program codes.

[0152] Finally, it should be noted that the above-described embodiments are only specific embodiments of the present invention, used to illustrate the technical solutions of the present invention, rather than limiting it. The protection scope of the present invention is not limited thereto. Although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that: any person skilled in the art within the technical scope disclosed by the present invention can still modify the technical solutions described in the foregoing embodiments or easily think of changes, or perform equivalent replacements for some of the technical features; and these modifications, changes, or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be covered within the protection scope of the present invention. Therefore, the protection scope of the present invention should be subject to the protection scope of the claims.

Claims

1. An image processing method, characterized in that, The method is used to process the smooth effect of human hair in a digital image; the method includes: Determine the human image to be processed as the first image, and obtain the hair region included in the first image; After cropping the first image based on the position parameters corresponding to the hair region, obtain the second image, and obtain the mask image corresponding to the second image; After scaling the second image and the mask image to the same size according to a preset scaling ratio, obtain the second scaled image and the mask scaled image; Input the second scaled image and the mask scaled image into the trained hair smoothing mask generation network model, control the hair smoothing mask generation network model to obtain the pixel fusion value corresponding to the second scaled image and the mask scaled image at the same pixel position, and determine the hair smoothing mask image corresponding to the human hair region based on the convolution result between the pixel fusion value and the inverse soft light value; wherein, the dataset used in the training of the hair smoothing mask generation network model includes multiple groups of original images of human hair regions, mask images of human hair regions, and hair smoothing mask images of human hair; the hair smoothing mask image of human hair is generated by the inverse soft light value between the original image of the human hair region and its corresponding hair smoothing reference template; the input data of the hair smoothing mask generation network model is the digital image corresponding to the human hair region and its corresponding mask image, and the output data of the hair smoothing mask generation network model is the hair smoothing mask image; Obtain the hair smoothing mask image output by the hair smoothing mask generation network model, use the scaling ratio to perform layer fusion on the hair smoothing mask image and the second image to obtain the fusion image corresponding to the hair region, and use the smooth ratio value corresponding to the fusion image to merge the fusion image into the first image according to the position parameters.

2. The image processing method according to claim 1, wherein Determine the human image to be processed as the first image, and obtain the hair region included in the first image, including: Obtain the human image to be processed, and determine the digital image corresponding to the human image to be processed as the first image; Determine the hair mask corresponding to the human image to be processed, and use the hair mask to determine the hair mask corresponding to the human image to be processed; After performing region segmentation on the first image based on the hair mask, obtain the hair region included in the first image.

3. The image processing method according to claim 2, wherein After cropping the first image based on the position parameters corresponding to the hair region, obtain the second image, and obtain the mask image corresponding to the second image, including: Obtain the size parameters corresponding to the digital image, and determine the extension direction of the digital image based on the size parameters; Determine the minimum circumscribed rectangle of the hair region according to the extension direction, and determine the position parameters corresponding to the hair region based on the pixel positions corresponding to the minimum circumscribed rectangle in the digital image; The image corresponding to the hair region obtained by cropping the first image using the position parameter is determined as the second image, and the mask image is determined using the hair mask corresponding to the second image.

4. The image processing method according to claim 1, wherein The hair smoothing mask generation network model is constructed based on the Pix2Pix model; the loss functions used in the hair smoothing mask generation network model are VGG and L2.

5. The image processing method according to claim 1, characterized in that The inverse soft light value is calculated by the following formula: where b is the inverse soft light value; a is the first pixel value corresponding to the original image of the human portrait hair region; y is the second pixel value corresponding to the hair smoothing reference template.

6. The image processing method according to claim 3, wherein Fusing the hair smoothing mask image and the second image by layer using the scaling ratio to obtain the fused image corresponding to the hair region includes: Restoring the hair smoothing mask image to the same size as the second image based on the scaling ratio; Obtaining the first layer corresponding to the hair smoothing mask image after scaling and obtaining the second layer corresponding to the second image; Performing layer mixing calculation on the first layer and the second layer to obtain the fused image corresponding to the hair region.

7. The image processing method according to claim 6, wherein Merging the fused image into the first image according to the position parameter using the smoothing ratio value corresponding to the fused image includes: Covering the fused image into the first image using the position parameter based on the pixel position of the minimum bounding rectangle corresponding to the second image; Obtaining the smoothing ratio value corresponding to the fused image, and calculating the processing result of the fused image in the first image using the first transparent layer of the fused image, the second transparent layer of the first image, and the smoothing ratio value.

8. The image processing method according to claim 7, wherein The processing result is calculated by the following formula: D end = D * k+(1 - k)*S; Among them, D end is the processing result; k is the compliance ratio value; D is the first transparent layer; S is the second transparent layer.

9. An image processing system, characterized in that, The system is used to process the hair smoothing effect of the human portrait in the digital image; the system includes: A first processing module, configured to determine the to-be-processed human portrait image as the first image and obtain the hair region included in the first image; A second processing module, configured to crop the first image based on the position parameter corresponding to the hair region to obtain a second image, and obtain the mask image corresponding to the second image; An image scaling module, configured to scale the second image and the mask image to the same size according to a preset scaling ratio to obtain a second scaled image and a mask scaled image; A soft hair mask acquisition module, configured to input the second scaled image and the mask scaled image into a trained hair soft mask generation network model, control the hair soft mask generation network model to obtain the pixel fusion value corresponding to the second scaled image and the mask scaled image at the same pixel position, and determine the hair soft mask image corresponding to the human hair region based on the convolution result between the pixel fusion value and the inverse soft light value; wherein, the dataset used in training the hair soft mask generation network model includes multiple groups of original images of human hair regions, mask images of human hair regions, and hair soft mask images of human hair regions; the hair soft mask image of human hair regions is generated by the inverse soft light value between the original image of human hair regions and its corresponding hair soft reference template; the input data of the hair soft mask generation network model is the digital image corresponding to the human hair region and its corresponding mask image, and the output data of the hair soft mask generation network model is the hair soft mask image; An image fusion processing module, configured to obtain the hair soft mask image output by the hair soft mask generation network model, perform layer fusion on the hair soft mask image and the second image using the scaling ratio to obtain the fusion image corresponding to the hair region, and merge the fusion image into the first image according to the position parameter using the softness ratio value corresponding to the fusion image.

10. An electronic device, characterized in that, It includes a processor and a memory, the memory stores computer executable instructions that can be executed by the processor, and the processor executes the computer executable instructions to implement the steps of the image processing method according to any one of claims 1 to 8.