Image restoration method, image restoration device, electronic equipment and storage medium
Through the structure reconstruction and color reconstruction of the image repair network, combined with the feature extraction of U-Net and transformer modules, the problem of difficult balance between structure reconstruction and color consistency in the existing technology is solved, and high-quality repair effects for any type of defects are achieved. .
Patent Information
- Application Number
- CN202410460657.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-17
- Publication Date
- 2024-09-10
- Estimated Expiration
- 2044-04-17
AI Technical Summary
Existing image repair technology is difficult to achieve a good balance between structural reconstruction and color consistency, especially for non-rectangular or irregular-shaped defects.
The image repair network is used, including the structure reconstruction network and the color reconstruction network. The structure reconstruction network is composed of the U-Net module and the transformer module. Through the combination of local feature extraction and global feature extraction, the structure reconstruction and color reconstruction of the image are performed, and feature fusion is performed. to improve the image repair effect.
It achieves high-quality repair of any type of defects, ensures the structural integrity and color consistency of the image, and significantly improves the repair effect of non-rectangular or irregular-shaped defects.
Smart Images

Figure CN118628406A
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing technology, and in particular to an image restoration method, an image restoration device, an electronic device and a storage medium. Background Art
[0002] In the related art, image restoration technology is used to restore damaged or incomplete image content. However, these methods perform well in dealing with specific types of defects, but each method has its limitations. For example, some methods may perform well in structural reconstruction or color consistency, but cannot achieve a good balance between the two. In addition, these methods have poor repair effects on non-rectangular or irregularly shaped defects. Summary of the invention
[0003] The main purpose of the embodiments of the present application is to propose an image restoration method and device, an electronic device and a storage medium, aiming to improve the image restoration effect and ensure the accuracy and authenticity of the restored image.
[0004] To achieve the above-mentioned purpose, a first aspect of an embodiment of the present application provides an image restoration method, the method comprising:
[0005] Acquire a damaged image of the target;
[0006] Inputting the target damaged image into an image restoration network, wherein the image restoration network includes a structure reconstruction network and a color reconstruction network; the structure reconstruction network includes a U-Net module and a transformer module;
[0007] Performing local feature extraction on the target damaged image through the U-Net module to obtain a reference feature map;
[0008] Performing global feature extraction on the reference feature map through the transformer module to obtain a structural reconstruction image;
[0009] Performing color reconstruction on the structure reconstructed image through the color reconstruction network to obtain color features;
[0010] The color feature and the structural reconstruction image are fused to obtain a complete image of the target damaged image.
[0011] In some embodiments, the image restoration network is trained according to the following steps:
[0012] Acquire a sample damaged image and a sample complete image; the sample damaged image has a damaged area;
[0013] Performing edge detection on the sample complete image to obtain a wireframe image of the sample complete image;
[0014] Inputting the sample damaged image and the wireframe diagram into a first generator for image generation to obtain a first image;
[0015] Obtaining pixel points of the first image at the damaged area to obtain a mask image, and performing image completion on the sample damaged image according to the mask image to obtain a second image;
[0016] Obtaining the code of the damaged area to obtain a position coding feature map;
[0017] Inputting the second image and the position coding feature map into a second generator to generate an image, thereby obtaining a sample color feature map;
[0018] Obtaining pixel points of the sample color feature map in the damaged area to obtain a target color feature map, and performing image completion on the second image according to the target color feature map to obtain a repaired image;
[0019] Inputting the repaired image into a discriminator for image discrimination to obtain an adversarial loss;
[0020] A loss is calculated based on the sample complete image, the repaired image and the adversarial loss;
[0021] The structure reconstruction network is obtained by adjusting the model parameters of the first generator according to the generation loss, and the color reconstruction network is obtained by adjusting the model parameters of the second generator according to the generation loss.
[0022] In some embodiments, the generating loss according to the sample complete image, the repaired image and the adversarial loss calculation includes:
[0023] Perform loss calculation based on the sample complete image and the repaired image to obtain an L1 loss;
[0024] Inputting the sample complete image and the repaired image into a preset network, wherein the preset network includes a plurality of network layers, and the network layer includes an activation layer;
[0025] Extracting features of the complete sample image through multiple network layers to obtain first sample features of each network layer, and extracting features of the repaired image through multiple network layers to obtain second sample features of each network layer;
[0026] Performing loss calculation according to the first sample feature of the target network layer and the second sample feature of the target network layer to obtain content loss;
[0027] Obtain a first Gram matrix of the first sample features of each network layer and a second Gram matrix of the second sample features of each network layer;
[0028] Perform loss calculation according to the first Gram matrix of each network layer, the second Gram matrix of each network layer, and the weight parameter of each network layer to obtain a style loss;
[0029] Performing activation processing on the sample complete image through the multiple activation layers to obtain a first activation feature of each activation layer, and performing activation processing on the repaired image through the multiple activation layers to obtain a second activation feature of each activation layer;
[0030] The loss is calculated according to the first activation feature of each activation layer, the second activation feature of each activation layer, and the weight parameter of each activation layer to obtain a histogram loss;
[0031] The L1 loss, the content loss, the style loss, the histogram loss and the adversarial loss are weighted to obtain the generation loss.
[0032] In some embodiments, after inputting the repaired image into a discriminator for image discrimination to obtain the adversarial loss, the image repair method further includes:
[0033] Inputting the first image into the discriminator for image discrimination to obtain discrimination information;
[0034] Perform loss calculation according to the adversarial loss and the discriminant information to obtain a discriminant loss;
[0035] The model parameters of the discriminator are adjusted according to the discriminant loss.
[0036] In some embodiments, the U-Net module includes a plurality of encoding blocks, a residual block and a plurality of decoding blocks, the encoding blocks correspond to the decoding blocks one by one, and there is a jump connection between the encoding blocks and the decoding blocks, and the local feature extraction of the target damaged image by the U-Net module to obtain a reference feature map includes:
[0037] Extracting coding features of the target damaged image step by step through multiple coding blocks to obtain multiple coding image features; the spatial resolution of the coding image features is gradually reduced;
[0038] Extracting residual features of the encoded image features output by the last encoding block through the residual block to obtain residual image features;
[0039] The residual image features are subjected to step-by-step decoding feature extraction through multiple decoding blocks, thereby obtaining multiple decoded image features; the spatial resolution of the decoded image features is gradually increased; the decoded image features output by the current decoding block are obtained by feature fusion of the decoded image features output by the previous decoding block and the encoded image features output by the encoding block having a jump connection with the current decoding block;
[0040] The decoded image features output by the last decoding block are used as the reference feature map.
[0041] In some embodiments, the coding block includes a partial convolution layer, a first batch of normalization layers, and a spatial variation activation unit, and the step-by-step coding feature extraction of the target damaged image through the multiple coding blocks is performed to obtain multiple coded image features, including:
[0042] Performing convolution processing on the target damaged image through the partial convolution layer of the first encoding block to obtain a first convolution feature;
[0043] Performing batch normalization processing on the first convolutional features through the first batch normalization layer to obtain a first batch of normalized features;
[0044] Activating the first batch of normalized features by the spatial variation activation unit to obtain the coded image features output by the first coding block;
[0045] Extracting the encoded image features output by the current encoding block through the next encoding block until the encoded image features output by the last encoding block are obtained, thereby obtaining a plurality of the encoded image features;
[0046] The decoding block includes a dual frequency domain convolution layer, a second batch normalization layer and a leakage space variation activation unit. The residual image features are subjected to step-by-step decoding feature extraction through multiple decoding blocks to obtain multiple decoded image features, including:
[0047] Activating the residual image feature through the dual-frequency domain convolution layer of the first decoding block to obtain a second convolution feature;
[0048] performing batch normalization processing on the second convolutional features through the second batch normalization layer to obtain a second batch normalized features;
[0049] Activating the second batch of normalized features by the leakage space variation activation unit to obtain the decoded image features output by the first decoding block;
[0050] Fusing the decoded image features output by the previous decoding block with the encoded image features output by the encoding block corresponding to the current decoding block to obtain a fused feature;
[0051] The fusion feature is subjected to decoding feature extraction through the current decoding block until the decoded image feature output by the last decoding block is obtained, thereby obtaining a plurality of the decoded image features.
[0052] In some embodiments, performing global feature extraction on the reference feature map through the transformer module to obtain a structural reconstructed image includes:
[0053] Extract the first attention feature from the reference feature map to obtain the axial attention feature;
[0054] Performing second attention feature extraction on the axial attention feature to obtain the standard attention feature;
[0055] The standard attention features are upsampled to obtain the structured reconstructed image.
[0056] To achieve the above-mentioned purpose, a second aspect of an embodiment of the present application provides an image restoration device, the device comprising:
[0057] An acquisition module, used for acquiring a damaged image of a target;
[0058] An input module, used to input the target damaged image into an image restoration network, wherein the image restoration network includes a structure reconstruction network and a color reconstruction network; the structure reconstruction network includes a U-Net module and a transformer module;
[0059] A first feature extraction module, configured to extract local features of the target damaged image through the U-Net module to obtain a reference feature map;
[0060] A second feature extraction module is used to perform global feature extraction on the reference feature map through the transformer module to obtain a structural reconstruction image;
[0061] A color reconstruction module, used for performing color reconstruction on the structure reconstruction image through the color reconstruction network to obtain color features;
[0062] A fusion module is used to fuse the color feature and the structural reconstruction image to obtain a complete image of the target damaged image.
[0063] To achieve the above-mentioned purpose, the third aspect of an embodiment of the present application proposes an electronic device, the electronic device comprising a memory and a processor, the memory storing a computer program, and the image restoration method of the above-mentioned first aspect is implemented when the processor executes the computer program.
[0064] To achieve the above-mentioned purpose, the fourth aspect of the embodiments of the present application proposes a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the image restoration method of the above-mentioned first aspect is implemented.
[0065] The image restoration method, image restoration device, electronic device and computer-readable storage medium proposed in the present application obtain a target damaged image and input the target damaged image into an image restoration network to repair the damaged area of the target damaged image. The restoration network includes a structure reconstruction network and a color reconstruction network to ensure that the image restoration method achieves a good balance between structure reconstruction and color consistency. The structure information of the missing or damaged area in the image can be restored through the structure reconstruction network to ensure the structural integrity of the image. The color information of the missing or damaged area in the image can be restored through the color reconstruction network to ensure the color consistency of the image. The structure reconstruction network includes a U-Net module and a transformer module. The U-Net module is used to extract local features of the target damaged image to improve the feature encoding capability of the missing or damaged area, enhance the network's processing capability of structural complexity and texture richness, thereby improving the repair effect of non-rectangular or irregular shape defects and obtaining a reference feature map. The global feature extraction of the reference feature map through the transformer module can capture global information and long-distance dependence, strengthen the global perception capability of the network, and obtain a structurally reconstructed image. By combining the powerful feature extraction capabilities of the U-Net module and the global information processing capabilities of the transformer module, the semantic coherence and style consistency of the image are guaranteed to achieve high-quality image restoration. In order to ensure the color consistency of the image, the color reconstruction network is used to reconstruct the color of the structural reconstruction image to obtain color features. The color features and the structural reconstruction image are fused to perform color correction on the structural reconstruction image to obtain a complete image of the target damaged image. BRIEF DESCRIPTION OF THE DRAWINGS
[0066] Figure 1 is a flow chart of an image restoration method provided by an embodiment of the present application;
[0067] Figure 2 is a structural diagram of an image restoration network provided in an embodiment of the present application;
[0068] Figure 3 It is a U-Net network architecture diagram provided in an embodiment of the present application;
[0069] Figure 4 is a flow chart of the training process of the image restoration network provided in an embodiment of the present application;
[0070] Figure 5 is a schematic diagram of an image restoration method provided in an embodiment of the present application;
[0071] Figure 6 is another flow chart of the image restoration method provided by an embodiment of the present application;
[0072] Figure 7 yes Figure 4 Flowchart of step S4090 in FIG.
[0073] Figure 8 yes Figure 1 Flow chart of step S130 in FIG.
[0074] Fig. 9 yes Figure 8 Flowchart of step S810 and step S830 in FIG.
[0075] Fig.10 yes Figure 1 Flow chart of step S140 in FIG.
[0076] Fig.11 is a schematic structural diagram of an image restoration device provided in an embodiment of the present application;
[0077] Fig.12 It is a schematic diagram of the hardware structure of the electronic device provided in the embodiment of the present application. DETAILED DESCRIPTION
[0078] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0079] It should be noted that, although the functional modules are divided in the device schematic diagram and the logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than the module division in the device or the order in the flowchart. The terms "first", "second", etc. in the specification, claims and the above drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.
[0080] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein are only for the purpose of describing the embodiments of this application and are not intended to limit this application.
[0081] Image restoration technology occupies an important position in the field of digital image processing, especially in the protection and digital restoration of cultural heritage. Image restoration technology can effectively restore damaged or incomplete image content. At present, facing the problem of image restoration, a variety of restoration methods including but not limited to local and global ones have been proposed, such as RFR, DeepFillv2, EdgeConnect, etc. These methods perform well in dealing with specific types of defects, but each method has its limitations. For example, some methods may excel in structural reconstruction or color consistency, but cannot achieve a good balance between the two. In addition, these methods have the problem of poor restoration effect for defects with non-rectangular or irregular shapes.
[0082] Based on this, the embodiments of the present application provide an image restoration method, an image restoration device, an electronic device and a computer-readable storage medium, which aim to balance structure reconstruction and color consistency, improve the image restoration effect, and realize the repair of any type of defects.
[0083] The image restoration method, image restoration device, electronic device and computer-readable storage medium provided in the embodiments of the present application are specifically described through the following embodiments. First, the image restoration method in the embodiments of the present application is described.
[0084] The image repair method provided in the embodiment of the present application relates to the field of image processing technology. The image repair method provided in the embodiment of the present application can be applied to a terminal, can be applied to a server side, or can be software running in a terminal or a server side. In some embodiments, the terminal can be a smart phone, a tablet computer, a laptop computer, a desktop computer, etc.; the server side can be configured as an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms; the software can be an application that implements the image repair method, etc., but is not limited to the above forms.
[0085] The present application can be used in many general or special computer system environments or configurations. For example: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, etc. The present application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present application can also be practiced in distributed computing environments, in which tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media including storage devices.
[0086] Figure 1 is an optional flow chart of the image restoration method provided in the embodiment of the present application. Figure 1 The method may include but is not limited to steps S110 to S160.
[0087] Step S110, obtaining a target damaged image;
[0088] Step S120, inputting the target damaged image into an image restoration network, the image restoration network including a structure reconstruction network and a color reconstruction network; the structure reconstruction network including a U-Net module and a transformer module;
[0089] Step S130, extracting local features of the target damaged image through a U-Net module to obtain a reference feature map;
[0090] Step S140, performing global feature extraction on the reference feature map through a transformer module to obtain a structural reconstruction image;
[0091] Step S150, performing color reconstruction on the structure reconstructed image through a color reconstruction network to obtain color features;
[0092] Step S160: fusing the color feature and the structural reconstruction image to obtain a complete image of the target damaged image.
[0093] In step S110 of some embodiments, the target damaged image refers to an image whose quality is degraded due to compression, noise interference, data loss, etc. during the acquisition, transmission, and storage process. The target damaged image may be an everyday photographic work, medical image, ancient painting, mural, etc., whose image content is incomplete or damaged. The target damaged image may be acquired through a camera or other shooting device, or may be directly acquired from a data set.
[0094] In step S120 of some embodiments, in order to restore the missing or damaged parts of the target damaged image and improve the quality and visual effect of the image, the target damaged image is input into the image restoration network for image restoration. The image restoration network includes a structure reconstruction network and a color reconstruction network. The structure reconstruction network is used to restore the basic structure and edge lines of the target damaged image to ensure the structural integrity and accuracy of the image. The visual quality of the image cannot be fully restored by relying solely on the structure reconstruction network. Therefore, the color of the image restoration area is adjusted through the color reconstruction network to match the hue and brightness of the original image to ensure the color consistency of the image and achieve seamless visual integration. Based on the asymptotic image restoration strategy, the image restoration process is divided into two stages: structure reconstruction and color reconstruction. In the structure reconstruction stage, the lost edges and lines are finely restored, and in the color reconstruction stage, the preliminary restoration results are further improved. A good balance can be achieved between structure reconstruction and color consistency, and a restoration effect closer to the original image can be obtained.
[0095] like Figure 2 As shown in the figure, the image restoration network adopts the generative adversarial network framework, including two generators and a discriminator. The first generator is a structure reconstruction network, and the second generator is a color reconstruction network. Both the first generator and the second generator include multiple encoding blocks and multiple decoding blocks, and there are jump connections between the encoding blocks and the corresponding decoding blocks. The second generator adds a self-attention block after the last encoding block. The discriminator carefully evaluates the generated image according to the pre-defined quality standards to ensure the high quality of the output image. The input features and output features of the second generator are fused and input to the discriminator. In order to improve the performance of the discriminator, the network structure of the discriminator is optimized so that the discriminator can more accurately evaluate the quality and authenticity of the generated image. The design of the discriminator adopts a deep convolutional network structure to extract features layer by layer, and evaluates the authenticity of the image through a fully connected layer. The discriminator is only used in the network training stage. By comparing the real image and the generated image, it guides the generator to further optimize and achieve a more visually realistic restoration effect. Existing image restoration technologies encounter difficulties when processing images with large-area damage, complex textures, and structures. This application improves and optimizes the traditional generative adversarial network framework, embedding the U-Net architecture and transformer module in the generator to replace the standard convolutional layer in the original network. The structural reconstruction network includes a U-Net module and a transformer module. The U-Net module adopts the U-Net architecture. The U-Net module is used to capture and retain local information. The transformer module is based on its self-attention mechanism and can effectively capture and retain global information. By combining the global information processing capabilities of the transformer and the powerful feature extraction capabilities of the U-Net, high-quality image restoration is achieved. Figure 3 As shown in the figure, the U-Net module includes multiple encoding blocks, residual blocks and multiple decoding blocks. Multiple encoding blocks constitute the left branch of the U-shaped structure, and multiple decoding blocks constitute the right branch of the U-shaped structure. The residual block is used to connect the left branch and the right branch. The left branch is used to downsample the input, and the right branch is used to upsample the input. The encoding block corresponds to the decoding block one by one, and there is a jump connection between the encoding block and the decoding block. Combining the U-Net structure, the transformer module and the generative adversarial network framework improves the quality of the repaired image and realizes the accurate prediction and repair of the damaged area of the complex image.
[0096] See also Figure 4 In some embodiments, the training process of the image restoration network may include but is not limited to steps S4010 to S4100:
[0097] Step S4010, obtaining a sample damaged image and a sample complete image; the sample damaged image has a damaged area;
[0098] Step S4020, performing edge detection on the complete sample image to obtain a wireframe image of the complete sample image;
[0099] Step S4030, inputting the sample damaged image and the wireframe image into a first generator for image generation to obtain a first image;
[0100] Step S4040, obtaining pixel points of the first image in the damaged area to obtain a mask image, and completing the sample damaged image according to the mask image to obtain a second image;
[0101] Step S4050, obtaining the code of the damaged area to obtain a position coding feature map;
[0102] Step S4060, inputting the second image and the position coding feature map into a second generator for image generation to obtain a sample color feature map;
[0103] Step S4070, obtaining pixel points of the sample color feature map in the damaged area to obtain a target color feature map, and performing image completion on the second image according to the target color feature map to obtain a repaired image;
[0104] Step S4080, inputting the repaired image into the discriminator for image discrimination to obtain adversarial loss;
[0105] Step S4090, calculating and generating a loss based on the sample complete image, the repaired image, and the adversarial loss;
[0106] Step S4100, adjusting the model parameters of the first generator according to the generation loss to obtain a structure reconstruction network, and adjusting the model parameters of the second generator according to the generation loss to obtain a color reconstruction network.
[0107] In step S4010 of some embodiments, the sample damaged image refers to a low-quality damaged image used for model training, and the sample complete image refers to a high-quality image that matches the sample damaged image. The sample damaged image can be obtained by blurring the sample complete image, adding noise, etc. The sample damaged image has a damaged area, and the damaged area is an image area where the image content is incomplete or damaged. Figure 5 As shown in FIG. 1 , a damaged image of a sample is obtained by covering a certain area of the complete image of the sample. The covered area is the damaged area.
[0108] In step S4020 of some embodiments, a wireframe guidance strategy is used to enhance the model's ability to restore the structure and texture of the image, and the wireframe is used as the key guiding information for image restoration, so that the trained image restoration network is suitable for scenes with complex structural features such as artwork restoration and cultural heritage protection. Detailed wireframes are generated from the sample complete image using high-precision image processing tools such as Adobe Photoshop, GIMP, Sketch, etc. These tools support advanced editing functions and layer processing capabilities, and use edge detection techniques such as the Canny edge detection algorithm, contour extraction, threshold processing, and image segmentation to extract structural features of the sample complete image to obtain a wireframe. The wireframe includes but is not limited to edge information, key nodes, and important texture areas, accurately capturing the key structural features that need to be restored in the damaged image, and providing precise guidance for subsequent image restoration. The edge information in the image can be identified by the Canny edge detection algorithm, and then the structure is further refined by contour extraction and image segmentation techniques, ensuring that the image can be reconstructed with high accuracy in the subsequent restoration process. The application of these technologies not only strengthens the deep learning model's understanding of image structure, but also significantly improves the quality and accuracy of image restoration in actual image restoration. Through such preprocessing steps, the image restoration method can achieve a more refined and high-quality restoration effect.
[0109] In step S4030 of some embodiments, the powerful feature extraction and encoding capabilities of the U-Net architecture are used to accurately predict and repair the missing areas of the image, and the wireframe guidance information is combined to further improve the repair quality. During the repair process of the generator, the wireframe is used together with the covered damaged image, i.e., the sample damaged image, to guide the repair, so as to enhance the network's learning of structural information. Figure 5As shown, after the damaged sample image and the wireframe image are spliced, they are input into the first generator for image generation to obtain the first image. The first image is the image after structural reconstruction.
[0110] In step S4040 of some embodiments, in order to obtain the repair information of the damaged area, the first image is cropped, and the pixels of the first image in the damaged area are obtained to obtain a mask image, and the mask image is the image of the damaged area after repair. The present application retains the information of the undamaged area, and only performs image repair on the damaged area. The mask image and the sample damaged image are image fused to complete the detail information of the damaged area to obtain the second image. For example, the pixel value of the damaged area is set to 1, and the pixel values of other areas of the sample damaged image except the damaged area are set to 0, and a binary mask of the sample damaged image can be obtained. The first image is multiplied by the binary mask to obtain the mask image. The pixel value of each pixel point of the mask image is added to the pixel value of each pixel point of the sample damaged image to obtain the second image.
[0111] In step S4050 of some embodiments, the binary mask of the sample damaged image is used as the encoding of the damaged area to obtain a position encoding feature map.
[0112] In step S4060 of some embodiments, in order to make the style of the damaged area after repair consistent with the style of the undamaged area, the output of the first generator is optimized by the second generator. The second generator combines the output and mask of the first generator, splices the second image and the position coding feature map, and inputs them into the second generator for image generation to obtain a sample color feature map. The sample color feature map is the color feature of the damaged area inferred by the second generator based on the sample damaged image. The sample color feature map includes the saturation, brightness, color temperature, contrast, hue, etc. of the image.
[0113] In step S4070 of some embodiments, the sample color feature map is cropped, that is, the position coding feature map is multiplied with the sample color feature map to obtain the pixel points of the sample color feature map in the damaged area to obtain the target color feature map. The target color feature map is added to the second image to complete the color features of the damaged area in the second image to obtain a repaired image.
[0114] In step S4080 of some embodiments, in the generative adversarial network, the discriminator is used to distinguish between real images and generated images. The discriminator is trained to recognize that real images are true and generated images are false. In order to improve the image generation effect of the first generator and the second generator, the repaired image is input into the discriminator for image discrimination, and the adversarial loss is obtained, and the first generator and the second generator are optimized using the adversarial loss. The adversarial loss is used to characterize the probability of the authenticity of the repaired image, that is, the probability that the repaired image is a real image or the probability that the repaired image is a generated image, and the sum of these two probabilities is 1. If the repaired image is represented by G(z), then the adversarial loss is represented by D(G(z)). z represents the sample damaged image, G represents the generator, and D represents the discriminator.
[0115] In step S4090 of some embodiments, a generation loss is calculated based on the sample complete image, the repaired image and the adversarial loss, and the generation loss is the loss of the first generator and the second generator.
[0116] In step S4100 of some embodiments, the generation loss is minimized, the model parameters of the first generator are updated to obtain a structure reconstruction network, and the model parameters of the second generator are updated to obtain a color reconstruction network.
[0117] In the above steps S4010 to S4100, the wireframe diagram is introduced to guide the first generator to repair the structure and texture of the damaged area, thereby ensuring the continuity of the image structure and the accuracy of the detailed texture, so as to improve the repair effect of images with large-area damage and complex structures and textures. The repair effect of the first generator is improved by the second generator, ensuring the color consistency between the damaged area and the original image, and improving the naturalness of the visual effect.
[0118] See also Figure 6 In some embodiments, after step S4080, the following steps may be performed, including but not limited to steps S610 to S630:
[0119] Step S610, inputting the first image into a discriminator for image discrimination to obtain discrimination information;
[0120] Step S620, calculating the loss according to the adversarial loss and the discrimination information to obtain the discrimination loss;
[0121] Step S630, adjusting the model parameters of the discriminator according to the discriminant loss.
[0122] In step S610 of some embodiments, the discriminator is used to evaluate the difference between the generated image and the real image to optimize the performance of the generator. The loss function of the discriminator adopts binary cross entropy loss, which is expressed as:
[0123] L Discriminator=-∑[ylog(D(x))+(1-y)log(1-D(G(z)))]
[0124] Among them, L Discriminator represents the discriminant loss, D(x) represents the discriminator's prediction for the real image, D(G(z)) represents the discriminator's prediction for the generated image; y is the ground truth label of the real image, which represents the probability that the real image is real.
[0125] This loss function aims to optimize the discriminator parameters to make it more accurate in distinguishing generated images from real images. Based on the loss function, the first image is input into the discriminator for image discrimination, and the discriminant information D(x) is obtained. The discriminant information is the discriminator's prediction result of the authenticity of the first image.
[0126] In step S620 of some embodiments, the discriminant information is represented as D(x), the adversarial loss is represented as D(G(z)), and based on the binary cross entropy loss, the loss is calculated according to the adversarial loss and the discriminant information to obtain the discriminant loss.
[0127] In step S630 of some embodiments, the model parameters of the discriminator are adjusted by minimizing the discriminant loss.
[0128] In the above steps S610 to S630, by training the discriminator, the discriminator's ability to distinguish between generated images and real images can be improved, thereby optimizing the generator and improving the generator's repair effect on damaged images.
[0129] See also Figure 7 In some embodiments, step S4090 may include but is not limited to steps S710 to S790:
[0130] Step S710, performing loss calculation based on the sample complete image and the repaired image to obtain the L1 loss;
[0131] Step S720, inputting the sample complete image and the repaired image into a preset network, where the preset network includes a plurality of network layers, and the network layers include an activation layer;
[0132] Step S730, extracting features of the sample complete image through multiple network layers to obtain a first sample feature of each network layer, and extracting features of the repaired image through multiple network layers to obtain a second sample feature of each network layer;
[0133] Step S740, performing loss calculation according to the first sample feature of the target network layer and the second sample feature of the target network layer to obtain content loss;
[0134] Step S750, obtaining a first Gram matrix of the first sample features of each network layer and a second Gram matrix of the second sample features of each network layer;
[0135] Step S760, performing loss calculation according to the first Gram matrix of each network layer, the second Gram matrix of each network layer, and the weight parameter of each network layer to obtain the style loss;
[0136] Step S770, performing activation processing on the sample complete image through multiple activation layers to obtain a first activation feature of each activation layer, and performing activation processing on the repaired image through multiple activation layers to obtain a second activation feature of each activation layer;
[0137] Step S780, performing loss calculation according to the first activation feature of each activation layer, the second activation feature of each activation layer, and the weight parameter of each activation layer to obtain a histogram loss;
[0138] In step S790, the L1 loss, content loss, style loss, histogram loss and adversarial loss are weighted to obtain the generation loss.
[0139] In step S710 of some embodiments, in the framework of the generative adversarial network, two loss functions, namely, the generative loss and the discriminative loss, usually work together to train the network. A comprehensive loss function is used for the generator, and the generator loss is decomposed into perceptual loss, L1 loss, histogram loss and adversarial loss. These four loss functions evaluate and optimize the restoration quality from different angles, and the joint action of these loss functions achieves a comprehensive improvement in the image restoration effect.
[0140] It should be noted that perceptual loss is widely used in the field of image restoration and style transfer. It is the core part of the generator's comprehensive loss function, which mainly consists of content loss and style loss to improve the visual quality of the restored image, especially focusing on the coherence of detail texture and structure. The expression of perceptual loss is:
[0141] L Gram =αL Content +βL Style
[0142] Among them, L Gram is the perceptual loss, L Content is the content loss, L Style is the style loss, α and β are the weight parameters used to adjust the contribution of the two losses. By adjusting the weight parameters of content loss and style loss, not only can the essential features of the image be captured and reproduced more accurately, the authenticity of the restored image can be maintained, but also the perceptual quality of the restored image can be significantly improved.
[0143] L1 loss is also known as Mean Absolute Error (MAE), which is defined by the sum of the absolute differences between the predicted image and the actual image at the pixel level. This loss function helps maintain the consistency of color and brightness during the image restoration process, ensuring that the restored image maintains a high degree of similarity with the original image as a whole. Its calculation formula is as follows:
[0144]
[0145] Among them, L1 represents L1 loss, n is the number of image pixels, and y i Represents the pixel value of the i-th pixel in the repaired image; Represents the pixel value of the i-th pixel in the complete sample image.
[0146] Since the image size of the repaired image and the sample complete image is the same, the number of image pixels of the two images is also the same. Get the first pixel value of each pixel in the repaired image and the second pixel value of each pixel in the sample complete image, and subtract the first pixel value from the second pixel value to obtain the absolute value of the pixel difference of each pixel. Calculate the sum of the absolute values of all pixel differences, and multiply the sum of the absolute values by the number of image pixels to obtain the L1 loss.
[0147] In step S720 of some embodiments, the content loss and style loss are calculated using a pre-trained deep network, reflecting the similarity between the restored image and the sample complete image in terms of content and style. The preset network is a pre-trained network for feature extraction, such as a VGG network. The sample complete image and the restored image are input into the preset network, which is composed of a plurality of network layers cascaded, and the network layers include activation layers.
[0148] In step S730 of some embodiments, feature extraction is performed on the sample complete image through multiple network layers to obtain a first sample feature output by each network layer, and feature extraction is performed on the repaired image through multiple network layers to obtain a second sample feature output by each network layer. The first sample feature and the second sample feature are feature mappings of the sample complete image and the repaired image at the network layer, including low-level features such as edges and textures, as well as high-level features such as object morphology and image spatial hierarchy.
[0149] In step S740 of some embodiments, the content loss quantifies the feature difference between the generated image and the reference content image at certain layers. The target network layer is a specific network layer among the multiple network layers, and the feature difference between the first sample feature and the second sample feature output by the target network layer is calculated to obtain the content loss. The definition of content loss is as follows:
[0150]
[0151] Among them, G represents the second sample feature of the generated image, i.e. the repaired image, outputted at the target network layer, and T represents the first sample feature of the target image, i.e. the sample complete image, outputted at the target network layer. C, H, and W are the number of feature channels, feature height, and feature width, respectively.
[0152] In step S750 of some embodiments, the style features of color arrangement are particularly important in tasks such as mural restoration. The Gram matrix is a tool for measuring image style features, which can reflect the characteristics of pixel arrangement in an image. The Gram matrix captures the style information of the image, such as texture, color distribution, etc. The calculation formula of the Gram matrix is as follows:
[0153]
[0154] Among them, G ij Represents the inner product between the feature maps of the i-th feature channel and the j-th feature channel, reflecting the correlation between features of different channels; F is a given set of feature maps, F∈R C×H×W , C is the number of channels, H and W are the height and width of the feature map respectively; Gram matrix G∈R C×C .
[0155] The first Gram matrix is the Gram matrix of the first sample feature, and the second Gram matrix is the Gram matrix of the second sample feature. For each network layer, the feature similarity between any two feature channels in the first sample feature is calculated to obtain the first Gram matrix of each network layer, and the feature similarity between any two feature channels in the second sample feature is calculated to obtain the second Gram matrix of each network layer.
[0156] In step S760 of some embodiments, the style loss is defined by comparing the difference between the Gram matrices of the generated image and the target style image. For each network layer, a matrix difference is obtained based on the first Gram matrix and the second Gram matrix, a weighting coefficient is constructed based on the weight parameter, the number of feature channels, and the feature dimension of the network layer, and the weighting coefficient is multiplied by the matrix difference to obtain the style sub-loss of each network layer. The style sub-losses of each network layer are summed to obtain the style loss. The style loss can be expressed as:
[0157]
[0158] Among them, L Style is the style loss; L is the number of network layers of the preset network, l represents the lth network layer, G l and A l are the first Gram matrix and the second Gram matrix of the output image (repaired image) and the target image (complete sample) at the lth layer, respectively.l is the number of feature maps output by the lth layer, i.e., the number of feature channels, M l is the dimension of the output feature map of the lth layer, expressed as H×W; w l is the weight parameter of the lth layer.
[0159] In step S770 of some embodiments, the preset network includes multiple activation layers. The sample complete image is activated by the multiple activation layers to obtain a first activation feature output by each activation layer, and the repaired image is activated by the multiple activation layers to obtain a second activation feature output by each activation layer.
[0160] In step S780 of some embodiments, the histogram loss is used to characterize the difference in color distribution between the restored image and the sample complete image, further optimizing the color restoration and overall visual coordination of the image, especially in image restoration scenes with rich colors and wide dynamic range. The calculation formula of the histogram loss is:
[0161]
[0162] Among them, L Histogram is the histogram loss; N is the number of activation layers; w l is the weight parameter of the lth activation layer; R represents the histogram matching of the lth activation layer; l It is the second activation feature output by the lth activation layer.
[0163] For each activation layer, the histogram matching of the second activation feature with the first activation feature as a template is calculated, and the difference data between the second activation feature and the histogram matching is calculated. The difference data is weighted using the weight parameter of the activation layer to obtain the histogram sub-loss of each network layer. The histogram sub-losses of each network layer are summed to obtain the histogram loss.
[0164] In step S790 of some embodiments, the generation loss is a comprehensive loss. The L1 loss, content loss, style loss, histogram loss and adversarial loss are weighted to obtain the generation loss. The calculation formula of the generation loss is as follows:
[0165]
[0166] Among them, L Generator represents the generation loss; α, β, γ, δ, α1, β1 are all weight coefficients; L Perceptual is the perceptual loss; L1 is the L1 loss; L Histogram is the histogram loss; L Content is the content loss; L Style is the style loss; L adver To combat losses.
[0167] This application designs a composite loss function that includes perceptual loss. This composite loss function provides a comprehensive evaluation of the quality of image restoration and is used to guide the generator to produce images with high visual quality. Perceptual loss is used to optimize visual details. Perceptual loss combines content loss and style loss to optimize the details and overall style of the restored image by comparing the high-level features of the generated image and the real image. L1 loss ensures color and brightness consistency, histogram loss adjusts color distribution, and adversarial loss is used to optimize the generator based on the feedback of the discriminator. This method not only enhances the authenticity and visual coordination of the restored image, but also significantly improves the restoration quality through careful attention to details and structure, which is closer to the visual standard of the human eye.
[0168] In the above steps S710 to S790, the visual quality of the repaired image can be significantly improved by training the generator with comprehensive loss, ensuring the naturalness and authenticity of the image repair results in details and as a whole. The quality of the generated image is evaluated by using a loss function with discriminative ability and combining it with the generative adversarial network framework, and the realism and visual effect of the repaired image are further improved through adversarial training.
[0169] The structure reconstruction network (first generator) is constructed by combining the U-Net architecture and the transformer module. The U-Net architecture is used to replace the standard convolution layer of the generator as the core structure of the first generator. The missing area is encoded by its powerful feature extraction ability, which greatly enhances the network's ability to capture image details and repair missing areas. The guidance information of the wireframe diagram is input into the network together with the damaged image to achieve accurate prediction and repair of the missing area during the training phase. U-Net is responsible for capturing local features and details. In the application phase, the local features of the target damaged image are extracted through the U-Net module to obtain a benchmark feature map. The benchmark feature map is the local feature of the target damaged image, which can be the color information, texture information, shape information, brightness information, etc. of the local area in the target damaged image.
[0170] See also Figure 8 In some embodiments, step S130 may include but is not limited to steps S810 to S840:
[0171] Step S810, extracting coding features of the target damaged image step by step through multiple coding blocks to obtain multiple coding image features; the spatial resolution of the coding image features is reduced step by step;
[0172] Step S820, performing residual feature extraction on the coded image features output by the last coding block through the residual block to obtain residual image features;
[0173] Step S830, extracting the residual image features step by step through multiple decoding blocks to obtain multiple decoded image features; the spatial resolution of the decoded image features is gradually increased; the decoded image features output by the current decoding block are obtained by feature fusion of the decoded image features output by the previous decoding block and the encoded image features output by the encoding block having a jump connection with the current decoding block;
[0174] Step S840: Using the decoded image features output by the last decoding block as a reference feature map.
[0175] In step S810 of some embodiments, the number of coded image features is the same as the number of coded blocks, and the target damaged image is downsampled step by step through multiple coded blocks, so that the spatial resolution of the coded image features is gradually reduced. Figure 3 As shown in the figure, the left branch of the U-Net module includes four encoding blocks, namely Enc_1, Enc_2, Enc_3 and Enc_4, and the right branch of the U-Net module includes four decoding blocks, namely Dec_1, Dec_2, Dec_3 and Dec_4. Enc_1 uses 7×7 convolution to convolve the target damaged image to obtain the encoded image features output by Enc_1. The encoded image features are downsampled, and Enc_2 uses 5×5 convolution to convolve the downsampled encoded image features to obtain the encoded image features output by Enc_2. Enc_3 uses 5×5 convolution to convolve the downsampled encoded image features to obtain the encoded image features output by Enc_3. For the downsampled encoded image features, Enc_4 uses 3×3 convolution to convolve the downsampled encoded image features to obtain the encoded image features output by Enc_4.
[0176] In step S820 of some embodiments, the residual block includes position encoding, self-attention block, residual sub-block + dilated convolution, position recovery, etc. The encoded image features and the position encoding vector output by the last encoding block are fused, and the regularization technology dropout is used to randomly discard 10% of the fused features. The regularized fused features are convolved by a combination of residual sub-blocks and dilated convolutions, and the positions of the convolved features are restored to obtain residual image features. Position recovery is used to restore the spatial position information of the target object in the image, which can be achieved through upsampling, jump connections, feature fusion or attention mechanisms. The use of residual blocks enables the model to learn dependencies of different scales, thereby achieving high-quality output during image restoration.
[0177] Position encoding increases the model's sensitivity to position information, which enables the model to more accurately locate structures and textures when restoring image details, further improving the quality and accuracy of image restoration. In the generator, position encoding is added to the input features in a special form, providing the model with position information for each element in the input sequence. Position encoding can be a fixed encoding based on sine and cosine functions, or it can be a learnable parameter obtained through training.
[0178] It should be noted that in the training phase, the repair process guided by the wireframe can be expressed as:
[0179] G enhanced =G generator (O masked ,O struct ,P positional )
[0180] Among them, G generator is a generator function used to generate the repaired image G after being guided by the wireframe enhanced ;I masked is the damaged and covered image, i.e., the sample damaged image; P positional is the position encoding vector.
[0181] In steps S830 to S840 of some embodiments, the residual image features are upsampled step by step through multiple decoding blocks to obtain multiple decoded image features, the number of decoded image features is equal to the number of decoding blocks, and the spatial resolution of the decoded image features is gradually increased. The convolution kernel size used by the decoding block can be 1×1. The upsampled residual image features are feature spliced with the encoded image features output by the last encoding block through the first decoding block Dec_1, and the spliced features are convolved to obtain the decoded image features output by Dec_1. The decoded image features output by Dec_1 are upsampled, and the upsampled decoded image features and the encoded image features output by the third encoding block are feature spliced through the second decoding block Dec_2, and the spliced features are convolved to output the decoded image features. The decoded image features output by Dec_2 are upsampled, and the above steps are repeated until the decoded image features output by the last decoding block are obtained, and the decoded image features are used as the reference feature map.
[0182] In the above steps S810 to S840, the target loss image is subjected to detailed feature extraction and encoding through the deep symmetrical encoding and decoding structure of the U-Net module and the convolution and upsampling operations, and the local details and global structures in the encoding image are encoded. At the same time, the jump connection strategy of U-Net can ensure the effective transmission and reconstruction of image features in the encoding and decoding stages, so as to utilize the specific network hierarchy to enhance the feature encoding capability of the missing area.
[0183] For feature extraction of missing areas, partial convolution (PConv) and dual-domain convolution (DpConv) provide advantages that traditional convolution does not have. PConv focuses on pixels in undamaged areas, effectively avoiding the impact of missing areas on feature extraction. DPConv enhances the model's ability to recover image details and structures by operating in the spatial and frequency domains. In order to dynamically adjust the activation threshold, the activation function is integrated into U-Net, and the spatial variation activation unit and the leakage spatial variation activation unit are introduced. By dynamically adjusting the activation threshold, the model's capture of details and emphasis on important features are enhanced. The spatial variation activation unit can use the Sigmoid function, and the leakage spatial variation activation unit can use the LeakyReLU function. By applying weight matrices and bias terms to the input features, combined with the Sigmoid function and the LeakyReLU function, dynamic adjustment is achieved, making the activation process more refined and adaptive. The Sigmoid function is applicable to a wide range of eigenvalues, and the LeakyReLU function is more flexible when dealing with negative inputs. Together, the two improve the refinement and adaptability of image restoration. At different network levels, the activation threshold can be dynamically adjusted according to the specific content of the feature map, which helps to suppress noise while retaining details, especially in deep networks, which is crucial for the restoration of complex textures and structures and optimizes the restoration effect. The combination of PConv, DpConv, spatially varying activation units, and leaky spatially varying activation units provides accurate structural information and rich texture details for the restoration of complex images. The integration of these methods optimizes the traditional U-Net structure and enhances the network's ability to handle structural complexity and texture richness in image restoration tasks.
[0184] In the U-Net architecture, the introduction of custom convolutional layers, combined with downsampling and upsampling processes, can improve the model's ability to handle missing areas of the image. The weight initialization technology ensures the stability and efficiency of training.
[0185] See also Fig. 9 In some embodiments, the coding block includes a portion of the convolutional layers, a first batch of normalization layers, and a spatially varying activation unit, and step S810 may include but is not limited to steps S910 to S940:
[0186] Step S910, performing convolution processing on the target damaged image through a partial convolution layer of the first coding block to obtain a first convolution feature;
[0187] Step S920, performing batch normalization processing on the first convolutional features through a first batch normalization layer to obtain a first batch of normalized features;
[0188] Step S930, performing activation processing on the first batch of normalized features through a spatial variation activation unit to obtain coded image features output by the first coding block;
[0189] Step S940, extracting coding features from the coded image features output by the current coding block through the next coding block until the coded image features output by the last coding block are obtained, thereby obtaining a plurality of coded image features;
[0190] In step S910 of some embodiments, the partial convolutional layer is defined as:
[0191]
[0192] Among them, X represents the input feature map, M represents the binary mask corresponding to the input feature map, and W T is the transpose of the convolution kernel weight, b is the bias term, ⊙ represents element-wise multiplication, and S(M) represents the number of elements with a value of 1 in the mask M.
[0193] In the training stage, M is a wireframe image, and the specific processing process of the partial convolution layer is as follows: the sample damaged image and the wireframe image are multiplied element by element, and the feature map obtained by multiplication is convolved to obtain the first sample convolution feature, and the first sample convolution feature is divided by the number of elements with element values of 1 in the wireframe image to achieve partial convolution of the sample damaged image. The wireframe image is convolved to obtain the second sample convolution feature, and the second sample convolution feature is divided by the number of elements with element values of 1 in the wireframe image to achieve partial convolution of the wireframe image. In the application stage, the target damaged image can be directly convolved to obtain the first convolution feature.
[0194] In step S920 of some embodiments, batch normalization is performed on the first convolutional features through a first batch of normalization layers to obtain a first batch of normalized features.
[0195] In step S930 of some embodiments, the spatial variation activation unit may be defined as:
[0196]
[0197] in, is the weight of the activation unit, b act is the bias term, and σ represents the activation function, such as Sigmoid or ReLU function.
[0198] The process of activation processing through the spatial variation activation unit is as follows: the first batch of normalized features are activated through the ReLU activation function or the Sigmoid function to obtain a sample activation feature map, the sample activation feature map is convolved to obtain a standard convolution feature, the sample activation feature map is dilated and convolved to obtain a dilated convolution feature, the standard convolution feature and the dilated convolution feature are concatenated, the concatenated features are convolved and batch normalized, the normalized result is Gaussian transformed by a Gaussian function, and the Gaussian transformed result is element-wise multiplied with the first batch of normalized features to obtain the encoded image feature output by the first encoding block.
[0199] In step S940 of some embodiments, the coded image features output by the current coding block are downsampled, and the downsampled coded image features are again coded and extracted by the next coding block until the coded image features output by the last coding block are obtained, thereby obtaining multiple coded image features.
[0200] In the above steps S910 to S940, during the downsampling process, PConv can extract features for valid pixels and ignore damaged areas, thereby maintaining important feature information when the image is reduced. Downsampling and partial convolution techniques process incomplete data in the masked area while retaining key image information. The activation unit further improves the learning efficiency of the features. The comprehensive application of these methods greatly optimizes the effect and efficiency of image restoration.
[0201] The decoding block includes a dual frequency domain convolution layer, a second batch of normalization layers, and a leaky space-variant activation unit. Step S830 may include but is not limited to steps S950 to S990:
[0202] Step S950, performing convolution processing on the residual image feature through the dual-frequency domain convolution layer of the first decoding block to obtain a second convolution feature;
[0203] Step S960, performing batch normalization processing on the second convolutional features through a second batch normalization layer to obtain a second batch of normalized features;
[0204] Step S970, performing convolution processing on the second batch of normalized features through the leakage space variation activation unit to obtain decoded image features output by the first decoding block;
[0205] Step S980, performing feature fusion on the decoded image features output by the previous decoding block and the encoded image features output by the encoding block corresponding to the current decoding block to obtain fused features;
[0206] Step S990, extracting decoding features from the fusion features through the current decoding block until the decoded image features output by the last decoding block are obtained, thereby obtaining a plurality of decoded image features.
[0207] In step S950 of some embodiments, the residual image feature is convolved in the spatial domain and the frequency domain by a dual-frequency domain convolution layer to obtain a second convolution feature. The expression of the dual-frequency domain convolution layer is:
[0208]
[0209] in, and Represent the convolution kernel weights in the spatial domain and frequency domain respectively, b represents the bias, and F represents the discrete cosine transform to capture and encode higher-level frequency features; S(M) represents the number of elements with a value of 1 in the binary mask M; ⊙ represents element-wise multiplication; · represents the dot product operation.
[0210] In the training stage, M is a wireframe, and the specific processing process of the dual-frequency domain convolution layer is as follows: obtain the residual image features extracted from the sample damaged image based on multiple coding blocks and residual blocks, obtain the residual image features extracted from the wireframe based on multiple coding blocks and residual blocks, and multiply the two residual image features element by element. Perform fast discrete cosine transform on the feature map obtained by multiplication to obtain frequency domain features, convolve the frequency domain features, and perform inverse discrete cosine transform on the frequency domain features after convolution to obtain the first spatial domain features. Convolve the feature map obtained by multiplication to obtain the second spatial domain features. Feature splicing is performed on the first spatial domain features and the second spatial domain features, and the spliced features are convolved to obtain the target spatial domain features. The target spatial domain features are divided by the number of elements with element values of 1 in the residual image features extracted from the wireframe, so as to realize the dual-frequency domain convolution layer of the residual image features. In the application stage, since there is no wireframe, the residual image features can be directly convolved to obtain the second convolution features.
[0211] In step S960 of some embodiments, the second convolutional features are batch normalized by a second batch normalization layer to obtain a second batch of normalized features.
[0212] In step S970 of some embodiments, the leakage space variation activation unit is defined as:
[0213]
[0214] in, is the weight of the activation unit, b act is the bias term, LeakyReLU provides a nonlinear positive activation as well as a slight activation for negative input values.
[0215] The activation function used by the leaky space-variant activation unit is LeakyReLU, and the rest are the same as the space-variant activation unit. The specific processing process of the leaky space-variant activation unit on the residual image feature can refer to step S930, which will not be repeated here.
[0216] In step S980 of some embodiments, the decoded image features output by the previous decoding block are upsampled, and the upsampled features are concatenated with the encoded image features output by the encoding block corresponding to the current decoding block to obtain fused features.
[0217] In step S990 of some embodiments, decoding features are extracted from the fusion features through the current decoding block, and the above steps are repeated for each decoding block until the decoded image features output by the last decoding block are obtained, thereby obtaining multiple decoded image features.
[0218] In the above steps S950 to S990, during the upsampling process, DPConv uses frequency domain information to assist in feature reconstruction in the spatial domain, thereby providing additional context information for the recovery of multi-scale features.
[0219] In order to improve the model's ability to handle complex texture and structure repair tasks and large-area damaged image repair tasks, a transformer module is embedded in the generator, and the self-attention mechanism is used to capture the global information and long-distance dependencies of the image, so as to strengthen the model's control over global content consistency and structural coherence during structural recovery and upsampling, so that the repair process pays more attention to the overall semantic coherence and style consistency of the image. The global features are extracted from the benchmark feature map through the transformer module to obtain global features, and the global features are upsampled at any ratio through the upsampler to obtain a structural reconstructed image. Global features include edges and line structures generated by the generator. By combining the transformer module with the upsampler, it can not only effectively handle the feature extraction and encoding process of the missing area of the image, but also handle large-area damage and complex texture and structure tasks in image repair.
[0220] See also Fig.10 In some embodiments, step S140 may include but is not limited to steps S1010 to S1030:
[0221] Step S1010, extracting a first attention feature from the reference feature map to obtain an axial attention feature;
[0222] Step S1020, performing a second attention feature extraction on the axial attention feature to obtain a standard attention feature;
[0223] Step S1030, up-sample the standard attention features to obtain a structured reconstructed image.
[0224] In step S1010 of some embodiments, the transformer module is used alternately through the axial attention and standard attention modules. The axial attention features include row attention features and column attention features. The axial attention features are axial attention scores, which can be calculated by the following formula:
[0225]
[0226]
[0227] Among them, W rq , W rk , W cq , W ck is a trainable parameter in the axial attention module, W rq and W cq For row and column queries respectively, W rk and W ck Keys for rows and columns respectively. and Respectively represent the relative position encoding values of rows and columns; T represents the transposition operation, x rj and x cj They represent the input features of the row attention module and the column attention module respectively. After the attention scores are processed by the softmax operation, they can be used for weight aggregation.
[0228] Specifically, the first normalization layer performs layer normalization processing on the reference feature map to obtain the first normalized features. The second normalization layer performs layer normalization processing on the reference feature map to obtain the second normalized features. The row attention module performs feature extraction on the first normalized features to obtain the row attention features. The column attention module performs feature extraction on the second normalized features to obtain the column attention features.
[0229] In step S1020 of some embodiments, the row attention feature is feature multiplied with the baseline feature map, the column attention feature is feature multiplied with the baseline feature map, and the two multiplication results are added to obtain a first fused feature. The first fused feature is layer normalized to obtain a third-layer normalized feature. The third-layer normalized feature is feedforward extracted through a first feedforward neural network to obtain a first feedforward feature. The first fused feature and the first feedforward feature are feature fused to obtain a second fused feature. The second fused feature is layer normalized to obtain a fourth-layer normalized feature. The fourth-layer normalized feature is subjected to standard attention feature extraction to obtain a standard attention feature, which is an attention feature extracted based on a self-attention mechanism.
[0230] In step S1030 of some embodiments, feature fusion is performed on the standard attention feature and the second fusion feature to obtain a third fusion feature. The third fusion feature is layer normalized to obtain a fifth-layer normalized feature. Feedforward feature extraction is performed on the fifth-layer normalized feature through a second feedforward neural network to obtain a second feedforward feature. Feature fusion is performed on the second feedforward feature and the third fusion feature to obtain a fourth fusion feature. The fourth fusion feature is upsampled to obtain a structural reconstructed image.
[0231] The above steps S1010 to S1030, by alternating between axial attention and standard attention, can effectively process the global information of the image while improving computational efficiency to restore the details and global structure of the image.
[0232] In step S150 of some embodiments, the color reconstruction network is used to perform color reconstruction on the structural reconstruction image to obtain color features. The color features are used to characterize the hue, color temperature, contrast, and other features of the target damaged image. The process of color reconstruction by the color reconstruction network can refer to the structural reconstruction process, and will not be repeated here.
[0233] In step S160 of some embodiments, feature addition is performed on the color feature and the structure reconstructed image to optimize the structure reconstructed image and obtain a complete image of the target damaged image.
[0234] The image restoration method of this application makes comprehensive use of the excellent local feature capture capability of the U-Net architecture and the efficient global information processing capability of the transformer architecture. In order to quantitatively evaluate the performance improvement during the training process and continuously detect the restoration effect of the model, the peak signal-to-noise ratio and mean absolute error are selected as the main indicators for evaluating the model performance. These indicators provide real-time feedback during the iteration process, which can guide the direction of model optimization and ensure that the restoration quality can be effectively improved.
[0235] Peak signal-to-noise ratio is a common indicator for evaluating image reconstruction quality. It measures the quality of the reconstructed image by comparing the difference between the original image and the restored image. The calculation formula of peak signal-to-noise ratio is as follows:
[0236]
[0237] Among them, MAX is the maximum possible pixel value of the image. Usually, if the pixel value ranges from 0 to 255, MAX = 255. MSE is the average square value of the difference between the original image (the complete sample image) and the repaired image (the complete image obtained by image repair of the damaged sample image), that is:
[0238]
[0239] Where m and n are the number of rows and columns of the image, respectively. original (i, j) is the pixel value of the original image at position (i, j), and I repaired (i,j) is the pixel value of the inpainted image at the same position.
[0240] The mean absolute error is the average absolute value of the difference between the real-valued output and the target value. It provides another way to measure the performance of image restoration and intuitively reflects the average error between the restored image and the original image at the pixel level. The calculation formula is as follows:
[0241]
[0242] In order to evaluate the performance of the image restoration method during the training process, this scheme is compared with DeepFillv2, EdgeConnect and RFR, and the performance of these methods on four key performance indicators: structural similarity (SSIM), mean square error (MSE), peak signal-to-noise ratio (PSNR) and perceptual image quality evaluation calculated by AlexNet (LPIPS_alex). The evaluation results are shown in Table 1:
[0243] method This application DeepFillv2 EdgeConnect RFR SSIM 0.8651 0.8269 0.8162 0.6881 MSE 0.0010 0.0055 0.0056 0.0108 PSNR 26.5820 23.7190 23.3491 20.4561 LPIPS_alex 0.0949 0.1131 0.1210 0.2517
[0244] Table 1
[0245] As can be seen from Table 1, the image restoration method of the present application performs well in various performance evaluation indicators, especially in structural similarity and mean absolute error, which is significantly better than other comparison methods. This shows that the image restoration method of the present application can restore images more accurately while maintaining high visual quality. The image restoration method of the present application makes comprehensive use of structural guidance and color correction strategies, so that the generated image is significantly enhanced in structure and texture, showing higher naturalness and realism compared to the original image. The present application has achieved remarkable results in structural integrity, detail clarity and color consistency.
[0246] See also Fig.11 The embodiment of the present application further provides an image restoration device, which can implement the above-mentioned image restoration method, and the image restoration device includes:
[0247] An acquisition module 1110 is used to acquire a target damaged image;
[0248] An input module 1120 is used to input the target damaged image into an image restoration network, where the image restoration network includes a structure reconstruction network and a color reconstruction network; the structure reconstruction network includes a U-Net module and a transformer module;
[0249] A first feature extraction module 1130 is used to extract local features of the target damaged image through a U-Net module to obtain a reference feature map;
[0250] A second feature extraction module 1140 is used to perform global feature extraction on the reference feature map through a transformer module to obtain a structural reconstruction image;
[0251] A color reconstruction module 1150 is used to perform color reconstruction on the structure reconstruction image through a color reconstruction network to obtain color features;
[0252] The fusion module 1160 is used to fuse the color feature and the structure reconstruction image to obtain a complete image of the target damaged image.
[0253] The specific implementation of the image restoration device is substantially the same as the specific implementation of the above-mentioned image restoration method, and will not be described in detail here.
[0254] The embodiment of the present application also provides an electronic device, the electronic device includes a memory and a processor, the memory stores a computer program, and the processor implements the above-mentioned image restoration method when executing the computer program. The electronic device can be any intelligent terminal including a tablet computer, a car computer, etc.
[0255] See also Fig.12 , Fig.12 The hardware structure of an electronic device of another embodiment is illustrated, and the electronic device includes:
[0256] The processor 1210 may be implemented by a general-purpose CPU (Central Processing Unit), a microprocessor, an application-specific integrated circuit (Application Specific Integrated Circuit, ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of the present application;
[0257] The memory 1220 can be implemented in the form of a read-only memory (ROM), a static storage device, a dynamic storage device, or a random access memory (RAM). The memory 1220 can store an operating system and other application programs. When the technical solution provided in the embodiment of this specification is implemented by software or firmware, the relevant program code is stored in the memory 1220, and the processor 1210 calls and executes the image restoration method of the embodiment of this application;
[0258] Input / output interface 1230, used to implement information input and output;
[0259] The communication interface 1240 is used to realize the communication interaction between the device and other devices. The communication can be realized through a wired manner (such as USB, network cable, etc.) or a wireless manner (such as mobile network, WIFI, Bluetooth, etc.);
[0260] The bus 1250 transmits information between the various components of the device (e.g., the processor 1210, the memory 1220, the input / output interface 1230, and the communication interface 1240);
[0261] The processor 1210 , the memory 1220 , the input / output interface 1230 , and the communication interface 1240 are connected to each other in communication within the device via a bus 1250 .
[0262] An embodiment of the present application further provides a computer-readable storage medium, which stores a computer program, and the computer program implements the above-mentioned image restoration method when executed by a processor.
[0263] The memory, as a non-transient computer-readable storage medium, can be used to store non-transient software programs and non-transient computer executable programs. In addition, the memory may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some embodiments, the memory may optionally include a memory remotely disposed relative to the processor, and these remote memories may be connected to the processor via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0264] The embodiments described in the embodiments of the present application are intended to more clearly illustrate the technical solutions of the embodiments of the present application and do not constitute a limitation on the technical solutions provided in the embodiments of the present application. Those skilled in the art will appreciate that with the evolution of technology and the emergence of new application scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.
[0265] Those skilled in the art will appreciate that the technical solutions shown in the figures do not constitute a limitation on the embodiments of the present application, and may include more or fewer steps than shown in the figures, or a combination of certain steps, or different steps.
[0266] The device embodiments described above are merely illustrative, and the units described as separate components may or may not be physically separated, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0267] In addition, each functional unit in each embodiment of the present application 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. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0268] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including multiple instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, referred to as ROM), random access memory (Random Access Memory, referred to as RAM), disk or optical disk and other media that can store programs.
[0269] The preferred embodiments of the present invention are described above with reference to the accompanying drawings, but the scope of the rights of the present invention is not limited thereto. Any modification, equivalent substitution and improvement made by a person skilled in the art without departing from the scope and essence of the present invention should be within the scope of the rights of the present invention.
Claims
1. An image restoration method, characterized in that: The method comprises: Acquire a damaged image of the target; Inputting the target damaged image into an image restoration network, wherein the image restoration network includes a structure reconstruction network and a color reconstruction network; the structure reconstruction network includes a U-Net module and a transformer module; Performing local feature extraction on the target damaged image through the U-Net module to obtain a reference feature map; Performing global feature extraction on the reference feature map through the transformer module to obtain a structural reconstruction image; Performing color reconstruction on the structure reconstructed image through the color reconstruction network to obtain color features; The color feature and the structural reconstruction image are fused to obtain a complete image of the target damaged image.
2. The image restoration method according to claim 1, characterized in that: The image restoration network is trained according to the following steps: Acquire a sample damaged image and a sample complete image; the sample damaged image has a damaged area; Performing edge detection on the sample complete image to obtain a wireframe image of the sample complete image; Inputting the sample damaged image and the wireframe diagram into a first generator for image generation to obtain a first image; Obtaining pixel points of the first image at the damaged area to obtain a mask image, and performing image completion on the sample damaged image according to the mask image to obtain a second image; Obtaining the code of the damaged area to obtain a position coding feature map; Inputting the second image and the position coding feature map into a second generator to generate an image, thereby obtaining a sample color feature map; Obtaining pixel points of the sample color feature map in the damaged area to obtain a target color feature map, and performing image completion on the second image according to the target color feature map to obtain a repaired image; Inputting the repaired image into a discriminator for image discrimination to obtain an adversarial loss; A loss is generated based on the sample complete image, the repaired image and the adversarial loss calculation; The structure reconstruction network is obtained by adjusting the model parameters of the first generator according to the generation loss, and the color reconstruction network is obtained by adjusting the model parameters of the second generator according to the generation loss.
3. The image restoration method according to claim 2, characterized in that: The generating loss according to the sample complete image, the repaired image and the adversarial loss calculation includes: Perform loss calculation based on the sample complete image and the repaired image to obtain an L1 loss; Inputting the sample complete image and the repaired image into a preset network, wherein the preset network includes a plurality of network layers, and the network layer includes an activation layer; Extracting features of the complete sample image through multiple network layers to obtain first sample features of each network layer, and extracting features of the repaired image through multiple network layers to obtain second sample features of each network layer; Performing loss calculation according to the first sample feature of the target network layer and the second sample feature of the target network layer to obtain content loss; Obtain a first Gram matrix of the first sample features of each network layer and a second Gram matrix of the second sample features of each network layer; Perform loss calculation according to the first Gram matrix of each network layer, the second Gram matrix of each network layer, and the weight parameter of each network layer to obtain a style loss; Performing activation processing on the sample complete image through the multiple activation layers to obtain a first activation feature of each activation layer, and performing activation processing on the repaired image through the multiple activation layers to obtain a second activation feature of each activation layer; The loss is calculated according to the first activation feature of each activation layer, the second activation feature of each activation layer, and the weight parameter of each activation layer to obtain a histogram loss; The L1 loss, the content loss, the style loss, the histogram loss and the adversarial loss are weighted to obtain the generation loss.
4. The image restoration method according to claim 2, characterized in that: After inputting the repaired image into the discriminator for image discrimination to obtain the adversarial loss, the image repair method further includes: Inputting the first image into the discriminator for image discrimination to obtain discrimination information; Perform loss calculation according to the adversarial loss and the discriminant information to obtain a discriminant loss; The model parameters of the discriminator are adjusted according to the discriminant loss.
5. The image restoration method according to any one of claims 1 to 4, characterized in that: The U-Net module includes a plurality of encoding blocks, a residual block and a plurality of decoding blocks, wherein the encoding blocks correspond to the decoding blocks one by one, and there is a jump connection between the encoding blocks and the decoding blocks. The U-Net module is used to extract local features of the target damaged image to obtain a reference feature map, including: Extracting coding features of the target damaged image step by step through multiple coding blocks to obtain multiple coding image features; the spatial resolution of the coding image features is gradually reduced; Extracting residual features of the encoded image features output by the last encoding block through the residual block to obtain residual image features; The residual image features are subjected to step-by-step decoding feature extraction through multiple decoding blocks, thereby obtaining multiple decoded image features; the spatial resolution of the decoded image features is gradually increased; the decoded image features output by the current decoding block are obtained by feature fusion of the decoded image features output by the previous decoding block and the encoded image features output by the encoding block having a jump connection with the current decoding block; The decoded image features output by the last decoding block are used as the reference feature map.
6. The image restoration method according to claim 5, characterized in that: The coding block includes a part of the convolution layer, a first batch of normalization layers and a spatial variation activation unit. The target damaged image is subjected to step-by-step coding feature extraction through multiple coding blocks to obtain multiple coded image features, including: Performing convolution processing on the target damaged image through the partial convolution layer of the first encoding block to obtain a first convolution feature; Performing batch normalization processing on the first convolutional features through the first batch normalization layer to obtain a first batch of normalized features; Activating the first batch of normalized features by the spatial variation activation unit to obtain the coded image features output by the first coding block; Extracting the encoded image features output by the current encoding block through the next encoding block until the encoded image features output by the last encoding block are obtained, thereby obtaining a plurality of the encoded image features; The decoding block includes a dual frequency domain convolution layer, a second batch normalization layer and a leakage space variation activation unit. The residual image features are subjected to step-by-step decoding feature extraction through multiple decoding blocks to obtain multiple decoded image features, including: Activating the residual image feature through the dual-frequency domain convolution layer of the first decoding block to obtain a second convolution feature; performing batch normalization processing on the second convolutional features through the second batch normalization layer to obtain a second batch normalized features; Activating the second batch of normalized features by the leakage space variation activation unit to obtain the decoded image features output by the first decoding block; Fusing the decoded image features output by the previous decoding block with the encoded image features output by the encoding block corresponding to the current decoding block to obtain a fused feature; The fusion feature is subjected to decoding feature extraction through the current decoding block until the decoded image feature output by the last decoding block is obtained, thereby obtaining a plurality of the decoded image features.
7. The image restoration method according to any one of claims 1 to 4, characterized in that: The global feature extraction of the reference feature map by the transformer module to obtain a structural reconstruction image includes: Extract the first attention feature from the reference feature map to obtain the axial attention feature; Performing second attention feature extraction on the axial attention feature to obtain the standard attention feature; The standard attention features are upsampled to obtain the structured reconstructed image.
8. An image restoration device, characterized in that: The device comprises: An acquisition module, used for acquiring a damaged target image; An input module, used to input the target damaged image into an image restoration network, wherein the image restoration network includes a structure reconstruction network and a color reconstruction network; the structure reconstruction network includes a U-Net module and a transformer module; A first feature extraction module, configured to extract local features of the target damaged image through the U-Net module to obtain a reference feature map; A second feature extraction module is used to perform global feature extraction on the reference feature map through the transformer module to obtain a structural reconstruction image; A color reconstruction module, used for performing color reconstruction on the structure reconstruction image through the color reconstruction network to obtain color features; A fusion module is used to fuse the color feature and the structural reconstruction image to obtain a complete image of the target damaged image.
9. An electronic device, characterized in that The electronic device comprises a memory and a processor, the memory stores a computer program, and the processor implements the image restoration method according to any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the image restoration method according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Method and device for image stylized reconstruction
CN109325903A
Digital image restoration method based on structural information embedding and attention mechanism
CN114820381A
Image restoration method
CN116051407A
SAR-optical image fusion method based on hybrid model
CN117314811A
Method for performing stereo matching by using color image and monochrome image and device using the same
KR102418000B1
Cited By
Image restoration method and device, electronic equipment and storage medium
CN119941574A
Blind image restoration method and system
CN119941584A
Blind Image Inpainting Method and System
CN119941584B
Image generation system and method for LED display system
CN120353355A
Image generation system and method for LED display system
CN120353355B
