Image processing method, device, mobile terminal and storage medium

Preprocessing of masks through face detection and image segmentation network extraction, the missed detection and missed detection caused by lighting changes and posture complexity in ID photo processing is solved, and efficient and reliable ID photo generation is achieved.

CN112669197BActive Publication Date: 2024-11-29SF TECH CO LTD +1
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
CN201910983237.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2019-10-16
Publication Date
2024-11-29
Estimated Expiration
2039-10-16

AI Technical Summary

Technical Problem

When processing document photos, the prior art is affected by changes in ambient light, complex posture, and occlusion factors, missed and missed inspections, low efficiency and poor effect of manual photo editing, making it difficult to achieve robust automated processing.

Method used

Portraits and skin masks are extracted through face detection and image segmentation networks, pre-processing and color adjustments are performed, and ID photos that meet the requirements are generated.

Benefits of technology

It improves the efficiency and reliability of image processing, reduces manual review costs, and the generated ID photos are effective, adapting to different lighting conditions and people.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112669197B_ABST
    Figure CN112669197B_ABST
Patent Text Reader

Abstract

The embodiment of the present application discloses an image processing method, device, mobile terminal and storage medium. The embodiment of the present application can obtain an image to be processed, perform face detection on the image, and obtain a face area; when the face area meets the preset compliance condition, extract a portrait area mask and a skin area mask from the image; extract a target area that meets the preset ratio from the image; pre-process the skin area in the target area according to the skin area mask, and perform color adjustment on the non-portrait area in the target area according to the portrait area mask to obtain a target image. Not only can compliance detection be performed on the face area in the image, but also the skin area in the target area can be pre-processed and the non-portrait area can be color adjusted based on the portrait area mask and the skin area mask, so as to obtain a target image that meets the requirements, thereby improving the efficiency and reliability of image processing.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer vision technology, and in particular to an image processing method, device, mobile terminal and storage medium. Background Art

[0002] With the continuous development of Internet technology, many examination registration websites, visa processing agencies, corporate internal management platforms and other personnel registration systems require submission of personal ID photos. The ID photo sizes and background colors required by different platforms are often different. Usually, users need to pay for professional photographers to take photos and process them multiple times. At the same time, platform managers need to take the trouble to check whether the ID photos uploaded by users are compliant. For complex scenes, factors such as drastic changes in ambient lighting, diverse and complex human postures, and face occlusion by glasses or hair are prone to missed detections and false detections, and the performance is not robust enough. Alternatively, the face area is manually cut out from the picture through the photo editing software Photoshop, and then the face area is placed in a suitable background layer. The face edge obtained by manual cutout is relatively rough and inefficient. Under different lighting conditions or for people with specific skin colors, manual tedious adjustments are required, the synthesis effect is poor, and the reliability is low. Summary of the invention

[0003] The embodiments of the present application provide an image processing method, device, mobile terminal and storage medium, which can improve the efficiency and reliability of image processing.

[0004] In a first aspect, an embodiment of the present application provides an image processing method, comprising:

[0005] Acquire an image to be processed, perform face detection on the image, and obtain a face region;

[0006] When the face area meets a preset compliance condition, extracting a portrait area mask and a skin area mask from the image;

[0007] Extracting a target area that meets a preset ratio from the image;

[0008] The skin area in the target area is preprocessed according to the skin area mask, and the non-portrait area in the target area is color adjusted according to the portrait area mask to obtain a target image.

[0009] In some embodiments, preprocessing the skin area in the target area according to the skin area mask, and color-adjusting the non-portrait area in the target area according to the portrait area mask to obtain the target image includes:

[0010] Performing a beautification operation on the skin area in the ID photo area according to the skin area mask to obtain a beautified foreground area;

[0011] Replacing the non-portrait area in the ID photo area with a preset color according to the portrait area mask to obtain a replaced background area;

[0012] The foreground area and the background area are fused to obtain a target image.

[0013] In some embodiments, performing a beautification operation on the skin area in the ID photo area according to the skin area mask to obtain a beautified foreground area includes:

[0014] Extracting a skin area from the ID photo area according to the skin area mask;

[0015] Performing skin resurfacing processing on the skin area by using a bilateral filtering algorithm to obtain a skin area after skin resurfacing;

[0016] The skin area after the skin grinding is whitened by a three-dimensional table lookup method to obtain a foreground area after beautification.

[0017] In some implementations, before extracting the portrait region mask and the skin region mask from the image, the method further includes:

[0018] Detecting the number, area, clarity, exposure and posture of faces in the face area;

[0019] When the number of faces, face area, clarity, exposure and face posture in the face area all meet the conditions, it is determined that the face area meets the preset compliance conditions.

[0020] In some implementations, detecting the clarity within the face region includes:

[0021] Converting the face region into a grayscale image, and performing a convolution operation on the grayscale image and a preset Laplace kernel to obtain a response image;

[0022] The variance of the response image is calculated, and when the variance is greater than a preset threshold, it is determined that the clarity in the face region meets a condition.

[0023] In some implementations, detecting the exposure level in the face region includes:

[0024] Counting the ratio of pixels in the face region that are smaller than a first pixel threshold to the total pixels in the face region to obtain a first ratio value;

[0025] Counting the ratio of pixels in the face area that are greater than a second pixel threshold to the total pixels in the face area to obtain a second ratio value, and the first pixel threshold is less than the second pixel threshold;

[0026] When the first ratio value is less than a first preset value, and the second ratio value is less than a second preset value, it is determined that the exposure in the face area meets a condition, and the first preset value is less than the second preset value.

[0027] In some implementations, detecting a facial gesture within the facial region includes:

[0028] The angle between the straight line where the two eyes are located and the horizontal line in the face region is calculated, and when the angle is less than a preset angle, it is determined that the face posture in the face region meets the condition.

[0029] In some implementations, performing face detection on the image to obtain a face region includes:

[0030] Performing size normalization processing on the image to obtain a size-normalized image;

[0031] Performing face detection on the size-normalized image using a convolutional neural network face detector;

[0032] When a human face is detected, a face region of a preset size is extracted from the size-normalized image with the human face as the center.

[0033] In some implementations, extracting a portrait region mask and a skin region mask from the image includes:

[0034] Obtaining the mean and standard deviation of pixels in the image;

[0035] Performing pixel normalization processing on the image according to the mean and the standard deviation to obtain a pixel-normalized image;

[0036] The pixel-normalized image is segmented by an image segmentation network to obtain a portrait area mask and a skin area mask.

[0037] In some embodiments, the segmenting process of the pixel-normalized image through an image segmentation network to obtain a portrait area mask and a skin area mask includes:

[0038] Extracting local features of the pixel-normalized image through an initial network module of an image segmentation network to obtain a first feature image;

[0039] Extracting shared features from the first feature image through a shared feature module of an image segmentation network to obtain a second feature image;

[0040] Extracting portrait features and skin features from the second feature image through a branch task module of an image segmentation network to obtain a portrait feature image and a skin feature image;

[0041] Through the integrated module of the image segmentation network, a portrait region mask and a skin region mask are extracted based on the second feature image, the portrait feature image and the skin feature image.

[0042] In some implementations, extracting a target area that meets a preset ratio from the image includes:

[0043] Acquire a portrait frame according to the portrait area mask;

[0044] Obtain a face detection frame, and calculate the height of the face according to the face detection frame;

[0045] Determine the region boundary according to the portrait frame, the face detection frame and the height of the face;

[0046] A target area conforming to a preset ratio is extracted from the image according to the area boundary.

[0047] In a second aspect, an embodiment of the present application further provides an image processing device, including:

[0048] The first detection module is used to obtain an image to be processed, perform face detection on the image, and obtain a face area;

[0049] A mask extraction module, configured to extract a portrait area mask and a skin area mask from the image when the face area meets a preset compliance condition;

[0050] A region extraction module, used to extract a target region that meets a preset ratio from the image;

[0051] The processing module is used to pre-process the skin area in the target area according to the skin area mask, and to perform color adjustment on the non-portrait area in the target area according to the portrait area mask to obtain a target image.

[0052] In some embodiments, the processing module includes:

[0053] A beautification submodule, configured to perform a beautification operation on the skin area in the ID photo area according to the skin area mask to obtain a beautified foreground area;

[0054] A replacement submodule, used to replace the non-portrait area in the ID photo area with a preset color according to the portrait area mask to obtain a replaced background area;

[0055] The fusion submodule is used to fuse the foreground area and the background area to obtain a target image.

[0056] In some implementations, the beauty submodule is specifically used for:

[0057] Extracting a skin area from the ID photo area according to the skin area mask;

[0058] Performing skin resurfacing processing on the skin area by using a bilateral filtering algorithm to obtain a skin area after skin resurfacing;

[0059] The skin area after the skin grinding is whitened by a three-dimensional table lookup method to obtain a foreground area after beautification.

[0060] In some implementations, the image processing apparatus further includes:

[0061] A second detection module is used to detect the number of faces, face area, clarity, exposure and face posture in the face area;

[0062] The determination module is used to determine whether the face area meets the preset compliance condition when the number of faces, face area, clarity, exposure and face posture in the face area all meet the conditions.

[0063] In some embodiments, the second detection module is specifically used to:

[0064] Converting the face region into a grayscale image, and performing a convolution operation on the grayscale image and a preset Laplace kernel to obtain a response image;

[0065] The variance of the response image is calculated, and when the variance is greater than a preset threshold, it is determined that the clarity in the face region meets a condition.

[0066] In some embodiments, the second detection module is specifically used to:

[0067] Counting the ratio of pixels in the face region that are smaller than a first pixel threshold to the total pixels in the face region to obtain a first ratio value;

[0068] Counting the ratio of pixels in the face area that are greater than a second pixel threshold to the total pixels in the face area to obtain a second ratio value, and the first pixel threshold is less than the second pixel threshold;

[0069] When the first ratio value is less than a first preset value, and the second ratio value is less than a second preset value, it is determined that the exposure in the face area meets a condition, and the first preset value is less than the second preset value.

[0070] In some embodiments, the second detection module is specifically used to:

[0071] The angle between the straight line where the two eyes are located and the horizontal line in the face region is calculated, and when the angle is less than a preset angle, it is determined that the face posture in the face region meets the condition.

[0072] In some embodiments, the first detection module is specifically used to:

[0073] Performing size normalization processing on the image to obtain a size-normalized image;

[0074] Performing face detection on the size-normalized image using a convolutional neural network face detector;

[0075] When a human face is detected, a face region of a preset size is extracted from the size-normalized image with the human face as the center.

[0076] In some implementations, the mask extraction module includes:

[0077] An acquisition submodule, used to acquire the mean and standard deviation of pixels in the image;

[0078] A processing submodule, used for performing pixel normalization processing on the image according to the mean and the standard deviation to obtain a pixel-normalized image;

[0079] The segmentation submodule is used to perform segmentation processing on the pixel-normalized image through an image segmentation network to obtain a portrait area mask and a skin area mask.

[0080] In some embodiments, the segmentation submodule is specifically used to:

[0081] Extracting local features of the pixel-normalized image through an initial network module of an image segmentation network to obtain a first feature image;

[0082] Extracting shared features from the first feature image through a shared feature module of an image segmentation network to obtain a second feature image;

[0083] Extracting portrait features and skin features from the second feature image through a branch task module of an image segmentation network to obtain a portrait feature image and a skin feature image;

[0084] Through the integrated module of the image segmentation network, a portrait region mask and a skin region mask are extracted based on the second feature image, the portrait feature image and the skin feature image.

[0085] In some implementations, the region extraction module is specifically used to:

[0086] Acquire a portrait frame according to the portrait area mask;

[0087] Obtain a face detection frame, and calculate the height of the face according to the face detection frame;

[0088] Determine the region boundary according to the portrait frame, the face detection frame and the height of the face;

[0089] A target area conforming to a preset ratio is extracted from the image according to the area boundary.

[0090] In a third aspect, an embodiment of the present application further provides a mobile terminal, comprising a memory and a processor, wherein the memory stores a computer program, and when the processor calls the computer program in the memory, it executes any image processing method provided in the embodiment of the present application.

[0091] In a fourth aspect, an embodiment of the present application further provides a storage medium, wherein the storage medium is used to store a computer program, and the computer program is loaded by a processor to execute any image processing method provided in the embodiment of the present application.

[0092] The embodiment of the present application can obtain an image to be processed, perform face detection on the image, and obtain a face area; when the face area meets the preset compliance conditions, extract a portrait area mask and a skin area mask from the image, and extract a target area that meets the preset ratio from the image; then the skin area in the target area can be preprocessed according to the skin area mask, and the non-portrait area in the target area can be color adjusted according to the portrait area mask to obtain a target image. This solution can not only perform compliance detection on the face area extracted from the image, but also preprocess the skin area in the target area based on the extracted portrait area mask and skin area mask, and adjust the color of the non-portrait area, so as to obtain a target image that meets the requirements (such as an ID photo image), without the need for reshooting costs and manual compliance review costs, and avoids manual photo editing, and has a good synthesis effect, thereby improving the efficiency and reliability of image processing. BRIEF DESCRIPTION OF THE DRAWINGS

[0093] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.

[0094] Figure 1 is a flowchart of an image processing method provided in an embodiment of the present application;

[0095] Figure 2 is another flowchart of the image processing method provided by an embodiment of the present application;

[0096] Figure 3 is a schematic diagram of image processing provided by an embodiment of the present application;

[0097] Figure 4 is another schematic diagram of image processing provided by an embodiment of the present application;

[0098] Figure 5 is a schematic diagram of a visualization interface for image processing provided in an embodiment of the present application;

[0099] Figure 6 is a structural schematic diagram of an image processing device provided in an embodiment of the present application;

[0100] Figure 7 It is a structural diagram of a mobile terminal provided in an embodiment of the present application. DETAILED DESCRIPTION

[0101] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of this application.

[0102] See also Figure 1 , Figure 1 : is a flowchart of an image processing method provided by an embodiment of the present application. The execution subject of the image processing method may be an image processing device provided by an embodiment of the present application, or a mobile terminal integrated with the image processing device, wherein the image processing device may be implemented in hardware or software, and the mobile terminal may be a smart phone, a tablet computer, a PDA, or a laptop computer, etc. The image processing method may include:

[0103] S101, obtaining an image to be processed, performing face detection on the image, and obtaining a face region.

[0104] The image to be processed may be an image obtained by photographing the user, or an image downloaded from a server, and the image may include the user or other objects. After the image is obtained, face detection may be performed on the image.

[0105] In some embodiments, performing face detection on an image to obtain a face area may include: performing size normalization on the image to obtain a size-normalized image; performing face detection on the size-normalized image using a face detector based on a convolutional neural network; and when a face is detected, extracting a face area of ​​a preset size from the size-normalized image with the face as the center.

[0106] Specifically, in order to improve the accuracy of face detection, faces can be detected by convolutional neural networks, and in order to improve the efficiency and accuracy of face detection by convolutional neural networks, the image can be first size normalized, that is, the size of the image can be corrected. For example, in order to maintain the ratio between the length and width of the image, when one side of the image is h and the other side is w, the image can be normalized to: one side (e.g., the long side) is 256 pixels, and the other side (e.g., the short side) is 256*(min(h, w) / max(h, w)), so that a size-normalized image can be obtained.

[0107] After obtaining the size-normalized image, the face detector of the convolutional neural network (MTCNN, Multi-task Cascaded Convolutional Networks) can be used to perform face detection on the size-normalized image. Among them, MTCNN can include three cascaded subnetworks: (1) Proposal subnetwork P-Net (Proposal Network), which can be used to generate some candidate frames; (2) Refine subnetwork R-Net (Refine Network), which can be used to remove a large number of non-face frames from the candidate frames generated by P-Net to obtain face frames; (3) Output subnetwork O-Net (Output Network), which can be used to determine the final candidate area (i.e., face area) and facial feature information from the face frames screened by R-Net. The feature information may include eyes or mouth, etc., so as to be used for subsequent calculation of face posture. In addition, in order to speed up the detection speed, the grouped convolution Depthwise in the hybrid network ShuffleNet can be used to replace the traditional convolution layer in MTCNN. The three stages of the three cascaded sub-networks detect faces from coarse to fine, using a feature pyramid to resolve multi-scale faces.

[0108] It should be noted that the MTCNN is pre-trained based on training sample images. For example, multiple training sample images containing faces and the real face area marked in each training sample image can be obtained. Each training sample image is input into the MTCNN respectively. The face area in the training sample image is calculated by MTCNN to obtain the predicted face area, and the loss function is constructed. The real face area and the predicted face area can be converged through the preset loss function. By adjusting the parameters of MTCNN to appropriate values, the loss is low and the gradient no longer decreases, and the error between the real face area and the predicted face area is reduced until the real face area is close to the predicted face area, that is, the loss function is as close to zero as possible, and the trained MTCNN can be obtained. The trained MTCNN can detect faces in any image and obtain the face area.

[0109] During the process of detecting faces, when no face is detected, the trained MTCNN can output prompt information related to the undetected face. When a face is detected, a face area of ​​a preset size is extracted from the size-normalized image with the face as the center. The preset size can be flexibly set according to actual needs, and the specific content is not limited here. For example, a quadrilateral face area B1 (l1, t1, r1, b1) can be extracted from the size-normalized image, where (l1, t1) is the coordinate of the upper left vertex of the face area, and (r1, b1) is the coordinate of the lower right vertex of the face area. The shape of the face area can be flexibly set according to actual needs. For example, the face area can be rectangular, square or circular.

[0110] S102: When the face area meets a preset compliance condition, extract a portrait area mask and a skin area mask from the image.

[0111] In order to avoid subsequent manual compliance detection, after obtaining the face area, it can be determined whether the face area meets the preset compliance conditions, thereby realizing automatic compliance detection of the face area. The preset compliance conditions can be flexibly set according to actual needs.

[0112] In some embodiments, before extracting the portrait area mask and the skin area mask from the image, the image processing method may further include: detecting the number of faces, face area, clarity, exposure and face posture in the face area; when the number of faces, face area, clarity, exposure and face posture in the face area all meet the conditions, determining that the face area meets the preset compliance conditions.

[0113] Specifically, for example, Figure 2 As shown in the figure, after obtaining the face region, the number of faces, face area, clarity, exposure and face posture in the face region can be tested in many aspects, that is, the number of faces, the face area, the clarity, the exposure, the face posture, etc. can be counted, so as to evaluate the face quality. When the number of faces, face area, clarity, exposure and face posture in the face region all meet the conditions, it is determined that the face region meets the preset compliance conditions; when one of the number of faces, face area, clarity, exposure and face posture in the face region does not meet the conditions, detailed information that does not meet the conditions can be output.

[0114] It should be noted that in addition to the above-mentioned detection methods, one or more of the number of faces, face area, clarity, exposure and face posture in the face area can also be detected. When one or more of the number of faces, face area, clarity, exposure and face posture meet the conditions, it can be determined that the face area meets the preset compliance conditions. Otherwise, detailed information that does not meet the conditions can be output.

[0115] In some embodiments, detecting the number of faces in a face area may include: counting the number of faces in the face area, when the number of faces is 1, determining that the number of faces in the face area meets a condition, and when the number of faces is greater than 1, determining that the number of faces in the face area does not meet the condition.

[0116] In some embodiments, when the face region is a rectangular region, detecting the face area in the face region may include: obtaining the length and width of the face region, calculating the face area according to the length and width, and then determining whether the face area is greater than a preset area threshold, the preset area threshold can be flexibly set according to actual needs, and the specific value is not limited here. When the face area is greater than the preset area threshold, it is determined that the face area in the face region meets the condition, and when the face area is less than or equal to the preset area threshold, it is determined that the face area in the face region does not meet the condition.

[0117] In some embodiments, when the face region is a circular region, detecting the face area in the face region may include: obtaining the diameter or radius of the face region, calculating the face area according to the diameter or radius, and then determining whether the face area is greater than a preset area threshold, the preset area threshold can be flexibly set according to actual needs, and the specific value is not limited here. When the face area is greater than the preset area threshold, it is determined that the face area in the face region meets the condition, and when the face area is less than or equal to the preset area threshold, it is determined that the face area in the face region does not meet the condition.

[0118] In some embodiments, detecting the clarity in the face area may include: converting the face area into a grayscale image, convolving the grayscale image with a preset Laplace kernel to obtain a response image; calculating the variance of the response image, and when the variance is greater than a preset threshold, determining that the clarity in the face area meets a condition.

[0119] For example, in order to improve the accuracy and effect of the subsequent generation of the target image, the clarity of the face area can be determined in advance to screen out the face area with higher clarity for processing. First, the face area can be converted from the three primary colors (RGB, Red Green Blue) image to a grayscale image. Then the grayscale image is Laplace transformed (Laplacian Transform), for example, the grayscale image can be convolved with a preset Laplace kernel to obtain a response image, wherein the preset Laplace kernel can be flexibly set according to actual needs, for example, the preset Laplace kernel can be a 3*3 Laplace kernel.

[0120] At this time, the variance of the response image can be calculated to determine whether the variance is greater than a preset threshold. When the variance is greater than the preset threshold, it is determined that the clarity in the face area meets the condition. When the variance is less than or equal to the preset threshold, it is determined that the clarity in the face area does not meet the condition. The preset threshold can be flexibly set according to actual needs. For example, the preset threshold can be set to 100. If the variance is greater than or equal to the preset threshold, it means that the face area is clearer, and if the variance is less than the preset threshold, it means that the face area is fuzzy. Therefore, it is necessary to remove the fuzzy face area with a variance less than the preset threshold.

[0121] In some embodiments, detecting the exposure level in the face area may include: counting the proportion of pixels in the face area that are less than a first pixel threshold to the total pixels in the face area to obtain a first proportion value; counting the proportion of pixels in the face area that are greater than a second pixel threshold to the total pixels in the face area to obtain a second proportion value, and the first pixel threshold is less than the second pixel threshold; when the first proportion value is less than a first preset value, and the second proportion value is less than a second preset value, it is determined that the exposure level in the face area meets the condition, and the first preset value is less than the second preset value.

[0122] For example, the ratio of pixels in the face area that are smaller than a first pixel threshold to the total pixels in the face area can be counted to obtain a first ratio value, and the first pixel threshold can be flexibly set according to actual needs. For example, the first pixel threshold can be set to 0 to 30, and pixels smaller than the first pixel threshold can be called extremely low pixel values. Also, the ratio of pixels in the face area that are larger than a second pixel threshold to the total pixels in the face area can be counted to obtain a second ratio value, and the second pixel threshold can be flexibly set according to actual needs. For example, the second pixel threshold can be set to 220 to 255, and pixels larger than the second pixel threshold can be called extremely high pixel values. Then, determine whether the first ratio value is less than the first preset value, and determine whether the second ratio value is less than the second preset value, wherein the first preset value and the second preset value can be flexibly set according to actual needs. For example, when the first ratio value is less than 40% and the second ratio value is less than 60%, it is determined that the exposure in the face area meets the conditions; when the first ratio value is greater than or equal to 40%, it means that the face area is exposed, and it is determined that the exposure in the face area does not meet the conditions; or when the second ratio value is greater than or equal to 60%, it means that the face area is low light, and it is determined that the exposure in the face area does not meet the conditions.

[0123] In some embodiments, detecting the facial posture in the face area may include: calculating the angle between the straight line where the two eyes are located in the face area and the horizontal line, and when the angle is less than a preset angle, determining that the facial posture in the face area meets the condition.

[0124] For example, the positions of the two eyes in the face region can be detected, and the straight line where the two eyes are located can be determined based on the positions of the two eyes. For example, the line connecting the center points of the two eyes is the straight line where the two eyes are located, and the angle between the straight line where the two eyes are located and the horizontal line in the face region is calculated. The horizontal line can be the horizontal axis that crosses the face. For example, the horizontal line can divide the mouth into the upper lip and the lower lip. For example, if the center point of the left eye is p1(x1, y1) and the center point of the right eye is p2(x2, y2), then the angle between the straight line where the two eyes are located and the horizontal line is tan -1 (|y2-y1| / |x2-x1|). Then, it is determined whether the angle is less than a preset angle. The preset angle can be flexibly set according to actual needs. For example, the preset angle can be set to 15 degrees. When the angle is less than the preset angle, it means that the face is frontal, and the face posture in the face area meets the condition; when the angle is greater than or equal to the preset angle, it means that the face is profile, and the face posture in the face area does not meet the condition.

[0125] When the face area does not meet the preset compliance conditions, relevant information about the non-compliance of the face area is output, for example, the face area is not clear or the face posture is not standard. When the face area meets the preset compliance conditions, the portrait area mask and the skin area mask can be extracted from the image, for example, Figure 2 As shown, the portrait area mask and the skin area mask can be extracted from the image through the image segmentation network.

[0126] In some embodiments, extracting a portrait area mask and a skin area mask from an image may include: obtaining the mean and standard deviation of pixels in the image; performing pixel normalization processing on the image according to the mean and standard deviation to obtain a pixel normalized image; and performing segmentation processing on the pixel normalized image through an image segmentation network to obtain a portrait area mask and a skin area mask.

[0127] In order to improve the efficiency and reliability of image processing by the image segmentation network, the image can be pixel-normalized in advance. For example, the mean and standard deviation of the pixels in the image can be obtained, and the image can be pixel-normalized according to the mean and standard deviation: pixel-normalized pixel value = ((pixel value in the image - mean) / standard deviation), so that a pixel-normalized image can be obtained. At this time, the pixel-normalized image can be input into the image segmentation network, and the pixel-normalized image is segmented by the image segmentation network to obtain a portrait area mask (portrait mask, p) and a skin area mask (skin mask, s).

[0128] In some implementations, performing segmentation processing on the pixel-normalized image through an image segmentation network to obtain a portrait region mask and a skin region mask may include:

[0129] The local features of the pixel-normalized image are extracted through the initial network module of the image segmentation network to obtain a first feature image; the shared features of the first feature image are extracted through the shared feature module of the image segmentation network to obtain a second feature image; the portrait features and skin features of the second feature image are extracted through the branch task module of the image segmentation network to obtain a portrait feature image and a skin feature image; the portrait region mask and the skin region mask are extracted based on the second feature image, the portrait feature image and the skin feature image through the integrated module of the image segmentation network.

[0130] The image segmentation network is a pre-trained image segmentation network, which is a multi-task based image segmentation network. The image segmentation network may include four parts: an initial network module, a shared features module, a factored module, and an aggregation module. Specifically, the strong prior information that the skin area must be in the portrait area is incorporated into the image segmentation network design, and a multi-task image segmentation network is used. The segmentation submodules in each module of the image segmentation network adopt an encoder and a decoder structure, for example, Figure 3 As shown in the figure, the initial network module is used to learn shallow local features in the image (including edges and textures, etc.), the shared feature module is used to learn the features shared by the two segmentation tasks, such as portrait region segmentation and skin region segmentation (including human region features), the branch task module is used to learn the features of the portrait segmentation task (including portrait region features), and the integration module is used to fuse the learned portrait region features to learn the skin region, and finally obtain the portrait region mask and the skin region mask. It should be noted that Figure 3 In order to protect the user's privacy, the facial features in the input image have been masked.

[0131] In order to improve the accuracy of image segmentation network detection, the image segmentation network can be trained: multiple training sample images containing human faces can be obtained, and the real portrait area mask and the real skin area mask corresponding to each training sample image can be obtained, each training sample image is input into the image segmentation network respectively, and the predicted portrait area mask and the predicted skin area mask in the training sample image are calculated by the image segmentation network, and a first loss function and a second loss function are constructed, and the real portrait area mask and the predicted portrait area mask can be converged through the first loss function, and the real skin area mask and the predicted skin area mask can be converged. The skin area mask converges through the second loss function, and the parameters of the image segmentation network are adjusted to appropriate values ​​so that the loss is low and the gradient no longer decreases, thereby reducing the error between the real portrait area mask and the predicted portrait area mask until the real portrait area mask is close to the predicted portrait area mask, and reducing the error between the real skin area mask and the predicted skin area mask until the real skin area mask is close to the predicted skin area mask. In this way, the trained image segmentation network can be obtained, so that the portrait area mask and the skin area mask can be extracted from the image subsequently through the trained image segmentation network.

[0132] For example, Figure 3In the process of extracting the portrait region mask and the skin region mask, first, the local features of the pixel-normalized image are extracted through the initial network module of the image segmentation network to obtain a first feature image. The local features are shallow local features, and the local features may include features such as edges and textures. Then, the shared features of the first feature image may be extracted through the shared feature module of the image segmentation network to obtain a second feature image, and the shared features may include human region features. Secondly, the portrait features and skin features of the second feature image are extracted through the branch task module of the image segmentation network to obtain a portrait feature image and a skin feature image. Finally, the portrait region mask and the skin region mask may be extracted based on the second feature image, the portrait feature image and the skin feature image through the integrated module of the image segmentation network.

[0133] S103: extracting a target area that meets a preset ratio from the image.

[0134] The preset ratio can be flexibly set according to actual needs. The target area can be an area larger than the face area. For example, the target area can include the area from the head to the chest of the portrait. Figure 2 The ID photo area in .

[0135] In some embodiments, extracting a target area that meets a preset ratio from an image may include: obtaining a portrait frame based on a portrait area mask; obtaining a face detection frame, and calculating the height of the face based on the face detection frame; determining a region boundary based on the portrait frame, the face detection frame, and the height of the face; and extracting a target area that meets the preset ratio from the image based on the region boundary.

[0136] For example, Figure 4 As shown, the portrait frame B2 (l2, t2, r2, b2) and the face detection frame B1 (l1, t1, r1, b1) can be obtained according to the portrait area mask p, and the height of the face h = (b1-t2) can be calculated according to the face detection frame. The region boundary is determined according to the portrait frame, the face detection frame and the height of the face; the target region that meets the preset ratio is extracted from the image according to the region boundary, that is, the ID Photo Area. For example, the upper boundary of the target region is t2, the lower boundary of the target region is min (b1+h, b2), the left boundary of the target region is l2, and the right boundary of the target region is r2. It should be noted that Figure 4 In order to protect the user's privacy, the facial features in the input image have been masked.

[0137] S104, preprocessing the skin area in the target area according to the skin area mask, and color-adjusting the non-portrait area in the target area according to the portrait area mask to obtain a target image.

[0138] After obtaining the target area, the skin area in the target area can be pre-processed by beautification, and the background area (i.e., non-portrait area) can be color adjusted. Figure 2 Foreground portrait beautification and background color replacement in order to obtain the target image with the desired background color.

[0139] In some embodiments, the skin area in the target area is preprocessed according to the skin area mask, and the color of the non-portrait area in the target area is adjusted according to the portrait area mask to obtain the target image, which may include: beautifying the skin area in the ID photo area according to the skin area mask to obtain the beautified foreground area; replacing the non-portrait area in the ID photo area with a preset color according to the portrait area mask to obtain the replaced background area; and fusing the foreground area and the background area to obtain the target image.

[0140] Specifically, Figure 4 As shown, the skin area in the ID photo area can be determined according to the skin area mask, and the skin area can be beautified to obtain the foreground area after beautification (i.e., the skin area after beautification). The beautification operation can include skin smoothing and whitening. Also, the non-portrait area in the ID photo area can be determined according to the portrait area mask, and the non-portrait area can be replaced with a preset color to obtain the replaced background area. The preset color can be flexibly set according to actual needs. For example, the preset color can be white, blue, or red. At this time, the foreground area and the background area can be fused to obtain a target image. The target image can be an ID photo image. For example, the foreground area A and the background area B can be added: (1-alpha)*A+alpha*B. The value of alpha can be flexibly set according to actual needs.

[0141] In some embodiments, a skin area within the ID photo area is beautified according to a skin area mask to obtain a foreground area after beautification, which may include: extracting the skin area from the ID photo area according to the skin area mask; performing a skin resurfacing process on the skin area through a bilateral filtering algorithm to obtain a skin resurfacing area; and performing a whitening process on the skin resurfacing area through a three-dimensional table lookup method to obtain a foreground area after beautification.

[0142] For example, in the process of skin beautification (Portrait Make-up), the skin area can be extracted from the ID photo area according to the skin area mask, and then the skin area can be smoothed by the bilateral filtering algorithm to obtain the skin area after smoothing. The parameters of the bilateral filtering algorithm can be flexibly set according to actual needs. For example, the bilateral filtering algorithm can be a nonlinear filter, which can achieve the effect of keeping the edge of the skin area and reducing noise and smoothing. Finally, the skin area after smoothing can be whitened by a three-dimensional lookup table method (3d-LUT, Look-UpTable) to obtain the foreground area after beauty. The three-dimensional lookup table method can be flexibly set according to actual needs. For example, the three-dimensional lookup table method can be a mapping relationship between the RGB pixels before whitening and the RGB pixels after whitening, and the RGB pixel value of the skin area after skin smoothing can be obtained. The corresponding R1G1B1 pixel value after transformation is found by the three-dimensional lookup table method, that is, the pixels in the foreground area after beauty are R1G1B1 pixel values.

[0143] In this embodiment, MTCNN can be used to perform face detection on the image to obtain the face area, and then the face area in the image is checked for compliance such as the number of faces, face area, clarity, exposure, and face posture. If the compliance conditions are met, the image segmentation network is used to obtain the portrait area mask and the skin area mask. Based on the portrait area mask and the skin area mask, the ID photo area that meets the proportion is extracted, and the skin in the ID photo area is beautified to obtain an ID photo image that meets the requirements.

[0144] The following will take the automatically generated ID card photo (photo is an image) as an example to explain in detail. Figure 5 As shown, an application (or mini-program) that implements the image processing of this embodiment can be installed on a mobile terminal, the application (or mini-program) can be opened, and the visual interface of the ID photo can be entered, in which relevant information can be entered. For example, an image can be uploaded in the area for uploading the ID photo in the ID photo collection interface, and a work badge photo can be automatically generated based on the photo requirements and the selected background color of green. The photo requirements can also be modified accordingly according to actual needs, so that only the image taken by the mobile terminal needs to be uploaded to automatically generate an ID photo that meets the requirements, without the need to go to a special shooting location for shooting. This can not only greatly save personal time, but also reduce the cost of manual compliance review. It has good robustness and real-time performance, can detect complex faces in a timely manner, and can generate the required ID photos quickly. In addition, the skin area is beautified naturally, and the skin area mask limits the skin area, and will not make the non-skin area blurred or overexposed. It should be noted that Figure 5In order to protect the user's privacy, the facial features in the input image have been masked. Figure 5 In addition to the layout in , it can also be flexibly set according to actual needs, and the specific content is not limited here.

[0145] The embodiment of the present application can obtain an image to be processed, perform face detection on the image, and obtain a face area; when the face area meets the preset compliance conditions, extract a portrait area mask and a skin area mask from the image, and extract a target area that meets the preset ratio from the image; then the skin area in the target area can be preprocessed according to the skin area mask, and the non-portrait area in the target area can be color adjusted according to the portrait area mask to obtain a target image. This solution can not only perform compliance detection on the face area extracted from the image, but also preprocess the skin area in the target area based on the extracted portrait area mask and skin area mask, and adjust the color of the non-portrait area, so as to obtain a target image that meets the requirements (such as an ID photo image), without the need for reshooting costs and manual compliance review costs, and avoids manual photo editing, and has a good synthesis effect, thereby improving the efficiency and reliability of image processing.

[0146] In order to better implement the image processing method provided in the embodiment of the present application, the embodiment of the present application also provides a device based on the above image processing method. The meanings of the terms are the same as those in the above image processing method, and the specific implementation details can refer to the description in the method embodiment.

[0147] See also Figure 6 , Figure 6 This is a schematic diagram of the structure of an image processing device provided in an embodiment of the present application, wherein the image processing device 300 may include a first detection module 301, a mask extraction module 302, a region extraction module 303 and a processing module 304, etc.

[0148] The first detection module 301 is used to obtain an image to be processed, perform face detection on the image, and obtain a face region.

[0149] The mask extraction module 302 is used to extract a portrait area mask and a skin area mask from the image when the face area meets a preset compliance condition.

[0150] The region extraction module 303 is used to extract a target region that meets a preset ratio from the image.

[0151] The processing module 304 is used to pre-process the skin area in the target area according to the skin area mask, and to perform color adjustment on the non-portrait area in the target area according to the portrait area mask to obtain a target image.

[0152] In some implementations, the processing module 304 may include a beautification submodule, a replacement submodule, and a fusion submodule, etc., which may be specifically as follows:

[0153] A beautification submodule is used to perform a beautification operation on the skin area in the ID photo according to the skin area mask to obtain a foreground area after beautification;

[0154] A replacement submodule, used to replace the non-portrait area in the ID photo area with a preset color according to the portrait area mask to obtain a replaced background area;

[0155] The fusion submodule is used to fuse the foreground area and the background area to obtain the target image.

[0156] In some embodiments, the beautification submodule is specifically used to: extract a skin area from the ID photo area according to a skin area mask; perform skin resurfacing processing on the skin area through a bilateral filtering algorithm to obtain a skin area after resurfacing; perform whitening processing on the skin area after resurfacing through a three-dimensional table lookup method to obtain a foreground area after beautification.

[0157] In some implementations, the image processing device may further include a second detection module and a determination module, etc., which may be specifically as follows:

[0158] The second detection module is used to detect the number of faces, face area, clarity, exposure and face posture in the face area;

[0159] The determination module is used to determine whether the face area meets the preset compliance conditions when the number of faces, face area, clarity, exposure and face posture in the face area all meet the conditions.

[0160] In some embodiments, the second detection module is specifically used to: convert the face area into a grayscale image, convolve the grayscale image with a preset Laplace kernel to obtain a response image; calculate the variance of the response image, and when the variance is greater than a preset threshold, determine that the clarity within the face area meets the conditions.

[0161] In some embodiments, the second detection module is specifically used to: count the proportion of pixels in the face area that are smaller than a first pixel threshold to the total pixels in the face area to obtain a first proportion value; count the proportion of pixels in the face area that are larger than a second pixel threshold to the total pixels in the face area to obtain a second proportion value, and the first pixel threshold is smaller than the second pixel threshold; when the first proportion value is smaller than a first preset value, and the second proportion value is smaller than a second preset value, it is determined that the exposure in the face area meets the condition, and the first preset value is smaller than the second preset value.

[0162] In some embodiments, the second detection module is specifically used to: calculate the angle between the straight line where the two eyes are located in the face area and the horizontal line, and when the angle is less than a preset angle, determine that the face posture in the face area meets the condition.

[0163] In some embodiments, the first detection module 301 is specifically used to: perform size normalization on the image to obtain a size-normalized image; perform face detection on the size-normalized image using a face detector based on a convolutional neural network; when a face is detected, extract a face area of ​​a preset size from the size-normalized image with the face as the center.

[0164] In some implementations, the mask extraction module 302 may include an acquisition submodule, a processing submodule, and a segmentation submodule, etc., which may be specifically as follows:

[0165] The acquisition submodule is used to obtain the mean and standard deviation of pixels in the image;

[0166] A processing submodule, used for performing pixel normalization processing on the image according to the mean and standard deviation to obtain a pixel normalized image;

[0167] The segmentation submodule is used to segment the pixel-normalized image through an image segmentation network to obtain a portrait area mask and a skin area mask.

[0168] In some embodiments, the segmentation submodule is specifically used to: extract local features of the pixel-normalized image through the initial network module of the image segmentation network to obtain a first feature image; extract shared features of the first feature image through the shared feature module of the image segmentation network to obtain a second feature image; extract portrait features and skin features of the second feature image through the branch task module of the image segmentation network to obtain a portrait feature image and a skin feature image; extract a portrait area mask and a skin area mask based on the second feature image, the portrait feature image and the skin feature image through the integration module of the image segmentation network.

[0169] In some embodiments, the region extraction module is specifically used to: obtain a portrait frame based on a portrait region mask; obtain a face detection frame, and calculate the height of the face based on the face detection frame; determine the region boundary based on the portrait frame, the face detection frame and the height of the face; and extract a target region that meets a preset ratio from the image based on the region boundary.

[0170] The specific implementation of the above operations can be found in the previous embodiments, which will not be described in detail here.

[0171] The embodiment of the present application can obtain an image to be processed, perform face detection on the image, and obtain a face area; when the face area meets the preset compliance conditions, extract a portrait area mask and a skin area mask from the image, and extract a target area that meets the preset ratio from the image; then the skin area in the target area can be preprocessed according to the skin area mask, and the non-portrait area in the target area can be color adjusted according to the portrait area mask to obtain a target image. This solution can not only perform compliance detection on the face area extracted from the image, but also preprocess the skin area in the target area based on the extracted portrait area mask and skin area mask, and adjust the color of the non-portrait area, so as to obtain a target image that meets the requirements (such as an ID photo image), without the need for reshooting costs and manual compliance review costs, and avoids manual photo editing, and has a good synthesis effect, thereby improving the efficiency and reliability of image processing.

[0172] Accordingly, an embodiment of the present invention further provides a mobile terminal, such as Figure 7 As shown, the mobile terminal may include a radio frequency (RF) circuit 601, a memory 602 including one or more computer-readable storage media, an input unit 603, a display unit 604, a sensor 605, an audio circuit 606, a wireless fidelity (WiFi) module 607, a processor 608 including one or more processing cores, and a power supply 609. Those skilled in the art will appreciate that Figure 7 The mobile terminal structure shown in the figure does not constitute a limitation on the mobile terminal, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.

[0173] The RF circuit 601 can be used for receiving and sending signals during information transmission or calls. In particular, after receiving the downlink information of the base station, it is handed over to one or more processors 608 for processing; in addition, the data related to the uplink is sent to the base station. Usually, the RF circuit 601 includes but is not limited to an antenna, at least one amplifier, a tuner, one or more oscillators, a subscriber identity module (SIM) card, a transceiver, a coupler, a low noise amplifier (LNA), a duplexer, etc. In addition, the RF circuit 601 can also communicate with the network and other devices through wireless communication. The wireless communication can use any communication standard or protocol, including but not limited to the Global System of Mobile Communication (GSM), General Packet Radio Service (GPRS), Code Division Multiple Access (CDMA), Wideband Code Division Multiple Access (WCDMA), Long Term Evolution (LTE), email, Short Messaging Service (SMS), etc.

[0174] The memory 602 can be used to store software programs and modules. The processor 608 executes various functional applications and data processing by running the software programs and modules stored in the memory 602. The memory 602 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area may store data created according to the use of the mobile terminal (such as audio data, a phone book, etc.), etc. In addition, the memory 602 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage devices. Accordingly, the memory 602 may also include a memory controller to provide the processor 608 and the input unit 603 with access to the memory 602.

[0175] The input unit 603 can be used to receive input digital or character information, and generate keyboard, mouse, joystick, optical or trackball signal input related to user settings and function control. Specifically, in a specific embodiment, the input unit 603 may include a touch-sensitive surface and other input devices. The touch-sensitive surface, also known as a touch display screen or a touch pad, can collect the user's touch operations on or near it (such as the user's operation on or near the touch-sensitive surface using any suitable object or accessory such as a finger, a stylus, etc.), and drive the corresponding connection device according to a pre-set program. Optionally, the touch-sensitive surface may include a touch detection device and a touch controller. Among them, the touch detection device detects the user's touch orientation, detects the signal brought by the touch operation, and transmits the signal to the touch controller; the touch controller receives the touch information from the touch detection device, converts it into the touch point coordinates, and then sends it to the processor 608, and can receive and execute the command sent by the processor 608. In addition, the touch-sensitive surface can be implemented using multiple types such as resistive, capacitive, infrared and surface acoustic waves. In addition to the touch-sensitive surface, the input unit 603 may also include other input devices. Specifically, other input devices may include, but are not limited to, one or more of a physical keyboard, function keys (such as a volume control key, a switch key, etc.), a trackball, a mouse, a joystick, and the like.

[0176] The display unit 604 can be used to display information input by the user or information provided to the user and various graphical user interfaces of the mobile terminal, which can be composed of graphics, text, icons, videos and any combination thereof. The display unit 604 may include a display panel. Optionally, the display panel may be configured in the form of a liquid crystal display (LCD), an organic light-emitting diode (OLED), etc. Further, the touch-sensitive surface may cover the display panel. When the touch-sensitive surface detects a touch operation on or near it, it is transmitted to the processor 608 to determine the type of touch event. The processor 608 then provides a corresponding visual output on the display panel according to the type of touch event. Although in Figure 7 In the embodiment, the touch-sensitive surface and the display panel are used as two independent components to realize input and output functions, but in some embodiments, the touch-sensitive surface and the display panel can be integrated to realize input and output functions.

[0177] The mobile terminal may also include at least one sensor 605, such as a light sensor, a motion sensor, and other sensors. Specifically, the light sensor may include an ambient light sensor and a proximity sensor, wherein the ambient light sensor may adjust the brightness of the display panel according to the brightness of the ambient light, and the proximity sensor may turn off the display panel and / or backlight when the mobile terminal is moved to the ear. As a type of motion sensor, the gravity acceleration sensor can detect the magnitude of acceleration in each direction (generally three axes), and can detect the magnitude and direction of gravity when stationary. It can be used for applications that identify the posture of the mobile terminal (such as horizontal and vertical screen switching, related games, magnetometer posture calibration), vibration recognition related functions (such as pedometer, tapping), etc.; as for other sensors that can be configured in the mobile terminal, such as gyroscopes, barometers, hygrometers, thermometers, infrared sensors, etc., they will not be repeated here.

[0178] The audio circuit 606, the speaker, and the microphone can provide an audio interface between the user and the mobile terminal. The audio circuit 606 can transmit the electrical signal converted from the received audio data to the speaker, which is converted into a sound signal for output; on the other hand, the microphone converts the collected sound signal into an electrical signal, which is received by the audio circuit 606 and converted into audio data, and then the audio data is output to the processor 608 for processing, and then sent to another mobile terminal through the RF circuit 601, or the audio data is output to the memory 602 for further processing. The audio circuit 606 may also include an earplug jack to provide communication between an external headset and the mobile terminal.

[0179] WiFi is a short-range wireless transmission technology. The mobile terminal can help users send and receive emails, browse web pages, and access streaming media through the WiFi module 607. It provides users with wireless broadband Internet access. Figure 7 A WiFi module 607 is shown, but it is understandable that it is not an essential component of the mobile terminal and can be omitted as required without changing the essence of the invention.

[0180] The processor 608 is the control center of the mobile terminal. It uses various interfaces and lines to connect various parts of the entire mobile terminal. It executes various functions of the mobile terminal and processes data by running or executing software programs and / or modules stored in the memory 602, and calling data stored in the memory 602, so as to monitor the mobile terminal as a whole. Optionally, the processor 608 may include one or more processing cores; preferably, the processor 608 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface, and application programs, and the modem processor mainly processes wireless communications. It is understandable that the above-mentioned modem processor may not be integrated into the processor 608.

[0181] The mobile terminal also includes a power supply 609 (such as a battery) for supplying power to each component. Preferably, the power supply can be logically connected to the processor 608 through a power management system, so that the power management system can manage charging, discharging, and power consumption management. The power supply 609 can also include one or more DC or AC power supplies, recharging systems, power failure detection circuits, power converters or inverters, power status indicators, and other arbitrary components.

[0182] Although not shown, the mobile terminal may also include a camera, a Bluetooth module, etc., which will not be described in detail here. Specifically in this embodiment, the processor 608 in the mobile terminal will load the executable files corresponding to the processes of one or more applications into the memory 602 according to the following instructions, and the processor 608 will run the applications stored in the memory 602 to perform the following functions:

[0183] Acquire an image to be processed, perform face detection on the image, and obtain a face area; when the face area meets a preset compliance condition, extract a portrait area mask and a skin area mask from the image; extract a target area that meets a preset ratio from the image; pre-process the skin area in the target area according to the skin area mask, and perform color adjustment on the non-portrait area in the target area according to the portrait area mask to obtain a target image.

[0184] In some embodiments, when the skin area in the target area is preprocessed according to the skin area mask, and the color of the non-portrait area in the target area is adjusted according to the portrait area mask to obtain the target image, the processor 608 further executes: performing a beautification operation on the skin area in the ID photo area according to the skin area mask to obtain a beautified foreground area; replacing the non-portrait area in the ID photo area with a preset color according to the portrait area mask to obtain a replaced background area; and merging the foreground area and the background area to obtain the target image.

[0185] In some embodiments, when a skin area within the ID photo area is beautified according to a skin area mask to obtain a foreground area after beautification, the processor 608 further executes: extracting the skin area from the ID photo area according to the skin area mask; performing skin resurfacing processing on the skin area through a bilateral filtering algorithm to obtain a skin area after skin resurfacing; and performing whitening processing on the skin area after skin resurfacing through a three-dimensional table lookup method to obtain a foreground area after beautification.

[0186] In some embodiments, before extracting the portrait area mask and the skin area mask from the image, the processor 608 further performs: detecting the number of faces, face area, clarity, exposure and face posture in the face area; when the number of faces, face area, clarity, exposure and face posture in the face area all meet the conditions, determining that the face area meets the preset compliance conditions.

[0187] In some embodiments, when detecting the clarity in the face area, the processor 608 further executes: converting the face area into a grayscale image, convolving the grayscale image with a preset Laplace kernel to obtain a response image; calculating the variance of the response image, and when the variance is greater than a preset threshold, determining that the clarity in the face area meets the conditions.

[0188] In some embodiments, when detecting the exposure in the face area, the processor 608 further executes: counting the proportion of pixels in the face area that are less than a first pixel threshold to the total pixels in the face area to obtain a first proportion value; counting the proportion of pixels in the face area that are greater than a second pixel threshold to the total pixels in the face area to obtain a second proportion value, and the first pixel threshold is less than the second pixel threshold; when the first proportion value is less than a first preset value, and the second proportion value is less than a second preset value, it is determined that the exposure in the face area meets the condition, and the first preset value is less than the second preset value.

[0189] In some embodiments, when detecting the facial posture in the face area, the processor 608 further executes: calculating the angle between the straight line where the two eyes are located and the horizontal line in the face area, and when the angle is less than a preset angle, determining that the facial posture in the face area meets the conditions.

[0190] In some embodiments, when performing face detection on an image to obtain a face area, the processor 608 further executes: performing size normalization on the image to obtain a size-normalized image; performing face detection on the size-normalized image using a face detector based on a convolutional neural network; and when a face is detected, extracting a face area of ​​a preset size from the size-normalized image with the face as the center.

[0191] In some embodiments, when extracting a portrait area mask and a skin area mask from an image, the processor 608 further executes: obtaining the mean and standard deviation of pixels in the image; performing pixel normalization processing on the image according to the mean and standard deviation to obtain a pixel normalized image; and performing segmentation processing on the pixel normalized image through an image segmentation network to obtain a portrait area mask and a skin area mask.

[0192] In some embodiments, when the pixel-normalized image is segmented through the image segmentation network to obtain a portrait area mask and a skin area mask, the processor 608 further executes: extracting local features of the pixel-normalized image through the initial network module of the image segmentation network to obtain a first feature image; extracting shared features of the first feature image through the shared feature module of the image segmentation network to obtain a second feature image; extracting portrait features and skin features of the second feature image through the branch task module of the image segmentation network to obtain a portrait feature image and a skin feature image; extracting a portrait area mask and a skin area mask based on the second feature image, the portrait feature image and the skin feature image through the integration module of the image segmentation network.

[0193] In some embodiments, when extracting a target area that meets a preset ratio from an image, the processor 608 further executes: obtaining a portrait frame based on a portrait area mask; obtaining a face detection frame, and calculating the height of the face based on the face detection frame; determining the region boundary based on the portrait frame, the face detection frame, and the height of the face; and extracting a target area that meets the preset ratio from the image based on the region boundary.

[0194] In the above embodiments, the description of each embodiment has its own emphasis. For the part that is not described in detail in a certain embodiment, please refer to the detailed description of the image processing method above, and will not be repeated here.

[0195] A person of ordinary skill in the art will appreciate that all or part of the steps in the various methods of the above embodiments may be completed by a computer program, or by controlling related hardware through a computer program. The computer program may be stored in a computer-readable storage medium and loaded and executed by a processor.

[0196] To this end, an embodiment of the present application provides a storage medium in which a computer program is stored. The computer program can be loaded by a processor to execute any image processing method provided in the embodiment of the present application. For example, the computer program is loaded by a processor and can execute the following steps:

[0197] Acquire an image to be processed, perform face detection on the image, and obtain a face area; when the face area meets a preset compliance condition, extract a portrait area mask and a skin area mask from the image; extract a target area that meets a preset ratio from the image; pre-process the skin area in the target area according to the skin area mask, and perform color adjustment on the non-portrait area in the target area according to the portrait area mask to obtain a target image.

[0198] The specific implementation of the above operations can be found in the previous embodiments, which will not be described in detail here.

[0199] The storage medium may include: a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.

[0200] Since the instructions stored in the storage medium can execute any image processing method provided in the embodiments of the present application, the beneficial effects that can be achieved by any image processing method provided in the embodiments of the present application can be achieved. Please refer to the previous embodiments for details and will not be repeated here.

[0201] The above is a detailed introduction to an image processing method, device, mobile terminal and storage medium provided in the embodiments of the present application. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea; at the same time, for technical personnel in this field, according to the idea of ​​the present application, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.

Claims

1. An image processing method, characterized in that: include: Acquire an image to be processed, perform face detection on the image, and obtain a face region; When the face area meets a preset compliance condition, extracting a portrait area mask and a skin area mask from the image; Extracting a target area that meets a preset ratio from the image; Preprocessing the skin area in the target area according to the skin area mask, and color-adjusting the non-portrait area in the target area according to the portrait area mask to obtain a target image; Extracting a portrait area mask and a skin area mask from the image includes: Obtaining the mean and standard deviation of pixels in the image; Performing pixel normalization processing on the image according to the mean and the standard deviation to obtain a pixel-normalized image; Extracting local features of the pixel-normalized image through an initial network module of the image segmentation network to obtain a first feature image, wherein the local features are shallow local features including edges and textures; Extracting shared features from the first feature image through a shared feature module of an image segmentation network to obtain a second feature image, wherein the shared features include human region features; Extracting portrait features and skin features from the second feature image through a branch task module of the image segmentation network to obtain a portrait feature image and a skin feature image; Through the integrated module of the image segmentation network, a portrait region mask and a skin region mask are extracted based on the second feature image, the portrait feature image and the skin feature image.

2. The image processing method according to claim 1, characterized in that: The preprocessing of the skin area in the target area according to the skin area mask, and the color adjustment of the non-portrait area in the target area according to the portrait area mask to obtain the target image comprises: Performing a beautification operation on the skin area in the ID photo according to the skin area mask to obtain a beautified foreground area; Replacing the non-portrait area in the ID photo area with a preset color according to the portrait area mask to obtain a replaced background area; The foreground area and the background area are fused to obtain a target image.

3. The image processing method according to claim 2, characterized in that: The beautification operation is performed on the skin area in the ID photo area according to the skin area mask to obtain the foreground area after beautification, including: Extracting a skin area from the ID photo area according to the skin area mask; Performing skin resurfacing processing on the skin area by using a bilateral filtering algorithm to obtain a skin area after skin resurfacing; The skin area after the skin grinding is whitened by a three-dimensional table lookup method to obtain a foreground area after beautification.

4. The image processing method according to claim 1, characterized in that: Before extracting the portrait area mask and the skin area mask from the image, the method further includes: Detecting the number, area, clarity, exposure and posture of faces in the face area; When the number of faces, face area, clarity, exposure and face posture in the face area all meet the conditions, it is determined that the face area meets the preset compliance conditions.

5. The image processing method according to claim 4, characterized in that: Detecting the clarity in the face area includes: Converting the face region into a grayscale image, and performing a convolution operation on the grayscale image and a preset Laplace kernel to obtain a response image; Calculating the variance of the response image, and when the variance is greater than a preset threshold, determining that the clarity in the face region meets a condition; Detecting the exposure in the face area includes: Counting the ratio of pixels in the face region that are smaller than a first pixel threshold to the total pixels in the face region to obtain a first ratio value; Counting the ratio of pixels in the face area that are greater than a second pixel threshold to the total pixels in the face area to obtain a second ratio value, and the first pixel threshold is less than the second pixel threshold; When the first ratio value is less than a first preset value, and the second ratio value is less than a second preset value, it is determined that the exposure in the face area meets a condition, and the first preset value is less than the second preset value; Detecting the facial posture in the facial area includes: The angle between the straight line where the two eyes are located and the horizontal line in the face region is calculated, and when the angle is less than a preset angle, it is determined that the face posture in the face region meets the condition.

6. The image processing method according to claim 1, characterized in that: The performing face detection on the image to obtain the face area comprises: Performing size normalization processing on the image to obtain a size-normalized image; Performing face detection on the size-normalized image using a convolutional neural network face detector; When a human face is detected, a face region of a preset size is extracted from the size-normalized image with the human face as the center.

7. The image processing method according to any one of claims 1 to 6, characterized in that: The step of extracting a target area that meets a preset ratio from the image comprises: Acquire a portrait frame according to the portrait area mask; Obtain a face detection frame, and calculate the height of the face according to the face detection frame; Determine the region boundary according to the portrait frame, the face detection frame and the height of the face; A target area conforming to a preset ratio is extracted from the image according to the area boundary.

8. An image processing device, characterized in that: include: The first detection module is used to obtain an image to be processed, perform face detection on the image, and obtain a face area; A mask extraction module, configured to extract a portrait area mask and a skin area mask from the image when the face area meets a preset compliance condition; A region extraction module, used to extract a target region that meets a preset ratio from the image; a processing module, configured to pre-process the skin area in the target area according to the skin area mask, and perform color adjustment on the non-portrait area in the target area according to the portrait area mask, so as to obtain a target image; The mask extraction module is further used for: Obtaining the mean and standard deviation of pixels in the image; Performing pixel normalization processing on the image according to the mean and the standard deviation to obtain a pixel-normalized image; Extracting local features of the pixel-normalized image through an initial network module of the image segmentation network to obtain a first feature image, wherein the local features are shallow local features including edges and textures; Extracting shared features from the first feature image through a shared feature module of an image segmentation network to obtain a second feature image, wherein the shared features include human region features; Extracting portrait features and skin features from the second feature image through a branch task module of the image segmentation network to obtain a portrait feature image and a skin feature image; Through the integrated module of the image segmentation network, a portrait region mask and a skin region mask are extracted based on the second feature image, the portrait feature image and the skin feature image.

9. A mobile terminal, characterized in that: The method comprises a processor and a memory, wherein a computer program is stored in the memory, and when the processor calls the computer program in the memory, the image processing method according to any one of claims 1 to 7 is executed.

10. A storage medium, characterized in that: The storage medium is used to store a computer program, and the computer program is loaded by a processor to execute the image processing method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • An end-to-end face annotation method based on detection and segmentation

    CN108985181A

  • Image segmentation method and device

    CN109389076A

  • A control method based on face region exposure

    CN109918993A

  • Portrait picture generation method and device and computer device

    CN110047053A

  • Face image quality evaluation method based on face geometrical characteristics

    CN110321753A