Image processing method and apparatus
The image processing method and apparatus enhance detail processing in specific image regions by using target and attention mask images to optimize the image processing model, addressing the inadequacies of existing beautification software in areas like wrinkle removal.
Patent Information
- Application Number
- US19/158439
- Authority / Receiving Office
- US · United States
- Patent Type
- Applications(United States)
- Current Assignee / Owner
- Priority Date
- 2023-02-24
- Filing Date
- 2024-02-07
- Publication Date
- 2026-11-26
AI Technical Summary
Existing beautification software often fails to provide adequate detail processing on specific regions of images, leading to poor results in areas like deep wrinkles, such as nasolabial folds and crow's feet, during portrait beautification.
An image processing method and apparatus that utilizes an image processing model supervised by a target region mask image and attention mask image to focus on specific regions, optimizing the model through techniques like cross-entropy loss, L1 loss, edge detection, and adversarial networks to enhance detail processing accuracy.
Improves the processing accuracy of image processing models on target regions, ensuring better detail enhancement in areas like wrinkle removal.
Smart Images

Figure US20260378207A1-D00000_ABST
Abstract
Description
[0001] This application claims priority to Chinese Patent Application No. 202310187657.2 filed on Feb. 24, 2023, the entire disclosure of which is incorporated herein by reference as part of the present disclosure.TECHNICAL FIELD
[0002] The present disclosure relates to an image processing method and an apparatus.BACKGROUND
[0003] With the development of smart devices, the smart devices have been increasingly used for shooting photos. However, for reasons such as shooting skills or shooting conditions, the shot photos often need to be beautified. Generally, when beautifying a photo based on beautification software, the beautification software may often beautify the photo on the whole. In this way, the effect of detail processing on a partial region of the photo may be poor. The beautification capability needs to be improved.SUMMARY
[0004] Embodiments of the present disclosure provide an image processing method and an apparatus.
[0005] On the first aspect, embodiments of the present disclosure provide an image processing method, comprising: obtaining a first image; processing a target region of the first image to obtain a first corrected image, and determining a target region mask image corresponding to the target region; inputting the first image to an image processing model to obtain a first predicted image, and an attention mask image corresponding to the first predicted image, and optimizing the image processing model based on the first corrected image, the first predicted image, the target region mask image, and the attention mask image.
[0006] On the second aspect, embodiments of the present disclosure provide an image processing apparatus, comprising: an obtaining module configured to obtain a first image; a determination module configured to process a target region of the first image to obtain a first corrected image, and determine a target region mask image corresponding to the target region; and a processing module configured to input the first image to an image processing model to obtain a first predicted image, and an attention mask image corresponding to the first predicted image, and optimize the image processing model based on the first corrected image, the first predicted image, the target region mask image, and the attention mask image.
[0007] On the third aspect, embodiments of the present disclosure provide 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 runs, the processor communicates with the memory by the bus; and when the machine-readable instructions are executed by the processor, the steps in the above first aspect or any one possible implantation of the above first aspect are implemented.
[0008] On the fourth aspect, embodiments of the present disclosure provide a computer-readable storage medium, storing a computer program which, when run by a processor, implements the steps in the above first aspect or any one possible implantation of the above first aspect.
[0009] To provide a clearer understanding of the objectives, features, and advantages of the present disclosure, detailed description are made below in combination with the preferred embodiments and the drawings.BRIEF DESCRIPTION OF DRAWINGS
[0010] In order to illustrate the technical solutions of the embodiments of the present disclosure more clearly, the accompanying drawings needing to be used in the embodiments will be briefly described below. The accompanying drawings incorporated into and constituting part of the specification illustrate the embodiments of the present disclosure, and serve, together with the specification, to illustrate the technical solutions of the present disclosure. It should be understood that the following figures show merely some embodiments of the present disclosure, and thus should not be regarded as a limitation to the scope. A person of ordinary skill in the art may still derive other related figures from these figures without creative efforts.
[0011] FIG. 1 illustrates a flowchart of an image processing method provided by an embodiment of the present disclosure;
[0012] FIG. 2a illustrates a schematic diagram of a target region mask image provided by an embodiment of the present disclosure;
[0013] FIG. 2b illustrates a schematic diagram of an attention mask image provided by an embodiment of the present disclosure;
[0014] FIG. 3 illustrates a schematic diagram of an overall flow of model optimization and model reasoning provided by an embodiment of the present disclosure;
[0015] FIG. 4 illustrates a schematic diagram of an image processing apparatus provided by an embodiment of the present disclosure; and
[0016] FIG. 5 illustrates a structural schematic diagram of a computer device provided by an embodiment of the present disclosure.DETAILED DESCRIPTION
[0017] In order to make the objectives, technical solutions, and advantages of the embodiments of the present disclosure clearer, the technical solutions in the embodiments of the present disclosure are clearly and completely described below with reference to the drawings in the embodiments of the present disclosure. Apparently, the described embodiments are merely a part rather than all of the embodiments of the present disclosure. Generally, the components of the embodiments of the present disclosure described and shown in the drawings may be arranged and designed in various manners. Therefore, the detailed description of the embodiments of the present disclosure with reference to the accompanying drawings is not intended to limit the protection scope of the present disclosure, but merely to represent the selected embodiments of the present disclosure. All other embodiments derived from the embodiments of the present disclosure by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present disclosure.
[0018] When beautifying a photo based on beautification software, the beautification software may often beautify the photo on the whole, causing a poor effect of detail processing on a partial region of the photo.
[0019] For example, when a portrait photo is beautified, the processing capability for a deep wrinkle region (such as nasolabial folds and crow's feet) might be poor. Consequently, the processed portrait photo still has wrinkles. The processing effect is poor.
[0020] On this basis, the present disclosure provides an image processing method and apparatus. An attention mask image determined by an image processing model can be supervised based on a target region mask image corresponding to a target region in a first image. Thus, attention correction on the image processing model in the image processing process can be realized such that the image processing model focuses more on the processing of the target region. The processing accuracy of the image processing model for the target region is improved.
[0021] Further, when image processing is performed based on the image processing model in the image processing method provided by the present disclosure, specific processing on the target region can be realized. The detail processing accuracy of the image can be improved.
[0022] It should be noted that similar reference signs and letters represent similar items in the drawings below. Therefore, once an item is defined in one drawing, it does not need to be further defined and described in subsequent drawings.
[0023] The term “and / or” used herein merely describes an association relationship, and indicates that three types of relationships may exist. For example, A and / or B may indicate that A exists alone, A and B coexist, or B exists alone. In addition, the term “at least one” used herein represents any one of a plurality of things or any combination of at least two of a plurality of things. For example, at least one of A, B, C may represent any one or more elements selected from a set constituted by A, B, and C.
[0024] It will be understood that before using the technical solutions disclosed in various embodiments of the present disclosure, a user should be notified of a type, a range of use, a usage scenario, etc. of personal information involved in the present disclosure in an appropriate manner in accordance with relevant laws and regulations, and these should be authorized by the user.
[0025] For example, in response to receiving an active request from a user, prompt information is sent to the user to explicitly prompt the user that the operation the user requests to perform will require to acquire and use the personal information of the user. Thus, the use can independently select, according to the prompt information, whether or not to provide the personal information to software or hardware such as an electronic device, an application, a server or a storage medium that performs the operations of the technical solutions of the present disclosure.
[0026] As an alternative but non-limiting implementation, in response to receiving an active request from a user, a manner of sending a prompt information to the user may be, for example, using a pop-up window in which the prompt information may be presented in the form of text. Furthermore, the pop-up window may also carry option controls for a user to select to “agree” or “disagree” with providing personal information to an electronic device.
[0027] It will be understood that the processes of notifying of and authorizing by a user described above are merely exemplary and do not constitute a limitation on the implementations of the present disclosure, and other manners meeting relevant laws and regulations may also be applied to the implementations of the present disclosure.
[0028] In order to facilitate the understanding of the embodiments of the present disclosure, firstly, an image processing method disclosed by an embodiment of the present disclosure is introduced in detail. An execution body for the image processing method provided by the embodiment of the present disclosure is generally a computer device having a certain computing power. The computer device may include, for example, a terminal device or a server or other processing device. The terminal device may be a user equipment (UE), a mobile device, a user terminal, a terminal, a cell phone, a cordless telephone, a personal digital assistant (PDA), a hand-held device, a computing device, a vehicle device, a wearable device, and the like. In some possible implementations, the image processing method may be implemented by a processor calling computer-readable instructions stored on a memory.
[0029] With reference to FIG. 1, there is shown a flowchart of an image processing method provided by an embodiment of the present disclosure. It needs to be noted that “optimize”, “adjust”, and “train” used below may all be construed as adjusting model parameters to improve the model accuracy.
[0030] The image processing method includes steps 101 to step 103.
[0031] In step 101, a first image is obtained.
[0032] In step 102, a target region of the first image is processed to obtain a first corrected image, and a target region mask image corresponding to the target region is determined.
[0033] In step 103, the first image is input to an image processing model to obtain a first predicted image, and an attention mask image corresponding to the first predicted image; and the image processing model is optimized based on the first corrected image, the first predicted image, the target region mask image, and the attention mask image.
[0034] The above steps will be described in detail below.
[0035] For step 101 and step 102:
[0036] In a possible implementation, in order to improve the accuracy of the image processing model, the first image may be a high-definition image, e.g., a high-definition image including a human face. The target region in the first image may be a region including a feature to be processed.
[0037] For example, if the image processing model is a network model for wrinkle removal processing, the target region in the first image may be a region including wrinkles. The target region may be, for example, the region around the eye, the forehead, the neck, or the cheek.
[0038] The target region may be at least one preset region. For example, the preset region refers to a preset region type, such as an eye region and a forehead region. For different first images, the specific positions of the target region in the first images may be different.
[0039] Optionally, when position information of the target region in the first image is determined, a key point corresponding to the target region may be determined first, and then the position information of the key point is detected in the first image; and the position information of the target region in the first image is then determined based on the position information of the key point.
[0040] The processing the target region of the first image may be construed as processing the target region by other methods than the image processing model provided by the present disclosure, with a processing objective being the same as a reasoning objective of the image processing model. For example, if the reasoning objective of the image processing model is to remove wrinkles, the processing the target region of the first image may refer to manually removing the wrinkles in the target region in the first image.
[0041] Other image processing methods capable of achieving the reasoning objective of the image processing model will not be limited in the present disclosure.
[0042] A size of the target region mask image may be the same as a size of the first image. A pixel value of a mask region corresponding to the target region in the target region mask image is a first preset value, and a pixel value of other region than the mask region corresponding to the target region is a second preset value. The first preset value may be, for example 1, and the second preset value may be, for example, 0.
[0043] Specifically, when determining the target region mask image, after determining the position information of the target region of the first image based on the above embodiment, a pixel value of the target region in the first image may be set to the first preset value based on the position information, and a pixel value of other region may be set to the second preset value. Thus, the target region mask image can be obtained.
[0044] Since the pixel values of the target region and other region are different in the target region mask image, the target region can be accurately distinguished from other region. Exemplarily, if the target region is the eye region and the forehead region, the target region mask image may be as shown in FIG. 2a.
[0045] For step 103:
[0046] In a possible implementation, after the first image is input to the image processing model, the image processing model may output the first predicted image, and the attention mask image corresponding to the first predicted image.
[0047] For example, the first predicted image may refer to an image obtained after processing the target region in the first image based on the image processing model. The reasoning objective of the image processing model may be the same as the processing objective of processing the target region.
[0048] Since the target region mask image is intended to distinguish between the target region and a non-target region, the target region mask image may be a binary image. However, the attention mask image is used for representing an attention degree of the image processing model for each region of the first image when processing the first image; when the image processing model processes the first image, it needs to pay attention to both the whole region of the first image and the target region of the first image, with different attention degrees for the two. Therefore, the attention mask image is not a binary image. For example, the attention mask image may be a grayscale image as shown in FIG. 2b.
[0049] 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, a value of the first predicted image on the α channel of a color space may constitute the attention mask image.
[0050] That is, for any pixel in the first predicted image, a value of the pixel on the α channel is a value of the pixel at a corresponding position on the attention mask image. In another word, an output of the image processing model is merely the first predicted image, and the attention mask image is determined based on the value of the first predicted image on the α channel.
[0051] It needs to be noted that when the image processing model processes the first image, an overall feature of the first image needs to be combined, and when the image processing model processes the first image, since the reasoning objective of the image processing model is to process the first image on the whole rather than only process the target region, a region paid close attention to in the processing process by the image processing model before being trained (before being optimized) might have a deviation from the target region.
[0052] In a possible implementation, when the image processing model is optimized based on the first corrected image, the first predicted image, the target region mask image, and the attention mask image, a first prediction loss value may be firstly determined based on the first corrected image and the first predicted image, and an attention loss value of the image processing model for the target region is determined based on the target region mask image and the attention mask image; the target loss value is then determined based on the first prediction loss value and the attention loss value; and the image processing model is optimized based on the target loss value.
[0053] For example, the first corrected image may be used as supervision data. When the first prediction loss value is determined based on the first corrected image and the first predicted image, a cross-entropy loss value, an L1 loss, and the like may be calculated for example.
[0054] The target region mask image may also be supervision data of the attention mask image. When the attention loss value is determined, a cross-entropy loss value, an L1 loss value, or the like between the target region mask image and the attention mask image may be calculated for example.
[0055] Since a region of interest of the target region mask image is the target region, and a region of interest for the attention mask image might be different from the target region mask image, therefore, the attention loss value may be used for representing an attention deviation of the image processing model. The introduction of the attention loss value during the optimization of the image processing model can realize attention correction on the image processing model in the image processing process, and allow the image processing model to focus more on the processing of the target region.
[0056] The first prediction loss may represent a 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 in a plurality of dimensions, when the first prediction loss value is determined based on the first corrected image and the first predicted image, feature extraction may be firstly performed on the first corrected image in a plurality of feature dimensions to obtain a plurality of first feature images, and the feature extraction is performed on the first predicted image in the plurality of feature dimensions to obtain a plurality of second feature images; then, for any feature dimension, a processing loss value in the feature dimension is determined based on the first feature image and the second feature image in the feature dimension; and the first prediction loss value is determined based on the processing loss values in the feature dimensions.
[0057] For example, the preforming feature extraction on the first corrected image in a plurality of feature dimensions may, for example, refer to inputting the image to a feature extraction network to obtain the plurality of first feature images. The determination method of the second feature images is the same. The feature extraction in the plurality of 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 the feature extraction network may be optimized in advance.
[0058] The determining the first prediction loss value based on the processing loss values in the feature dimensions may, for example, refer to using a sum of the processing loss values in the feature dimensions as the first prediction loss value.
[0059] In this way, the difference between the first corrected image and the first predicted image is analyzed in the plurality of feature dimensions so that the difference 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.
[0060] When the target loss value is determined based on the first prediction loss value and the attention loss value, for example, the first prediction loss value and the attention loss value may be subjected to weighted summation according to a preset weight to obtain the target loss value.
[0061] In a possible implementation, after the image processing model processes the first image to obtain the first predicted image, the edge information of the first predicted image and the first corrected image should be close. Therefore, when the target loss value is calculated, a difference in edge information between the first predicted image and the first corrected image may also be used.
[0062] Exemplarily, when the target loss value is determined, first edge information corresponding to the first corrected image and second edge information corresponding to the first predicted image may be determined respectively; an edge detection loss value is then determined based on the first edge information and the second edge information; and the target loss value is determined based on the first prediction loss value, the attention loss value, and the edge detection loss value.
[0063] For example, when the first edge information and the second edge information are determined, the first edge information and the second edge information may be extracted by a high pass algorithm, a canny operator, or the like.
[0064] Taking wrinkle removal as an example, theoretically, wrinkles may produce extra edge information. After the image processing model performs wrinkle removal processing 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 during the calculation of the target loss value, it can be guaranteed that the image processing model completely removes the wrinkles in the target region and that the image processing model does not process other non-wrinkle regions of the first image. Thus, the image processing model is allowed to focus more on the processing of the target region.
[0065] In another possible implementation, when the target loss value is calculated, in order to improve the processing effect on the target region, a prediction loss between regions may also be increased.
[0066] Specifically, a first region image corresponding to the target region may be firstly determined from the first predicted image based on the target region mask image, and a second region image corresponding to the target region may be determined from the first corrected image based on the target region mask image; and then a second prediction loss value is determined based on the first region image and the second region image. In this way, when the target loss value is calculated, the target loss value may be determined based on the first prediction loss value, the second prediction loss value, and the attention loss value.
[0067] When the second prediction loss value is determined based on the first region image and the second region image, a cross-entropy loss value, an L1 loss value, or the like between the first region image and the second region image may be calculated for example.
[0068] Likewise, in order to analyze a difference between the first region image and the second region image more comprehensively, feature extraction may be performed on the first region image in a plurality of feature dimensions to obtain a plurality of third feature images, and the feature extraction is performed on the second region image in the plurality of feature dimensions to obtain a plurality of fourth feature images; then, for any feature dimension, a processing loss value in the feature dimension may be determined based on the third feature image and the fourth feature image in the feature dimension; and the second prediction loss value is determined based on the processing loss values in the feature dimensions.
[0069] The method of determining the third feature images and the fourth feature images may be, for example, the same as the method of determining the second feature images and the first feature images described above, which will not be described redundantly here.
[0070] Since the main role of the image processing model is to process the target region, the optimal processing result for other regions than the target region is keeping unchanged. Therefore, in a possible implementation, when the target loss value is determined, a difference in non-attention region between the first image and the first predicted image may also be used.
[0071] Exemplarily, a first non-attention image may be determined based on the first image and the attention mask image, and a second non-attention image may be determined based on the first predicted image and the attention mask image; and then a non-attention prediction loss value may be determined based on the first non-attention image and the second non-attention image. In this way, when the target loss value is calculated, the target loss value may be determined based on the first prediction loss value, the attention loss value, and the non-attention prediction loss value.
[0072] Specifically, when the first non-attention image is determined based on the first image and the attention mask image, an inverse mask image of the attention mask image may be determined first, and then a value of each pixel of the first image is multiplied by a value at a corresponding value of the inverse mask image to obtain the first non-attention image. The method of determining the second non-attention image is similar, which will not be described repeatedly here.
[0073] The non-attention prediction loss value may, for example, refer to an L1 loss, a cross-entropy loss value, or the like between the first non-attention image and the second non-attention image.
[0074] Exemplarily, the non-attention prediction loss value may be calculated by the following formula:L=l1(A*(α−Attmask), C*(1−Attmask)wherein 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.
[0076] When the target loss value is calculated, in combination with the non-attention prediction loss value, the optimization of the attention mask image can be realized. Further, the image processing model can be allowed to focus more on the target region.
[0077] In a possible implementation, the image processing model is an adversarial network. The adversarial network includes a generator configured to generate the first predicted image corresponding to the first image and a discriminator configured to determine whether an image input to the discriminator is a real image.
[0078] Therefore, when the target loss value is determined, the target loss value may further include adversarial losses of the generator and the discriminator.
[0079] Specifically, the generator is configured to process the first image and subject the processed image to discrimination by the discriminator. The objective of the generator is to generate an image for which the discriminator cannot distinguish truth from falsehood. The objective of the discriminator is to accurately determine whether an input image is a real image. Therefore, the objectives of the generator and the discriminator are opposed objectives, and thus, the calculated losses are the adversarial losses.
[0080] When the adversarial losses are calculated, discrimination results of the discriminator for the first predicted image and the first corrected image may be determined, and then the adversarial losses may be determined based on the discrimination results, and preset labels corresponding to the first predicted image and the first corrected image.
[0081] The generator and the discriminator are trained separately. When the generator is trained, parameters of the discriminator keep unchanged. When the discriminator is trained, parameters of the generator keep unchanged. Generally, the discriminator may be trained for one round after the generator is trained for K rounds, and the training processes of both are performed alternately.
[0082] When the discriminator is trained, the parameters of the generator are fixed. The generator may generate the first predicted image based on the first image. The label of the first predicted image may be set to 0 to mark that the predicted image is not a real image; meanwhile, the label of the first corrected image is set to 1 to mark that the first corrected image is a real image. The first corrected image and the first predicted image are then input to the discriminator, and the discriminator may output labels predicted for the first corrected image and the first predicted image. A loss calculated based on the predicted labels and originally set labels is the adversarial loss of the discriminator.
[0083] When the generator is trained, the parameters of the discriminator are fixed. The generator may generate the first predicted image based on the first image. Label 1 may be set for the generated first predicted image to mark that the first predicted image is a real image. The first predicted image is then input to the discriminator, and then the discriminator may output a predicted label. A 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.
[0084] After the adversarial loss values are determined, when the target loss value is determined, the target loss value may be determined based on the first prediction loss value, the attention loss value, and the adversarial loss values.
[0085] It needs to be noted that, when the target loss value is determined, in addition to the first prediction loss value and the attention loss value, any one or more of the edge detection loss value, the second prediction loss value, the non-attention prediction loss value, and the adversarial loss values may be used.
[0086] For example, when the target loss value is calculated in combination with the second prediction loss value, in order to emphasize the importance of the target region and enhance the processing effect of the target region, when the target loss value is calculated, the second prediction loss value may be set with a high weight.
[0087] In a possible scenario, after the image processing model processes the first image, the generated image might be distorted, or the like. Therefore, when the first predicted image is determined, low-frequency information of the first image may also be used.
[0088] Exemplarily, when the first image is input to the image processing model to be optimized to obtain the first predicted image corresponding to the first image, the image processing model may output an intermediate processed image rather than directly output the first predicted image. Blurring processing may be performed on the first image in advance to obtain a low-frequency image corresponding to the first image, and then a low-frequency information image corresponding to the first image may be determined based on the attention mask image and the low-frequency image. 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.
[0089] For example, the performing blurring processing on the first image may, for example, refer to performing Gaussian filtering on the first image, or the like. When the low-frequency information image and the intermediate processed image are fused, for example, values at corresponding positions of the low-frequency information image and the intermediate processed image may be added together, then input to an activation layer and subjected to normalization processing by the activation layer, thereby obtaining the first predicted image.
[0090] In a possible implementation, the first image is a high-definition image. In this case, there might be few first images. Therefore, when the image processing model is optimized, in order to improve the richness of training data, different illumination conditions may be set for the first image, and the first images under the different illumination conditions may be used as different inputs to the image processing model for optimization.
[0091] However, even though the limitation of the illumination condition is added, there might be still little optimization data of the image processing model (the reason is that the image quality of the first image is high). Therefore, after the image processing model is optimized based on the first image to obtain an initial image processing model, the initial image processing model may also be readjusted to improve the stability and generalization capability of the initial image processing model.
[0092] Specifically, a second image is obtained, wherein the number of the second images may be greater than the number of the first images, but the overall image quality of the second image may be lower than that of the first image; a second corrected image corresponding to the second image may be determined based on the initial image processing model; and the initial image processing model is readjusted based on the second image and the second corrected image to obtain a target image processing model.
[0093] For example, the method of readjusting the initial image processing model is the same as the method of optimizing the image processing model for the first time to obtain the initial image processing model except that the step of manually processing an image is replaced with the initial image processing model. that is, the second image is processed based on the initial image processing model, which is equivalent to processing the first image to obtain the first corrected image.
[0094] 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 reasoning process, if the target image processing model is an adversarial network, image processing may be performed only based on a generator in the target image processing model.
[0095] Based on the above embodiments, an embodiment of the present disclosure further provides an image processing method. The image processing method specifically includes the following steps:
[0096] Step 1, obtaining an image to be processed.
[0097] Step 2, processing the image to be processed based on a target image processing model to obtain a target image. The target image processing model is optimized by the method provided in the above embodiments.
[0098] In conclusion, in the optimization process of the image processing model and the reasoning process of the image processing model described above may be as shown in FIG. 3, and specifically include: obtaining a first image, then processing the obtained first image to obtain a first corrected image, and optimizing an image processing model based on the first corrected image and the first image. In the process of optimizing the image processing model, different supervision strategies may be combined. The supervision strategy may refer to combining different types of losses when calculating a target loss value in optimizing the model.
[0099] After the completion of the optimization of the image processing model, a second corrected image of a second image may be generated based on the optimized image processing model, and the optimized image processing model is adjusted based on the second image and the second corrected image.
[0100] In the model reasoning process, the image to be processed may be obtained first and then cropped according to the reasoning objective to reduce the influence of the remaining part of the image on the model accuracy, and the processed target image is generated based on the adjusted target image processing model (i.e., the generator in the adversarial network).
[0101] For the specific description of the above steps, a reference may be made to the above embodiments.
[0102] The optimization process of the image processing model is described below by taking as an example that the target region is the eye region and the forehead region, the reasoning objective of the image processing model is to remove wrinkles, and the image processing model is the adversarial network.
[0103] 1, a high-resolution first image including wrinkles in the eye region and the forehead region may be obtained first, and then the wrinkles in the eye region and the forehead region in the first image may be eliminated by means of manual wrinkle removal to obtain the first corrected image corresponding to the first image.
[0104] 2, each first image is detected with respect to an eye key point and a forehead key point to determine position information of the eye region and the forehead region in each image, and the target region mask image corresponding to each first image is generated based on the position information. In the target region mask image, values of pixels corresponding to the eye region and the forehead region are 1, and values of pixels in other regions are 0.
[0105] 3, the first image including the wrinkles is input to the adversarial network to be optimized. The adversarial network includes the generator and the discriminator. Specifically, the first image may be input to the generator to determine the first predicted image corresponding to the first image. The first predicted image is an image obtained after performing wrinkle removal processing on the eye region and the forehead region in the first image.
[0106] An attention degree of the adversarial network for each region when processing the first image may be determined based on a value of the first predicted image on the α channel. That is, the attention mask image is determined.
[0107] Further, in order to avoid distortion of the first predicted image, the generator may output an intermediate processed image. After being subjected to blurring processing, the first image is fused with the intermediate processed image to obtain the first predicted image.
[0108] 4, calculation is then carried out: (1) the first prediction loss is determined based on the first corrected image and the first predicted image; (2) the attention loss value is determined based on the target region mask image and the attention mask image; (3) the first region image is determined from the first predicted image based on the target region mask image, and the second region image is determined from the first corrected image, and then the second prediction loss value is determined based on the first region image and the second region image; (4) the edge detection loss value is determined based on the first edge information of the first corrected image and the second edge information of the first predicted image; (5) the non-attention prediction loss value for representing the difference in non-attention region between the first image and the predicted processed image is determined based on the attention mask image; and (6) the adversarial loss value of the adversarial network is determined.
[0109] The target loss value is determined based on the above loss values (e.g., by weighted summation), and the adversarial network is optimized based on the target loss value.
[0110] 5, after the adversarial network is optimized based on the target loss value, in order to improve the stability and generalization capability of the adversarial network, a large number of second images including a human face may be obtained. The second image may not be a high-resolution image. The second corrected image of the second image may be then generated based on the generator in the preliminarily optimized adversarial network. The second corrected image is equivalent to the above-mentioned first corrected image. The above-mentioned optimization process is repeatedly performed based on the second corrected image and the second image to adjust the optimized adversarial network.
[0111] The image processing method and apparatus provided by the embodiments of the present disclosure can supervise an attention mask image determined by an image processing model based on a target region mask image corresponding to a target region in a first image. Thus, attention correction on the image processing model in the image processing process can be realized such that the image processing model focuses more on the processing of the target region. The processing accuracy of the image processing model for the target region is improved.
[0112] It will be appreciated by those skilled in the art that in the cluster management method described above, the order of writing the steps does not mean a strict performing order, which imposes no any limitation on the implementation process. The specific order of performing the steps should be determined by the functions thereof and a possible internal logic.
[0113] Based on the same inventive concept, an embodiment of the present disclosure further provides an image processing apparatus corresponding to the image processing method. Since the principle of the image processing apparatus in the embodiment of the present disclosure to solve the problem is similar to that of the image processing method described above in the embodiments of the present disclosure. Therefore, for the implementations of the image processing apparatus, references may be made to the implementations of the image processing method, and repetitions may not be described herein.
[0114] With reference to FIG. 4, there is shown a schematic diagram of an architecture of an image processing apparatus provided by an embodiment of the present disclosure. The image processing apparatus includes an obtaining module 401, a determination module 402, and a processing module 403.
[0115] The obtaining module 401 is configured to obtain a first image.
[0116] The determination module 402 is configured to process a target region of the first image to obtain a first corrected image, and determine a target region mask image corresponding to the target region.
[0117] The processing module 403 is configured to input the first image to an image processing model to obtain a first predicted image, and an attention mask image corresponding to the first predicted image, and optimize the image processing model based on the first corrected image, the first predicted image, the target region mask image, and the attention mask image.
[0118] In a possible implementation, the processing module 403 is further configured to optimize the image processing model by: determining a first prediction loss value based on the first corrected image and the first predicted image, and determining an attention loss value of the image processing model to be adjusted for the target region based on the target region mask image and the attention mask image; determining the target loss value based on the first prediction loss value and the attention loss value; and optimizing the image processing model based on the target loss value.
[0119] In a possible implementation, the processing module 403, when determining the first prediction loss value based on the first corrected image and the first predicted image, is configured to: perform feature extraction on the first corrected image in a plurality of feature dimensions to obtain a plurality of first feature images, and perform the feature extraction on the first predicted image in the plurality of feature dimensions to obtain a plurality of second feature images, wherein the feature extraction in the plurality of feature dimensions includes high-dimensional feature extraction and low-dimensional feature extraction; for any feature dimension, determine a processing loss value in the feature dimension based on the first feature image and the second feature image in the feature dimension; and determine the first prediction loss value based on the processing loss values in the feature dimensions.
[0120] In a possible implementation, the processing module 403, when determining the target loss value based on the first prediction loss value and the attention loss value, is configured to: determine first edge information corresponding to the first corrected image and second edge information corresponding to the first predicted image, respectively, and determine an edge detection loss value based on the first edge information and the second edge information; and determine the target loss value based on the first prediction loss value, the attention loss value, and the edge detection loss value.
[0121] In a possible implementation, the determination module 402, when inputting the first image to the image processing model to obtain the first predicted image, is configured to: input the first image to the image processing model to determine an intermediate processed image output by the image processing model; perform blurring processing on the first image to obtain a low-frequency image corresponding to the first image; determine a low-frequency information image corresponding to the first image based on the attention mask image and the low-frequency image; and fuse the low-frequency information image and the intermediate processed image to obtain the first predicted image.
[0122] In a possible implementation, after optimizing the image processing model based on the first corrected image, the first predicted image, the target region mask image, and the attention mask image, the processing module 403 is further configured to: obtain a second image, wherein a number of the second images is greater than a number of the first images; determine a second corrected image corresponding to the second image based on the initial image processing model; and adjust the optimized image processing model based on the second image and the second corrected image.
[0123] In a possible implementation, the processing module 403, when determining the target loss value based on the first prediction loss value and the attention loss value, is configured to: determine a first region image corresponding to the target region from the first predicted image based on the target region mask image, and determine a second region image corresponding to the target region from the first corrected image based on the target region mask image; determine a second prediction loss value based on the first region image and the second region image; and determine the target loss value based on the first prediction loss value, the second prediction loss value, and the attention loss value.
[0124] Regarding the descriptions of the processing flow of each module in the apparatus and an interactive flow between the modules, a reference may be made to the related descriptions in the above method embodiments, which will not be described in detail here.
[0125] Based on the same technical concept, an embodiment of the present disclosure further provides a computer device. With reference to FIG. 5, there is shown a structural schematic diagram of a computer device 500 provided by an embodiment of the present disclosure, including a processor 501, a memory 502, and a bus 503. The memory 502 is configured to store executable instructions, and includes an internal memory 5021 and an external memory 5022. The internal memory 5021 mentioned here is configured to temporarily store operational data in the processor 501 and data exchanged with the external memory 5022 such as a hard disk. The processor 501 exchanges data with the external memory 5022 through the internal memory 5021. When the computer device 500 runs, the processor 501 communicates with the memory 502 by the bus 503 such that the processor 501 executes the following instructions: obtaining a first image; processing a target region of the first image to obtain a first corrected image, and determining a target region mask image corresponding to the target region; inputting the first image to an image processing model to obtain a first predicted image, and an attention mask image corresponding to the first predicted image; and optimizing the image processing model based on the first corrected image, the first predicted image, the target region mask image, and the attention mask image.
[0126] In a possible implementation, among the instructions executed by the processor 501, the optimizing the image processing model based on the first corrected image, the first predicted image, the target region mask image, and the attention mask image includes: determining a first prediction loss value based on the first corrected image and the first predicted image, and determining an attention loss value of the image processing model to be adjusted for the target region based on the target region mask image and the attention mask image; determining the target loss value based on the first prediction loss value and the attention loss value; and optimizing the image processing model based on the target loss value.
[0127] In a possible implementation, among the instructions executed by the processor 501, the determining a first prediction loss value based on the first corrected image and the first predicted image includes: performing feature extraction on the first corrected image in a plurality of feature dimensions to obtain a plurality of first feature images, and performing the feature extraction on the first predicted image in the plurality of feature dimensions to obtain a plurality of second feature images, wherein the feature extraction in the plurality of feature dimensions includes high-dimensional feature extraction and low-dimensional feature extraction; 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; and determining the first prediction loss value based on the processing loss values in the feature dimensions.
[0128] In a possible implementation, among the instructions executed by the processor 501, the determining a target loss value based on the first prediction loss value and the attention loss value includes: determining first edge information corresponding to the first corrected image and second edge information corresponding to the first predicted image, respectively, and determining an edge detection loss value based on the first edge information and the second edge information; and determining the target loss value based on the first prediction loss value, the attention loss value, and the edge detection loss value.
[0129] In a possible implementation, among the instructions executed by the processor 501, the inputting the first image to an image processing model to obtain a first predicted image includes: inputting the first image to the image processing model to determine an intermediate processed image output by the image processing model; performing blurring 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; and fusing the low-frequency information image and the intermediate processed image to obtain the first predicted image.
[0130] In a possible implementation, among the instructions executed by the processor 501, after the optimizing the image processing model based on the first corrected image, the first predicted image, the target region mask image, and the attention mask image, the image processing method further includes: obtaining a second image, wherein a number of the second images is greater than a number of the first images; determining a second corrected image corresponding to the second image based on the initial image processing model; and adjusting the optimized image processing model based on the second image and the second corrected image.
[0131] In a possible implementation, among the instructions executed by the processor 501, the determining a target loss value based on the first prediction loss value and the attention 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 prediction loss value based on the first region image and the second region image; and determining the target loss value based on the first prediction loss value, the second prediction loss value, and the attention loss value.
[0132] An embodiment of the present disclosure further provides a computer-readable storage medium. The computer-readable storage medium stores a computer program which, when run by a processor, performs the steps of the image processing method in the above method embodiments. The storage medium may be a volatile or nonvolatile computer-readable storage medium.
[0133] An embodiment of the present disclosure further provides a computer program product. The computer program product bears a program code. Instructions included in the program code may be configured to perform the steps of the image processing method in the above method embodiments. Details may be as shown in the above method embodiments and will not be described redundantly here.
[0134] The computer program product may be implemented specifically by hardware, software, or a combination thereof. In one optional embodiment, the computer program product is embodied as a computer storage medium. In another optional embodiment, the computer program product is embodied as a software product, e.g., a software development kit (SDK) and the like.
[0135] A person skilled in the art can clearly understand that, for convenience and brevity of description, a reference may be made to corresponding processes in the foregoing method embodiments for the specific working process of the system and apparatus described above, which will not be described here redundantly. In several embodiments provided in the present disclosure, it should be understood that the disclosed system, apparatus and method may be implemented in other manners. The apparatus embodiment described above is merely an example. For example, the unit division is merely logical function division and may be other division in actual implementation. For another example, a plurality of units or components may be combined or integrated into another system, or some features may be ignored or not performed. In addition, the displayed or discussed mutual couplings or direct couplings or communication connections may be implemented through some communication interfaces. The indirect couplings or communication connections between the apparatuses or units may be implemented in electrical, mechanical, or other forms.
[0136] The units described as separate parts may or may not be physically separate. Parts shown as units may or may not be physical units, which may be located in one position, or may be distributed on a plurality of network units. Some or all of the units may be selected according to actual requirements to achieve the objectives of the solutions of the embodiments.
[0137] In addition, functional units in the embodiments of the present disclosure may be integrated into one processing unit, or each of the units may exist alone physically, or two or more units are integrated into one unit.
[0138] If implemented in a form of a software functional unit and sold or used as a stand-alone product, functions may be stored in a nonvolatile computer-readable storage medium executable by a processor. Based on such an understanding, the technical solutions of the present disclosure that essentially make contributions or part of the technical solutions may be implemented in the form of a software product. The computer software product is stored in a storage medium, and includes a number of instructions for enabling a computer device (which may be a personal computer, a server, a network device, or the like) to perform all or some steps of the image processing method described in the embodiments of the present disclosure. The storage medium described previously includes any medium capable of storing a program code, such as a USB flash disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.
[0139] Finally, it should be noted that the above embodiments are merely specific implementations of the present disclosure, and are used to describe rather than limit the technical solutions of the present disclosure. The protection scope of the present disclosure is not limited thereto. Although the present disclosure is described in detail with reference to the above embodiments, it should be understood that a person of ordinary skill in the art can still make modifications to or readily figure out changes in the technical solutions described in the above embodiments, or make equivalent substitutions on some technical features therein. These modifications, changes, or substitutions do not make the essence of the corresponding technical solutions depart from the spirit and scope of the technical solutions of the embodiments of the present disclosure, and shall all fall within the protection scope of the present disclosure. Therefore, the protection scope of the present disclosure shall be subject to the protection scope of the claims.
Claims
1. An image processing method, comprising:obtaining a first image;processing a target region of the first image to obtain a first corrected image, and determining a target region mask image corresponding to the target region;inputting the first image to an image processing model to obtain a first predicted image, and an attention mask image corresponding to the first predicted image, and optimizing the image processing model based on the first corrected image, the first predicted image, the target region mask image, and the attention mask image.
2. The image processing method according to claim 1, wherein optimizing the image processing model based on the first corrected image, the first predicted image, the target region mask image, and the attention mask image comprises:determining a first prediction loss value based on the first corrected image and the first predicted image;determining an attention loss value of the image processing model to be adjusted for the target region based on the target region mask image and the attention mask image;determining a target loss value based on the first prediction loss value and the attention loss value; andoptimizing the image processing model based on the target loss value.
3. The image processing method according to claim 2, wherein the determining a first prediction loss value based on the first corrected image and the first predicted image comprises:performing feature extraction on the first corrected image in a plurality of feature dimensions respectively to obtain a plurality of first feature images, and performing the feature extraction on the first predicted image in the plurality of feature dimensions to obtain a plurality of second feature images, wherein the feature extraction in the plurality of feature dimensions comprises high-dimensional feature extraction and low-dimensional feature extraction;for any one of the plurality of feature dimensions, determining a processing loss value in the feature dimension based on the first feature image and the second feature image in the feature dimension; anddetermining the first prediction loss value based on processing loss values in the plurality of feature dimensions.
4. The image processing method according to claim 2, wherein the determining a target loss value based on the first prediction loss value and the attention loss value comprises:determining first edge information corresponding to the first corrected image and second edge information corresponding to the first predicted image, respectively, and determining an edge detection loss value based on the first edge information and the second edge information; anddetermining the target loss value based on the first prediction loss value, the attention loss value, and the edge detection loss value.
5. The image processing method according to claim 1, wherein the inputting the first image to an image processing model to obtain a first predicted image comprises:inputting the first image to the image processing model to determine an intermediate processed image output by the image processing model;performing blurring 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; andfusing the low-frequency information image and the intermediate processed image to obtain the first predicted image.
6. The image processing method according to claim 1, after optimizing the image processing model based on the first corrected image, the first predicted image, the target region mask image, and the attention mask image, further comprising:obtaining a second image, wherein a number of second images is greater than a number of first images;determining a second corrected image corresponding to the second image based on the image processing model; andadjusting the optimized image processing model based on the second image and the second corrected image.
7. The image processing method according to claim 2, wherein the determining a target loss value based on the first prediction loss value and the attention loss value comprises: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 prediction loss value based on the first region image and the second region image; anddetermining the target loss value based on the first prediction loss value, the second prediction loss value, and the attention loss value.
8. (canceled)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 runs, the processor communicates with the memory by the bus; and when the machine-readable instructions are executed by the processor, an image processing method is implemented, comprising:obtaining a first image;processing a target region of the first image to obtain a first corrected image, and determining a target region mask image corresponding to the target region;inputting the first image to an image processing model to obtain a first predicted image, and an attention mask image corresponding to the first predicted image, and optimizing the image processing model based on the first corrected image, the first predicted image, the target region mask image, and the attention mask image.
10. A computer-readable storage medium, storing a computer program which, when run by a processor, implements an image processing method comprising:obtaining a first image;processing a target region of the first image to obtain a first corrected image, and determining a target region mask image corresponding to the target region;inputting the first image to an image processing model to obtain a first predicted image, and an attention mask image corresponding to the first predicted image, and optimizing the image processing model based on the first corrected image, the first predicted image, the target region mask image, and the attention mask image.
11. The computer device according to claim 9, wherein optimizing the image processing model based on the first corrected image, the first predicted image, the target region mask image, and the attention mask image comprises:determining a first prediction loss value based on the first corrected image and the first predicted image;determining an attention loss value of the image processing model to be adjusted for the target region based on the target region mask image and the attention mask image;determining a target loss value based on the first prediction loss value and the attention loss value; andoptimizing the image processing model based on the target loss value.
12. The computer device according to claim 11, wherein the determining a first prediction loss value based on the first corrected image and the first predicted image comprises:performing feature extraction on the first corrected image in a plurality of feature dimensions respectively to obtain a plurality of first feature images, and performing the feature extraction on the first predicted image in the plurality of feature dimensions to obtain a plurality of second feature images, wherein the feature extraction in the plurality of feature dimensions comprises high-dimensional feature extraction and low-dimensional feature extraction;for any one of the plurality of feature dimensions, determining a processing loss value in the feature dimension based on the first feature image and the second feature image in the feature dimension; anddetermining the first prediction loss value based on processing loss values in the plurality of feature dimensions.
13. The computer device according to claim 11, wherein the determining a target loss value based on the first prediction loss value and the attention loss value comprises:determining first edge information corresponding to the first corrected image and second edge information corresponding to the first predicted image, respectively, and determining an edge detection loss value based on the first edge information and the second edge information; anddetermining the target loss value based on the first prediction loss value, the attention loss value, and the edge detection loss value.
14. The computer device according to claim 9, wherein the inputting the first image to an image processing model to obtain a first predicted image comprises:inputting the first image to the image processing model to determine an intermediate processed image output by the image processing model;performing blurring 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; andfusing the low-frequency information image and the intermediate processed image to obtain the first predicted image.
15. The computer device according to claim 9, after optimizing the image processing model based on the first corrected image, the first predicted image, the target region mask image, and the attention mask image, further comprising:obtaining a second image;determining a second corrected image corresponding to the second image based on the image processing model; andadjusting the optimized image processing model based on the second image and the second corrected image.
16. The computer device according to claim 11, wherein the determining a target loss value based on the first prediction loss value and the attention loss value comprises: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 prediction loss value based on the first region image and the second region image; anddetermining the target loss value based on the first prediction loss value, the second prediction loss value, and the attention loss value.
