Image processing method and apparatus
By using the target area mask image and the attention mask image for optimization in the image processing model, the problem of insufficient photo detail processing in the existing technology is solved, especially in wrinkle processing, and the processing effect is significantly improved.
Patent Information
- Application Number
- PCT/CN2024/076605
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-02-24
- Filing Date
- 2024-02-07
- Publication Date
- 2024-08-29
AI Technical Summary
When existing beautification software beautifies photos, they often process them as a whole, resulting in poor detail processing in some areas, especially in areas such as deep wrinkles.
By obtaining the mask image and attention mask image of the target area, the image processing model is optimized so that the model can focus more on the processing of the target area and improve the accuracy of detail processing.
It achieves targeted processing of the target area and improves the accuracy and detail processing effect of the image processing model. Especially in tasks such as wrinkle removal, it can remove wrinkles more effectively and improve the processing effect.
Smart Images

Figure CN2024076605_29082024_PF_FP_ABST
Abstract
Description
Image processing method and device
[0001] This application claims priority to Chinese Patent Application No. 202310187657.2 filed on February 24, 2023, and the contents of the above-mentioned Chinese patent application disclosure are hereby incorporated by reference in their entirety as a part of this application. Technical Field
[0002] The present disclosure relates to an image processing method and device. Background Art
[0003] With the development of smart devices, more and more people are using them to take photos. However, due to issues with shooting technology or conditions, photos often need to be beautified. Generally, when beautifying photos using beautification software, the software tends to beautify the photo as a whole, resulting in poor processing of details in some areas of the photo. The beautification capability needs to be improved.
[0004] Summary of the Invention
[0005] The embodiments of the present disclosure at least provide an image processing method and apparatus.
[0006] In a first aspect, an embodiment of the present disclosure provides an image processing method, comprising:
[0007] acquiring a first image;
[0008] Processing the target area of the first image to obtain a first corrected image, and determining a target area mask image corresponding to the target area;
[0009] Input the first image into an image processing model to obtain a first predicted image and an attention mask image corresponding to the first predicted image; wherein the image processing model is optimized based on the first corrected image, the first predicted image, the target area mask image and the attention mask image.
[0010] In a second aspect, an embodiment of the present disclosure further provides an image processing device, including:
[0011] An acquisition module, configured to acquire a first image;
[0012] a determination module, configured to process the target area of the first image to obtain a first corrected image, and determine a target area mask image corresponding to the target area;
[0013] A processing module is used to input the first image into an image processing model to obtain a first predicted image and an attention mask image corresponding to the first predicted image; wherein the image processing model is optimized based on the first corrected image, the first predicted image, the target area mask image and the attention mask image.
[0014] In a third aspect, an embodiment of the present disclosure further provides a computer device comprising: a processor, a memory and a bus, wherein the memory stores machine-readable instructions executable by the processor, and when the computer device is running, the processor and the memory communicate via the bus, and when the machine-readable instructions are executed by the processor, the steps of the above-mentioned first aspect or any possible implementation of the first aspect are performed.
[0015] In a fourth aspect, an embodiment of the present disclosure further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the above-mentioned first aspect or any possible implementation of the first aspect are executed.
[0016] In order to make the above-mentioned objectives, features and advantages of the present disclosure more obvious and easy to understand, preferred embodiments are given below and described in detail with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] In order to more clearly illustrate the technical solutions of the embodiments of the present disclosure, the following briefly introduces the drawings required for use in the embodiments. The drawings herein are incorporated into and constitute a part of the specification. These drawings illustrate embodiments consistent with the present disclosure and, together with the specification, are used to illustrate the technical solutions of the present disclosure. It should be understood that the following drawings only illustrate certain embodiments of the present disclosure and should not be regarded as limiting the scope. For those of ordinary skill in the art, other relevant drawings can be obtained based on these drawings without inventive effort.
[0018] FIG1 shows a flow chart of an image processing method provided by an embodiment of the present disclosure;
[0019] FIG2a shows a schematic diagram of a target area mask image provided by an embodiment of the present disclosure;
[0020] FIG2 b shows a schematic diagram of an attention mask image provided by an embodiment of the present disclosure;
[0021] FIG3 shows a schematic diagram of an overall process of model optimization and model reasoning provided by an embodiment of the present disclosure;
[0022] FIG4 shows a schematic diagram of an image processing device provided by an embodiment of the present disclosure; and
[0023] FIG5 shows a schematic structural diagram of a computer device provided by an embodiment of the present disclosure. DETAILED DESCRIPTION
[0024] In order to make the purpose, technical solutions and advantages of the embodiments of the present disclosure clearer, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are only part of the embodiments of the present disclosure, not all of the embodiments. The components of the embodiments of the present disclosure generally described and shown in the drawings herein can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present disclosure provided in the drawings is not intended to limit the scope of the disclosure for which protection is sought, but merely represents selected embodiments of the present disclosure. Based on the embodiments of the present disclosure, all other embodiments obtained by those skilled in the art without making creative work are within the scope of protection of the present disclosure.
[0025] When beautifying a photo using beautifying software, the beautifying software often beautifies the photo as a whole, which results in poor detail processing of some areas of the photo.
[0026] For example, when beautifying a portrait photo, the processing capability for deep wrinkle areas, such as nasolabial folds and crow's feet, may be poor, which results in wrinkles still existing in the processed portrait photo and poor processing effect.
[0027] Based on this, the present disclosure provides an image processing method and device, which can supervise the attention mask image determined by the image processing model based on the target area mask image corresponding to the target area in the first image, thereby realizing attention correction of the image processing model during the image processing process, making the image processing model more focused on the processing of the target area, and improving the processing accuracy of the image processing model for the target area.
[0028] Furthermore, when performing image processing based on the image processing model in the method provided by the present disclosure, targeted processing of the target area can be achieved, thereby improving the accuracy of image detail processing.
[0029] It should be noted that similar reference numerals and letters denote similar items in the following drawings, and therefore, once an item is defined in one drawing, it does not need to be further defined or explained in subsequent drawings.
[0030] The term "and / or" herein simply describes an association relationship, indicating that three relationships can exist. For example, A and / or B can represent the existence of A alone, the simultaneous existence of A and B, and the existence of B alone. In addition, the term "at least one" herein refers to any combination of at least two of any one or more of a plurality of items. For example, "at least one of A, B, and C" can represent any one or more elements selected from the set consisting of A, B, and C.
[0031] It is understandable that before using the technical solutions disclosed in the various embodiments of this disclosure, the type, scope of use, usage scenarios, etc. of the personal information involved in this disclosure should be informed to the user and the user's authorization should be obtained in an appropriate manner in accordance with relevant laws and regulations.
[0032] For example, in response to a user's active request, a prompt message is sent to the user to clearly inform the user that the operation requested will require the acquisition and use of the user's personal information. This allows the user to independently choose whether to provide personal information to the electronic device, application, server, storage medium, or other software or hardware that performs the operations of the disclosed technical solution based on the prompt message.
[0033] As an optional but non-limiting implementation, in response to receiving a user's active request, the prompt information may be sent to the user in the form of a pop-up window, in which the prompt information may be presented in text form. Furthermore, the pop-up window may also contain a selection control for the user to select "agree" or "disagree" to provide personal information to the electronic device.
[0034] It is understandable that the above notification and user authorization process are merely illustrative and do not limit the implementation of the present disclosure. Other methods that comply with relevant laws and regulations may also be applied to the implementation of the present disclosure.
[0035] To facilitate understanding of this embodiment, an image processing method disclosed in an embodiment of the present disclosure is first introduced in detail. The execution subject of the image processing method provided in the embodiment of the present disclosure is generally a computer device with certain computing capabilities. The computer device includes, for example, a terminal device or a server or other processing device. The terminal device can be a user equipment (UE), a mobile device, a user terminal, a terminal, a cellular phone, a cordless phone, a personal digital assistant (PDA), a handheld device, a computing device, an in-vehicle device, a wearable device, etc. In some possible implementations, the image processing method can be implemented by a processor calling computer-readable instructions stored in a memory.
[0036] Referring to FIG1 , which is a flowchart of an image processing method according to an embodiment of the present disclosure, it should be noted that the following “optimization,” “adjustment,” and “training” can all be understood as adjusting the parameters of the model to improve the accuracy of the model.
[0037] The image processing method includes steps 101 to 103, wherein:
[0038] Step 101: Acquire a first image.
[0039] Step 102: Process the target area of the first image to obtain a first corrected image, and determine a target area mask image corresponding to the target area.
[0040] Step 103: Input the first image into an image processing model to obtain a first predicted image and an attention mask image corresponding to the first predicted image; wherein the image processing model is optimized based on the first corrected image, the first predicted image, the target area mask image, and the attention mask image.
[0041] The following is a detailed description of the above steps.
[0042] For step 101 and step 102,
[0043] In a possible implementation, in order to improve the accuracy of the image processing model, the first image may be a high-definition image, for example, a high-definition image including a face; and the target area in the first image may be an area including features to be processed.
[0044] For example, if the image processing model is a network model for wrinkle removal, the target area in the first image may be an area containing wrinkles, and the target area may be, for example, the area around the eyes, forehead, neck, cheeks, etc.
[0045] The target area may be at least one pre-set area. For example, the pre-set area refers to a pre-set area type, such as an eye area, a forehead area, etc. For different first images, the specific position of the target area in the first image may be different.
[0046] Optionally, when determining the position information of the target area in the first image, the key points corresponding to the target area can be determined first, and then the position information of the key points can be detected in the first image, and then the position information of the target area in the first image can be determined based on the position information of the key points.
[0047] The processing of the target area of the first image can be understood as processing the target area using methods other than the image processing model provided in the present disclosure, where the processing target is the same as the inference target of the image processing model. For example, if the inference target of the image processing model is wrinkle removal, then the processing of the target area of the first image can be artificially removing wrinkles in the target area of the first image.
[0048] The present disclosure does not limit other image processing methods that can achieve the reasoning goal of the image processing model.
[0049] The size of the target area mask image can be the same as the size of the first image. The pixel value of the mask area corresponding to the target area in the target area mask image is a first preset value, and the pixel value of other areas except the mask area corresponding to the target area is a second preset value. The first preset value can be, for example, 1, and the second preset value can be, for example, 0.
[0050] Specifically, when determining the target area mask image, after determining the position information of the target area of the first image based on the above embodiment, the pixel value of the target area in the first image can be set to the first preset value based on the position information, and the pixel values of other areas can be set to the second preset value, thereby obtaining the target area mask image.
[0051] Since the pixel values of the target area are different from those of other areas in the target area mask image, the target area can be accurately distinguished from other areas. For example, if the target area is the eye area and the forehead area, the target area mask image can be as shown in Figure 2a.
[0052] For step 103,
[0053] In a possible implementation, after the first image is input into the image processing model, the image processing model may output the first predicted image and an attention mask image corresponding to the first predicted image.
[0054] For example, the first predicted image may refer to an image obtained by processing the target area in the first image based on the image processing model, and the inference target of the image processing model may be the same as the processing target of processing the target area.
[0055] Since the purpose of the target area mask image is to distinguish the target area from the non-target area, the target area mask image can be a binary image; however, the attention mask image is used to characterize the degree of attention of the image processing model to each area of the first image when processing the first image. When processing the first image, the image processing model needs to pay attention to the overall area of the first image and also needs to pay attention to the target area of the first image, but the degree of attention of the two is different. Therefore, the attention mask image is not a binary image. For example, the attention mask image can be a grayscale image as shown in Figure 2b.
[0056] For example, the attention mask image may not be stored separately. After the image processing model processes the first image to obtain the first predicted image, the value of the first predicted image on the α channel of the color space may constitute the attention mask image.
[0057] That is, for any pixel in the first predicted image, the value of the alpha channel of that pixel is the value of the corresponding position of that pixel in the attention mask image. In other words, the output of the image processing model is only the first predicted image, and the attention mask image is determined based on the value of the alpha channel of the first predicted image.
[0058] It should be noted that when the image processing model processes the first image, it needs to combine the overall features of the first image, and when the image processing model processes the first image, since the inference goal of the image processing model is not to process only the target area, but to process the first image as a whole, the image processing model may deviate from the target area in the processing area before it is trained (that is, before the optimization is completed).
[0059] In one possible implementation, when optimizing the image processing model based on the first corrected image, the first predicted image, the target area mask image, and the attention mask image, a first prediction loss value can be first determined based on the first corrected image and the first predicted image; and, based on the target area mask image and the attention mask image, the attention loss value of the image processing model for the target area can be determined; then, based on the first prediction loss value and the attention loss value, the target loss value can be determined, and then the image processing model can be optimized based on the target loss value.
[0060] For example, the first rectified image can be used as supervisory data. When determining the first prediction loss value based on the first rectified image and the first predicted image, for example, a cross entropy loss value, an L1 loss, etc. can be calculated.
[0061] The target area mask image can also be the supervision data of the attention mask image. When determining the attention loss value, the cross entropy loss value, L1 loss value, etc. between the target area mask image and the attention mask image can be calculated, for example.
[0062] Since the focus area of the target area mask image is the target area, the focus area of the attention mask image may be different from the target area mask image. Therefore, the attention loss value can be used to characterize the attention deviation of the image processing model. When optimizing the image processing model, the attention loss value is introduced to achieve attention correction of the image processing model during the image processing process, so that the image processing model can focus more on the processing of the target area.
[0063] The first prediction loss can represent the difference between the first predicted image and the supervision data (i.e., the first corrected image). In order to further analyze the difference between the first predicted image and the first corrected image from multiple dimensions, when determining the first prediction loss value based on the first corrected image and the first predicted image, feature extraction of multiple feature dimensions can be performed on the first corrected image to obtain multiple first feature images, and feature extraction of the multiple feature dimensions can be performed on the first predicted image to obtain multiple second feature images; then, for any feature dimension, based on the first feature image and the second feature image under the feature dimension, the processing loss value under the feature dimension is determined; and then, based on the processing loss values under each feature dimension, the first prediction loss value is determined.
[0064] For example, extracting features from the first rectified image across multiple feature dimensions may involve inputting the image into a feature extraction network to obtain the multiple first feature images; the second feature images may be determined in the same manner. Extracting features from multiple feature dimensions may include high-dimensional feature extraction and low-dimensional feature extraction. The feature extraction network may be optimized along with the image processing model, or it may be pre-optimized.
[0065] The first predicted loss value is determined based on the processing loss values in each feature dimension. For example, the sum of the processing loss values in each feature dimension may be used as the first predicted loss value.
[0066] In this way, by analyzing the differences between the first corrected image and the first predicted image from multiple feature dimensions, the differences between the first corrected image and the first predicted image can be determined more comprehensively, and the determined first prediction loss value is also more accurate.
[0067] When determining the target loss value based on the first predicted loss value and the focus loss value, for example, the first predicted loss value and the focus loss value may be weighted and summed according to preset weights to obtain the target loss value.
[0068] In one possible implementation, after the image processing model processes the first image to obtain the first predicted image, the edge information between the first predicted image and the first corrected image should be similar. Therefore, the edge information difference between the first predicted image and the first corrected image can also be combined when calculating the target loss value.
[0069] Exemplarily, when determining the target loss value, the first edge information corresponding to the first corrected image and the second edge information corresponding to the first predicted image can be determined respectively, and then the edge detection loss value is determined based on the first edge information and the second edge information, and then the target loss value is determined based on the first predicted loss value, the focus loss value and the edge detection loss value.
[0070] For example, when determining the first edge information and the second edge information, the first edge information and the second edge information may be extracted by using a high contrast preservation algorithm, a Canny operator, or the like.
[0071] Taking wrinkle removal as an example, in theory, wrinkles will bring additional edge information. After the image processing model performs wrinkle removal on the first image, the edge information of the first predicted image should be consistent with the edge information of the corrected image. Therefore, by adding the edge detection loss value when calculating the target loss value, it can be ensured that the image processing model completely removes the wrinkles in the target area and ensures that the image processing model does not process other non-wrinkle areas of the first image, so that the image processing model can focus more on the processing of the target area.
[0072] In another possible implementation, when calculating the target loss value, in order to improve the processing effect on the target area, the prediction loss between areas may be added.
[0073] Specifically, the first area image corresponding to the target area can be first determined from the first predicted image based on the target area mask image; and the second area image corresponding to the target area can be determined from the first corrected image based on the target area mask image; and then the second predicted loss value can be determined based on the first area image and the second area image; in this way, when calculating the target loss value, the target loss value can be determined based on the first predicted loss value, the second predicted loss value and the focus loss value.
[0074] When determining the second prediction loss value based on the first region image and the second region image, for example, a cross entropy loss value, an L1 loss value, etc. between the first region image and the second region image may be calculated.
[0075] Similarly, in order to more comprehensively analyze the differences between the first area image and the second area image, feature extraction of multiple feature dimensions can be performed on the first area image to obtain multiple third feature images, and feature extraction of multiple feature dimensions can be performed on the second area image to obtain multiple fourth feature images. Then, for any feature dimension, the processing loss value under the feature dimension can be determined based on the third feature image and the fourth feature image under the feature dimension, and the second predicted loss value can be determined based on the processing loss values under each feature dimension.
[0076] The method for determining the third characteristic image and the fourth characteristic image may be the same as the method for determining the second characteristic image and the first characteristic image, and will not be described in detail here.
[0077] Since the image processing model primarily processes the target region, the optimal processing result for regions other than the target region is to keep them unchanged. Therefore, in one possible implementation, when determining the target loss value, the difference between the first image and the first predicted image in the non-attention region may also be considered.
[0078] Exemplarily, a first non-attention image can be determined based on the first image and the attention mask image; and a second non-attention image can be determined based on the first predicted image and the attention mask image; and then a non-attention prediction loss value can be determined based on the first non-attention image and the second non-attention image; in this way, when determining the target loss value, the target loss value can be determined based on the first predicted loss value, the attention loss value and the non-attention prediction loss value.
[0079] Specifically, when determining the first non-attention image based on the first image and the attention mask image, the inverse mask image of the attention mask image can be first determined, and then the value of each pixel point in the first image is multiplied by the value at the corresponding position in the inverse mask image to obtain the first non-attention image. The method for determining the second non-attention image is similar to this and will not be repeated here.
[0080] The non-attention prediction loss value may, for example, refer to the L1 loss, cross entropy loss value, etc. between the first non-attention image and the second non-attention image.
[0081] Exemplarily, the non-attention prediction loss value can be calculated by the following formula: L = l1(A*(1-Attmask), C*(1-Attmask))
[0082] Where A represents the first image, C represents the first corrected image, Attmask represents the attention mask image, and 1-Attmask represents the inverse mask image of the attention mask image.
[0083] When calculating the target loss value, combined with the non-attention prediction loss value, the attention mask image can be optimized, and further, the image processing model can be made more focused on the target area.
[0084] In one possible implementation, the image processing model is an adversarial network, which includes a generator and a discriminator. The generator is used to generate a first predicted image corresponding to the first image, and the discriminator is used to determine whether the image input to the discriminator is a real image.
[0085] Therefore, when determining the target loss value, the target loss value may also include the adversarial loss of the generator and the discriminator.
[0086] Specifically, the generator is used to process the first image, and the processed image is handed over to the discriminator for discrimination. The goal of the generator is to generate an image that the discriminator cannot distinguish between true and false, and the goal of the discriminator is to accurately determine whether the input image is a real image. Therefore, the goals of the generator and the discriminator are opposite goals, and the loss calculated thereby is the adversarial loss.
[0087] When calculating the adversarial loss, the discriminator may determine a discrimination result of the first predicted image and the first corrected image, and then determine the adversarial loss based on the discrimination result, the preset labels corresponding to the first predicted image and the first corrected image.
[0088] The generator and discriminator are trained separately. When training the generator, the parameters of the discriminator remain unchanged. When training the discriminator, the parameters of the generator remain unchanged. Generally, after training the generator for K rounds, the discriminator can be trained for one round, and the training process of the two can be alternating.
[0089] When training the discriminator, the parameters of the generator are fixed. The generator can generate a first predicted image based on the first image. The label of the first predicted image can be set to 0 to mark the predicted processed image as not a real image. At the same time, the label of the first corrected image is set to 1 to mark the first corrected image as a real image. Then, the first corrected image and the first predicted image are input into the discriminator. The discriminator can output predicted labels for the first corrected image and the first predicted image. The loss calculated based on the predicted labels and the originally set labels is the adversarial loss of the discriminator.
[0090] When training the generator, the parameters of the discriminator are fixed. The generator can generate a first predicted image based on the first image, and set a label 1 for the generated first predicted image to mark the first predicted image as a real image. After the first predicted image is input into the discriminator, the discriminator can output a predicted label. The loss calculated based on the label set for the first predicted image and the label predicted by the discriminator for the first predicted image is the adversarial loss of the generator.
[0091] After determining the adversarial loss value, when determining the target loss value, the target loss value may be determined based on the first predicted loss value, the focus loss value, and the adversarial loss value.
[0092] It should be noted that when determining the target loss value, in addition to the first predicted loss value and the attention loss value, it can also be combined with any one or more of the edge detection loss value, the second predicted loss value, the non-attention predicted loss value, and the adversarial loss value.
[0093] For example, when calculating the target loss value in combination with the second predicted loss value, in order to emphasize the importance of the target area and enhance the processing effect of the target area, the second predicted loss value can be set with a higher weight when calculating the target loss value.
[0094] In one possible scenario, after the image processing model processes the first image, the generated image may be distorted. Therefore, when determining the first predicted image, the low-frequency information of the first image may also be combined.
[0095] Exemplarily, when the first image is input into the image processing model to be optimized and the first predicted image corresponding to the first image is obtained, the image processing model may output an intermediate processed image rather than directly outputting the first predicted image; the first image may be blurred in advance to obtain a low-frequency image corresponding to the first image, and then based on the attention mask image and the low-frequency image, the low-frequency information image corresponding to the first image is determined; after the image processing model outputs the intermediate processed image, the low-frequency information image and the intermediate processed image are fused to obtain the first predicted image.
[0096] For example, the blurring process of the first image may include, for example, performing Gaussian filtering on the first image; when the low-frequency information image and the intermediate processed image are fused, for example, the values at corresponding positions of the low-frequency information image and the intermediate processed image are added together, and then input into an activation layer, which performs normalization processing to obtain the first predicted image.
[0097] In one possible embodiment, the first image is a high-definition image. In this case, the number of the first images may be small. Therefore, when optimizing the image processing model, in order to improve the richness of the training data, different lighting conditions can be set for the first images, and the first images under different lighting conditions can be used as different inputs to the image processing model for optimization.
[0098] However, even if the restrictions on lighting conditions are added, the amount of optimization data of the image processing model may still be small (the reason is that the image quality of the first image is higher). Therefore, after optimizing the image processing model based on the first image to obtain the initial image processing model, the initial image processing model can be readjusted to improve the stability and generalization ability of the initial image processing model.
[0099] Specifically, a second image can be obtained, wherein the number of the second images can be higher than the number of the first images, but the overall image quality of the second image is lower than that of the first image; then a second corrected image corresponding to the second image can be determined based on the initial image processing model, and then the initial image processing model can be readjusted based on the second image and the second corrected image to obtain a target image processing model.
[0100] For example, when the initial image processing model is readjusted, the optimization method is the same as that used to optimize the image processing model for the first time to obtain the initial image processing model. The only difference is that the step of manually processing the image is replaced by the initial image processing model, that is, processing the second image based on the initial image processing model is equivalent to processing the first image to obtain the first corrected image.
[0101] For example, after the image processing model is optimized and adjusted to obtain the target image processing model, when the target image processing model is applied to the model inference process, if the target image processing model is an adversarial network, image processing can be performed only based on the generator in the target image processing model.
[0102] Based on the above embodiment, the present disclosure further provides an image processing method, which specifically includes the following steps:
[0103] Step 1: Get the image to be processed.
[0104] Step 2: Process the image to be processed based on the target image processing model to obtain a target image. The target image processing model is optimized based on the method provided in the above embodiment.
[0105] In summary, the optimization process of the above image processing model and the inference process of the image processing model can be shown in Figure 3, which specifically includes:
[0106] Acquire a first image, then process the acquired first image to obtain a first corrected image, and then optimize the image processing model based on the first corrected image and the first image. Different supervision strategies can be combined in the process of optimizing the image processing model. The supervision strategy can refer to combining different types of losses when calculating the target loss value when calculating the optimization model.
[0107] After the image processing model is optimized, a second corrected image of the second image may be generated based on the optimized image processing model, and then the optimized image processing model may be adjusted based on the second image and the second corrected image.
[0108] During the model inference process, the image to be processed can be obtained first, and then the image to be processed can be cropped according to the inference target to reduce the impact of the remaining image on the model accuracy, and then the processed target image can be generated based on the adjusted target image processing model (that is, the generator in the adversarial network).
[0109] For detailed description of the above steps, please refer to the above embodiments.
[0110] The following takes the target areas as the eye area and the forehead area, the inference goal of the image processing model as wrinkle removal, and the image processing model as an adversarial network as an example to introduce the optimization process of the above image processing model.
[0111] 1. First, a high-definition first image containing wrinkles in the eye area and forehead area can be obtained. Then, the wrinkles in the eye area and forehead area in the first image can be removed by artificial wrinkle removal to obtain a first corrected image corresponding to the first image.
[0112] 2. Perform eye key point and forehead key point detection on each first image, determine the position information of the eye area and forehead area in each first image, and generate a target area mask image corresponding to each first image based on the position information. In the target area mask image, the pixel points corresponding to the eye area and forehead area have a value of 1, and the pixel points in the remaining areas have a value of 0.
[0113] 3. Input the first image containing wrinkles into the adversarial network to be optimized. The adversarial network includes a generator and a discriminator. Specifically, the first image can be input into the generator to determine a first predicted image corresponding to the first image. The first predicted image is an image obtained after wrinkle removal processing is performed on the eye area and forehead area in the first image.
[0114] Based on the value of the first predicted image on the α channel, the degree of attention that the adversarial network pays to each area when processing the first image can be determined, that is, the attention mask image is determined.
[0115] Furthermore, in order to avoid distortion of the first predicted image, the generator may output an intermediate processed image, which is blurred and then fused with the intermediate processed image to obtain the first predicted image.
[0116] 4. Then calculate: (1) determine the first prediction loss based on the first corrected image and the first predicted image; (2) determine the attention loss value based on the target area mask image and the attention mask image; (3) determine the first area image from the first predicted image based on the target area mask image, and determine the second area image from the first corrected image, and then determine the second prediction loss value based on the first area image and the second area image; (4) determine the edge detection loss value based on the first edge information of the first corrected image and the second edge information of the first predicted image; (5) determine the non-attention prediction loss value for characterizing the difference between the non-attention area between the first image and the predicted processed image based on the attention mask image; (6) the adversarial loss value of the adversarial network.
[0117] Then, a target loss value is determined based on the above loss value (for example, a weighted sum can be used), and the adversarial network is optimized based on the target loss value.
[0118] 5. After optimizing the adversarial network based on the first image, in order to improve the stability and generalization ability of the adversarial network, a large number of second images containing human faces can be obtained, and the second images may not be high-definition images. Then, based on the generator in the preliminarily optimized adversarial network, a second corrected image of the second image is generated, and the second corrected image is equivalent to the above-mentioned first corrected image. The above-mentioned optimization process is repeated based on the second corrected image and the second image to adjust the optimized adversarial network.
[0119] The image processing method and device provided by the embodiments of the present disclosure can supervise the attention mask image determined by the image processing model based on the target area mask image corresponding to the target area in the first image, thereby realizing attention correction of the image processing model during the image processing process, making the image processing model more focused on the processing of the target area, and improving the processing accuracy of the image processing model for the target area.
[0120] Those skilled in the art will understand that in the above-mentioned method of the specific implementation method, the writing order of each step does not mean a strict execution order and does not constitute any limitation on the implementation process. The specific execution order of each step should be determined by its function and possible internal logic.
[0121] Based on the same inventive concept, an image processing device corresponding to the image processing method is also provided in the embodiment of the present disclosure. Since the principle of solving the problem by the device in the embodiment of the present disclosure is similar to the above-mentioned image processing method in the embodiment of the present disclosure, the implementation of the device can refer to the implementation of the method, and the repeated parts will not be repeated.
[0122] 4 is a schematic diagram of the architecture of an image processing device provided by an embodiment of the present disclosure, wherein the device includes: an acquisition module 401, a determination module 402, and a processing module 403; wherein,
[0123] An acquisition module 401 is configured to acquire a first image;
[0124] a determination module 402 configured to process the target area of the first image to obtain a first corrected image, and to determine a target area mask image corresponding to the target area;
[0125] The processing module 403 is used to input the first image into the image processing model to obtain a first predicted image and an attention mask image corresponding to the first predicted image; wherein the image processing model is optimized based on the first corrected image, the first predicted image, the target area mask image and the attention mask image.
[0126] In a possible implementation, the processing module 403 is further configured to optimize the image processing model according to the following method:
[0127] Determining a first prediction loss value based on the first rectified image and the first predicted image; and determining an attention loss value of the image processing model to be adjusted for the target area based on the target area mask image and the attention mask image;
[0128] Determining the target loss value based on the first predicted loss value and the target loss value;
[0129] The image processing model is optimized based on the target loss value.
[0130] In one possible implementation, when determining the first prediction loss value based on the first rectified image and the first predicted image, the processing module 403 is configured to:
[0131] Performing feature extraction of multiple feature dimensions on the first rectified image to obtain multiple first feature images; and performing feature extraction of the multiple feature dimensions on the first predicted image to obtain multiple second feature images; wherein the feature extraction of the multiple feature dimensions includes high-dimensional feature extraction and low-dimensional feature extraction;
[0132] For any feature dimension, determining a processing loss value in the feature dimension based on the first feature image and the second feature image in the feature dimension;
[0133] The first predicted loss value is determined based on the processing loss value under each feature dimension.
[0134] In a possible implementation, when determining the target loss value based on the first predicted loss value and the target loss value, the processing module 403 is configured to:
[0135] respectively determining first edge information corresponding to the first rectified image and second edge information corresponding to the first predicted image, and determining an edge detection loss value based on the first edge information and the second edge information;
[0136] The target loss value is determined based on the first prediction loss value, the focus loss value, and the edge detection loss value.
[0137] In a possible implementation, when inputting the first image into an image processing model to obtain a first predicted image, the determining module 402 is configured to:
[0138] inputting the first image into the image processing model, and determining an intermediate processed image output by the image processing model;
[0139] performing blur processing on the first image to obtain a low-frequency image corresponding to the first image;
[0140] Determining a low-frequency information image corresponding to the first image based on the attention mask image and the low-frequency image;
[0141] The low-frequency information image and the intermediate processed image are fused to obtain the first predicted image.
[0142] In one possible implementation, after the image processing model is optimized based on the first rectified image, the first predicted image, the target area mask image, and the attention mask image, the processing module 403 is further configured to:
[0143] acquiring a second image, wherein the number of the second image is greater than the number of the first image;
[0144] determining a second corrected image corresponding to the second image based on the initial image processing model;
[0145] The optimized image processing model is adjusted based on the second image and the second corrected image.
[0146] In a possible implementation, when determining the target loss value based on the first predicted loss value and the target loss value, the processing module 403 is configured to:
[0147] determining a first region image corresponding to the target region from the first predicted image based on the target region mask image; and determining a second region image corresponding to the target region from the first corrected image based on the target region mask image;
[0148] determining a second predicted loss value based on the first area image and the second area image;
[0149] The target loss value is determined based on the first predicted loss value, the second predicted loss value, and the focus loss value.
[0150] For descriptions of the processing flow of each module in the device and the interaction flow between each module, reference can be made to the relevant descriptions in the above method embodiment, which will not be described in detail here.
[0151] Based on the same technical concept, the embodiment of the present disclosure also provides a computer device. Referring to Figure 5, there is a structural diagram of the computer device 500 provided in the embodiment of the present disclosure, which includes a processor 501, a memory 502, and a bus 503. Among them, the memory 502 is used to store execution instructions, including a memory 5021 and an external memory 5022; the memory 5021 here is also called an internal memory, which is used to temporarily store the calculation data in the processor 501, as well as the data exchanged with the external memory 5022 such as a hard disk. The processor 501 exchanges data with the external memory 5022 through the memory 5021. When the computer device 500 is running, the processor 501 communicates with the memory 502 through the bus 503, so that the processor 501 executes the following instructions:
[0152] acquiring a first image;
[0153] Processing the target area of the first image to obtain a first corrected image, and determining a target area mask image corresponding to the target area;
[0154] Input the first image into an image processing model to obtain a first predicted image and an attention mask image corresponding to the first predicted image; wherein the image processing model is optimized based on the first corrected image, the first predicted image, the target area mask image and the attention mask image.
[0155] In one possible implementation, in the instructions executed by the processor 501, the image processing model is optimized based on the first rectified image, the first predicted image, the target area mask image, and the attention mask image, including:
[0156] Determining a first prediction loss value based on the first rectified image and the first predicted image; and determining an attention loss value of the image processing model to be adjusted for the target area based on the target area mask image and the attention mask image;
[0157] Determining the target loss value based on the first predicted loss value and the target loss value;
[0158] The image processing model is optimized based on the target loss value.
[0159] In one possible implementation, in the instructions executed by the processor 501, determining the first prediction loss value based on the first rectified image and the first predicted image includes:
[0160] Performing feature extraction of multiple feature dimensions on the first rectified image to obtain multiple first feature images; and performing feature extraction of the multiple feature dimensions on the first predicted image to obtain multiple second feature images; wherein the feature extraction of the multiple feature dimensions includes high-dimensional feature extraction and low-dimensional feature extraction;
[0161] For any feature dimension, determining a processing loss value in the feature dimension based on the first feature image and the second feature image in the feature dimension;
[0162] The first predicted loss value is determined based on the processing loss value under each feature dimension.
[0163] In a possible implementation, in the instructions executed by the processor 501, determining the target loss value based on the first predicted loss value and the target loss value includes:
[0164] respectively determining first edge information corresponding to the first rectified image and second edge information corresponding to the first predicted image, and determining an edge detection loss value based on the first edge information and the second edge information;
[0165] The target loss value is determined based on the first prediction loss value, the focus loss value, and the edge detection loss value.
[0166] In a possible implementation, in the instructions executed by the processor 501, inputting the first image into an image processing model to obtain a first predicted image includes:
[0167] inputting the first image into the image processing model, and determining an intermediate processed image output by the image processing model;
[0168] performing blur processing on the first image to obtain a low-frequency image corresponding to the first image;
[0169] Determining a low-frequency information image corresponding to the first image based on the attention mask image and the low-frequency image;
[0170] The low-frequency information image and the intermediate processed image are fused to obtain the first predicted image.
[0171] In one possible implementation, in the instructions executed by the processor 501, after the image processing model is optimized based on the first rectified image, the first predicted image, the target area mask image, and the attention mask image, the method further includes:
[0172] acquiring a second image, wherein the number of the second image is greater than the number of the first image;
[0173] determining a second corrected image corresponding to the second image based on the initial image processing model;
[0174] The optimized image processing model is adjusted based on the second image and the second corrected image.
[0175] In a possible implementation, in the instructions executed by the processor 501, determining the target loss value based on the first predicted loss value and the target loss value includes:
[0176] determining a first region image corresponding to the target region from the first predicted image based on the target region mask image; and determining a second region image corresponding to the target region from the first corrected image based on the target region mask image;
[0177] determining a second predicted loss value based on the first area image and the second area image;
[0178] The target loss value is determined based on the first predicted loss value, the second predicted loss value, and the focus loss value.
[0179] The present disclosure also provides a computer-readable storage medium having a computer program stored thereon. When executed by a processor, the computer program executes the steps of the image processing method described in the above method embodiment. The storage medium may be a volatile or non-volatile computer-readable storage medium.
[0180] The embodiments of the present disclosure also provide a computer program product, which carries program code. The instructions included in the program code can be used to execute the steps of the image processing method described in the above method embodiment. For details, please refer to the above method embodiment and will not be repeated here.
[0181] The computer program product may be implemented in hardware, software, or a combination thereof. In one embodiment, the computer program product is implemented as a computer storage medium. In another embodiment, the computer program product is implemented as a software product, such as a software development kit (SDK).
[0182] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems and devices described above can refer to the corresponding processes in the aforementioned method embodiments, and will not be repeated here. In the several embodiments provided in the present disclosure, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some communication interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0183] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.
[0184] In addition, each functional unit in each embodiment of the present disclosure may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0185] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a non-volatile computer-readable storage medium that is executable by a processor. Based on this understanding, the part that essentially contributes to the technical solution of the present disclosure or the part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present disclosure. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0186] Finally, it should be noted that the above-described embodiments are only specific implementation methods of the present disclosure, which are used to illustrate the technical solutions of the present disclosure, rather than to limit them. The scope of protection of the present disclosure is not limited thereto. Although the present disclosure has been described in detail with reference to the above-described embodiments, those skilled in the art should understand that any person skilled in the art can modify or easily conceive of changes to the technical solutions described in the above-described embodiments within the technical scope disclosed in the present disclosure, or replace some of the technical features therein with equivalents. Such modifications, changes, or replacements do not deviate from the spirit and scope of the technical solutions of the embodiments of the present disclosure, and should be included in the scope of protection of the present disclosure. Therefore, the scope of protection of the present disclosure shall be subject to the scope of protection of the claims.
Claims
1. An image processing method, comprising: acquiring a first image; Processing the target area of the first image to obtain a first corrected image, and determining a target area mask image corresponding to the target area; Input the first image into an image processing model to obtain a first predicted image and an attention mask image corresponding to the first predicted image; wherein the image processing model is optimized based on the first corrected image, the first predicted image, the target area mask image and the attention mask image.
2. The method according to claim 1, wherein: The image processing model is optimized based on the first rectified image, the first predicted image, the target area mask image, and the attention mask image, including: Determining a first prediction loss value based on the first rectified image and the first predicted image; Based on the target area mask image and the attention mask image, determining an attention loss value of the image processing model to be adjusted for the target area; Determining a target loss value based on the first predicted loss value and the focus loss value; The image processing model is optimized based on the target loss value.
3. The method according to claim 2, wherein: The determining a first prediction loss value based on the first rectified image and the first predicted image includes: Performing feature extraction of multiple feature dimensions on the first rectified image to obtain multiple first feature images; and performing feature extraction of the multiple feature dimensions on the first predicted image to obtain multiple second feature images; wherein the feature extraction of the multiple feature dimensions includes high-dimensional feature extraction and low-dimensional feature extraction; For any feature dimension, based on the first feature image and the second feature image in the feature dimension, determine the processing loss value in the feature dimension; The first predicted loss value is determined based on the processing loss value under each feature dimension.
4. The method according to claim 2, wherein: The determining the target loss value based on the first predicted loss value and the focus loss value includes: Determine the first edge information corresponding to the first rectified image and the first predicted image respectively corresponding second edge information, and determining an edge detection loss value based on the first edge information and the second edge information; The target loss value is determined based on the first prediction loss value, the focus loss value, and the edge detection loss value.
5. The method according to any one of claims 1 to 4, wherein: The step of inputting the first image into an image processing model to obtain a first predicted image includes: Inputting the first image into the image processing model, and determining an intermediate processed image output by the image processing model; Performing fuzzy processing on the first image to obtain a low-frequency image corresponding to the first image; Determining a low-frequency information image corresponding to the first image based on the attention mask image and the low-frequency image; The low-frequency information image and the intermediate processed image are fused to obtain the first predicted image.
6. The method according to claim 1, wherein: After the image processing model is optimized based on the first rectified image, the first predicted image, the target area mask image, and the attention mask image, the method further includes: acquiring a second image, wherein the number of the second image is greater than the number of the first image; determining a second corrected image corresponding to the second image based on the image processing model; The optimized image processing model is adjusted based on the second image and the second corrected image.
7. The method according to claim 2 or 4, wherein: The determining the target loss value based on the first predicted loss value and the focus loss value includes: Determining a first region image corresponding to the target region from the first predicted image based on the target region mask image; and determining a second region image corresponding to the target region from the first corrected image based on the target region mask image; determining a second predicted loss value based on the first area image and the second area image; The target loss value is determined based on the first predicted loss value, the second predicted loss value, and the focus loss value.
8. An image processing device, comprising: An acquisition module, configured to acquire a first image; a determination module configured to obtain a first corrected image after processing the target area of the first image, and to determine a target area mask image corresponding to the target area; as well as A processing module is configured to input the first image into an image processing model to obtain a first predicted image and an attention mask image corresponding to the first predicted image; wherein the image processing model is optimized based on the first corrected image, the first predicted image, the target area mask image and the attention mask image.
9. A computer device comprising a processor, a memory and a bus, wherein: The memory stores machine-readable instructions executable by the processor. When the computer device is running, the processor and the memory communicate through the bus. When the machine-readable instructions are executed by the processor, the image processing method according to any one of claims 1 to 7 is implemented.
10. A computer-readable storage medium, wherein: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the image processing method according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Image processing model training method, and image processing method and device
CN113808003A
Wrinkle removal processing method and system for images, terminal equipment and storage medium
CN113989149A
Image processing method and device, electronic equipment and storage medium
CN114463212A
Image processing method and device
CN114820363A
Image inpainting method and apparatus, computer device, and storage medium
US20210183022A1
