Image processing method, electronic equipment and storage medium

By dividing the shadow image into slices and utilizing the parallel processing of the global U-Net and local U-Net networks, combined with global guidance, the problem of poor shadow removal in the existing technology is solved, and illumination consistency and no residue are achieved. Shadow removal effect.

CN118537243AActive Publication Date: 2024-08-23YUANLI TUXIN (CHONGQING) TECHNOLOGY CO LTD

Patent Information

Application Number
CN202410513431.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-04-26
Publication Date
2024-08-23
Estimated Expiration
2044-04-26

AI Technical Summary

Technical Problem

The existing technology has poor performance in the shadow removal process. Methods based on the Transformer architecture will cause afterimages, while methods based on the diffusion model will cause inconsistent illumination in the output image due to the lack of global information.

Method used

By dividing the shadow image, shadow mask image and noisy image into slices, and using the global U-Net network and local U-Net network in the diffusion model for parallel processing, combined with global guidance, the target image after removing the shadow is generated , ensure illumination consistency and avoid image ghosting.

Benefits of technology

It improves the shadow removal effect, ensures the illumination consistency of the output image, avoids the appearance of afterimages, and significantly improves the accuracy of shadow removal.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118537243A
    Figure CN118537243A
Patent Text Reader

Abstract

The embodiment of the invention provides an image processing method, electronic equipment and a storage medium. The method comprises the following steps: acquiring a shadow image to be processed, a shadow mask image and a noisy image; the shadow image, the shadow mask image and the noisy image are respectively segmented into slices with target sizes, multiple groups of slices are obtained, and each group of slices comprises a shadow slice, a shadow mask slice and a noisy slice which are corresponding in position; performing down-sampling processing on the shadow image and the shadow mask image to obtain a global shadow image and a global shadow mask image of a target size; according to the global shadow mask image, performing shadow removal processing on the global shadow image through a global U-Net network to obtain an intermediate feature map; respectively processing each group of slices through a local U-Net network according to the intermediate feature map to obtain a local noise image; and generating a shadow-removed target image according to each group of local noise images and noisy images. According to the embodiment of the invention, the shadow removal effect is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the field of image processing technology, and in particular, to an image processing method, an electronic device, and a storage medium. Background Art

[0002] A shadow in an image is a situation where light is blocked during shooting. The presence of shadows complicates image processing and many subsequent visual tasks, such as object detection, tracking, etc. The purpose of shadow removal is to increase the brightness of the shadow area of ​​the image and achieve consistent lighting distribution between shadowed and non-shadowed areas. The shadow removal task is essentially an image restoration task that aims to use the information in the image affected by shadows to recover the information lost due to light occlusion. Shadow removal can be applied to scenarios such as autonomous driving and face recognition. Shadow removal in autonomous driving scenarios can improve the accuracy of target detection, and shadow removal in face recognition scenarios can improve the accuracy of face recognition.

[0003] In the prior art, when removing shadows, you can use ShadowFormer, a deep learning shadow removal method based on the Transformer architecture, or you can use ShadowDiffusion, a shadow removal method based on a diffusion model. ShadowFormer, a deep learning shadow removal method based on the Transformer architecture, designs a shadow interaction module based on the Transformer architecture, and tries to use non-shadow information to help restore the shadow area, but the generated result will have obvious afterimages; ShadowDiffusion, a shadow removal method based on a diffusion model, is based on the diffusion model Diffusion-model, and uses a simple U-Net architecture in the network structure, which leads to inconsistent lighting of the output image. It can be seen that the prior art has the problem of poor shadow removal effect. Summary of the invention

[0004] In view of the above problems, embodiments of the present application are proposed to provide an image processing method, electronic device, and storage medium that overcome the above problems or at least partially solve the above problems.

[0005] According to a first aspect of an embodiment of the present application, there is provided an image processing method, comprising:

[0006] Acquire a shadow image to be processed, a shadow mask image corresponding to the shadow image, and a noisy image, where the noisy image is obtained by adding noise to the shadow image;

[0007] The shadow image, the shadow mask image and the noisy image are respectively cut into slices of target size to obtain multiple groups of slices, each group of slices includes shadow slices, shadow mask slices and noisy slices corresponding to positions;

[0008] Downsampling the shadow image to obtain a global shadow image of the target size, and downsampling the shadow mask image to obtain a global shadow mask image of the target size;

[0009] According to the global shadow mask image, removing shadows from the global shadow image through a global U-Net network in a diffusion model, and obtaining an intermediate feature map output by a non-final network layer in the global U-Net network;

[0010] Processing each group of slices according to the intermediate feature map through a local U-Net network in the diffusion model to obtain a local noise image corresponding to each group of slices;

[0011] A target image after removing shadows is generated according to each group of the local noise image and the noisy image.

[0012] According to a second aspect of an embodiment of the present application, an electronic device is provided, comprising: a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein when the computer program is executed by the processor, the image processing method described in the first aspect is implemented.

[0013] According to a third aspect of an embodiment of the present application, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the image processing method described in the first aspect is implemented.

[0014] According to a fourth aspect of an embodiment of the present application, a computer program product is provided, comprising a computer program or computer instructions, wherein when the computer program or computer instructions are executed by a processor, the image processing method described in the first aspect is implemented.

[0015] The image processing method, electronic device and storage medium provided in the embodiments of the present application respectively divide the shadow image, shadow mask image and noisy image into slices of target size to obtain multiple groups of slices, each group of slices includes shadow slices, shadow mask slices and noisy slices corresponding to the position, downsamples the shadow image to obtain a global shadow image of the target size, and downsamples the shadow mask image to obtain a global shadow mask image of the target size, removes shadows from the global shadow image through a global U-Net network in a diffusion model according to the global shadow mask image, obtains an intermediate feature map output by a non-final network layer in the global U-Net network, processes each group of slices according to the intermediate feature map through a local U-Net network in the diffusion model, obtains a local noise image corresponding to each group of slices, and generates a target image after removing shadows according to each group of local noise images and noisy images. It can be seen that in the processing process, the underlying distribution of natural images is modeled by processing each group of slices through the local U-Net network, and the intermediate feature maps in the global U-Net network are combined with the processing of the local U-Net network. Global guidance is provided for the processing of the local U-Net network, thereby ensuring the consistency of the illumination of the final target image, and no afterimage will appear after removing the shadow, thereby improving the shadow removal effect.

[0016] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] Various other advantages and benefits will become apparent to those of ordinary skill in the art by reading the following detailed description of the preferred embodiment.The accompanying drawings are only for the purpose of illustrating the preferred embodiments and are not to be considered as limiting the present application.

[0018] Figure 1 is a flowchart of the steps of an image processing method provided by an embodiment of the present application;

[0019] Figure 2 Schematic diagram of shadow removal by parallel local U-Net network and global U-Net network in an embodiment of the present application;

[0020] Figure 3 is a flowchart of the steps of an image processing method provided by an embodiment of the present application;

[0021] Figure 4 is a structural block diagram of an image processing device provided in an embodiment of the present application;

[0022] Figure 5 It is a structural block diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0023] The exemplary embodiments of the present application will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present application are shown in the accompanying drawings, it should be understood that the present application can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided in order to enable a more thorough understanding of the present application and to fully convey the scope of the present application to those skilled in the art.

[0024] In recent years, research on computer vision, deep learning, machine learning, image processing, image recognition and other technologies based on artificial intelligence has made important progress. Artificial Intelligence (AI) is an emerging science and technology that studies and develops theories, methods, technologies and application systems for simulating and extending human intelligence. Artificial intelligence is a comprehensive discipline involving many types of technologies such as chips, big data, cloud computing, the Internet of Things, distributed storage, deep learning, machine learning, neural networks, etc. Computer vision, as an important branch of artificial intelligence, specifically allows machines to recognize the world. Computer vision technology usually includes face recognition, liveness detection, fingerprint recognition and anti-counterfeiting verification, biometric recognition, face detection, pedestrian detection, target detection, pedestrian recognition, image processing, image recognition, image semantic understanding, image retrieval, text recognition, video processing, video content recognition, 3D reconstruction, virtual reality, augmented reality, simultaneous localization and mapping (SLAM), computational photography, robot navigation and positioning and other technologies. With the research and advancement of artificial intelligence technology, this technology has been applied in many fields, such as security control, urban management, traffic management, building management, park management, facial access, facial attendance, logistics management, warehouse management, robots, intelligent marketing, computational photography, mobile phone imaging, cloud services, smart homes, wearable devices, unmanned driving, automatic driving, smart medical care, facial payment, facial unlocking, fingerprint unlocking, identity verification, smart screens, smart TVs, cameras, mobile Internet, live streaming, beauty, makeup, medical beauty, and smart temperature measurement.

[0025] Figure 1 is a flowchart of the steps of an image processing method provided in an embodiment of the present application. The method can be applied to the scene of repairing the shadow in the image, such as Figure 1 As shown, the method may include:

[0026] Step 101 : obtaining a shadow image to be processed, a shadow mask image corresponding to the shadow image, and a noisy image, wherein the noisy image is obtained by adding noise to the shadow image.

[0027] Among them, the shadow image to be processed is the original image containing shadows. The shadow mask image identifies the area where the shadow is located in the shadow image. The shadow mask image can be provided directly, or it can be generated by performing shadow detection on the shadow image. In practical applications or in the testing phase of the model, the noisy image can be a pure noise image at the time of initialization, or it can be an intermediate image obtained after denoising at each time step by the diffusion model; in the training phase of the model, the noisy image is an image obtained by adding noise at each time step to the shadow-free image corresponding to the shadow image to be processed. The pure noise image is a randomly generated pure Gaussian noise image.

[0028] Step 102 , respectively dividing the shadow image, the shadow mask image and the noisy image into slices of target sizes to obtain multiple groups of slices, each group of slices including shadow slices, shadow mask slices and noisy slices corresponding to positions.

[0029] According to the target step size and target size, the shadow image, shadow mask image and noisy image are sliced ​​respectively, the shadow image is sliced ​​into multiple shadow slices, the shadow mask image is sliced ​​into multiple shadow mask slices, the noisy image is sliced ​​into multiple noisy slices, and the shadow slices, shadow mask slices and noisy slices at the same position are taken as a group of slices, so as to obtain multiple groups of slices. There may be no overlap between slices, or there may be overlap. Exemplarily, the target step size is 16, and the slice size, i.e., the target size, is 64×64. After slicing, 256 slice images are obtained for each of the three types of images, i.e., 256 groups of slices are obtained. These slices are used as the input of the subsequent local U-Net network, and the input size of the local U-Net network is 64×64×256×7 (where 7 represents the number of channels, specifically the sum of 3 channels of the shadow image, 3 channels of the noisy image and 1 channel of the shadow mask image).

[0030] Step 103 , down-sampling the shadow image to obtain a global shadow image of the target size, and down-sampling the shadow mask image to obtain a global shadow mask image of the target size.

[0031] The shadow image and the shadow mask image are downsampled respectively so that the size of the downsampled image is the same as the size of each slice image, that is, the same as the target size, and a global shadow image and a global shadow mask image of the target size are obtained. Exemplarily, when the target size is 64×64, a 64×64 global shadow image and a 64×64 shadow mask image are obtained by downsampling. The global shadow image and the global shadow mask image are used as inputs of the subsequent global U-Net network, and the input size of the global U-Net network is 64×64×4 (where 4 represents the number of channels, specifically the sum of 3 channels of the shadow image and 1 channel of the shadow mask image).

[0032] Step 104: According to the global shadow mask image, the global shadow image is subjected to shadow removal processing by a global U-Net network in a diffusion model to obtain an intermediate feature map output by a non-final network layer in the global U-Net network.

[0033] Among them, the U-Net network is a U-shaped network structure, which consists of an encoder, a decoder, and a cross-layer connection (residual connection) between the encoder and the decoder.

[0034] The global shadow image and the global shadow mask image are input into the global U-Net network in the diffusion model. The encoder in the global U-Net network downsamples the global shadow image according to the global shadow mask image to remove the shadows in the global shadow image and obtain a feature map. The feature map is upsampled by the decoder, and the features between the encoder and the decoder are spliced ​​through cross-layer connections to finally obtain a global shadow-removed image. Each downsampling layer of the encoder is used as a network layer of the global U-Net network, and each upsampling layer of the decoder is also used as a network layer of the global U-Net network. After being processed by each non-final network layer of the global U-Net network, the intermediate feature map output by the network layer can be obtained.

[0035] Step 105, processing each group of slices separately according to the network layer feature map through the local U-Net network in the diffusion model to obtain a local noise image corresponding to each group of slices.

[0036] Among them, the network structures of the local U-Net network and the global U-Net network are the same and are parallel.

[0037] The intermediate feature map of the global U-Net network is used as the global guide of the local U-Net network in the diffusion model. Each group of slices is input into the local U-Net network in the diffusion model, and the group of slices is downsampled by the encoder in the local U-Net network to obtain the feature map. The feature map is upsampled into noise by the decoder in the local U-Net network, and the features between the encoder and the decoder are spliced ​​through cross-layer connections to finally obtain the local noise image corresponding to each group of slices. In the process of processing by the encoder and decoder, the intermediate feature map of the global U-Net network is combined with the feature map of the corresponding network layer of the local U-Net network, and the combined feature map is input into the next network layer of the local U-Net network for processing.

[0038] It should be noted that when training the diffusion model, the shadow image is taken as input, and the shadow-free image corresponding to the shadow image is taken as the annotated image. The constrained diffusion model takes the shadow-free image as the training target, and the shadow image is used as a conditional guide to guide the diffusion model to finally generate a shadow-free image. Therefore, in the inference stage of the diffusion model, the diffusion model uses the shadow image as a conditional guide, so that the image finally generated by the diffusion model conforms to the content of the conditional guidance, and finally the shadow-removed image is obtained. That is, the process of the local U-Net network processing each group of slices is to combine the global information of the global U-Net network to remove the shadows in the shadow image.

[0039] In an embodiment of the present application, the diffusion model is a diffusion model based on global guidance, including a global U-Net network and a local U-Net network, both of which process the image in parallel, and the network layer feature map obtained by processing the global U-Net network is combined with the local U-Net network, providing global guidance for the processing of the local U-Net network.

[0040] Step 106: Generate a target image after removing shadows according to each group of the local noise image and the noisy image.

[0041] According to the local noise image corresponding to each group of slices, a global noise image is generated. Based on the noisy image, the global noise image is transformed by formula to generate a target image after removing the shadow. It should be noted that in the processing of the diffusion model, multiple time steps of denoising are required to finally obtain the target image. In the processing of each time step, according to each group of local noise images and the noisy image in the input network (that is, the intermediate image after the previous time step processing or the initialized pure noise image), an intermediate image after removing the shadow can be generated. The intermediate image still contains noise. The intermediate image is used as a new noisy image to perform the processing of the next time step, that is, the steps 101 to 106 are executed repeatedly until the total number of time steps is circulated, and finally the target image after removing the shadow is obtained.

[0042] In an optional implementation, when there is no overlap between groups of slices, the local noise images can be directly spliced ​​into a global noise image, and the global noise image can be transformed by a formula to generate a target image after removing shadows.

[0043] In another optional implementation, when there is overlap between groups of slices, the average pixel value of each local noise image in the overlapping part can be used as the pixel value of the overlapping part after splicing, and then the non-overlapping part and the overlapping part in each local noise image can be spliced ​​into a global noise image, and the global noise image is transformed by formula to generate a target image after removing the shadow. Further, when determining the average pixel value of each local noise image in the overlapping part, the noise weight corresponding to each group of slices can be determined based on the local noise image, the global shadow removal image and the shadow slice, and a group of slices corresponds to a local noise image, so that the noise weight corresponding to the slice is the noise weight corresponding to the corresponding local noise image, and then the pixel values ​​of each local noise image in the overlapping part are weighted averaged according to the noise weight to obtain a weighted average pixel value.

[0044] The image processing method provided in this embodiment divides the shadow image, the shadow mask image and the noisy image into slices of the target size respectively to obtain multiple groups of slices, each group of slices includes shadow slices, shadow mask slices and noisy slices corresponding to the position, down-samples the shadow image to obtain a global shadow image of the target size, down-samples the shadow mask image to obtain a global shadow mask image of the target size, removes shadows from the global shadow image through a global U-Net network in a diffusion model according to the global shadow mask image, obtains an intermediate feature map output by a non-final network layer in the global U-Net network, processes each group of slices according to the intermediate feature map through a local U-Net network in the diffusion model, obtains a local noise image corresponding to each group of slices, and generates a target image after removing shadows according to each group of local noise images and noisy images. It can be seen that in the processing process, the underlying distribution of natural images is modeled by processing each group of slices through the local U-Net network, and the intermediate feature map in the global U-Net network is combined with the processing of the local U-Net network to provide global guidance for the processing of the local U-Net network. This solves the problem of inconsistent illumination of the output image caused by the inability of the U-Net architecture to obtain global information in the shadow removal method based on the diffusion model in the prior art, and solves the problem of residual images in the deep learning shadow removal method based on the Transformer architecture in the prior art, thereby ensuring the consistency of illumination of the final target image, and no residual images will appear after removing the shadows, thereby improving the shadow removal effect.

[0045] On the basis of the above technical solution, the intermediate feature map includes a first first-layer feature map and a first non-first-layer feature map, the first first-layer feature map is a feature map output by the first layer in the global U-Net network, and the first non-first-layer feature map is a feature map output by the intermediate network layer of the global U-Net network;

[0046] According to the network layer feature map, each group of the slices is processed respectively by a local U-Net network in a diffusion model to obtain a local noise image corresponding to each group of the slices, including: for each group of the slices, obtaining a second first-layer feature map output by the first layer when the local U-Net network processes the group of slices; fusing the first first-layer feature map and the second first-layer feature map to obtain a first fused feature map; according to the first non-first-layer feature map, the first fused feature map is processed in sequence by the second layer and each network layer after the second layer in the local U-Net network to obtain a local noise image corresponding to the group of slices.

[0047] Among them, the first first-layer feature map is the feature map obtained by the first layer (i.e., the first network layer) of the global U-Net network processing the global shadow image and the global shadow mask image. The second first-layer feature map is the feature map corresponding to each group of slices obtained by the first layer of the local U-Net network processing each group of slices. The middle network layer is the network layer at the center of the global U-Net network.

[0048] Each group of slices is processed separately by the local U-Net network. For the group of slices currently being processed, the second first-layer feature map output by the first layer when the local U-Net network processes the group of slices is first obtained, and the first first-layer feature map and the second first-layer feature map are fused to obtain the first fused feature map, and then the first fused feature map is used as the input feature of the second layer of the local U-Net network, and the first fused feature map is processed in turn based on the first non-first-layer feature map by the second and subsequent network layers of the local U-Net network to obtain the local noise image corresponding to the group of slices.

[0049] By introducing the first-layer feature map and the first non-first-layer feature map into the processing of each group of slices by the local U-Net network, global guidance is provided for the processing of the local U-Net network, which can improve the shadow removal effect.

[0050] In one embodiment of the present application, the fusing of the first first-layer feature map and the second first-layer feature map to obtain a first fused feature map includes: performing cross-attention processing on the first first-layer feature map and the second first-layer feature map to obtain a processed first-layer feature map; and determining a first fused feature map of the processed first-layer feature map and the second first-layer feature map.

[0051] The first layer feature map and the second layer feature map are cross-attended by the cross-attention mechanism to obtain a processed first layer feature map, which is a global feature map. The pixel values ​​of corresponding pixels in the processed first layer feature map and the second first layer feature map are added to obtain the first fused feature map.

[0052] By fusing the processed first-layer feature map obtained by cross-attention processing on the first-layer feature map and the second-layer feature map with the second-layer feature map, the global information obtained by processing the global U-Net network is introduced into the local U-Net network, thereby providing global guidance for the processing of the local U-Net network, which can improve the shadow removal effect of the final target image.

[0053] In one embodiment of the present application, the cross-attention processing is performed on the first first-layer feature map and the second first-layer feature map to obtain a processed first-layer feature map, including: determining a projection key vector and a projection value vector of the first first-layer feature map, and determining a projection query vector of the second first-layer feature map; performing matrix multiplication processing on the projection query vector and the projection key vector to obtain an initial weight; reweighting the initial weight and the global shadow mask image to obtain a reweighted weight; multiplying the reweighted weight and the projection value vector to obtain the processed first-layer feature map.

[0054] In an embodiment of the present application, when cross-attention processing is performed on the first first-layer feature map and the second first-layer feature map, a reweighted cross attention (RCA) module is used for processing, and the reweighted cross attention module improves the traditional cross attention mechanism. The input of the reweighted cross attention module includes the first first-layer feature map (which is a global feature map), the second first-layer feature map (which is a local feature map) and a global shadow mask image of the same size. The pixel value of the shadow area in the global shadow mask image is 0, and the pixel value of the non-shadow area is 1. The output of the reweighted cross attention module is the processed first-layer feature map, which is a global feature map processed by the reweighted cross attention module.

[0055] Among them, the first first-layer feature map is used to calculate the projection key vector (the projection key vector is a Key row vector), and the second first-layer feature map is used to calculate the projection query vector (the projection query vector is a Query column vector). The two vectors perform matrix multiplication and perform Softmax processing after scaling to obtain the initial weight W_. The initial weight W_ is then multiplied with the global shadow mask image M_ to perform reweighting to obtain the reweighted weight. The purpose of reweighting is to suppress the value of the part represented as the shadow in the global mask image in the initial weight W_. The reweighted weight is multiplied again with the projection value vector (Value vector) calculated by the first first-layer feature map to obtain the final global feature map processed by the cross-attention module, that is, the processed first-layer feature map. The processing process of the reweighted cross-attention module can be expressed as the following formula:

[0056]

[0057] Wherein, Q represents the projected query vector, K represents the projected key vector, V represents the projected value vector, and d represents a scaling parameter. Represents the global shadow mask image, which is used to multiply the features.

[0058] Exemplarily, the size of the first-layer feature map is 64×64, and the size of the second-layer feature map is 64×64. The size of the calculated projection key vector is the row vector of 4096 pixels in the first-layer feature map, where the row vector is obtained by flattening each pixel in the first-layer feature map; the projection query vector is a column vector of 4096 pixels, where the column vector is obtained by arranging each pixel in the second-layer feature map into a column vector; the projection key vector and the projection query vector perform matrix multiplication to obtain an initial weight W_ of size 4096×4096, in which the i-th row and j-th column of the initial weight represent the i-th pixel in the first-layer feature map for the second The mutual information value of the j-th pixel in the first-layer feature map indicates the mutual attention of the two pixels. The larger the value, the more related the two pixels are, and the more they should be strengthened. At this time, the global shadow mask image is introduced to determine which pixels in the first-layer feature map are shadows. For example, if the i-th pixel in the first-layer feature map is a shadow, then the i-th row in the initial weight W_ corresponding to it is set to negative infinity as a whole. In this way, the connection between the shadow pixels in the global information and the pixels in other local information is suppressed, and finally the weights are normalized, thereby strengthening the correlation value between the non-shadow pixels in the global information and the pixels in the local information.

[0059] By determining the projection key vector and the projection value vector from the first layer feature map, determining the projection query vector from the second layer feature map, and performing reweighting processing, the shadow part can be suppressed, so that the processed first layer feature map is a global feature map after the shadow is suppressed, which can provide global guidance for the local U-Net network after the shadow is suppressed, thereby further improving the shadow removal effect of the final target image.

[0060] In one embodiment of the present application, according to the first non-first layer feature map, the first fused feature map is processed in sequence by the second layer and each network layer after the second layer in the local U-Net network to obtain a local noise image corresponding to the group of slices, including: the first fused feature map is processed in sequence from the second layer to the middle network layer of the local U-Net network to obtain a second non-first layer feature map; the first non-first layer feature map and the second non-first layer feature map are convolutionally processed to obtain a processed non-first layer feature map; the second fused feature map of the processed non-first layer feature map and the second non-first layer feature map is input into the network layer after the middle network layer of the local U-Net network, and the second fused feature map is processed in sequence by each network layer after the middle network layer of the local U-Net network to obtain a local noise image corresponding to the group of slices.

[0061] Among them, the middle network layer of the local U-Net network is the network layer at the center of the local U-Net network.

[0062] When the global shadow image and the global shadow mask image are processed by the global U-Net network, the feature map output by the intermediate network layer of the global U-Net network is obtained to obtain the first non-first layer feature map. When each group of slices is processed by the local U-Net network, the second layer to the intermediate network layer of the local U-Net network sequentially processes the first fused feature map corresponding to the group of slices, obtains the feature map output by the intermediate network layer of the local U-Net network, and obtains the second non-first layer feature map. The first non-first layer feature map and the second non-first layer feature map are convoluted to obtain the processed non-first layer feature map, and the processed non-first layer feature map and the second non-first layer feature map are added to obtain the second fused feature map, and the second fused feature map is used as the input of a network layer after the intermediate network layer of the local U-Net network, and the second fused feature map is sequentially processed by each network layer after the intermediate network layer of the local U-Net network to obtain the local noise image corresponding to the group of slices.

[0063] The processed non-first-layer feature map is obtained by convolving the first non-first-layer feature map with the second non-first-layer feature map, and the processed central feature map and the second non-first-layer feature map are fused, so that the global information of the intermediate network layer of the global U-Net network is combined with the local U-Net network. The network prediction of the local U-Net network is assisted by the global information, thereby further improving the shadow removal effect of the final target image.

[0064] Figure 2 is a schematic diagram of shadow removal by parallel local U-Net network and global U-Net network in an embodiment of the present application, such as Figure 2 As shown, after the local U-Net network performs the first-layer processing on each group of slices, the second first-layer feature map is obtained, and after the global U-Net network performs the first-layer processing on the global shadow image and the global shadow mask image, the first first-layer feature map is obtained; the first first-layer feature map and the second first-layer feature map are processed by the cross attention (RCA) module to obtain a processed feature map, the processed feature map is fused with the first first-layer feature map to obtain a first fused feature map, and the first fused feature map is used as the input feature of the second layer of the local U-Net network; the first fused feature map is processed in sequence from the second layer to the middle network layer of the local U-Net network to obtain a second non-first-layer feature map, and The second non-first-layer feature map is convolved with the first non-first-layer feature map output by the intermediate network layer of the global U-Net network to obtain a processed non-first-layer feature map, and the processed non-first-layer feature map is fused with the second non-first-layer feature map to obtain a second fused feature map, and the second fused feature map is used as the input feature of the network layer after the intermediate network layer of the local U-Net network; the second fused feature map is processed in turn by each network layer after the intermediate network layer of the local U-Net network, and a local noise image corresponding to each group of slices is finally obtained through cross-layer connection (when cross-layer connection is made, the first fused feature map obtained by the cross-attention module is cross-layer connected with the output feature of the last network layer). The global U-Net network finally outputs a global shadow-removed image.

[0065] Figure 3 is a flowchart of the steps of an image processing method provided in an embodiment of the present application. The method can be applied to the scene of repairing the shadow in the image, such as Figure 3 As shown, the method may include:

[0066] Step 301 : Obtain a shadow image to be processed, a shadow mask image corresponding to the shadow image, and a noisy image, wherein the noisy image is obtained by adding noise to the shadow image.

[0067] Step 302 , respectively cut the shadow image, the shadow mask image and the noisy image into slices of target sizes to obtain multiple groups of slices, each group of slices including shadow slices, shadow mask slices and noisy slices corresponding to positions.

[0068] Step 303: downsample the shadow image to obtain a global shadow image of the target size, and downsample the shadow mask image to obtain a global shadow mask image of the target size.

[0069] Step 304, according to the global shadow mask image, remove the shadows of the global shadow image through the global U-Net network in the diffusion model, obtain the intermediate feature map output by the non-final network layer in the global U-Net network, and obtain the global shadow-removed image output by the global U-Net network.

[0070] Step 305 , processing each group of slices separately according to the intermediate feature map through the local U-Net network in the diffusion model to obtain a local noise image corresponding to each group of slices.

[0071] Step 306: Perform restoration processing on each group of the local noise images to obtain multiple groups of local restored images.

[0072] Formula transformation processing is performed on each group of local noise images to obtain the local restored image corresponding to each group of local noise images.

[0073] Step 307: Determine the noise weight corresponding to each group of slices according to each group of the local restored images, the global shadow removed images and the shadow slices.

[0074] According to the local restored image, the global shadow removed image and the shadow slices, the noise weight corresponding to each group of slices is determined, that is, the noise weight of the local noise image corresponding to each group of slices in the overlapping part of each local noise image is determined.

[0075] In one embodiment of the present application, determining the noise weight corresponding to each group of slices according to each group of the local restored images, the global shadow-removed images and the shadow slices includes: for each group of slices, determining the brightness score of the group of slices according to the local restored images and the global shadow-removed images, the brightness score characterizing the degree of brightness consistency between the local restored image and the global shadow-removed image; determining a first proportion of non-shadow areas in the shadow slices according to the shadow slices, and determining a mask score for the group of slices according to the first proportion, the mask score characterizing the proportion of non-shadow areas in the group of slices; determining the noise weight corresponding to the group of slices according to the brightness score and the mask score.

[0076] In the slice-based Diffusion image restoration process, adaptive noise estimation can be performed for each pixel in the overlapping part at all given denoising time steps t. The weight of each group of slices is determined by two parts: the brightness score and the mask score. The brightness score considers that the local restored image should have the same brightness consistency as the global shadow removal image, while the mask score considers the ratio of shadow and non-shadow areas inside the slice. The brightness score assumes that the local restored image obtained by the local U-Net network should show similar brightness to the global shadow removal image generated by the global U-Net network.

[0077] A naive idea is that when the shadow area in the slice has a larger proportion, the recovery is more difficult. Therefore, based on the mask score, we pay more attention to the first proportion of the non-shadow area in the slice: R sf =P sf / P total , where P sf represents the number of pixels in the non-shadow area, P total Indicates the number of pixels in the entire shadow slice. When determining the mask score according to the first ratio, the first ratio is compared with the ratio threshold. If the first ratio is greater than or equal to the ratio threshold, the mask score is determined to be 1. If the first ratio is less than the ratio threshold, the mask score is determined to be the ratio of the first ratio to the ratio threshold. That is, the mask score can be expressed as follows:

[0078]

[0079] Among them, S m represents the mask score, R sf Indicates the first ratio, T sf Indicates the ratio threshold. Optionally, the ratio threshold T sf Can be set to 0.5.

[0080] The brightness score and mask score of each group of slices are combined to determine the noise weight corresponding to each group of slices.

[0081] The brightness score is used to ensure the brightness consistency between the local restored image and the global shadow-removed image, while the mask score is used to characterize the difficulty of image restoration. The larger the mask score, the easier it is to restore, which can further suppress the shadow part. In this way, the global noise image obtained by merging the noise weights obtained based on the brightness score and the mask score can further suppress the shadow part, thereby further improving the shadow removal effect of the final target image.

[0082] In one embodiment of the present application, determining the brightness score of the group of slices based on the local restored image and the global shadow-removed image includes: converting the local restored image into a grayscale image to obtain a local grayscale image, and converting the global shadow-removed image into a grayscale image to obtain a global grayscale image; determining the absolute value of the difference between the grayscale values ​​of each pixel in the local grayscale image and the global grayscale image, and determining the average and maximum values ​​of the absolute values ​​of the difference; determining a second ratio of the average value to the maximum value, and determining the brightness score of the group of slices based on the second ratio.

[0083] When determining the brightness score of the slice corresponding to the local restored image according to the second ratio, the difference between the constant 1 and the second ratio can be determined as the brightness score. The brightness score of each group of slices can be expressed as follows:

[0084]

[0085] Among them, S bri Indicates the brightness score, L gray Represents the local grayscale image, G gray represents the global grayscale image, and eps represents an adjustment coefficient. The adjustment coefficient can avoid the denominator being 0, and can be set to 0.01, for example.

[0086] In one embodiment of the present application, determining the noise weight corresponding to the group of slices according to the brightness score and the mask score includes:

[0087] According to the brightness score and the mask score, determine the noise weight corresponding to the group of slices according to the following formula;

[0088]

[0089] Among them, W d represents the noise weight corresponding to the group of slices, t represents the current denoising step number, T represents the total denoising step number of the diffusion model, S bri represents the brightness score, S m represents the mask score.

[0090] Step 308: Merge the local noise images according to the noise weights to obtain a global noise image.

[0091] After obtaining the noise weight corresponding to each group of slices, the average pixel value of each local noise image in the overlapping part can be determined based on the noise weight, and the average pixel value can be used as the pixel value of the overlapping part. The overlapping part and the non-overlapping part of each local noise can be spliced ​​into a global noise image.

[0092] In one embodiment of the present application, the local noise images are merged according to the noise weights to obtain a global noise image, including: according to the noise weights, weighted averaging the initial pixel values ​​of each pixel in the overlapping parts of each of the local noise images in different local noise images to obtain the target pixel value of each pixel in the overlapping parts; and merging the overlapping parts and the non-overlapping parts of each of the local noise images except the overlapping parts into the global noise image.

[0093] The noise weight represents the weight of each local noise image in the overlapping part. Based on the noise weight, the pixel value of each pixel point of the overlapping part of different local noise images is weighted averaged as the target pixel value of each pixel point in the overlapping part. The target pixel value of the overlapping part calculated in this way is the adaptive estimated noise. The entire adaptive estimated noise calculation formula can be expressed as follows:

[0094]

[0095] Where i∈{1,…,N p},N p Indicates the number of overlapping slices for each pixel, Represents the noise weight of a pixel in different slices (local noise images), represents the i-th local noise image (i.e., the local noise image obtained by processing the i-th group of slices through the local U-Net network), ∈ θ Represents the local U-Net network and the global U-Net network of the diffusion model, represents a noisy image (i.e., an intermediate variable), represents the input of the local U-Net network (including shadow slices and shadow mask slices), x G represents the input of the global U-Net network (including the global shadow image and the global shadow mask image), and t represents the current denoising step number.

[0096] The non-overlapping parts in each local noise image are the pixel values ​​of the corresponding pixels in the local noise image, so that the overlapping parts and the non-overlapping parts can be merged into a global noise image based on their positions in the global image.

[0097] Step 309: Generate the target image according to the global noise image and the noisy image.

[0098] Based on the noisy image, the global noise image is transformed by formula processing to obtain the image after removing the shadows in the current time step (i.e., the current denoising step). If the current time step is not the last time step of the diffusion model, the obtained image is an intermediate image, which still contains noise. The intermediate image is used as a new noisy image to perform the processing of the next time step, that is, step 301 to step 309 are executed repeatedly until the total number of time steps (total number of denoising steps) is looped, and finally the target image after removing the shadows is obtained.

[0099] Among them, the formula used when performing formula transformation processing on the global noise image based on the noisy image can be expressed as follows:

[0100]

[0101] Among them, t represents the current denoising step, x t represents the noisy image in the current denoising step, x t+1 represents the intermediate image obtained in the current denoising step, that is, the noisy image input in the next denoising step, Ω t represents the global noise image, Represents the constant corresponding to the Markov chain of the diffusion model at the current denoising step, Represents the constant corresponding to the Markov chain of the diffusion model in the next denoising step.

[0102] The image processing method provided in this embodiment obtains a global shadow-removed image output by a global U-Net network, restores each group of local noise images respectively, and obtains multiple groups of local restored images. The noise weight corresponding to each group of slices is determined according to each group of local restored images, the global shadow-removed image, and the shadow slices. The local noise images are merged according to the noise weights to obtain a global noise image. A target image is generated according to the global noise image and the noisy image. The global shadow-removed image output by the global U-Net network is further combined to perform image restoration, which can further improve the shadow removal effect.

[0103] It should be noted that, for the method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the embodiments of the present application are not limited by the described order of actions, because according to the embodiments of the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required by the embodiments of the present application.

[0104] Figure 4 is a structural block diagram of an image processing device provided in an embodiment of the present application, such as Figure 4 As shown, the image processing device may include:

[0105] An image acquisition module 401 is used to acquire a shadow image to be processed, a shadow mask image corresponding to the shadow image, and a noisy image, where the noisy image is obtained by adding noise to the shadow image;

[0106] A slice processing module 402 is used to slice the shadow image, the shadow mask image and the noisy image into slices of target sizes respectively to obtain multiple groups of slices, each group of slices including shadow slices, shadow mask slices and noisy slices corresponding to positions;

[0107] A downsampling module 403 is used to downsample the shadow image to obtain a global shadow image of the target size, and downsample the shadow mask image to obtain a global shadow mask image of the target size;

[0108] A global network processing module 404 is used to remove shadows from the global shadow image through a global U-Net network in a diffusion model according to the global shadow mask image, and obtain an intermediate feature map output by a non-final network layer in the global U-Net network;

[0109] A local network processing module 405 is used to process each group of slices according to the intermediate feature map through a local U-Net network in the diffusion model to obtain a local noise image corresponding to each group of slices;

[0110] The target image generation module 406 is used to generate a target image after removing shadows according to each group of the local noise image and the noisy image.

[0111] Optionally, the intermediate feature map includes a first first-layer feature map and a first non-first-layer feature map, the first first-layer feature map is a feature map output by the first layer in the global U-Net network, and the first non-first-layer feature map is a feature map output by an intermediate network layer of the global U-Net network;

[0112] The local network processing module includes:

[0113] A local first-layer feature acquisition unit, used for acquiring, for each group of slices, a second first-layer feature map output by the first layer when the local U-Net network processes the group of slices;

[0114] A first-layer feature fusion unit, used to fuse the first first-layer feature map and the second first-layer feature map to obtain a first fused feature map;

[0115] A local network processing unit is used to process the first fused feature map in sequence through the second layer and each network layer after the second layer in the local U-Net network according to the first non-first layer feature map, so as to obtain a local noise image corresponding to the group of slices.

[0116] Optionally, the first-layer feature fusion unit includes:

[0117] a cross attention subunit, configured to perform cross attention processing on the first first-layer feature map and the second first-layer feature map to obtain a processed first-layer feature map;

[0118] The first-layer feature fusion subunit is used to determine a first fused feature map of the processed first-layer feature map and the second first-layer feature map.

[0119] Optionally, the cross attention subunit is specifically used for:

[0120] Determine a projection key vector and a projection value vector of the first first-layer feature map, and determine a projection query vector of the second first-layer feature map;

[0121] Performing matrix multiplication processing on the projected query vector and the projected key vector to obtain an initial weight;

[0122] Reweighting the initial weight and the global shadow mask image to obtain a reweighted weight;

[0123] The reweighted weight is multiplied by the projection value vector to obtain the processed first-layer feature map.

[0124] Optionally, the local network processing unit includes:

[0125] A downsampling subunit, used to process the first fused feature map in sequence through the second layer to the middle network layer of the local U-Net network to obtain a second non-first layer feature map;

[0126] A convolution processing subunit, configured to perform convolution processing on the first non-first layer feature map and the second non-first layer feature map to obtain a processed non-first layer feature map;

[0127] The upsampling subunit is used to input the processed non-first layer feature map and the second fused feature map of the second non-first layer feature map into the network layer after the intermediate network layer of the local U-Net network, and process the second fused feature map in turn through each network layer after the intermediate network layer of the local U-Net network to obtain a local noise image corresponding to the group of slices.

[0128] Optionally, the device further comprises:

[0129] Obtaining a global shadow-removed image output by the global U-Net network;

[0130] The target image generation module comprises:

[0131] A local restoration unit, used for performing restoration processing on each group of the local noise images respectively to obtain multiple groups of local restoration images;

[0132] A noise weight determination unit, configured to determine a noise weight corresponding to each group of slices according to each group of the local restored images, the global shadow removed images and the shadow slices;

[0133] A global noise generating unit, configured to merge the local noise images according to the noise weights to obtain a global noise image;

[0134] A target image generating unit is used to generate the target image according to the global noise image and the noisy image.

[0135] Optionally, the noise weight determination unit includes:

[0136] a brightness score determination subunit, configured to determine, for each group of slices, a brightness score of the group of slices according to the local restored image and the global shadow-removed image, wherein the brightness score represents a degree of brightness consistency between the local restored image and the global shadow-removed image;

[0137] a mask score determination subunit, configured to determine, based on the shadow slice, a first proportion of the non-shadow area in the shadow slice, and determine a mask score of the group of slices based on the first proportion, wherein the mask score represents a proportion of the non-shadow area in the group of slices;

[0138] The noise weight determination subunit is used to determine the noise weight corresponding to the group of slices according to the brightness score and the mask score.

[0139] Optionally, the brightness score determination subunit is specifically used for:

[0140] Converting the local restored image into a grayscale image to obtain a local grayscale image, and converting the global shadow-removed image into a grayscale image to obtain a global grayscale image;

[0141] Determine the absolute value of the difference between the grayscale values ​​of each pixel in the local grayscale image and the global grayscale image, and determine the average value and the maximum value of the absolute value of the difference;

[0142] A second ratio of the average value to the maximum value is determined, and a brightness score of the group of slices is determined according to the second ratio.

[0143] Optionally, the noise weight determination subunit is specifically used for:

[0144] According to the brightness score and the mask score, determine the noise weight corresponding to the group of slices according to the following formula;

[0145]

[0146] Among them, W d represents the noise weight corresponding to the group of slices, t represents the current denoising step number, T represents the total denoising step number of the diffusion model, S bri represents the brightness score, S m represents the mask score.

[0147] Optionally, the global noise generation subunit is specifically used for:

[0148] According to the noise weight, weighted average is performed on the initial pixel value of each pixel point in the overlapping part of each local noise image in different local noise images to obtain the target pixel value of each pixel point in the overlapping part;

[0149] The overlapping portion and the non-overlapping portion of each of the local noise images except the overlapping portion are merged into the global noise image.

[0150] For the specific implementation process of the functions corresponding to each module and unit in the device provided in the embodiment of the present application, please refer to Figures 1 to 3 The method embodiment shown here will not repeat the specific implementation process of the functions corresponding to each module and unit of the device.

[0151] The image processing device provided by the present embodiment divides the shadow image, the shadow mask image and the noisy image into slices of the target size respectively to obtain multiple groups of slices, each group of slices includes shadow slices, shadow mask slices and noisy slices corresponding to the position, downsamples the shadow image to obtain a global shadow image of the target size, downsamples the shadow mask image to obtain a global shadow mask image of the target size, removes shadows from the global shadow image through a global U-Net network in a diffusion model according to the global shadow mask image, obtains an intermediate feature map output by a non-final network layer in the global U-Net network, processes each group of slices according to the intermediate feature map through a local U-Net network in the diffusion model, obtains a local noise image corresponding to each group of slices, and generates a target image after removing shadows according to each group of local noise images and noisy images. It can be seen that in the processing process, the underlying distribution of natural images is modeled by processing each group of slices through the local U-Net network, and the intermediate feature maps in the global U-Net network are combined with the processing of the local U-Net network. Global guidance is provided for the processing of the local U-Net network, thereby ensuring the consistency of the illumination of the final target image, and no afterimage will appear after removing the shadow, thereby improving the shadow removal effect.

[0152] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0153] Figure 5 is a structural block diagram of an electronic device provided in an embodiment of the present application, such as Figure 5 As shown, the electronic device 500 may include one or more processors 510 and one or more memories 520 connected to the processor 510. The electronic device 500 may also include an input interface 530 and an output interface 540 for communicating with another device or system. The program code executed by the processor 510 may be stored in the memory 520.

[0154] The processor 510 in the electronic device 500 calls the program code stored in the memory 520 to execute the image processing method in the above embodiment.

[0155] According to one embodiment of the present application, a computer-readable storage medium is also provided, and the computer-readable storage medium includes but is not limited to a disk storage, a CD-ROM, an optical storage, etc., and a computer program is stored on the computer-readable storage medium, and when the computer program is executed by a processor, the image processing method described in the aforementioned embodiment is implemented.

[0156] According to one embodiment of the present application, a computer program product is further provided, including a computer program or computer instructions, and when the computer program or computer instructions are executed by a processor, the image processing method described in the above embodiment is implemented.

[0157] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.

[0158] Those skilled in the art will appreciate that the embodiments of the present application can be provided as methods, devices, or computer program products. Therefore, the present application can adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application can adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0159] The embodiments of the present application are described with reference to the flowcharts and / or block diagrams of the methods, terminal devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0160] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing terminal device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0161] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable terminal device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1The steps for the functions specified in one or more boxes.

[0162] Although the preferred embodiments of the present application have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present application.

[0163] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or terminal device including the elements.

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

Claims

1. An image processing method, characterized in that: include: Acquire a shadow image to be processed, a shadow mask image corresponding to the shadow image, and a noisy image, where the noisy image is obtained by adding noise to the shadow image; The shadow image, the shadow mask image and the noisy image are respectively cut into slices of target size to obtain multiple groups of slices, each group of slices includes shadow slices, shadow mask slices and noisy slices corresponding to positions; Downsampling the shadow image to obtain a global shadow image of the target size, and downsampling the shadow mask image to obtain a global shadow mask image of the target size; According to the global shadow mask image, removing shadows from the global shadow image through a global U-Net network in a diffusion model, and obtaining an intermediate feature map output by a non-final network layer in the global U-Net network; Processing each group of slices according to the intermediate feature map through a local U-Net network in the diffusion model to obtain a local noise image corresponding to each group of slices; A target image after removing shadows is generated according to each group of the local noise image and the noisy image.

2. The method according to claim 1, characterized in that The intermediate feature map includes a first first-layer feature map and a first non-first-layer feature map, wherein the first first-layer feature map is a feature map output by the first layer in the global U-Net network, and the first non-first-layer feature map is a feature map output by the intermediate network layer of the global U-Net network; The method of processing each group of slices according to the intermediate feature map through the local U-Net network in the diffusion model to obtain a local noise image corresponding to each group of slices includes: For each group of slices, obtaining a second first-layer feature map output by the first layer when the local U-Net network processes the group of slices; Fusing the first first-layer feature map and the second first-layer feature map to obtain a first fused feature map; According to the first non-first layer feature map, the first fused feature map is processed in sequence by the second layer and each network layer after the second layer in the local Uet network to obtain a local noise image corresponding to the group of slices.

3. The method according to claim 2, characterized in that The fusing the first first-layer feature map and the second first-layer feature map to obtain a first fused feature map includes: Performing cross attention processing on the first first-layer feature map and the second first-layer feature map to obtain a processed first-layer feature map; Determine a first fused feature map of the processed first-layer feature map and the second first-layer feature map.

4. The method according to claim 3, characterized in that The performing cross attention processing on the first first-layer feature map and the second first-layer feature map to obtain a processed first-layer feature map includes: Determine a projection key vector and a projection value vector of the first first-layer feature map, and determine a projection query vector of the second first-layer feature map; Performing matrix multiplication processing on the projected query vector and the projected key vector to obtain an initial weight; Reweighting the initial weight and the global shadow mask image to obtain a reweighted weight; The reweighted weight is multiplied by the projection value vector to obtain the processed first-layer feature map.

5. The method according to claim 2, characterized in that: The method of processing the first fused feature map in sequence through the second layer and each network layer after the second layer in the local U-Net network according to the first non-first layer feature map to obtain a local noise image corresponding to the group of slices includes: The first fused feature map is processed sequentially through the second layer to the middle network layer of the local U-Net network to obtain a second non-first layer feature map; Performing convolution processing on the first non-first-layer feature map and the second non-first-layer feature map to obtain a processed non-first-layer feature map; The second fused feature map of the processed non-first layer feature map and the second non-first layer feature map is input into the network layer after the intermediate network layer of the local U-Net network, and the second fused feature map is processed in turn by each network layer after the intermediate network layer of the local U-Net network to obtain a local noise image corresponding to the group of slices.

6. The method according to any one of claims 1 to 5, characterized in that: Also includes: Obtaining a global shadow-removed image output by the global U-Net network; The step of generating a target image after removing shadows according to each group of the local noise image and the noisy image comprises: Performing restoration processing on each group of the local noise images respectively to obtain multiple groups of local restored images; Determine a noise weight corresponding to each group of slices according to each group of the local restored images, the global shadow removed images and the shadow slices; According to the noise weights, the local noise images are merged to obtain a global noise image; The target image is generated according to the global noise image and the noisy image.

7. The method according to claim 6, characterized in that The step of determining the noise weight corresponding to each group of slices according to each group of the local restored images, the global shadow removed images and the shadow slices includes: For each group of slices, determining a brightness score of the group of slices according to the local restored image and the global shadow removal image, wherein the brightness score represents a degree of brightness consistency between the local restored image and the global shadow removal image; Determine, according to the shadow slice, a first proportion of the non-shadow area in the shadow slice, and determine, according to the first proportion, a mask score of the group of slices, wherein the mask score represents the proportion of the non-shadow area in the group of slices; A noise weight corresponding to the group of slices is determined according to the brightness score and the mask score.

8. The method according to claim 7, characterized in that Determining the brightness scores of the group of slices according to the local restored image and the global shadow removed image includes: Converting the local restored image into a grayscale image to obtain a local grayscale image, and converting the global shadow-removed image into a grayscale image to obtain a global grayscale image; Determine the absolute value of the difference between the grayscale values ​​of each pixel in the local grayscale image and the global grayscale image, and determine the average value and the maximum value of the absolute value of the difference; A second ratio of the average value to the maximum value is determined, and a brightness score of the group of slices is determined according to the second ratio.

9. The method according to claim 7, characterized in that: The determining, according to the brightness score and the mask score, a noise weight corresponding to the group of slices includes: According to the brightness score and the mask score, determine the noise weight corresponding to the group of slices according to the following formula; Among them, W d represents the noise weight corresponding to the group of slices, t represents the current denoising step number, T represents the total denoising step number of the diffusion model, S bri represents the brightness score, S m represents the mask score.

10. The method according to claim 6, characterized in that The step of merging the local noise images according to the noise weights to obtain a global noise image includes: According to the noise weight, weighted average is performed on the initial pixel value of each pixel point in the overlapping part of each local noise image in different local noise images to obtain the target pixel value of each pixel point in the overlapping part; The overlapping portion and the non-overlapping portion of each of the local noise images except the overlapping portion are merged into the global noise image.

11. An electronic device, characterized in that: include: A processor, a memory, and a computer program stored in the memory and executable on the processor, wherein the computer program, when executed by the processor, implements the image processing method according to any one of claims 1 to 10.

12. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the image processing method according to any one of claims 1 to 10 is implemented.

13. A computer program product, characterized in that The method comprises a computer program or a computer instruction, which, when executed by a processor, implements the image processing method according to any one of claims 1 to 10.

Citation Information

Patent Citations

  • PCB automatic wiring method based on united Monte Carlo tree search

    CN112528591A

  • Image shadow removing method and device

    CN113052775A

  • Image shadow removal system and method based on potential diffusion model

    CN116485682A

  • Image shadow removal method and device, storage medium and equipment

    CN117011182A

  • Thermal infrared image enhancement method based on global and local feature fusion modulation

    CN117635489A

Cited By

  • Audio generation method and device, electronic equipment and storage medium

    CN119255028A

  • Face shadow elimination method and device based on adaptive face symmetry

    CN119515733A