Image processing method and device, electronic equipment and storage medium
By downsampling and feature extraction of high-resolution facial images, and fusing color channel values based on transparency channel values, the problem of skin defects appearing in real-time videos is solved, efficient beautification is achieved, and user experience is improved.
Patent Information
- Application Number
- CN202411155300.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-21
- Publication Date
- 2024-10-18
AI Technical Summary
Skin defects in high-resolution facial images appear in real-time video streams, affecting user experience. Existing technologies are difficult to efficiently beautify facial areas in real-time video scenarios.
By downsampling and feature extraction of the image to be processed, an intermediate image containing facial contour and texture information is generated, the fusion coefficient is determined based on the transparency channel value, the color channel value is fused, and a beautified image is generated, reducing the amount of model calculations.
It achieves efficient beautification processing of the facial area in real-time video scenes, ensuring the beautification effect and clarity, while reducing the amount of calculation and improving image processing efficiency.
Smart Images

Figure CN118799201A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technology, and in particular to an image processing method, device, electronic device and storage medium. Background Art
[0002] With the rapid development of high-definition photography technology, capturing high-resolution facial images has become the norm. However, high-resolution facial images will highlight facial skin flaws, such as wrinkles, spots, and dark circles. In scenarios such as mobile terminal live broadcasts, instant video communications, and online video conferencing, these flaws will appear in real-time video streams, which will affect the user experience. At this time, it is very necessary to process facial skin flaws in real time to improve skin texture and provide users with a better visual experience. Therefore, how to perform image processing on the facial area is a problem that needs to be solved. Summary of the invention
[0003] The present disclosure provides an image processing method, device, electronic device and storage medium, which reduce the amount of model calculation while ensuring the beautification effect and clarity, so that in a real-time video scene, the terminal can beautify the face area in the video in real time and efficiently. The technical solution of the present disclosure is as follows:
[0004] According to one aspect of an embodiment of the present disclosure, there is provided an image processing method, the method comprising:
[0005] Downsampling the first image to be processed to obtain a first intermediate image of a target resolution, wherein the first image includes a face of at least one target object;
[0006] Performing feature extraction and upsampling on the first intermediate image to obtain a second intermediate image, wherein a color channel value of the second intermediate image is used to indicate contour information of the face of the at least one target object, and a transparency channel value of the second intermediate image is used to indicate texture information of the face of the at least one target object;
[0007] Determining a first fusion coefficient and a second fusion coefficient based on a transparency channel value of the second intermediate image;
[0008] Based on the first fusion coefficient and the second fusion coefficient, the color channel values of the first image and the color channel values of the second intermediate image are fused to obtain a second image, and the facial features of the at least one target object in the second image are different from the facial features of the at least one target object in the first image.
[0009] According to another aspect of an embodiment of the present disclosure, there is provided an image processing apparatus, the apparatus comprising:
[0010] a processing unit configured to downsample a first image to be processed to obtain a first intermediate image of a target resolution, wherein the first image includes a face of at least one target object;
[0011] The processing unit is further configured to perform feature extraction and up-sampling on the first intermediate image to obtain a second intermediate image, wherein a color channel value of the second intermediate image is used to indicate contour information of the face of the at least one target object, and a transparency channel value of the second intermediate image is used to indicate texture information of the face of the at least one target object;
[0012] A first determining unit is configured to determine a first fusion coefficient and a second fusion coefficient based on a transparency channel value of the second intermediate image;
[0013] A fusion unit is configured to fuse the color channel values of the first image and the color channel values of the second intermediate image based on the first fusion coefficient and the second fusion coefficient to obtain a second image, wherein the facial features of the at least one target object in the second image are different from the facial features of the at least one target object in the first image.
[0014] In some embodiments, the first determination unit is configured to determine, for any pixel in the second intermediate image, a transparency channel value of the pixel as a first fusion coefficient corresponding to the pixel, and determine a difference between 1 and the transparency channel value of the pixel as a second fusion coefficient corresponding to the pixel.
[0015] In some embodiments, the fusion unit is configured to, for any pixel in the second intermediate image, multiply the first fusion coefficient corresponding to the pixel by multiple color channel values of the pixel in the second intermediate image to obtain multiple first intermediate values; multiply the second fusion coefficient corresponding to the pixel by multiple color channel values of the pixel in the first image to obtain multiple second intermediate values; and add the multiple first intermediate values and the second intermediate values to obtain multiple color channel values of the pixel in the second image.
[0016] In some embodiments, the apparatus further comprises:
[0017] A second determining unit is configured to determine the at least one target object from the original image;
[0018] an extraction unit, configured to perform face extraction on the at least one target object respectively to obtain a face region of each target object;
[0019] The stitching unit is configured to stitch the facial region of the at least one target object to obtain the first image.
[0020] In some embodiments, the resolution of the first image is a first preset resolution;
[0021] The stitching unit is configured to determine a second preset resolution based on the number of the at least one target object, the number of pixels contained in the image of the second preset resolution being the ratio of the number of pixels contained in the image of the first preset resolution to the number of the at least one target object; for any target object, based on the second preset resolution, compress the facial area of the target object to obtain the facial image of the target object, the resolution of the facial image of the target object being the second preset resolution; and stitch the facial image of the at least one target object to obtain the first image.
[0022] In some embodiments, the image processing method is implemented by generating a target image model, and the apparatus further comprises:
[0023] An updating unit is configured to process a sample image in the training data set through an image generation model in each iteration to obtain an output image, wherein the sample image is an unprocessed original image;
[0024] The updating unit is further configured to determine a loss value corresponding to a first loss function based on the output image, a label image in the training data set, and a mask image in the training data set, wherein the label image is an image containing facial reference features, and the mask image is an image retaining facial boundary features;
[0025] The updating unit is further configured to update the model parameters of the image generation model based on the loss value corresponding to the first loss function.
[0026] In some embodiments, the update unit is further configured to discriminate the output image and the sample image in the training data set through an image discrimination model during each iteration to obtain a discrimination result; based on the discrimination result, the output image, and the sample image, confirm the loss value corresponding to the second loss function; and based on the loss value corresponding to the second loss function, update the model parameters of the image discrimination model.
[0027] In some embodiments, the updating unit is further configured to, during any iteration process, determine the image generation model after updating the model parameters as the target image generation model when the number of iterations meets a preset number.
[0028] In some embodiments, the updating unit is further configured to determine, for each masked image in the training data set, an intermediate image corresponding to the masked image, the color channel value of the pixel in the masked image is between -1 and 1, and the color channel value of the pixel in the intermediate image corresponding to the masked image is between 0 and 1; based on the loss value corresponding to the third loss function and the intermediate image corresponding to the masked image, determine the loss value corresponding to the first loss function, the third loss function being used to indicate the error between the output image and the label image.
[0029] In some embodiments, the pixel value of the first type of area in the mask image is 1, the first type of area is the face boundary area, the pixel value of the second type of area in the mask image is -1, and the first type of area is other areas in the mask image except the first type of area.
[0030] According to another aspect of an embodiment of the present disclosure, an electronic device is provided, the electronic device comprising:
[0031] one or more processors;
[0032] A memory for storing program codes executable by the processor;
[0033] The processor is configured to execute the program code to implement the above-mentioned image processing method.
[0034] According to another aspect of an embodiment of the present disclosure, a computer-readable storage medium is provided. When a program code in the computer-readable storage medium is executed by a processor of an electronic device, the electronic device is enabled to perform the above-mentioned image processing method.
[0035] According to another aspect of an embodiment of the present disclosure, a computer program product is provided, including a computer program, and when the computer program is executed by a processor, the above-mentioned image processing method is implemented.
[0036] The disclosed embodiment provides an image processing method, in which a terminal obtains a first intermediate image of a target resolution by downsampling a first image to be processed, obtains a second intermediate image containing contour information and texture information of the face of at least one target object by performing feature extraction and upsampling on the first intermediate image, and then fuses the second intermediate image with the first image according to the transparency channel value to obtain a second image after face beautification. In the above manner, the terminal reduces the amount of model calculation while ensuring the beautification effect and clarity, so that in a real-time video scene, the terminal can beautify the face area in the video in real time and efficiently.
[0037] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] The drawings herein are incorporated into and constitute a part of the specification, illustrate embodiments consistent with the present disclosure, and together with the description are used to explain the principles of the present disclosure, and do not constitute improper limitations on the present disclosure.
[0039] Figure 1 It is a schematic diagram of an implementation environment of an image processing method according to an exemplary embodiment.
[0040] Figure 2 The figure is a flowchart of an image processing method according to an exemplary embodiment.
[0041] Figure 3 is a flowchart of another image processing method according to an exemplary embodiment.
[0042] Figure 4 is a schematic diagram of an image generation model according to an exemplary embodiment.
[0043] Figure 5 is a schematic diagram showing a mask image according to an exemplary embodiment.
[0044] Figure 6 is a schematic diagram of multiple facial images according to an exemplary embodiment.
[0045] Figure 7 is a schematic diagram of an image discrimination model according to an exemplary embodiment.
[0046] Figure 8 is a block diagram of an image processing apparatus according to an exemplary embodiment.
[0047] Fig. 9 is a block diagram of another image processing device according to an exemplary embodiment.
[0048] Fig.10 It is a block diagram of an electronic device according to an exemplary embodiment. DETAILED DESCRIPTION
[0049] In order to enable ordinary persons in the art to better understand the technical solutions of the present disclosure, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the accompanying drawings.
[0050] It should be noted that the terms "first", "second", etc. in the specification and claims of the present disclosure and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present disclosure described herein can be implemented in an order other than those illustrated or described herein. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.
[0051] It should be noted that the information (including but not limited to user device information, user personal information, etc.), data (including but not limited to data used for analysis, stored data, displayed data, etc.) and signals involved in this disclosure are all authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards of relevant countries and regions. For example, the first image, original image, etc. involved in this disclosure are all obtained with full authorization.
[0052] Figure 1 FIG. 1 is a schematic diagram of an implementation environment of an image processing method according to an exemplary embodiment. Figure 1 The implementation environment specifically includes: a terminal 101 and a server 102. The terminal 101 can be connected to the server 102 via a wireless network or a wired network.
[0053] The terminal 101 may be at least one of a smart phone, a smart watch, a desktop computer, a laptop computer, an MP3 player (Moving Picture Experts Group Audio Layer III), an MP4 player (Moving Picture Experts Group Audio Layer IV), and a laptop computer. An application may be installed and run on the terminal 101, and the application may beautify an image containing a face of a target object. The application is associated with the server 102, and the server 102 provides a background service to the terminal 101.
[0054] The terminal 101 may generally refer to one of a plurality of terminals. This embodiment is described by taking the terminal 101 as an example. Those skilled in the art may know that the number of the above terminals may be more or less. For example, the above terminals may be several, or the above terminals may be dozens or hundreds, or a greater number. The embodiment of the present disclosure does not limit the number and device type of the terminals.
[0055] The server 102 is at least one of a single server, multiple servers, a cloud computing platform, and a virtualization center. Optionally, the number of the above servers may be more or less, which is not limited in the embodiments of the present disclosure. Of course, the server 102 may also include other functional servers to provide more comprehensive and diversified services. In some embodiments, the server 102 undertakes the main computing work, and the terminal 101 undertakes the secondary computing work; or, the server 102 undertakes the secondary computing work, and the terminal 101 undertakes the main computing work; or, the server 102 and the terminal 101 use a distributed computing architecture for collaborative computing. The server 102 can be connected to the terminal 101 and other terminals via a wireless network or a wired network. Optionally, the number of the above servers may be more or less, which is not limited in the embodiments of the present disclosure.
[0056] Figure 2 is a flowchart of an image processing method according to an exemplary embodiment. Figure 2 As shown, the method is executed by the terminal and includes the following steps:
[0057] In step S201, the terminal downsamples a first image to be processed to obtain a first intermediate image of a target resolution, where the first image includes a face of at least one target object.
[0058] In the embodiments of the present disclosure, the target object refers to a single independent human body. The face of the target object may be a frontal face or a side face. The first image may contain only the face of a single target object or may contain the faces of multiple target objects at the same time. The first image may be a video frame image or a photo. The first image may be an entire image or an image containing a facial area extracted from the entire image. The embodiments of the present disclosure do not limit this.
[0059] For example, in a mobile terminal live broadcast scenario, as the live broadcast progress changes, the live broadcast screen may not include the target object, may include one target object, or may include multiple target objects. The terminal can perform image processing on the face of the target object appearing in the live broadcast screen.
[0060] The target resolution refers to the preset resolution required for subsequent feature extraction. Usually, the target resolution is set to 512×512. When the terminal directly processes an image with a resolution larger than the target resolution, the amount of calculation is large, more computing resources are consumed, and the real-time processing effect is difficult to meet the requirements; when the terminal directly processes an image with a resolution smaller than the target resolution, if the image includes the faces of multiple target objects, each target object's face may be small, resulting in a processing effect that is difficult to meet the requirements.
[0061] Typically, the resolution of the first image to be processed is greater than the target resolution. The terminal downsamples the first image and processes the first image into a first intermediate image of the target resolution, thereby ensuring that the processing effect on the face of each target object meets the requirements while consuming less computing resources. It should be noted that the size of the above target resolution is only an example, and the size of the target resolution can be set according to actual needs.
[0062] In step S202, the terminal performs feature extraction and upsampling on the first intermediate image to obtain a second intermediate image, wherein the color channel value of the second intermediate image is used to indicate the contour information of the face of at least one target object, and the transparency channel value of the second intermediate image is used to indicate the texture information of the face of at least one target object.
[0063] In the embodiment of the present disclosure, the resolution of the second intermediate image is usually the same as that of the first image, which facilitates the subsequent fusion of the two images. The second intermediate image is an RGBA image containing four channels. The four channels are R (red) channel, G (green) channel, B (blue) channel, and A (Alpha) channel. Among them, the three RGB channels are used to represent the color information of the image, and the A channel is used to represent the transparency information of the image. In the embodiment of the present disclosure, in the second intermediate image after feature extraction, the information indicated by the RGB channel is the contour information of the face of the target object, and the contour information can represent the information in the face of the first image that does not need to beautify. The information indicated by the A channel is the texture information of the face of the target object, and the texture information can indicate the texture to be beautified in the face of the first image. For the convenience of description, the values of the RGB channels are referred to as color channel values, and the values of the A channel are referred to as transparency channel values.
[0064] Among them, a transparency channel value of 0 indicates complete transparency, a transparency channel value of 255 indicates complete opacity, and a transparency channel value between 0 and 255 indicates varying degrees of translucency. Generally speaking, the closer the transparency channel value of a certain area is to 0, the more the area needs to be beautified; the closer the transparency channel value of a certain area is to 255, the less beautification is required for the area. In other words, through the transparency channel value, the terminal can highlight the area that needs to be beautified.
[0065] In step S203, the terminal determines a first fusion coefficient and a second fusion coefficient based on a transparency channel value of the second intermediate image.
[0066] In the disclosed embodiment, the first fusion coefficient and the second fusion coefficient are obtained by the terminal operating on the transparency channel value. The first fusion coefficient and the second fusion coefficient act on the second intermediate image and the first image respectively. Generally, for any pixel point, the mixing ratio of the color channel values of the two images at the pixel point is adjusted by the first fusion coefficient and the second fusion coefficient, so as to achieve a mixing effect that meets the requirements.
[0067] In step S204, the terminal fuses the color channel values of the first image and the color channel values of the second intermediate image based on the first fusion coefficient and the second fusion coefficient to obtain a second image, and the facial features of at least one target object in the second image are different from the facial features of at least one target object in the first image.
[0068] In the disclosed embodiment, the first fusion coefficient is used as the weighting coefficient of the first image, and the second fusion coefficient is used as the weighting coefficient of the second intermediate image. The first image refers to the image of the face to be beautified, and the second image refers to the image of the face after beautification. Therefore, the facial features of the first image and the second image are different, and the facial features of the second image are more in line with the requirements. Among them, the facial features include skin color, skin quality, facial features ratio, facial contour, etc. Skin color includes skin color brightness and skin color uniformity. Skin quality includes skin blemishes, skin gloss, etc.
[0069] The terminal performs a weighted summation of the color channel values of the first image and the color channel values of the second intermediate image to obtain the color channel values of the second image. Since the first image and the second intermediate image have the same resolution, the terminal obtains the second image after the color channel values of the pixels at corresponding positions in the two images are fused.
[0070] The disclosed embodiment provides an image processing method, in which a terminal obtains a first intermediate image of a target resolution by downsampling a first image to be processed, obtains a second intermediate image containing contour information and texture information of the face of at least one target object by performing feature extraction and upsampling on the first intermediate image, and then fuses the second intermediate image with the first image according to the transparency channel value to obtain a second image after face beautification. In the above manner, the terminal reduces the amount of model calculation while ensuring the beautification effect and clarity, so that in a real-time video scene, the terminal can beautify the face area in the video in real time and efficiently.
[0071] In some embodiments, determining the first fusion coefficient and the second fusion coefficient based on the transparency channel value of the second intermediate image includes:
[0072] For any pixel in the second intermediate image, the transparency channel value of the pixel is determined as the first fusion coefficient corresponding to the pixel, and the difference between 1 and the transparency channel value of the pixel is determined as the second fusion coefficient corresponding to the pixel.
[0073] In the disclosed embodiment, the terminal determines the first fusion coefficient and the second fusion coefficient corresponding to each pixel through the transparency channel value of the second intermediate image, thereby controlling the degree of fusion of the first image and the second intermediate image. At the same time, since the change of the transparency channel value is usually continuous, it is possible to ensure a smooth transition between different areas of the image, avoid the abruptness of the fusion boundary, and make the image more natural. The above method does not require complex algorithms or additional computing resources, thereby improving the efficiency of image processing.
[0074] In some embodiments, based on the first fusion coefficient and the second fusion coefficient, the color channel value of the first image and the color channel value of the second intermediate image are fused to obtain the second image, including:
[0075] For any pixel in the second intermediate image, multiply the first fusion coefficient corresponding to the pixel by multiple color channel values of the pixel in the second intermediate image to obtain multiple first intermediate values;
[0076] Multiplying the second fusion coefficient corresponding to the pixel point and the multiple color channel values of the pixel point in the first image respectively to obtain multiple second intermediate values;
[0077] The plurality of first intermediate values and the second intermediate values are added together to obtain a plurality of color channel values of the pixel points in the second image.
[0078] In the disclosed embodiment, the terminal achieves fusion of the first image and the second intermediate image by mixing each color channel according to the fusion coefficient. The above method ensures a smooth transition between different areas in the image. At the same time, since the fusion algorithm for the first image and the second intermediate image is relatively simple, the overall processing efficiency is also guaranteed, providing a fast and high-quality image processing function.
[0079] In some embodiments, the method further comprises:
[0080] determining at least one target object from the original image;
[0081] Performing face extraction on at least one target object to obtain a face region of each target object;
[0082] The facial region of at least one target object is spliced to obtain a first image.
[0083] In the embodiment of the present disclosure, the terminal can exclude redundant information in the original image that is not related to the facial area by extracting the facial area of the target object from the original image. This not only significantly reduces the complexity and difficulty of image processing, improves the image processing speed, and reduces the demand for computing resources, but also helps to improve the accuracy of image processing.
[0084] In some embodiments, the resolution of the first image is a first preset resolution; stitching the facial region of at least one target object to obtain the first image includes:
[0085] Based on the number of at least one target object, determine a second preset resolution, where the number of pixels included in the image of the second preset resolution is a ratio of the number of pixels included in the image of the first preset resolution to the number of the at least one target object;
[0086] For any target object, based on the second preset resolution, compressing the face area of the target object to obtain a face image of the target object, wherein the resolution of the face image of the target object is the second preset resolution;
[0087] The facial images of at least one target object are spliced to obtain a first image.
[0088] In the disclosed embodiment, the terminal can ensure that the size and proportion of each target object in the final image are relatively balanced by compressing the face area of the target object to the second preset resolution before splicing, thereby avoiding the problem of poor image processing effect caused by the size difference of the original face area. At the same time, since the resolution of the face area of each target object is compressed, the amount of data processed by the terminal is reduced, the demand for computing resources is reduced, and the image processing process is faster and smoother, thereby improving the overall image processing efficiency.
[0089] In some embodiments, the image processing method is implemented by a target image generation model, and the training steps of the target image generation model include:
[0090] In each iteration, the sample image in the training data set is processed by the image generation model to obtain an output image, where the sample image is the unprocessed original image;
[0091] Determine a loss value corresponding to a first loss function based on the output image, a label image in the training data set, and a mask image in the training data set, wherein the label image is an image containing facial reference features, and the mask image is an image retaining facial boundary features;
[0092] Based on the loss value corresponding to the first loss function, the model parameters of the image generation model are updated.
[0093] In the disclosed embodiment, the label image contains facial reference features, so that the image generation model can learn to generate images with facial reference features through the training process; the mask image retains facial boundary features, so that the image generation model focuses on more complex areas such as facial boundaries during the generation process. Through the above training method, the terminal ensures the image beautification performance of the image generation model and improves the image generation quality. At the same time, no regularization layer is set in the training process of the image generation model, which enhances the generalization ability of the image generation model, helps accelerate model convergence, and improves the practicality of the image generation model.
[0094] In some embodiments, the method further comprises:
[0095] In each iteration, the output image and the sample image in the training data set are discriminated by the image discrimination model to obtain the discrimination result;
[0096] Based on the discrimination result, the output image, and the sample image, determining a loss value corresponding to the second loss function;
[0097] Based on the loss value corresponding to the second loss function, the model parameters of the image discrimination model are updated.
[0098] In the disclosed embodiment, during the training process of the image generation model, the terminal can distinguish the output image from the sample image by introducing the image discrimination model and discriminating the output image and the sample image in the training data set through the image discrimination model. Through multiple iterations of training, the discrimination model can gradually improve the discrimination ability of the generated image. The above method prompts the image generation model to generate images that are more difficult to be distinguished by the image discrimination model, thereby enhancing the image processing effect, promoting the updating of model parameters, and improving the performance and practicality of the image generation model.
[0099] In some embodiments, the method further comprises:
[0100] In any iteration process, when the number of iterations meets the preset number, the image generation model after the model parameters are updated is determined as the target image generation model.
[0101] In the disclosed embodiment, during the iteration process, a preset number of times is set and the target image generation model is determined when conditions are met, so that the training process of the image generation model can be terminated in time, thereby avoiding the waste of computing resources and improving the performance and practicality of the image generation model.
[0102] In some embodiments, determining a loss value corresponding to the first loss function based on the output image, the label image in the training data set, and the mask image in the training data set includes:
[0103] For each masked image in the training data set, determine the intermediate image corresponding to the masked image, the color channel value of the pixel in the masked image is between -1 and 1, and the color channel value of the pixel in the intermediate image corresponding to the masked image is between 0 and 1;
[0104] Based on the loss value corresponding to the third loss function and the intermediate image corresponding to the masked image, the loss value corresponding to the first loss function is determined, and the third loss function is used to indicate the error between the output image and the label image.
[0105] In the disclosed embodiment, the terminal converts the color channel values of the pixels in the masked image from a range of -1 to 1 to a range of 0 to 1 in the intermediate image, so that in the subsequent process of determining the loss value of the first function, it can focus on the facial boundary, thereby avoiding interference from redundant information outside the facial boundary, which is beneficial for the image generation model to learn specific feature representations during the training process, thereby enhancing the image processing effect and improving the performance and practicality of the image generation model.
[0106] In some embodiments, the pixel value of the first type of area in the mask image is 1, the first type of area is the face boundary area, the pixel value of the second type of area in the mask image is -1, and the first type of area is other areas in the mask image except the first type of area.
[0107] In the disclosed embodiment, the mask image indicates the facial boundary area and other areas through the difference in pixel values. By clearly distinguishing the facial boundary from other areas, the image generation model can achieve more accurate image processing without introducing complex data, and focus on the image processing effect on the facial boundary area, thereby improving the performance and practicality of the image generation model while ensuring the demand for computing resources.
[0108] Above Figure 2 Shown is a flow chart of an image processing method of the present disclosure. The image processing solution provided by the present disclosure is further elaborated below. Figure 3 is a flowchart of another image processing method according to an exemplary embodiment. Figure 3, the method is executed by the terminal. At this time, the terminal implements the image processing method through a target image generation model. The target image generation model is a lightweight face beautification model suitable for mobile terminals. Under normal circumstances, the calculation amount of the target image generation model is below 100 megabytes, and it can run up to 30fps (frames per second) in most mobile terminals. The target image generation model has the function of removing negative effects on the face, for example, removing facial blemishes, dark circles, wrinkles, and nasolabial folds. Among them, facial blemishes include but are not limited to acne, blackheads, and spots. At the same time, the target image generation model has the function of enhancing positive effects on the face, for example, even skin color and age reduction. It should be noted that the above-mentioned multiple functions are only exemplary, and the target image generation model realizes face beautification through the above-mentioned multiple functions. In addition, the target image generation model supports beautifying multiple faces at the same time, and can solve the problem that complex areas such as facial boundaries and facial features boundaries are difficult to beautify. The image processing method includes the following steps:
[0109] In step S301, the terminal determines at least one target object from an original image.
[0110] In the embodiments of the present disclosure, the original image may be a video frame image or a photo, which is not limited in the embodiments of the present disclosure. The target object refers to a single independent human body, and different target objects are used to indicate different human bodies. The original image includes one target image or may include multiple target images. It should be noted that a human body whose face does not appear in the original image is usually not identified as a target object.
[0111] Typically, the terminal uses a human recognition algorithm or a human detection algorithm to locate and identify a human body appearing in the original image, thereby determining at least one target object. For example, in a real-time video scenario, the terminal obtains a video frame image based on a real-time video stream, and determines the human body contained in the video frame image through a human detection algorithm.
[0112] In step S302, the terminal performs face extraction on at least one target object to obtain a face region of each target object.
[0113] In the disclosed embodiments, the facial region refers to a region including all facial parts of the target object in the original image. For example, when the host's full face is shown in a live broadcast scene on a mobile terminal, the host's facial region is the host's full face region. For ease of description, the facial region may be referred to as a facial region image. Optionally, the terminal locates the approximate area where the face is located through a facial detection algorithm, and selects a facial region of a preset size in the approximate area to obtain a facial region image of a preset resolution.
[0114] It should be noted that the above steps S301 and S302 are only an exemplary description of determining the face area. In some embodiments, the terminal directly locates the face area through a face recognition algorithm or a face detection algorithm to obtain a face area image of a preset resolution without determining the target object in the original image.
[0115] In step S303, the terminal splices the facial region of at least one target object to obtain a first image.
[0116] In the disclosed embodiment, the first image is obtained by stitching together the facial region images of the at least one target object, and the first image includes the face of the at least one target object. It should be noted that the terminal extracts the facial region of the target object from the original image and then stitches together the first image, which not only eliminates redundant information irrelevant to the facial region in the original image, significantly reduces the complexity and difficulty of image processing, improves the image processing speed, reduces the demand for computing resources, and helps to improve the accuracy of image processing.
[0117] In some embodiments, the resolution of the first image is a first preset resolution. The first image is an input image of the target image generation model, and the first preset resolution is the resolution required for the input image of the target image generation model. For the target image generation model, the required resolution of the input image is fixed. Optionally, the required resolution of the input image is set to 512×512 or 640×640. Usually, during the deduction process of the target image generation model, the terminal directly splices the facial area to the resolution required for the input image, and then inputs it into the target image generation model. During the training process of the target image generation model, since the resolution of an image in the training data set may be greater than the resolution required for the input image, the terminal randomly scales and crops the image to the resolution required for the input image, and then inputs it into the target image generation model. Among them, when making multiple facial images in the training data set, in order to avoid each facial area being too small after splicing multiple facial areas, the terminal usually splices multiple facial areas into an image with a resolution greater than the resolution required for the input image.
[0118] In some embodiments, the terminal splices the facial regions of the target objects based on a preset rule corresponding to the number of target objects. Accordingly, the terminal determines a second preset resolution based on the number of at least one target object, and the number of pixels contained in the image of the second preset resolution is the ratio of the number of pixels contained in the image of the first preset resolution to the number of at least one target object; for any target object, the terminal compresses the facial region of the target object based on the second preset resolution to obtain a facial image of the target object, and the resolution of the facial image of the target object is the second preset resolution; the terminal splices the facial image of at least one target object to obtain the first image.
[0119] It should be noted that when the terminal directly locates the facial area through the facial recognition algorithm or the facial detection algorithm, the terminal splices the facial area of the target object based on the preset rules corresponding to the number of facial areas, which will not be repeated here.
[0120] For example, the first preset resolution is 640×640. When the number of at least one target object is 1, the second preset resolution corresponding to the facial image of the target object is 640×640. When the number of at least one target object is 2, the second preset resolution corresponding to the facial image of each target object is 640×320, and the facial images of the two target objects are horizontally spliced to obtain the first image.
[0121] Among them, when compressing the facial area of the target object, the terminal does not fix the aspect ratio of the facial area. For example, the size of the facial area of a target object is 640×640, and the size of the facial image obtained after compression is 640×320. At this time, the aspect ratio of the face of the target object changes, and the shape of the face also changes accordingly. Optionally, when compressing the facial area of the target object to the second preset resolution, the terminal can also appropriately scale and crop the facial area. For example, in the facial area determined by the terminal, there are more background areas outside the face, and the background area can be appropriately cropped. This will not be elaborated.
[0122] It should be noted that, when the number of target objects is large, in order to avoid the face in the first image after stitching being too small, the terminal first compresses the facial areas of multiple target objects into facial images of a second preset resolution, and then stitches them into a multi-person stitched image larger than the first preset resolution, and then randomly scales and crops the multi-person stitched image to obtain the first image corresponding to the first preset resolution. At this time, the number of pixels contained in the image of the second preset resolution is the ratio of the number of pixels contained in the multi-person stitched image to the number of at least one target object. Optionally, when the number of target objects is small, the terminal may also adopt the above method, which is not limited here.
[0123] For example, the first preset resolution is 640×640. When the number of at least one target object is 3, the resolution of the multi-person stitched image is 768×768, and the second preset resolutions corresponding to the three facial images are 768×384, 384×384, and 384×384, respectively. When the number of at least one target object is 4, the resolution of the multi-person stitched image is 1024×1024, and the second preset resolutions corresponding to each facial image are 512×512, respectively.
[0124] It should be noted that, by compressing the facial region of the target object to the second preset resolution before splicing, the terminal can ensure that the size and proportion of each target object in the final image are relatively balanced, avoiding the problem of poor image processing effect caused by the size difference of the original facial region. At the same time, since the resolution of the facial region of each target object is compressed, the amount of data processed by the terminal is reduced, the demand for computing resources is reduced, and the image processing process is faster and smoother, thereby improving the overall image processing efficiency.
[0125] In step S304, the terminal downsamples the first image to be processed by using a target image generation model to obtain a first intermediate image of a target resolution.
[0126] In the embodiment of the present disclosure, the terminal downsamples the first image in the same manner as step S201, which will not be described in detail here.
[0127] To facilitate the description of the process of downsampling the first image by the terminal through the target image generation model, see Figure 4 As shown, Figure 4 401 is a schematic diagram of an image generation model according to an exemplary embodiment, wherein 401 is a first image and 402 is a first intermediate image.
[0128] Optionally, the resolution of the first image 401 is usually set to 512×512 or 640×640. Taking 512×512 as an example, the terminal downsamples the first image 401 to obtain a first intermediate image 402, and the resolution of the first intermediate image 402 is 256×256.
[0129] In step S305, the terminal performs feature extraction and upsampling on the first intermediate image through a target image generation model to obtain a second intermediate image, wherein the color channel value of the second intermediate image is used to indicate the contour information of the face of at least one target object, and the transparency channel value of the second intermediate image is used to indicate the texture information of the face of at least one target object.
[0130] In the disclosed embodiment, the terminal performs feature extraction and upsampling on the first intermediate image in the same manner as step S202, which will not be elaborated herein.
[0131] To facilitate the description of the process of the terminal performing feature extraction and upsampling on the first intermediate image through the target image generation model, see Figure 4 As shown, 402 is a first intermediate image, 403 is used to indicate a plurality of residual convolution modules for feature extraction. 404 is an intermediate image without upsampling. 405 is a second intermediate image. The first intermediate image 402 is an RGB image with three channels, and the intermediate image 404 without upsampling and the second intermediate image 405 are both RGBA images with four channels.
[0132] For example, the resolution of the first intermediate image 402 is 256×256. The terminal performs feature extraction on the first intermediate image 402, and obtains an intermediate image 404 that has not been upsampled, and the resolution is 256×256. The terminal upsamples the intermediate image 404 that has not been upsampled, and obtains a second intermediate image 405 that has a resolution of 512×512.
[0133] It should be noted that the multiple convolution modules include multiple encoders, such as encoder 1, encoder 2, encoder 3 and encoder 4; the convolution module includes multiple decoders, such as decoder 1, decoder 2, decoder 3. In other words, the multiple convolution modules are divided into multiple levels. When the target image generation model processes the first intermediate image, the terminal uses multiple convolution modules to process the information of each frequency band layer by layer. In the low frequency band, the processing performed by the terminal includes but is not limited to skin color uniformity and removal of large area dirt. In the medium frequency band, the processing performed by the terminal includes but is not limited to removing blemishes and retaining the original structure. In the high frequency band, the processing performed by the terminal includes but is not limited to enhancing skin details and removing blemish traces. Optionally, there is a jump connection mechanism between the encoder and the decoder, that is, there is a ResPath structure in the multiple convolution modules, which is used to fuse the information between different levels of the multiple convolution modules. Correspondingly, the decoder contains a residual block, so that the decoder receives information such as feature maps from the corresponding encoder through the jump connection mechanism. The above structure is conducive to gradient back propagation and model convergence during training.
[0134] In step S306, the terminal determines a first fusion coefficient and a second fusion coefficient based on a transparency channel value of the second intermediate image by using a target image generation model.
[0135] In the embodiment of the present disclosure, the terminal determines the first fusion coefficient and the second fusion coefficient in the same manner as step S203, which will not be described in detail here.
[0136] In some embodiments, for any pixel in the second intermediate image, the terminal determines the transparency channel value of the pixel as the first fusion coefficient corresponding to the pixel, and the terminal determines the difference between 1 and the transparency channel value of the pixel as the second fusion coefficient corresponding to the pixel. It should be noted that the terminal determines the first fusion coefficient and the second fusion coefficient corresponding to each pixel through the transparency channel value of the second intermediate image, thereby realizing the control of the degree of fusion of the first image and the second intermediate image. At the same time, since the change of the transparency channel value is usually continuous, it is possible to ensure a smooth transition between different areas of the image, avoid the stiffness of the fusion boundary, and make the image more natural. The above method does not require complex algorithms or additional computing resources, thereby improving the efficiency of image processing.
[0137] In step S307, the terminal generates a target image model and fuses the color channel values of the first image and the color channel values of the second intermediate image based on the first fusion coefficient and the second fusion coefficient to obtain a second image, wherein the facial features of at least one target object in the second image are different from the facial features of at least one target object in the first image.
[0138] In the embodiment of the present disclosure, the terminal fuses the color channel value of the first image with the color channel value of the second intermediate image in the same manner as step S204, which will not be described in detail herein.
[0139] In some embodiments, the first fusion coefficient and the second fusion coefficient act on the second intermediate image and the first image respectively. Accordingly, for any pixel point in the second intermediate image, the terminal multiplies the first fusion coefficient corresponding to the pixel point and the multiple color channel values of the pixel point in the second intermediate image respectively to obtain multiple first intermediate values; the terminal multiplies the second fusion coefficient corresponding to the pixel point and the multiple color channel values of the pixel point in the first image respectively to obtain multiple second intermediate values; the terminal adds the multiple first intermediate values and the second intermediate values respectively to obtain multiple color channel values of the pixel point in the second image.
[0140] It should be noted that the terminal achieves the fusion of the first image and the second intermediate image by mixing each color channel according to the fusion coefficient. The above method ensures a smooth transition between different areas in the image. At the same time, since the fusion algorithm for the first image and the second intermediate image is relatively simple, it also guarantees the overall processing efficiency and provides a fast and high-quality image processing function. At the same time, during the training process, the image generation model fuses the feature extraction and upsampled image with the image of the input model, which helps the model converge quickly.
[0141] In some embodiments, the terminal pastes each facial region in the second image back to the original image to obtain an image after beautifying the facial region. It should be noted that since the resolution of the facial region in the original image may be greater than the resolution required by the input image of the target image generation model, the downsampling operation performed by the terminal on the facial region before the facial beautification is performed by the target image generation model will cause a loss of clarity in the facial region.
[0142] In some embodiments, after performing facial beautification through the target image generation model, the terminal upsamples the second image to the same resolution as the facial area, and upsamples the first image to the same resolution as the facial area. At this time, the terminal determines the difference between the image of the facial area and the upsampled first image, and the difference is used to indicate the loss of clarity of the facial area caused by the downsampling operation. The terminal determines the sum of the difference and the upsampled second image as the image to be pasted back to the original image. It should be noted that the terminal reduces the loss of clarity in the overall facial beautification process and improves the quality of image processing through the above method.
[0143] In some embodiments, during the training of the target image generation model, an image discrimination model is used to assist in training the image generation model, so as to determine the target image generation model when preset conditions are met. The image discrimination model may also be referred to as a discriminator, and the image generation model may also be referred to as a generator. The image discrimination model and the image generation model constitute a generative adversarial network (GAN).
[0144] It should be noted that the training data set includes sample images, label images, and mask images. The sample image refers to the face image to be beautified, that is, the unprocessed original image; the label image refers to the reference image, that is, the image containing the reference features of the face, and the label image is usually an artificially annotated image; the mask image is an image that assists the model in learning complex areas, that is, the image that retains the boundary features of the face. For the convenience of description, the sample image is called I, the label image is called L, and the mask image is called I m It should be noted that in the training data set, the sample images, label images, and mask images are all in one-to-one correspondence.
[0145] For the convenience of describing the mask image, see Figure 5 As shown, Figure 5is a schematic diagram of a mask image according to an exemplary embodiment. In order to construct a mask image corresponding to each sample image, the terminal obtains a target number of key points at the facial contour in the sample image through a facial association point detection algorithm. For example, the target number is set to 32, see Figure 5 As shown in (a), the target number of associated points are numbered 0-31. For ease of description, the target number of key points are called external points. Then, the terminal takes each external point as the starting point and the point numbered 32 as the end point to construct multiple line segments. For each line segment, the position corresponding to the length of the target ratio is selected as the internal point with the external point as the starting point, see Figure 5 (b) is shown. For example, the target ratio is set to 0.13. At this time, the terminal connects multiple external points and multiple internal points, and the area surrounded by the curves corresponding to the external points and the curves corresponding to the internal points is called the facial contour point masking area. The facial contour point masking area is represented by a value of 255, and the other areas are represented by a value of 0, and the masked image corresponding to the sample image is obtained, see Figure 5 Optionally, the terminal performs Gaussian filtering before determining the mask image to eliminate noise interference.
[0146] In some embodiments, after the pixel values of the mask image are normalized, the pixel values in the mask image are divided into 1 and -1. Accordingly, the pixel value of the first type of area in the mask image is 1, and the first type of area is the face boundary area, and the pixel value of the second type of area in the mask image is -1, and the first type of area is other areas in the mask image except the first type of area.
[0147] It should be noted that the mask image indicates the facial boundary area and other areas through the difference in pixel values. By clearly distinguishing the facial boundary and other areas, the image generation model can achieve more accurate image processing without introducing complex data, and focus on the image processing effect of the facial boundary area, which improves the performance and practicality of the image generation model while ensuring the demand for computing resources.
[0148] It should be noted that the above is only an exemplary description of the mask image that retains the facial boundary features. Optionally, the mask image can also retain the boundary features of the facial features such as the eye boundary features, eyebrow boundary features, mouth boundary features, and nose boundary features. At this time, the terminal determines the mask area in the same way as the above process, which will not be repeated here. In other words, the mask image is used to mark complex areas such as facial boundaries or facial feature boundaries.
[0149] In order to enable the target image generation model to process the faces of multiple target objects at the same time. In addition to a single face image, the training data set also includes multiple face images. Among them, since the resolution of the input image of the image generation model is set to 512×512 and 640×640. In order to ensure that reasonable scaling and cropping space is reserved, and to ensure that the face of each target object in multiple face images is of moderate size. Therefore, the resolution of a single face image is set to 640×640, the resolution of two face images is set to 640×640, the resolution of three face images is set to 768×768, and the resolution of four face images is set to 1024×1024.
[0150] Optionally, in the training data set, there are 26,526 single facial images, 10,000 two facial images, 6,000 three facial images, and 6,000 four facial images. It should be noted that the multiple facial images are obtained by randomly selecting a single facial image in the training data set, and then compressing and splicing. Optionally, the compression and splicing method is the same as step S303, and will not be repeated here. It should be noted that by constructing a data enhancement method for multiple facial images in the training data set, the image generation model has the function of beautifying multiple faces in parallel, and compared to beautifying a single face, there is no increase in any amount of calculation, which improves the image processing efficiency of the image generation model, improves the versatility and flexibility of the model, and facilitates image processing such as facial beautification in scenes such as single or multi-person live broadcasts and single or multi-person selfies in mobile terminals.
[0151] For the purpose of describing the multiple face representation, see Figure 6 As shown, Figure 6 is a schematic diagram of multiple facial images according to an exemplary embodiment. Figure 6 (a) is the masked image for a single face. Figure 6 (b) is the masked image in the case of two faces. Figure 6 (c) is the masked image for three faces. Figure 6 (d) is the masked image in the case of four faces.
[0152] In some embodiments, the steps for training the image generation model are shown in (1)-(3) below.
[0153] (1) In each iteration process, the terminal discriminates the output image and the sample images in the training data set through the image discrimination model to obtain a discrimination result; the terminal confirms the loss value corresponding to the second loss function based on the discrimination result, the output image, and the sample image; and updates the model parameters of the image discrimination model based on the loss value corresponding to the second loss function.
[0154] For the convenience of describing the image discrimination model, see Figure 7 As shown, Figure 7 It is a schematic diagram of an image discrimination model according to an exemplary embodiment. Among them, the discriminator adopts UNet Full Discriminator, and the regularization uses Spectral Norm. The discriminator is a specific discriminator based on the UNet structure. Among them, parameters such as (64, 128,, 128) are used to represent the number of channels, height, and width of the feature map in the structure. Spectral normalization is a weight regularization technology that improves the stability of the training process by normalizing the weight matrix. Optionally, the second loss function is MSE Loss (Mean Squared Error Loss).
[0155] It should be noted that during the training process of the image generation model, the terminal can distinguish between the output image and the sample image by introducing the image discrimination model and discriminating the output image and the sample image in the training data set through the image discrimination model. Through multiple iterations of training, the discrimination model can gradually improve its ability to discriminate the generated image. The above method prompts the image generation model to generate images that are more difficult to be distinguished by the image discrimination model, thereby enhancing the image processing effect, promoting the updating of model parameters, and improving the performance and practicality of the image generation model.
[0156] (2) During each iteration, the terminal processes the sample image in the training data set through the image generation model to obtain an output image; the terminal determines the loss value corresponding to the first loss function based on the output image, the label image in the training data set, and the mask image in the training data set; the terminal updates the model parameters of the image generation model based on the loss value corresponding to the first loss function. Optionally, during the training of the image generation model, the clarity and generalization ability of the model effect are further improved by not setting a regularization layer, extracting features before the activation layer, and calculating the perceptual loss.
[0157] It should be noted that the label image contains facial reference features, so that the image generation model can learn to generate images with facial reference features through the training process; the mask image retains the facial boundary features, so that the image generation model focuses on more complex areas such as facial boundaries during the generation process. Through the above training method, the terminal ensures the image beautification performance of the image generation model and improves the image generation quality.
[0158] In some embodiments, the terminal determines the loss value corresponding to the first loss function in combination with the masked image. Accordingly, for each masked image in the training data set, the terminal determines the intermediate image corresponding to the masked image, the color channel value of the pixel in the masked image is between -1 and 1, and the color channel value of the pixel in the intermediate image corresponding to the masked image is between 0 and 1; the terminal determines the loss value corresponding to the first loss function based on the loss value corresponding to the third loss function and the intermediate image corresponding to the masked image, and the third loss function is used to indicate the error between the output image and the label image.
[0159] The second loss function is GMask Loss. The third loss function is L1 Loss (mean absolute error). In addition, the terminal can also update the model parameters through Perceptual Loss (perceptual loss), which is not limited here.
[0160] For ease of description, the loss value of the first loss function is called L gmask . Correspondingly, the formula of the first loss function is as follows.
[0161] L gmask =∑I gm L1(pred,L) / ∑I gm
[0162] Among them, L1 is the loss value of the third loss function, pred is the output image of the image generation model, L is the label image corresponding to the mask image, and I gm is the intermediate image corresponding to the mask image.
[0163] To facilitate the description of the intermediate image corresponding to the masked image, see the following formula.
[0164] I gm =I m *0.5+0.5
[0165] Among them, I m To mask the image.
[0166] Correspondingly, when the pixel value in the masked image is 1, it can be obtained from the above formula that the pixel value in the intermediate image corresponding to the masked image is 1. At this time, after multiplying it with the loss value of the third loss function, the obtained value is the loss value, indicating that the loss values corresponding to complex areas such as facial boundaries or facial feature boundaries are retained; when the pixel value in the masked image is -1, it can be obtained from the above formula that the pixel value in the intermediate image corresponding to the masked image is 0. At this time, after multiplying it with the loss value of the third loss function, the obtained value is 0, indicating that the loss values of areas other than complex areas such as facial boundaries or facial feature boundaries are masked.
[0167] It should be noted that the terminal converts the pixel values in the mask image from the range of -1 to 1 to the range of 0 to 1 in the intermediate image, so that in the subsequent process of determining the loss value of the first function, it can focus on the part of the facial boundary, avoiding the interference of redundant information outside the facial boundary, which is conducive to the image generation model learning specific feature representations during the training process, thereby enhancing the image processing effect and improving the performance and practicality of the image generation model. In other words, through the third loss function, the terminal solves the beautification problem in complex areas such as facial boundaries or facial features boundaries, so that the terminal can still achieve effective beautification effects in complex areas, improving the quality and consistency of overall image processing.
[0168] In some embodiments, the third loss function can be replaced by OHEM (Online Hard Example Mining) loss. The above method can improve the learning effect of the image generation model on difficult samples (i.e., samples that are difficult for the model to correctly classify), thereby improving the overall performance. At this time, based on the distance sorting of all pixels in the Batch, different weights are assigned according to the distance size to achieve online hard example mining.
[0169] (3) In any iteration process, when the number of iterations meets the preset number, the image generation model after the model parameters are updated is determined as the target image generation model. By setting the preset number of times during the iteration process and determining the target image generation model when the conditions are met, the training process of the image generation model can be terminated in time, avoiding the waste of computing resources and improving the performance and practicality of the image generation model. It should be noted that the above-mentioned condition for stopping iteration is only an exemplary description, and the embodiments of the present disclosure are not limited to this.
[0170] The disclosed embodiment provides an image processing method, in which a terminal obtains a first intermediate image of a target resolution by downsampling a first image to be processed, obtains a second intermediate image containing contour information and texture information of the face of at least one target object by performing feature extraction and upsampling on the first intermediate image, and then fuses the second intermediate image with the first image according to the transparency channel value to obtain a second image after face beautification. In the above manner, the terminal reduces the amount of model calculation while ensuring the beautification effect and clarity, so that in a real-time video scene, the terminal can beautify the face area in the video in real time and efficiently.
[0171] All the above optional technical solutions can be arbitrarily combined to form optional embodiments of the present disclosure, and will not be described in detail here.
[0172] Figure 8 FIG. 1 is a block diagram of an image processing apparatus according to an exemplary embodiment. Figure 8As shown, the device includes: a processing unit 801, a first determining unit 802 and a fusion unit 803.
[0173] The processing unit 801 is configured to downsample a first image to be processed to obtain a first intermediate image of a target resolution, wherein the first image includes a face of at least one target object;
[0174] The processing unit 801 is further configured to perform feature extraction and up-sampling on the first intermediate image to obtain a second intermediate image, wherein a color channel value of the second intermediate image is used to indicate contour information of a face of at least one target object, and a transparency channel value of the second intermediate image is used to indicate texture information of the face of the at least one target object;
[0175] A first determining unit 802 is configured to determine a first fusion coefficient and a second fusion coefficient based on a transparency channel value of the second intermediate image;
[0176] The fusion unit 803 is configured to fuse the color channel values of the first image and the color channel values of the second intermediate image based on the first fusion coefficient and the second fusion coefficient to obtain a second image, wherein the facial features of at least one target object in the second image are different from the facial features of at least one target object in the first image.
[0177] In some embodiments, the first determination unit 802 is configured to determine, for any pixel in the second intermediate image, the transparency channel value of the pixel as the first fusion coefficient corresponding to the pixel, and determine the difference between 1 and the transparency channel value of the pixel as the second fusion coefficient corresponding to the pixel.
[0178] In some embodiments, the fusion unit 803 is configured to, for any pixel in the second intermediate image, multiply the first fusion coefficient corresponding to the pixel by the multiple color channel values of the pixel in the second intermediate image to obtain multiple first intermediate values; multiply the second fusion coefficient corresponding to the pixel by the multiple color channel values of the pixel in the first image to obtain multiple second intermediate values; and add the multiple first intermediate values and the second intermediate values to obtain multiple color channel values of the pixel in the second image.
[0179] In some embodiments, Fig. 9 is a block diagram of another image processing device according to an exemplary embodiment. Fig. 9 As shown, the device also includes:
[0180] A second determining unit 901 is configured to determine at least one target object from the original image;
[0181] The extraction unit 902 is configured to perform face extraction on at least one target object to obtain a face region of each target object;
[0182] The stitching unit 903 is configured to stitch the facial region of at least one target object to obtain a first image.
[0183] In some embodiments, the resolution of the first image is a first preset resolution;
[0184] The stitching unit 903 is configured to determine a second preset resolution based on the number of at least one target object, where the number of pixels contained in the image of the second preset resolution is the ratio of the number of pixels contained in the image of the first preset resolution to the number of at least one target object; for any target object, based on the second preset resolution, compress the facial area of the target object to obtain a facial image of the target object, where the resolution of the facial image of the target object is the second preset resolution; and stitch the facial image of at least one target object to obtain a first image.
[0185] In some embodiments, the image processing method is implemented by generating a target image model, and the apparatus further comprises:
[0186] The updating unit 904 is configured to process the sample image in the training data set through the image generation model in each iteration process to obtain an output image, where the sample image is an unprocessed original image;
[0187] The updating unit 904 is further configured to determine a loss value corresponding to the first loss function based on the output image, a label image in the training data set, and a mask image in the training data set, wherein the label image is an image containing facial reference features, and the mask image is an image retaining facial boundary features;
[0188] The updating unit 904 is further configured to update the model parameters of the image generation model based on the loss value corresponding to the first loss function.
[0189] In some embodiments, the updating unit 904 is further configured to discriminate the output image and the sample image in the training data set through the image discrimination model during each iteration to obtain a discrimination result; based on the discrimination result, the output image, and the sample image, confirm the loss value corresponding to the second loss function; and based on the loss value corresponding to the second loss function, update the model parameters of the image discrimination model.
[0190] In some embodiments, the updating unit 904 is further configured to, during any iteration process, determine the image generation model after updating the model parameters as the target image generation model when the number of iterations meets a preset number.
[0191] In some embodiments, the updating unit 904 is further configured to determine, for each masked image in the training data set, an intermediate image corresponding to the masked image, the color channel values of the pixels in the masked image are between -1 and 1, and the color channel values of the pixels in the intermediate image corresponding to the masked image are between 0 and 1; based on the loss value corresponding to the third loss function and the intermediate image corresponding to the masked image, determine the loss value corresponding to the first loss function, and the third loss function is used to indicate the error between the output image and the label image.
[0192] In some embodiments, the pixel value of the first type of area in the mask image is 1, the first type of area is the face boundary area, the pixel value of the second type of area in the mask image is -1, and the first type of area is other areas in the mask image except the first type of area.
[0193] The disclosed embodiment provides an image processing device, wherein the terminal obtains a first intermediate image of a target resolution by downsampling the first image to be processed, obtains a second intermediate image containing contour information and texture information of the face of at least one target object by performing feature extraction and upsampling on the first intermediate image, and then obtains a second image after face beautification by fusing the second intermediate image with the first image according to the transparency channel value. Through the above device, the terminal reduces the amount of model calculation while ensuring the beautification effect and clarity, so that in a real-time video scene, the terminal can beautify the face area in the video in real time and efficiently.
[0194] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure.
[0195] It should be noted that the image processing device provided in the above embodiment is only illustrated by the division of the above functional units. In actual applications, the above functions can be assigned to different functional units as needed, that is, the internal structure of the electronic device is divided into different functional units to complete all or part of the functions described above. In addition, the image processing device provided in the above embodiment and the image processing method embodiment belong to the same concept, and the specific implementation process is detailed in the method embodiment, which will not be repeated here.
[0196] Regarding the image processing device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.
[0197] Fig.10 1 is a block diagram of an electronic device according to an exemplary embodiment. Generally, the electronic device 1000 includes: a processor 1001 and a memory 1002 .
[0198] The processor 1001 may include one or more processing cores, such as a 4-core processor, a 10-core processor, etc. The processor 1001 may be implemented in at least one hardware form of DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), and PLA (Programmable Logic Array). The processor 1001 may also include a main processor and a coprocessor. The main processor is a processor for processing data in the awake state, also known as a CPU (Central Processing Unit); the coprocessor is a low-power processor for processing data in the standby state. In some embodiments, the processor 1001 may be integrated with a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the display screen. In some embodiments, the processor 1001 may also include an AI (Artificial Intelligence) processor, which is used to process computing operations related to machine learning.
[0199] The memory 1002 may include one or more computer-readable storage media, which may be non-transitory. The memory 1002 may also include a high-speed random access memory, and a non-volatile memory, such as one or more disk storage devices, flash memory storage devices. In some embodiments, the non-transitory computer-readable storage medium in the memory 1002 is used to store at least one program code, which is used to be executed by the processor 1001 to implement the image processing method provided by the method embodiment of the present disclosure.
[0200] In some embodiments, the electronic device 1000 may further optionally include: a peripheral device interface 1003 and at least one peripheral device. The processor 1001, the memory 1002 and the peripheral device interface 1003 may be connected via a bus or a signal line. Each peripheral device may be connected to the peripheral device interface 1003 via a bus, a signal line or a circuit board. Specifically, the peripheral device includes: at least one of a radio frequency circuit 1004, a display screen 1005, a camera assembly 1006, an audio circuit 1007 and a power supply 1008.
[0201] The peripheral device interface 1003 may be used to connect at least one peripheral device related to I / O (Input / Output) to the processor 1001 and the memory 1002. In some embodiments, the processor 1001, the memory 1002, and the peripheral device interface 1003 are integrated on the same chip or circuit board; in some other embodiments, any one or two of the processor 1001, the memory 1002, and the peripheral device interface 1003 may be implemented on a separate chip or circuit board, which is not limited in this embodiment.
[0202] The radio frequency circuit 1004 is used to receive and transmit RF (Radio Frequency) signals, also known as electromagnetic signals. The radio frequency circuit 1004 communicates with communication networks and other communication devices through electromagnetic signals. The radio frequency circuit 1004 converts electrical signals into electromagnetic signals for transmission, or converts received electromagnetic signals into electrical signals. Optionally, the radio frequency circuit 1004 includes: an antenna system, an RF transceiver, one or more amplifiers, a tuner, an oscillator, a digital signal processor, a codec chipset, a user identity module card, and the like. The radio frequency circuit 1004 can communicate with other electronic devices through at least one wireless communication protocol. The wireless communication protocol includes, but is not limited to: a metropolitan area network, various generations of mobile communication networks (2G, 3G, 4G and 5G), a wireless local area network and / or a WiFi (Wireless Fidelity) network. In some embodiments, the radio frequency circuit 1004 may also include circuits related to NFC (Near Field Communication), which is not limited in the present disclosure.
[0203] The display screen 1005 is used to display a UI (User Interface). The UI may include graphics, text, icons, videos, and any combination thereof. When the display screen 1005 is a touch display screen, the display screen 1005 also has the ability to collect touch signals on the surface or above the surface of the display screen 1005. The touch signal can be input to the processor 1001 as a control signal for processing. At this time, the display screen 1005 can also be used to provide virtual buttons and / or virtual keyboards, also known as soft buttons and / or soft keyboards. In some embodiments, the display screen 1005 can be one, and the front panel of the electronic device 1000 is set; in other embodiments, the display screen 1005 can be at least two, which are respectively set on different surfaces of the electronic device 1000 or are folded; in some other embodiments, the display screen 1005 can be a flexible display screen, which is set on the curved surface or folded surface of the electronic device 1000. Even, the display screen 1005 can also be set to a non-rectangular irregular shape, that is, a special-shaped screen. The display screen 1005 can be made of materials such as LCD (Liquid Crystal Display) and OLED (Organic Light-Emitting Diode).
[0204] The camera assembly 1006 is used to capture images or videos. Optionally, the camera assembly 1006 includes a front camera and a rear camera. Typically, the front camera is arranged on the front panel of the electronic device, and the rear camera is arranged on the back of the electronic device. In some embodiments, there are at least two rear cameras, which are any one of a main camera, a depth of field camera, a wide-angle camera, and a telephoto camera, so as to realize the fusion of the main camera and the depth of field camera to realize the background blur function, the fusion of the main camera and the wide-angle camera to realize the panoramic shooting and VR (Virtual Reality) shooting function or other fusion shooting functions. In some embodiments, the camera assembly 1006 may also include a flash. The flash can be a monochrome temperature flash or a dual-color temperature flash. A dual-color temperature flash refers to a combination of a warm light flash and a cold light flash, which can be used for light compensation at different color temperatures.
[0205] The audio circuit 1007 may include a microphone and a speaker. The microphone is used to collect sound waves from the user and the environment, and convert the sound waves into electrical signals and input them into the processor 1001 for processing, or input them into the radio frequency circuit 1004 to achieve voice communication. For the purpose of stereo acquisition or noise reduction, there may be multiple microphones, which are respectively arranged at different parts of the electronic device 1000. The microphone may also be an array microphone or an omnidirectional acquisition microphone. The speaker is used to convert the electrical signal from the processor 1001 or the radio frequency circuit 1004 into sound waves. The speaker may be a traditional film speaker or a piezoelectric ceramic speaker. When the speaker is a piezoelectric ceramic speaker, it can not only convert the electrical signal into sound waves audible to humans, but also convert the electrical signal into sound waves inaudible to humans for purposes such as ranging. In some embodiments, the audio circuit 1007 may also include a headphone jack.
[0206] The power supply 1008 is used to power various components in the electronic device 1000. The power supply 1008 can be an alternating current, a direct current, a disposable battery, or a rechargeable battery. When the power supply 1008 includes a rechargeable battery, the rechargeable battery can support wired charging or wireless charging. The rechargeable battery can also be used to support fast charging technology.
[0207] Those skilled in the art will understand that Fig.10 The structure shown in the figure does not constitute a limitation on the electronic device 1000, and the electronic device 1000 may include more or less components than those shown in the figure, or combine some components, or adopt a different component arrangement.
[0208] In an exemplary embodiment, a computer-readable storage medium including instructions is also provided, such as a memory 1002 including instructions, and the instructions can be executed by a processor 1001 of an electronic device 1000 to complete the above-mentioned image processing method. Alternatively, the computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.
[0209] A computer program product comprises a computer program, and when the computer program is executed by a processor, the image processing method is implemented.
[0210] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the invention disclosed herein. The present disclosure is intended to cover any variations, uses or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary techniques in the art that are not disclosed in the present disclosure. The description and examples are to be considered exemplary only, and the true scope and spirit of the present disclosure are indicated by the following claims.
[0211] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.
Claims
1. An image processing method, It is characterized in that The method comprises: Downsampling the first image to be processed to obtain a first intermediate image of a target resolution, wherein the first image includes a face of at least one target object; Performing feature extraction and upsampling on the first intermediate image to obtain a second intermediate image, wherein a color channel value of the second intermediate image is used to indicate contour information of the face of the at least one target object, and a transparency channel value of the second intermediate image is used to indicate texture information of the face of the at least one target object; Determining a first fusion coefficient and a second fusion coefficient based on a transparency channel value of the second intermediate image; Based on the first fusion coefficient and the second fusion coefficient, the color channel values of the first image and the color channel values of the second intermediate image are fused to obtain a second image, and the facial features of the at least one target object in the second image are different from the facial features of the at least one target object in the first image.
2. The image processing method according to claim 1, It is characterized in that The determining, based on the transparency channel value of the second intermediate image, the first fusion coefficient and the second fusion coefficient comprises: For any pixel in the second intermediate image, the transparency channel value of the pixel is determined as the first fusion coefficient corresponding to the pixel, and the difference between 1 and the transparency channel value of the pixel is determined as the second fusion coefficient corresponding to the pixel.
3. The image processing method according to claim 1, It is characterized in that The step of fusing the color channel value of the first image and the color channel value of the second intermediate image based on the first fusion coefficient and the second fusion coefficient to obtain a second image includes: For any pixel point in the second intermediate image, multiply the first fusion coefficient corresponding to the pixel point and multiple color channel values of the pixel point in the second intermediate image respectively to obtain multiple first intermediate values; Multiplying the second fusion coefficient corresponding to the pixel point and the multiple color channel values of the pixel point in the first image respectively to obtain multiple second intermediate values; The multiple first intermediate values and the second intermediate values are added together to obtain multiple color channel values of the pixel points in the second image.
4. The image processing method according to claim 1, It is characterized in that The method further comprises: determining the at least one target object from the original image; Performing face extraction on the at least one target object respectively to obtain a face region of each target object; The facial region of the at least one target object is spliced to obtain the first image.
5. The image processing method according to claim 4, It is characterized in that The resolution of the first image is a first preset resolution; and the step of splicing the facial region of the at least one target object to obtain the first image includes: Based on the number of the at least one target object, a second preset resolution is determined, wherein the number of pixels included in the image of the second preset resolution is a ratio of the number of pixels included in the image of the first preset resolution to the number of the at least one target object; For any target object, based on the second preset resolution, compressing the face area of the target object to obtain a face image of the target object, wherein the resolution of the face image of the target object is the second preset resolution; The facial images of the at least one target object are spliced to obtain the first image.
6. The image processing method according to claim 1, It is characterized in that The image processing method is implemented by a target image generation model, and the training steps of the target image generation model include: In each iteration, the sample image in the training data set is processed by the image generation model to obtain an output image, where the sample image is an unprocessed original image; Determine a loss value corresponding to a first loss function based on the output image, a label image in the training data set, and a mask image in the training data set, wherein the label image is an image containing facial reference features, and the mask image is an image retaining facial boundary features; Based on the loss value corresponding to the first loss function, the model parameters of the image generation model are updated.
7. The image processing method according to claim 6, further comprising: include: In each iteration, the output image and the sample images in the training data set are discriminated by the image discrimination model to obtain a discrimination result; Based on the discrimination result, the output image, and the sample image, determining a loss value corresponding to a second loss function; Based on the loss value corresponding to the second loss function, the model parameters of the image discrimination model are updated.
8. The image processing method according to claim 6, It is characterized in that The method further comprises: In any iteration process, when the number of iterations meets the preset number, the image generation model after updating the model parameters is determined as the target image generation model.
9. The image processing method according to claim 6, It is characterized in that The determining, based on the output image, the label image in the training data set, and the mask image in the training data set, a loss value corresponding to the first loss function comprises: For each masked image in the training data set, determining an intermediate image corresponding to the masked image, wherein the color channel value of a pixel in the masked image is between -1 and 1, and the color channel value of a pixel in the intermediate image corresponding to the masked image is between 0 and 1; Based on the loss value corresponding to a third loss function and the intermediate image corresponding to the masked image, a loss value corresponding to the first loss function is determined, wherein the third loss function is used to indicate an error between the output image and the label image.
10. The image processing method according to claim 6, It is characterized in that The pixel value of the first type of area in the mask image is 1, and the first type of area is the face boundary area. The pixel value of the second type of area in the mask image is -1, and the first type of area is other areas in the mask image except the first type of area.
11. An image processing device, It is characterized in that The device comprises: a processing unit configured to downsample a first image to be processed to obtain a first intermediate image of a target resolution, wherein the first image includes a face of at least one target object; The processing unit is further configured to perform feature extraction and up-sampling on the first intermediate image to obtain a second intermediate image, wherein a color channel value of the second intermediate image is used to indicate contour information of the face of the at least one target object, and a transparency channel value of the second intermediate image is used to indicate texture information of the face of the at least one target object; a first determining unit, configured to determine a first fusion coefficient and a second fusion coefficient based on a transparency channel value of the second intermediate image; A fusion unit is configured to fuse the color channel values of the first image and the color channel values of the second intermediate image based on the first fusion coefficient and the second fusion coefficient to obtain a second image, wherein the facial features of the at least one target object in the second image are different from the facial features of the at least one target object in the first image.
12. An electronic device, It is characterized in that The electronic device comprises: one or more processors; a memory for storing program code executable by the processor; The processor is configured to execute the program code to implement the image processing method according to any one of claims 1 to 10.
13. A computer-readable storage medium, It is characterized in that When the instructions in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device is enabled to perform the image processing method as described in any one of claims 1 to 10.
14. A computer program product, It is characterized in that The computer program product comprises a computer program / instruction, and when the computer program / instruction is executed by a processor, the image processing method according to any one of claims 1 to 10 is implemented.
