A thangka image restoration method, system and storage medium based on multi-level adaptive CNN and hybrid Transformer
Through the method of combining multi-level adaptive CNN and hybrid Transformer, the problem of cross-fusion of global information and local information in image repair is difficult to restore the original information, and a more complete and natural image repair effect is achieved.
Patent Information
- Application Number
- CN202410327336.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-03-21
- Publication Date
- 2024-09-10
- Estimated Expiration
- 2044-03-21
AI Technical Summary
Existing image restoration technology is difficult to fully restore the original image information during the cross-fusion process of global information and local information, resulting in incomplete restoration.
Using a method combining multi-level adaptive CNN and hybrid Transformer, through local feature extraction and global feature modeling, threshold segmentation is used to determine the missing area, and fusion features are generated through bilateral filters and histogram processing, and finally the depth is converted through the convolution layer to generate the repaired image.
It effectively captures global context information, avoids missing problems in image restoration, ensures the integrity of image restoration, restores the painting details on thangkas, and makes the restored image more accurate and natural.
Smart Images

Figure CN118172290B
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image restoration, and in particular to a thangka image restoration method, system and storage medium based on multi-level adaptive CNN and hybrid Transformer. Background Art
[0002] Image restoration is an important research direction in the field of computer vision. Its research content is to let the computer automatically fill in the missing or damaged areas of the image with the content that the image should have, so that the output result can be as real and natural as possible while retaining the original image information. The key to solving the image restoration problem is how to let the computer "understand" the information of natural images from shallow to deep layers, and use this information to obtain the image restoration result.
[0003] Thangka is a unique form of painting art in Tibetan culture. Its content involves many aspects of Tibetan history, politics, culture, social life, etc. It can be said to be a Tibetan encyclopedia. Unlike common natural images or paintings, Thangka contains a variety of colors, complex structures, extremely fine textures, and profound religious and cultural significance. It is a precious intangible cultural heritage in the folk art of the Chinese nation. Tibetan culture has a long history. As time goes by, the murals have fallen into disrepair and many precious Thangka murals have been destroyed. On the one hand, studying the restoration of Thangka mural images can restore the damaged parts of the murals as much as possible and protect the Tibetan cultural heritage; on the other hand, after the restoration of the Thangka mural images, the complete mural content can be obtained, further exploring the cultural and economic value of the Thangka murals.
[0004] In the prior art, the publication number CN117392016A provides an image restoration method based on the interaction of global and local heterogeneous information. The method uses a convolutional layer to extract shallow features of a degraded image; secondly, a Transformer is used in the encoder stage to extract the global representation of the image; then, the global information and local information between the encoder and the decoder are used to perform cross-attention operations to better achieve cross-fusion of global and local information; finally, a feature enhancement block designed by a convolutional neural network is used in the decoder stage to restore local details. The encoder part of the present invention uses a Transformer to extract the global representation of the image, while the decoder part uses a feature enhancement block designed by a CNN to restore local details, which can effectively solve the problem that the existing image restoration network lacks sufficient feature representation capabilities to restore high-quality images.
[0005] However, there are still some shortcomings. From the above statements, it can be seen that when using the global information and local information between the encoder and the decoder to perform cross-attention operations to better realize the cross-fusion of global information and local information, because in the process of feature fusion and processing, the model may not be able to completely restore the original image information, resulting in some missing images, causing the entire image to be incompletely restored.
[0006] The above information disclosed in this Background section is only for enhancement of understanding of the background of the present disclosure and therefore it may contain information that does not constitute the prior art that is already known to one of ordinary skill in the art. Summary of the invention
[0007] The purpose of the present invention is to provide a thangka image restoration method, system and storage medium based on multi-level adaptive CNN and hybrid Transformer to solve the problems raised in the above background technology.
[0008] To achieve the above object, the present invention provides the following technical solutions:
[0009] A thangka image restoration method based on multi-level adaptive CNN and hybrid Transformer, the specific steps include:
[0010] S1. Collecting an image of the thangka to be repaired, scaling the image of the thangka to be repaired, and adjusting the image size to a uniform size of 224*224 to obtain a first image;
[0011] S2. extract local features from the first image through a multi-level adaptive CNN, and send the local features to a hybrid Transformer module, extract first global features from the first image through the hybrid Transformer module and output a feature map, and then use threshold segmentation on the output feature map to determine the missing area in the image;
[0012] S3. Filter the missing area using a bilateral filter, count the frequency of pixels in each of the 256 levels to form a histogram, perform data processing on the histogram to generate a second image, perform global feature modeling on the second image through a hybrid Transformer model, and output a second global feature;
[0013] S4. Fusing the output second global features through the SFB module to generate fused features, and processing the fused features through the Reduction module and the Expansion module to generate a third image;
[0014] S5. Use a 1x1 convolution layer to convert the depth of the third image into the number of channels of the target image, output the target image, and process the output target image to generate a restored image.
[0015] Furthermore, in step S2, the process of extracting local features of the first image through the CNN module is as follows:
[0016] The first image is subjected to a small-kernel convolution layer to extract local features, wherein the local features include edge features and texture features. The formula used by the small-kernel convolution layer is as follows:
[0017] F jb =H conv (BT)+H conv (WT)
[0018] Among them, F jb is the local feature, H conv (·) is a 3×3 convolutional layer, BT is the edge feature, and WT is the texture feature;
[0019] After extracting the local features, the local features F jb Passed to the CNN module;
[0020] In the MARFB module, the local feature F jb During processing, assuming that the number of MARFB modules is M, the output of the mth (1≤m≤M) MARFB module can be expressed as follows:
[0021]
[0022] in, is the mth MARFB module, F m is the output of the mth MARFB module;
[0023] The output of the MARFB module is merged and sent to the hybrid Transformer to extract the first global feature, which includes shape features and structural features. Assuming that the number of HT modules is N, the output of the nth (1≤n≤N) HT module can be expressed as follows:
[0024]
[0025] in, For the nth HT module, F n is the first global feature output by the nth HT module, and || is the concatenation of m MARFB modules.
[0026] Furthermore, in step S2, the output feature map is segmented by threshold, and the process of determining the missing area in the image is as follows:
[0027] Traverse all possible thresholds, divide the feature map into missing parts and intact parts according to the value of each threshold, count the number of pixels in the missing area and the intact area, and calculate the mean of the grayscale values of the pixels in the damaged area and the intact area. Calculate the inter-class variance of the corresponding threshold according to the following formula:
[0028] σ(t) 2 =w B (t)*w F (t)*(μ B (t)-μ F (t)) 2
[0029] Among them, σ(t) 2 represents the inter-class variance when the threshold is t, t∈[0, 255], and t∈N + ,w B (t), w F (t) are the number of pixels in the missing part and the intact part when the threshold is t, μ B (t), μ F (t) are the mean gray values of the pixels in the missing part and the intact part when the threshold is t;
[0030] Calculate the threshold value when the inter-class variance reaches the maximum, and define this value as the optimal separation threshold. When segmenting into missing areas and intact areas, if the grayscale value of the pixel is less than or equal to t, the pixel is judged to belong to the intact area; if it is greater than t, the pixel is judged to belong to the missing area.
[0031] Furthermore, in step S3, the frequency of the pixel points in each level of the 256 levels is counted to form a histogram, and the histogram is processed to generate the second image as follows:
[0032] Calculate histogram: calculate the grayscale histogram of each color channel separately;
[0033] Calculate the cumulative distribution function CDF: Normalize the grayscale histogram of each color channel to obtain the cumulative distribution function CDF;
[0034] Map the original pixel values: Use the CDF of each color channel to independently map each pixel value of the original image; for each pixel value [p], map it to a new pixel value [p′] according to the following formula:
[0035] [p′=round(CDF(p)×(L-1))]
[0036] Where [L] is the total number of gray levels, usually 256, p is the original pixel value, and p′ is the new pixel value;
[0037] Create a new image: Based on the new pixel values of each channel, generate a second image, the pixel values of the second image range from 0 to [L-1], where [L] is the total number of gray levels;
[0038] Application results: Finally, the obtained second image is used as the image processed by histogram equalization.
[0039] Furthermore, in step S3, the process of global feature modeling of the second image by the hybrid Transformer model is as follows:
[0040] Feature extraction: First, extract the second global features from the second image, which can be achieved by a pre-trained hybrid Transformer model that accepts the second image as input and outputs a high-level semantic feature representation of the image;
[0041] Transformer encoder: Use the Transformer encoder to encode the features of the second image. The Transformer encoder maps the input feature sequence to a set of query vectors, key vectors, and value vectors, and uses the self-attention mechanism to model the dependencies between the input feature sequences.
[0042] Multi-layer encoder stacking: stacking multiple Transformer encoder layers, each layer contains a multi-head self-attention mechanism and a feed-forward neural network to capture different abstraction levels and spatial relationships of image features;
[0043] Global feature modeling: In the last layer of the encoder, the self-attention mechanism is used to aggregate all input features and generate the second global features;
[0044] Feature pooling: Use average pooling to reduce the feature dimension of the generated second global feature and extract the most representative features;
[0045] Feature output: Finally, the second global feature after feature pooling is used as the output of the model.
[0046] Furthermore, the fusion feature F is transformed into FF The process of processing and strengthening local features is as follows:
[0047] The Reduction module uses 1×1 convolution to reduce the number of channels of the feature image by half, while the Expansion module uses 1×1 convolution to restore the number of channels of the feature map. The residual function is used to dynamically adjust the size of the number of channels of the feature map to enhance local feature extraction. The formula is as follows:
[0048] Y=α x·F FF +α res ·H ex (H re (X)
[0049] Among them, α res is the scaling factor coefficient of dimensionality reduction, α x is the scaling factor coefficient of the expansion dimension, α res >α x >0, and α res +α x =1,H re (·) and H ex (·) is the dimension reduction and dimension expansion operation, F FF is the input of the residual function, and Y is the output of the residual function.
[0050] Furthermore, in step S5, the process of converting the depth of the third image into the number of channels of the target image using a 1×1 convolutional layer is as follows:
[0051] Conversion convolution layer: Use a 1x1 convolution layer to convert the depth of the third image into the number of channels of the target image. The number of channels of the 1x1 convolution layer is set to the number of channels of the target image, that is, 3.
[0052] Input-output relationship setting: The size of the third image is HxWxD, where H and W represent the height and width of the third image respectively, and D represents the depth of the third image. The size of the target image is also HxWx3, where 3 represents the number of channels of the target image.
[0053] Convolution: In the 1x1 convolution layer, the size of the convolution kernel is 1x1xD, where D is the depth of the third image, and the number of channels of the convolution kernel is set to the number of channels of the target image, that is, 3. In the convolution operation, each channel of the third image of each convolution kernel is multiplied by the weight, and the results of all channels are summed to generate a pixel value of the target image;
[0054] Result output: After processing by the 1x1 convolution layer, the size of the output feature image is still HxWx3, which is the same size as the target image;
[0055] The process of processing the output target image and generating the repaired image is as follows:
[0056] Apply the ReLU activation function to adjust the range of the output value and map the output value to the range of [0,1], or when the pixel value range of the target image is [0,255], multiply the output value by 255 to scale it to the correct range. The mapping process is as follows:
[0057] The ReLU activation function is a nonlinear activation function in deep learning neural networks. Its mathematical expression is as follows:
[0058] f(x)=max(0,x)
[0059] Where x is the input value and f(x) is the output value. The ReLU function outputs x when x>0 and outputs 0 when x<0. It sets negative values to 0 and keeps positive values unchanged.
[0060] When the size of the output target image does not match the size of the restored image, downsampling or upsampling is performed, wherein the downsampling or upsampling process is as follows:
[0061] When the output target image size is large, methods such as pooling can be used to reduce the size of the target image to match the target image size;
[0062] When the output target image size is small, the size of the target image can be increased by using methods such as interpolation to match the size of the restored image.
[0063] Further, in step S5-3, each channel of each convolution kernel third image is multiplied by the weight, and the results of all channels are summed to generate a pixel value of the target image in the following process:
[0064] Input: Assume there is a feature map with a depth of D, that is, the number of channels is D, and each channel has a matrix composed of corresponding eigenvalues;
[0065] Convolution kernel weight: The weight matrix of a 1x1 convolution kernel is 1x1xD, that is, there is a weight value on each channel;
[0066] Convolution operation: For each pixel position (i, j) of the target image, the convolution kernel will slide at the corresponding position (i, j) of the feature map, multiply each channel of the feature map element by element, and add the results of each channel to obtain a pixel value of the target image. The formula is as follows:
[0067]
[0068] Among them, C(i,j) is the pixel value of the target image, W_k is the weight of the convolution kernel on the kth channel, and F(i,j,k) is the feature value of the feature map on the kth channel at position (i,j).
[0069] A thangka image restoration system based on multi-level adaptive CNN and hybrid Transformer, including:
[0070] An image acquisition module is used to acquire an image of the thangka to be restored, and scale the image of the thangka to be restored, and adjust the size of the image to a uniform size of 224*224 to obtain a first image;
[0071] A feature extraction module, configured to extract local features of the first image through a multi-stage adaptive CNN, and send the local features to a hybrid Transformer module, extract first global features of the first image through the hybrid Transformer module and output a feature map, and then perform threshold segmentation on the output feature map to determine a missing area in the image;
[0072] An image processing module, configured to filter the missing area using a bilateral filter, count the frequency of pixel points at each level in 256 levels to form a histogram, perform data processing on the histogram, generate a second image, perform global feature modeling on the second image using a hybrid Transformer model, and output a second global feature;
[0073] A fusion module, used for fusing the second global features outputted by the SFB module to generate a fused feature, and processing the fused feature by a Reduction module and an Expansion module to generate a third image;
[0074] The restoration module is used to convert the depth of the third image into the number of channels of the target image by using a 1x1 convolution layer, output the target image, and process the output target image to generate a restored image.
[0075] A storage medium includes a computer program for storing the computer program, wherein when the computer program is executed by a processor, a thangka image restoration method based on a multi-level adaptive CNN and a hybrid Transformer as described in any one of the above items is implemented.
[0076] Compared with the prior art, the present invention has the following beneficial effects:
[0077] The present invention collects an image of a thangka to be repaired, extracts local features of a first image through a multi-level adaptive CNN, extracts a first global feature of the first image through a hybrid Transformer module and outputs a feature map, then uses a threshold segmentation method to segment the output feature map, determines a missing area in the image, performs histogram processing on the image, generates a second image, performs global feature modeling on the second image through a hybrid Transformer model, outputs a second global feature, fuses the output second global feature through an SFB module to generate a fused feature, processes the fused feature through a Reduction module and an Expansion module to generate a third image, converts the depth of the third image into the number of channels of a target image through a 1x1 convolution layer, outputs the target image, processes the output target image, and generates a repaired image. Therefore, the hybrid Transformer can better capture the global contextual information, avoid the problem of missing images when fusing features, and ensure the integrity of image restoration. The combination of multi-level adaptive CNN and hybrid Transformer can not only extract local features of the image, but also extract global features of the image, and then process complex image restoration, effectively restore the painting details on the thangka, so that the restored image is more accurate and natural. BRIEF DESCRIPTION OF THE DRAWINGS
[0078] Figure 1 It is a schematic diagram of the overall method flow of the present invention;
[0079] Figure 2 This is a block diagram of the module composition of the present invention. DETAILED DESCRIPTION
[0080] In order to make the objectives, technical solutions and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with specific embodiments.
[0081] It should be noted that, unless otherwise defined, the technical terms or scientific terms used in the present invention should be understood by people with ordinary skills in the field to which the present invention belongs. The words "first", "second" and similar words used in the present invention do not indicate any order, quantity or importance, but are only used to distinguish different components. "Include" or "comprise" and similar words mean that the elements or objects appearing before the word include the elements or objects listed after the word and their equivalents, without excluding other elements or objects. "Connect" or "connected" and similar words are not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. "Up", "down", "left", "right" and the like are only used to indicate relative positional relationships. When the absolute position of the described object changes, the relative positional relationship may also change accordingly.
[0082] Example:
[0083] See also Figure 1 to Figure 2 , the present invention provides a technical solution:
[0084] A thangka image restoration method based on multi-level adaptive CNN and hybrid Transformer, such as Figure 1 As shown, the specific steps include:
[0085] S1. Collecting an image of the thangka to be repaired, scaling the image of the thangka to be repaired, and adjusting the image size to a uniform size of 224*224 to obtain a first image;
[0086] S2. extracting local features of the first image through a multi-level adaptive CNN, extracting first global features of the first image through a hybrid Transformer module and outputting a feature map, and then applying threshold segmentation to the output feature map to determine the missing area in the image;
[0087] S3. Filter the missing area using a bilateral filter, count the frequency of pixels in each of the 256 levels to form a histogram, perform data processing on the histogram to generate a second image, perform global feature modeling on the second image through a hybrid Transformer model, and output a second global feature;
[0088] S4. Fusing the outputted second global features through the SFB module to generate fused features, and processing the fused features through the Reduction module and the Expansion module to generate a third image;
[0089] S5. Use a 1x1 convolution layer to convert the depth of the third image into the number of channels of the target image, output the target image, and process the output target image to generate a restored image.
[0090] In this embodiment, CNN is a deep learning model specifically designed for processing gridded data such as images and videos. It uses convolutional layers to effectively capture local patterns and features in input data, and is used in the fields of image classification, object detection, and image segmentation; Hybrid Transformer is a model that combines the Transformer architecture with other deep learning network architectures. The Transformer architecture was originally used in the field of natural language processing, but was subsequently proven to be effective in other fields such as image processing and video processing.
[0091] In this embodiment, in step S1, adjusting the size of the leaf image to 224*224 means adjusting the width and height of the image to the same fixed size, i.e., 224 pixels. Adjusting the images to the same size can ensure that each image has the same size when the method is used for inference recognition, thereby simplifying the inference process. Image resizing may introduce certain distortion or information loss. Adjusting the image to the common size of 224*224 can avoid excessive distortion and retain important features in the image. The coordinates of the pixel points of the image after the image is scaled are marked, with the bottom pixel row being the first row and the leftmost pixel column being the first column.
[0092] Based on the above embodiment, in step S2, the process of extracting local features of the first image through the CNN module is as follows:
[0093] S2-1. The first image is subjected to a small-kernel convolution layer to extract local features, where the local features include edge features and texture features. The formula used by the small-kernel convolution layer is as follows:
[0094] F jb =H conv (BT)+H conv (WT)
[0095] Among them, Fj b is the local feature, H conv (·) is a 3×3 convolutional layer, BT is the edge feature, and WT is the texture feature;
[0096] S2-2. After extracting the local features, the local features Fj b Pass it to the CNN module to obtain higher-level features, where the CNN module is composed of MARFB modules (multi-level adaptive residual feature blocks) and the hybrid Transformer module is composed of HT modules (hybrid attention mechanism model);
[0097] S2-3. In the MARFB module, the local feature Fj b During processing, assuming that the number of MARFB modules is M, the output of the mth (1≤m≤M) MARFB module can be expressed as follows:
[0098]
[0099] in, is the mth MARFB module, and Fm is the output of the mth MARFB module;
[0100] S2-4. The output of the MARFB module is merged and sent to the hybrid Transformer to extract the first global feature, which includes shape features and structural features. Assuming that the number of HT modules is N, the output of the nth (1≤n≤N) HT module can be expressed as follows:
[0101]
[0102] in, is the nth HT module, Fn is the first global feature output by the nth HT module, and || is the concatenation of m MARFB modules.
[0103] On the basis of the above embodiment, the SFB module (spatial frequency domain block) is introduced to convert the output local feature Fj b and the first global feature F n Fusion, enhance texture features, edge features, shape features and structural features, output fusion feature F FF , the formula is as follows:
[0104] F FF =H SFB (F qt ||F n )
[0105] Among them, H SFB (·) is the SFB module, F FF For fusion features.
[0106] Based on the above embodiment, in step S2, the output feature map is segmented by using a threshold value, and the process of determining the missing area in the image is as follows:
[0107] Traverse all possible thresholds, divide the feature map into missing areas and intact areas according to the value of each threshold, count the number of pixels in the missing area and the intact area, and calculate the mean of the grayscale value of the pixels in the missing area and the intact area. Calculate the inter-class variance of the corresponding threshold according to the following formula:
[0108] σ(t) 2 =W B (t)*W F (t)*(μ B (t)-μ F (t)) 2
[0109] Among them, σ(t) 2 represents the inter-class variance when the threshold is t, t∈[0, 255], and t∈N + , w B (t), W F(t) are the number of pixels in the missing part and the intact part when the threshold is t, μ B (t), μ F (t) are the mean gray values of the pixels in the missing area and intact area when the threshold is t;
[0110] Calculate the threshold value when the inter-class variance reaches the maximum, and define this value as the optimal separation threshold. When segmenting into missing areas and intact areas, if the grayscale value of the pixel is less than or equal to t, the pixel is judged to belong to the intact area; if it is greater than t, the pixel is judged to belong to the missing area.
[0111] In this embodiment, in step S3, the bilateral filter not only considers the spatial distance relationship between pixel points, but also the similarity of pixel values between pixel points when reducing noise. By combining these two together, the feature map processed by bilateral filtering and denoising can maintain the general block division of the original image and thus maintain the edge. Therefore, the bilateral filter can not only reduce noise but also keep the blurred feature map edges clear and smooth when filtering and denoising.
[0112] On the basis of the above embodiment, in step S3, the missing area of the feature map is filtered using a bilateral filter, the frequency of the pixel points of each level in the 256 levels is counted to form a histogram, and the histogram is processed to generate the second image as follows:
[0113] S3-1. Calculate histogram: calculate the grayscale histogram of each color channel respectively;
[0114] S3-2. Calculate the cumulative distribution function CDF: normalize the grayscale histogram of each color channel to obtain the cumulative distribution function CDF;
[0115] S3-3. Mapping original pixel values: Use the CDF of each color channel to independently map each pixel value of the original image; for each pixel value [p], map it to a new pixel value [p′] according to the following formula:
[0116] [p′=round(CDF(p)×(L-1))]
[0117] Where [L] is the total number of gray levels, usually 256, p is the original pixel value, and p′ is the new pixel value;
[0118] S3-4. Create a new image: Generate a second image according to the new pixel values of each channel, the pixel values of the second image range from 0 to [L-1], where [L] is the total number of gray levels;
[0119] S3-5. Application results: Finally, the obtained second image is used as the image processed by histogram equalization.
[0120] Based on the above embodiment, in step S3, the process of performing global feature modeling on the second image by using the hybrid Transformer model is as follows:
[0121] S3-6. Feature extraction: First, extract the second global feature from the second image, which can be achieved by a pre-trained hybrid Transformer model that accepts the second image as input and outputs a high-level semantic feature representation of the image;
[0122] S3-7. Transformer encoder: Use the Transformer encoder to encode the features of the second image. The Transformer encoder maps the input feature sequence to a set of query vectors, key vectors, and value vectors, and uses the self-attention mechanism to model the dependencies between the input feature sequences.
[0123] S3-8. Multi-layer encoder stacking: Multiple Transformer encoder layers are stacked to increase the depth and representation capability of the model. Each layer contains a multi-head self-attention mechanism and a feed-forward neural network to capture different abstraction levels and spatial relationships of image features.
[0124] S3-9. Global feature modeling: In the last layer of the encoder, the self-attention mechanism is used to aggregate all input features and generate a global feature representation. This second global feature representation can capture the overall structure, content, and semantic information in the image.
[0125] S3-10. Feature pooling: For the generated second global feature representation, average pooling or maximum pooling can be used to reduce the feature dimension and extract the most representative features;
[0126] S3-11. Feature output: Finally, the second global feature after feature pooling is used as the output of the model.
[0127] In this embodiment, the RU (Residual Unit) includes two parts: Reduction and Expansion.
[0128] Based on the above embodiment, the fusion feature F is fused by using the Reduction module and the Expansion module. FF The process of processing to enhance local features is as follows:
[0129] The Reduction module uses 1×1 convolution to reduce the number of channels of the feature image by half, while the Expansion module uses 1×1 convolution to restore the number of channels of the feature map. The residual function is used to dynamically adjust the size of the number of channels of the feature map to enhance local feature extraction. The formula is as follows:
[0130] Y=α x ·F FF +α res ·H ex (H re (X)
[0131] Among them, α res is the scaling factor coefficient of dimensionality reduction, α x is the scaling factor coefficient of dimensionality expansion, because the dimensionality reduction part usually leads to information loss. By reducing the number of channels, the model will discard some features. In order to minimize the loss of information, the scaling factor coefficient of dimensionality reduction may be set larger to retain as much useful information as possible. Therefore, α res >α x >0, and α res +α x =1,H re (·) and H ex (·) is the dimension reduction and dimension expansion operation, F FF is the input of the residual function, and Y is the output of the residual function.
[0132] Based on the above embodiment, in step S5, the process of converting the depth of the third image into the number of channels of the target image using a 1×1 convolution layer is as follows:
[0133] S5-1. Conversion convolution layer: Use a 1x1 convolution layer to convert the depth of the third image into the number of channels of the target image. The number of channels of the 1x1 convolution layer is set to the number of channels of the target image, that is, 3;
[0134] S5-2. Input-output relationship setting: The size of the third image is HxWxD, where H and W represent the height and width of the third image, respectively, and D represents the depth of the third image. The size of the target image is also HxWx3, where 3 represents the number of channels of the target image.
[0135] S5-3. Convolution: In the 1x1 convolution layer, the size of the convolution kernel is 1x1xD, where D is the depth of the third image, and the number of channels of the convolution kernel is set to the number of channels of the target image, that is, 3. In the convolution operation, each channel of the third image of each convolution kernel is multiplied by the weight, and the results of all channels are summed to generate a pixel value of the target image;
[0136] S5-4. Result output: After being processed by the 1x1 convolution layer, the size of the output feature image is still HxWx3, which is the same size as the target image.
[0137] On the basis of the above embodiment, in step S5, the output target image is analyzed and processed to generate a restored image as follows:
[0138] S5-5. Apply the ReLU activation function to adjust the range of the output value and map the output value to the range of [0,1], or when the pixel value range of the target image is [0,255], multiply the output value by 255 to scale it to the correct range. The mapping process is as follows:
[0139] The ReLU activation function is a nonlinear activation function in deep learning neural networks. Its mathematical expression is as follows:
[0140] f(x)=max(0,x)
[0141] Where x is the input value and f(x) is the output value. The ReLU function outputs x when x>0 and outputs 0 when x<0. It sets negative values to 0 and keeps positive values unchanged.
[0142] S5-6. When the size of the output target image does not match the size of the restored image, downsampling or upsampling is performed, wherein the downsampling or upsampling process is as follows:
[0143] When the output target image size is large, methods such as pooling can be used to reduce the size of the target image to match the target image size;
[0144] When the output target image size is small, the size of the target image can be increased by using methods such as interpolation to match the size of the restored image.
[0145] Based on the above embodiment, in step S5-3, each channel of each convolution kernel third image is multiplied by the weight, and the results of all channels are summed to generate a pixel value of the target image as follows:
[0146] S5-3-1. Input: Assume there is a feature map with a depth of D (the number of channels is D), and each channel has a matrix composed of corresponding eigenvalues;
[0147] S5-3-2. Convolution kernel weight: The weight matrix of a 1x1 convolution kernel is (1x1xD), that is, each channel has a weight value;
[0148] S5-3-3. Convolution operation: For each pixel position (i, j) of the target image, the convolution kernel will slide at the corresponding position (i, j) of the feature map, multiply each channel of the feature map element by element, and add the results of each channel to obtain a pixel value of the target image. The formula is as follows:
[0149]
[0150] Among them, C(i,j) is the pixel value of the target image, W_k is the weight of the convolution kernel on the kth channel, and F(i,j,k) is the feature value of the feature map on the kth channel at position (i,j).
[0151] α in the formula res and α x The specific value of is generally determined by those skilled in the art according to actual conditions. The essence of this formula is a comprehensive analysis by weighted summation. The technicians in this field collect multiple groups of sample data, set corresponding preset proportional coefficients for each group of sample data, substitute the preset proportional coefficients and the collected sample data into the formula, observe the accuracy of the model output and the rationality of the results through repeated experiments and parameter adjustments, gradually adjust these factor coefficients, and compare the performance and effect of the model under different parameter settings to find the optimal coefficient combination. The calculated factor coefficients are screened and averaged to obtain α res and α x The value of .
[0152] In addition, the size of the preset factor coefficient is to quantify each parameter to obtain a specific value. In order to facilitate subsequent comparison, the size of the coefficient depends on the amount of sample data and the preset proportional coefficient initially set by technical personnel in this field for each set of sample data. It is not unique as long as it does not affect the proportional relationship between the parameter and the quantized value.
[0153] The above formulas are all dimensionless and numerical calculations. The formula is a formula for the most recent real situation obtained by collecting a large amount of data and performing software simulation. The preset parameters in the formula are set by technicians in this field according to actual conditions.
[0154] A thangka image restoration system based on multi-level adaptive CNN and hybrid Transformer, such as Figure 2 As shown, including:
[0155] An image acquisition module is used to acquire an image of the thangka to be restored, and scale the image of the thangka to be restored, and adjust the size of the image to a uniform size of 224*224 to obtain a first image;
[0156] A feature extraction module, configured to extract local features of the first image through a multi-stage adaptive CNN, and send the local features to a hybrid Transformer module, extract first global features of the first image through the hybrid Transformer module and output a feature map, and then perform threshold segmentation on the output feature map to determine a missing area in the image;
[0157] An image processing module, used to filter the missing area using a bilateral filter, count the frequency of pixel points in each level of 256 levels to form a histogram, perform data processing on the histogram, generate a second image, perform global feature modeling on the second image through a hybrid Transformer model, and output a second global feature;
[0158] A fusion module, used for fusing the second global features outputted by the SFB module to generate a fused feature, and processing the fused feature by a Reduction module and an Expansion module to generate a third image;
[0159] The restoration module is used to convert the depth of the third image into the number of channels of the target image by using a 1x1 convolution layer, output the target image, and process the output target image to generate a restored image.
[0160] A storage medium includes a computer program for storing the computer program, wherein when the computer program is executed by a processor, a thangka image restoration method based on a multi-level adaptive CNN and a hybrid Transformer as described in any one of the above items is implemented.
[0161] The above formulas are all dimensionless and numerical calculations. The formula is a formula for the most recent real situation obtained by collecting a large amount of data and performing software simulation. The preset parameters in the formula are set by technicians in this field according to actual conditions.
[0162] The above embodiments may be implemented in whole or in part by software, hardware, firmware or any other combination thereof. When implemented using software, the above embodiments may be implemented in whole or in part in the form of a computer program product. Those skilled in the art may appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein may be implemented by electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed by hardware or software methods depends on the specific application and design constraints of the technical solution.
[0163] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, and may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0164] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be covered by the protection scope of the present application.
Claims
1. A thangka image restoration method based on multi-level adaptive CNN and hybrid Transformer, characterized in that: The specific steps include: S1. Collecting an image of the thangka to be repaired, scaling the image of the thangka to be repaired, and adjusting the image size to a uniform size of 224*224 to obtain a first image; S2. extract local features of the first image through a multi-level adaptive CNN module, and send the local features to a hybrid Transformer module, extract first global features of the first image through the hybrid Transformer module and output a feature map, and then use threshold segmentation on the output feature map to determine the missing area in the image; S3. Filter the missing area using a bilateral filter, count the frequency of pixels in each of the 256 levels to form a histogram, perform data processing on the histogram to generate a second image, perform global feature modeling on the second image through a hybrid Transformer model, and output a second global feature; S4. Fusing the output second global features through the spatial frequency domain block module to generate fused features, and processing the fused features through the dimensionality reduction module and the dimensionality expansion module to generate a third image; S5. using a 1x1 convolution layer to convert the depth of the third image into the number of channels of the target image, and outputting the target image, processing the output target image, and generating a restored image; In step S2, the process of extracting local features of the first image through the CNN module is as follows: The first image is subjected to a small-kernel convolution layer to extract local features, wherein the local features include edge features and texture features. The formula used by the small-kernel convolution layer is as follows: F jb =H conv (BT)+H conv (WT) Among them, F jb is the local feature, H conv (·) is a 3×3 convolutional layer, BT is the edge feature, and WT is the texture feature; After extracting the local features, the local features F jb Passed to the CNN module; In the multi-level adaptive residual feature block module, the local feature F jb During processing, assuming that the number of multi-level adaptive residual feature block modules is M, the output of the m-th multi-level adaptive residual feature block module can be expressed as follows: in, is the mth multi-level adaptive residual feature block module, F m is the output of the m-th multi-level adaptive residual feature block module; The outputs of the multi-level adaptive residual feature block modules are merged and sent to the hybrid Transformer to extract the first global feature, which includes shape features and structural features. Assuming that the number of hybrid attention mechanism modules is N, the output of the nth hybrid attention mechanism module can be expressed as follows: in, is the nth hybrid attention mechanism module, F n is the first global feature output by the nth hybrid attention mechanism module, || is the concatenation of m multi-level adaptive residual feature block modules; In step S3, the process of global feature modeling of the second image by the hybrid Transformer model is as follows: Feature extraction: First, extract the second global features from the second image, which is achieved by a pre-trained hybrid Transformer model that accepts the second image as input and outputs a high-level semantic feature representation of the image; Transformer encoder: Use the Transformer encoder to encode the features of the second image. The Transformer encoder maps the input feature sequence to a set of query vectors, key vectors, and value vectors, and uses the self-attention mechanism to model the dependencies between the input feature sequences. Multi-layer encoder stacking: stacking multiple Transformer encoder layers, each layer contains a multi-head self-attention mechanism and a feed-forward neural network to capture different abstraction levels and spatial relationships of image features; Global feature modeling: In the last layer of the encoder, the self-attention mechanism is used to aggregate all input features and generate the second global features; Feature pooling: Use average pooling to reduce the feature dimension of the generated second global feature and extract the most representative features; Feature output: Finally, the second global feature after feature pooling is used as the output of the model; Through the dimension reduction module and the dimension expansion module, the fusion feature F FF The process of processing and strengthening local features is as follows: The dimensionality reduction module uses 1×1 convolution to reduce the number of channels of the feature image by half, while the dimensionality expansion module uses 1×1 convolution to restore the number of channels of the feature map. The residual function is used to dynamically adjust the size of the number of channels of the feature map to enhance local feature extraction. The formula is as follows: Y=a x ·F FF +a res ·H ex (H re (X)) Among them, α res is the scaling factor coefficient of dimensionality reduction, α x is the scaling factor coefficient of the expansion dimension, α res >α x >0, and α res +α x =1,H re (·) and H ex (·) is the dimension reduction and dimension expansion operation, F FF is the input of the residual function, and Y is the output of the residual function.
2. According to claim 1, a thangka image restoration method based on multi-level adaptive CNN and hybrid Transformer is characterized in that: In step S2, the output feature map is segmented by threshold, and the process of determining the damaged area in the image is as follows: Traverse all possible thresholds, divide the feature map into missing parts and intact parts according to the value of each threshold, count the number of pixels in the missing area and the intact area, and calculate the mean of the grayscale values of the pixels in the missing area and the intact area. Calculate the inter-class variance of the corresponding threshold according to the following formula: σ(t) 2 = B (t)* F (t)*μ B (t)- F (t)) 2 Among them, σ(t) 2 represents the inter-class variance when the threshold is t, t∈[0, 255, and t∈N + ,w B (t), w F (t) are the number of pixels in the missing part and the intact part when the threshold is t, μ B (t), μ F (t) are the mean gray values of the pixels in the missing part and the intact part when the threshold is t; Calculate the threshold value when the inter-class variance reaches the maximum, and define this value as the optimal separation threshold. When segmenting into missing areas and intact areas, if the grayscale value of the pixel is less than or equal to t, the pixel is judged to belong to the intact area; if it is greater than t, the pixel is judged to belong to the missing area.
3. According to claim 1, a thangka image restoration method based on multi-level adaptive CNN and hybrid Transformer is characterized in that: The frequency of pixel points in each of the 256 levels is counted to form a histogram, and data processing is performed on the histogram to generate the second image as follows: Calculate histogram: calculate the grayscale histogram of each color channel separately; Calculate the cumulative distribution function CDF: Normalize the grayscale histogram of each color channel to obtain the cumulative distribution function CDF; Mapping original pixel values: Use the CDF of each color channel to independently map each pixel value of the original image; for each pixel value p, map it to a new pixel value p', according to the following formula: p′=round(CDF(p)×(L-1)) Where L is the total number of gray levels, which is 256, p is the original pixel value, and p′ is the new pixel value; Create a new image: Generate a second image based on the new pixel values of each channel, where the pixel values of the second image range from 0 to L-1, where L is the total number of gray levels; Application results: Finally, the obtained second image is used as the image processed by histogram equalization.
4. According to claim 1, a thangka image restoration method based on multi-level adaptive CNN and hybrid Transformer is characterized in that: In step S5, the process of converting the depth of the third image into the number of channels of the target image using a 1×1 convolutional layer is as follows: Conversion convolution layer: Use a 1x1 convolution layer to convert the depth of the third image into the number of channels of the target image. The number of channels of the 1x1 convolution layer is set to the number of channels of the target image, that is, 3. Input-output relationship setting: The size of the third image is HxWxD, where H and W represent the height and width of the third image respectively, and D represents the depth of the third image. The size of the target image is also HxWx3, where 3 represents the number of channels of the target image. Convolution: In the 1x1 convolution layer, the size of the convolution kernel is 1x1xD, where D is the depth of the third image, and the number of channels of the convolution kernel is set to the number of channels of the target image, that is, 3. In the convolution operation, each channel of the third image of each convolution kernel is multiplied by the weight, and the results of all channels are summed to generate a pixel value of the target image; Result output: After processing by the 1x1 convolution layer, the size of the output feature image is still HxWx3, which is the same size as the target image; The process of processing the output target image and generating the repaired image is as follows: Apply the ReLU activation function to adjust the range of the output value and map the output value to the range of [0,1], or when the pixel value range of the target image is [0,255], multiply the output value by 255 to scale it to the correct range. The mapping process is as follows: The ReLU activation function is a nonlinear activation function in deep learning neural networks. Its mathematical expression is as follows: f(x)=max(0,x) Where x is the input value and f(x) is the output value. The ReLU function outputs x when x>0 and outputs 0 when x<0. It sets negative values to 0 and keeps positive values unchanged. When the size of the output target image does not match the size of the restored image, downsampling or upsampling is performed, wherein the downsampling or upsampling process is as follows: When the output target image size is large, the pooling method is used to reduce the size of the target image to match the target image size; When the output target image size is small, an interpolation method is used to increase the size of the target image to match the size of the restored image.
5. According to claim 4, a thangka image restoration method based on multi-level adaptive CNN and hybrid Transformer is characterized in that: Each channel of each convolution kernel third image is multiplied by the weight and the results of all channels are summed to generate a pixel value of the target image as follows: Input: Assume there is a feature map with a depth of D, that is, the number of channels is D, and each channel has a matrix composed of corresponding eigenvalues; Convolution kernel weight: The weight matrix of a 1x1 convolution kernel is 1x1xD, that is, there is a weight value on each channel; Convolution operation: For each pixel position (i, j) of the target image, the convolution kernel will slide at the corresponding position (i, j) of the feature map, multiply each channel of the feature map element by element, and add the results of each channel to obtain a pixel value of the target image. The formula is as follows: Among them, C(i,j) is the pixel value of the target image, W k is the weight of the convolution kernel on the kth channel, and F(i,j,k) is the eigenvalue of the feature map at position (i,j) on the kth channel.
6. A thangka image restoration system based on multi-level adaptive CNN and hybrid Transformer, the system is used to execute a thangka image restoration method based on multi-level adaptive CNN and hybrid Transformer as described in any one of claims 1-5, characterized in that: include: An image acquisition module is used to acquire an image of the thangka to be restored, and scale the image of the thangka to be restored, and adjust the size of the image to a uniform size of 224*224 to obtain a first image; A feature extraction module, configured to extract local features of the first image through a multi-stage adaptive CNN, and send the local features to a hybrid Transformer module, extract first global features of the first image through the hybrid Transformer module and output a feature map, and then perform threshold segmentation on the output feature map to determine a missing area in the image; An image processing module, used to filter the missing area using a bilateral filter, count the frequency of pixel points in each level of 256 levels to form a histogram, perform data processing on the histogram, generate a second image, perform global feature modeling on the second image through a hybrid Transformer model, and output a second global feature; A fusion module, used for fusing the second global features outputted by the SFB module to generate a fused feature, and processing the fused feature by a Reduction module and an Expansion module to generate a third image; The restoration module is used to convert the depth of the third image into the number of channels of the target image by using a 1x1 convolution layer, output the target image, and process the output target image to generate a restored image.
7. A storage medium, characterized in that: It includes a computer program for storing, and when the computer program is executed by a processor, it implements a thangka image restoration method based on multi-level adaptive CNN and hybrid Transformer as described in any one of claims 1-5.
