# A Method for Detection of Rare Industrial Fake Film Based on Deep Learning

Authors: Wuqi Gao; Chao Li; Ting Yang; Liangliang Li; Xiaoyan Li
Journal: Security and Communication Networks
 (2022)

---

## Abstract

In order to solve the industrial fake film problem produced by repeated imaging in the field of nondestructive testing, this paper proposes an image similarity comparison algorithm of X-ray film based on the Siamese neural network. Firstly, in order to accurately locate and detect weld areas from high-resolution X-ray film, a robust location and detection algorithm based on the Gaussian function is proposed. Next, in order to solve the problem that the deep learning model system extracts features according to squares by default, which results in the disappearance of film features with high horizontal and vertical features, effective weld regions are used and processed in blocks. Then, a small sample data set for weld similarity discrimination is established by using each block region, and an industrial fake film discrimination model based on twin neural networks is constructed. Finally, the corresponding weights are set for different fake feature information areas, and a similarity comparison system for industrial fake film detection is proposed. The experiment shows that the method in this paper can not only accurately locate the weld area but also accurately detect the fake film in the industry, avoiding the influence of the geometric transformation of the image and the insufficient number of data sets in the process of similarity comparison, and has a good detection effect.


---

## Body

## 1. Introduction

With the rapid development of welding technology, the quality of welding has become an important issue in evaluating welding safety in the manufacturing industry. Due to the complex welding process and the large gap between the welds, the welding quality is easily affected by the welding process and environmental changes, resulting in welding defects. Therefore, it is necessary to evaluate and monitor the welding quality. Common nondestructive testing methods for welds include ultrasonic testing [1], radiographic testing [2], and eddy current testing [3], of which radiographic testing is more widely used in the industry [4]. Industrial negative images carry weld information. In industrial practice, in addition to detecting weld defects, it is often necessary to compare the similarity between negative images. If the similarity is too high, it means that industrial fake films will be produced and the weld will be missed and not evaluated, resulting in huge economic losses [5].The essence of the fake film detection problem in the industry is the image similarity comparison of the welds in the two negatives. At present, the human eye is generally used in the industry to identify fake films, which has problems such as heavy workload, cumbersome, and low accuracy. The image-based industrial fake film detection method mainly includes two steps: weld area extraction and image similarity comparison. Since the radiograph image contains the weld area and other areas, most of the image features are located in the weld area. Therefore , the weld area is the extracted region of interest to avoid the interference of the weld edge and improve the detection efficiency [6].As a key step in the overall process, the extraction of the weld region has attracted the research of many scholars, mainly using the threshold segmentation method [7], edge detection method, and morphological processing [8]. The above algorithms have good extraction results under certain conditions, but their adaptability is poor, and it is difficult to meet the needs of subsequent image similarity comparison processing.Common image similarity comparison algorithms mainly include histogram [9], image template matching [10], PSNR peak signal-to-noise ratio [11], SSIM structural similarity [12], perceptual hash algorithm [13], etc., which have problems of poor robustness and low accuracy. In recent years, a large number of scholars at home and abroad have studied and improved the similarity between images, and the main research direction is the traditional algorithm for the calculation of image similarity. Yang Zhan [14] proposed a new simple and effective hashing method, Scalable Deep Asymmetric Hashing (SDAH), which flexibly performs asymmetric similarity calculation by using real-value embedding of two unequal dimensions, namely, the real-value embedding of the image and label. AlZahir [15] proposed a blind image forgery detection method using the guided pyramid decomposition technique and the ensemble, which can be applied to a variety of image forgeries with similar results. Zhenjun [16] et al. proposed an objective measure based on the previously calculated correlation coefficient to calculate the ratio between the minimum and maximum correlation coefficient and defined it as a perceived similarity. Generally speaking, the above method may have a better effect in the similarity comparison between exactly the same images. However, in the similarity comparison between the images after geometric transformation, there will be a problem of high misjudgment rate. How to enhance the adaptability and accuracy in the comparison between images is still a difficult problem.In order to avoid the influence of geometric transformation and other external interference on the image similarity comparison, some scholars have carried out research on the image regional division and contrast and added the image preprocessing work. Caixia and Jiaxin [17] proposed a fusion method based on the regional similarity of wavelet coefficients. By decomposing the mean value, variance, and covariance of the coefficients to define the regional similarity, the matching degree and the adding coefficient can be obtained and then the fusion calculation of the high-frequency subimages can be completed. Xu and Zhang [18] combined image self-similarity with the EPLL (expected patch log-likelihood) method and proposed an EPLL denoting model based on internal and external image similarity to improve the preservation of image details.The above algorithms all use traditional algorithms for image similarity comparison, whether it is directly comparing the overall characteristics of the image to propose an objective metric or conducting a comparative study after regional division. They do not consider the specific influence of the geometric transformation between the images on the comparison of image similarity [19]. However, for the X-ray film with a large length-to-width ratio studied in this paper, direct image comparison will result in too many invalid features and excessive interference factors, which will cause problems such as low accuracy and excessive time overhead.Deep learning has the advantages of strong learning ability, wide coverage, and good adaptability for the similarity comparison between images, which can meet the similarity comparison in the presence of geometric transformations and even small-scale interference factors [20]. However, deep learning is often complicated in computation, and it needs neural network to extract features when making similarity comparisons. And if two neural networks are used to extract features from images, respectively, the extracted features may not be in the same domain. Moreover, deep learning requires a large number of data sets for support, and the number of data sets affects the accuracy of the model to some extent. The high-resolution radiograph film, which is relatively scarce in the industry, has difficulty in meeting the needs of the actual number of training data sets [21].In view of the shortcomings of the algorithms, this paper proposes a detection method based on rare high-resolution X-ray images of an industrial fake film processing algorithm. Through the accurate positioning of the X-ray image in the effective area and block processing, the paper builds a small sample data set based on the similarity criterion of weld and optimizes the data set. Using twin network processing characteristics, the paper forms the comparison between regions and establishes a set of complete contrast systems and discrimination criteria and realizes the accurate detection of industrial fake film. In particular, the accuracy and efficiency of this paper have greatly improved.


## 2. Materials and Methods

### 2.1. Algorithm Principle

The industrial radiographic fake film identification method constructed in this paper needs to input two X-ray images, which are the reference film and the to-be-discriminated film; that is, the reference film is used to detect whether the to-be-discriminated film is a fake film. It is worth noting that industrial X-ray images belong to high-resolution images. In this paper, the ray film with large horizontal and vertical ratio is divided into blocks to improve the efficiency of the algorithm. Figure1 shows the processing flow chart of the fake film identification algorithm constructed in this paper.Figure 1
Algorithm flow chart.Its algorithmic process mainly includes three parts:(1)
Weld area position: Gaussian function is used to extract the effective area of the weld, and five regions of interest containing the center point and the center point of the weld are extracted as the input for similarity judgment.(2)
Similarity comparison: the extracted weld area has been processed by pseudo-color and sent to the twin network for similarity discrimination to obtain the quantitative value of similarity.(3)
Fake film identification: The similarity evaluation system is established, and custom weight calculation is carried out. If the similarity calculation result is greater than the set threshold, it is determined as a fake.


### 2.2. Weld Positioning

This paper designs a Gaussian difference region segmentation method to preextract the weld area, which converts the traditional weld threshold segmentation problem into a statistical analysis problem of image information. The industrial radiographic film with a large length-to-width ratio is divided into several square images with the width of the film as the side length, from which the short length is extracted with the remaining length, as shown in Figure2.Figure 2
Schematic diagram of segmentation. (a–e) The block extraction areas of an X-ray film.
(a)(b)(c)(d)(e)The specific steps are as follows.


#### 2.2.1. Regional Block Extraction

The regional block extraction rule designed in this paper is shown in Figure3. Figure 3 shows the divided square area. The square area is divided into 16 equal blocks, and the parts 6, 7, and 10 are defined as HROI, while the rest are eliminated.Figure 3
Regional block diagram.


#### 2.2.2. The Gaussian Function Locates the Weld Area

The Gaussian function is used to process the lateral statistical results of the extracted region, and the effective weld area can be obtained through mathematical analysis of the statistical results, as shown in the following formulas:(1)Hgx,y=Gδx,y×HROI,where Gδx,y represents a Gaussian function, and this paper sets δ=5.(2)Gδx,y=12πδ2exp−x2+y22δ2.The negative image extracted by the blocks in Figure2 is processed using the blocking rules in Figure 3, and the Gaussian function is used to count the positioning weld area. Figure 4 is a visual display of statistical positioning output, in which the blue line represents the Gaussian statistical results.Figure 4
Statistical positioning of welding seam output rendering. (a–e) The local images extracted from the block area in Figure2 according to Figure 3, and the result of the statistical output of the welding seam.
(a)(b)(c)(d)(e)Looking for the coordinates of the intersection of the Gaussian curve and the horizontal axis, where the left coordinate is the longitudinal coordinate of the upper coordinate of the weld in the local area and the right coordinate is the longitudinal coordinate of the lower coordinate, further processing can accurately locate the effective long weld area; Figure5 shows the intuitive visual output effect diagram of coordinate positioning, in which the green dots represent the local wave crests and the blue cross lines represent the weld positioning coordinates.Figure 5
Weld positioning output rendering. (a–e) The intuitive output diagrams of the statistical location of the weld in Figure4, where “×” represents the boundary point of the local weld area and “·” represents the local extrema of the statistical output curve.
(a)(b)(c)(d)(e)


### 2.3. Siamese Neural Network Model Construction

The Siamese neural network contains two subnetworks, each of which receives an input, maps it to a high-dimensional feature space, and outputs the corresponding representation. By calculating the distance between two representations, such as the Euclidean distance, the user can compare the similarity of the two inputs [22–24]. The main architecture of the twin neural network constructed in this paper is shown in Figure 6.Figure 6
The basic framework of the Siamese neural network.LetX1and X2 be the inputs of a Siamese neural network, and the output Y is the binary label of whether X1 and X2 match with Y∈0,1. If X1 and X2 are similar, Y=0. And if they are not, Y=1. The cost function adopted is in the following form:(3)Lw,y,x1,x2=121−yDw2+12ymax0,m−Dw2,where Dw is the Euclidean distance between two characteristic vectors transmitted by the Siamese neural network and DwX1,X2=GwX1−GwX2. Gw says the Siamese neural network will enter X1 and X2 mapped to their characteristic vector. The m value is used to define a boundary on Gw, made only from within the scope of the negative samples having impact on the loss function. For all the training samples, the overall loss function is(4)Lw=1N∑i=1NLw,y,x1,x2i.This paper uses the neural network structure as a simple VGG network [25], with 105 ∗ 105 as input; the backbone network mainly includes five convolution layers, as shown in Table 1.Table 1
The backbone of model parameter table in this paper.
Conv2DKernel sizeMaxPooling2DOutput channelConv13 × 3 × 22 × 2 × 164Conv23 × 3 × 22 × 2 × 1128Conv33 × 3 × 32 × 2 × 1256Conv43 × 3 × 22 × 2 × 1512Conv53 × 3 × 22 × 2 × 1512


### 2.4. Construction of Fake Film Evaluation Function

The obtained similarity probability value is weighted with the weights defined in this article one by one, and the real similarity evaluation value is output. If it is greater than the similarity evaluation threshold, it is determined as a fake film.After a large number of experiments and data analysis, the five regions of interest extracted from the welding seam of the reference film and the to-be-discriminated film were compared in pairs. When the similarity of the region of interest in the middle part is higher, the probability of judging it as a fake film is also greater; therefore, this paper proposes to weight the similarity probability value and the custom weight value as the judgment output value. The output of the true evaluation of similarity is defined asSimA−B, and the operation expression is(5)SimA−B=∑i=15simAi−Bi·wAi−Bi.Among them,wAi−Bi is the custom weight and simAi−Bi is the similarity probability. When the output values of simA0−B0, simA1−B1, simA3−B3, and simA4−B4 are all between (0–0.05) and the output value of simA2−B2 is (0.45, 0.5), it is determined that the slice to be judged is the reference slice reversal diagram, that is, it is also determined to be similar.


## 2.1. Algorithm Principle

The industrial radiographic fake film identification method constructed in this paper needs to input two X-ray images, which are the reference film and the to-be-discriminated film; that is, the reference film is used to detect whether the to-be-discriminated film is a fake film. It is worth noting that industrial X-ray images belong to high-resolution images. In this paper, the ray film with large horizontal and vertical ratio is divided into blocks to improve the efficiency of the algorithm. Figure1 shows the processing flow chart of the fake film identification algorithm constructed in this paper.Figure 1
Algorithm flow chart.Its algorithmic process mainly includes three parts:(1)
Weld area position: Gaussian function is used to extract the effective area of the weld, and five regions of interest containing the center point and the center point of the weld are extracted as the input for similarity judgment.(2)
Similarity comparison: the extracted weld area has been processed by pseudo-color and sent to the twin network for similarity discrimination to obtain the quantitative value of similarity.(3)
Fake film identification: The similarity evaluation system is established, and custom weight calculation is carried out. If the similarity calculation result is greater than the set threshold, it is determined as a fake.


## 2.2. Weld Positioning

This paper designs a Gaussian difference region segmentation method to preextract the weld area, which converts the traditional weld threshold segmentation problem into a statistical analysis problem of image information. The industrial radiographic film with a large length-to-width ratio is divided into several square images with the width of the film as the side length, from which the short length is extracted with the remaining length, as shown in Figure2.Figure 2
Schematic diagram of segmentation. (a–e) The block extraction areas of an X-ray film.
(a)(b)(c)(d)(e)The specific steps are as follows.


### 2.2.1. Regional Block Extraction

The regional block extraction rule designed in this paper is shown in Figure3. Figure 3 shows the divided square area. The square area is divided into 16 equal blocks, and the parts 6, 7, and 10 are defined as HROI, while the rest are eliminated.Figure 3
Regional block diagram.


### 2.2.2. The Gaussian Function Locates the Weld Area

The Gaussian function is used to process the lateral statistical results of the extracted region, and the effective weld area can be obtained through mathematical analysis of the statistical results, as shown in the following formulas:(1)Hgx,y=Gδx,y×HROI,where Gδx,y represents a Gaussian function, and this paper sets δ=5.(2)Gδx,y=12πδ2exp−x2+y22δ2.The negative image extracted by the blocks in Figure2 is processed using the blocking rules in Figure 3, and the Gaussian function is used to count the positioning weld area. Figure 4 is a visual display of statistical positioning output, in which the blue line represents the Gaussian statistical results.Figure 4
Statistical positioning of welding seam output rendering. (a–e) The local images extracted from the block area in Figure2 according to Figure 3, and the result of the statistical output of the welding seam.
(a)(b)(c)(d)(e)Looking for the coordinates of the intersection of the Gaussian curve and the horizontal axis, where the left coordinate is the longitudinal coordinate of the upper coordinate of the weld in the local area and the right coordinate is the longitudinal coordinate of the lower coordinate, further processing can accurately locate the effective long weld area; Figure5 shows the intuitive visual output effect diagram of coordinate positioning, in which the green dots represent the local wave crests and the blue cross lines represent the weld positioning coordinates.Figure 5
Weld positioning output rendering. (a–e) The intuitive output diagrams of the statistical location of the weld in Figure4, where “×” represents the boundary point of the local weld area and “·” represents the local extrema of the statistical output curve.
(a)(b)(c)(d)(e)


## 2.2.1. Regional Block Extraction

The regional block extraction rule designed in this paper is shown in Figure3. Figure 3 shows the divided square area. The square area is divided into 16 equal blocks, and the parts 6, 7, and 10 are defined as HROI, while the rest are eliminated.Figure 3
Regional block diagram.


## 2.2.2. The Gaussian Function Locates the Weld Area

The Gaussian function is used to process the lateral statistical results of the extracted region, and the effective weld area can be obtained through mathematical analysis of the statistical results, as shown in the following formulas:(1)Hgx,y=Gδx,y×HROI,where Gδx,y represents a Gaussian function, and this paper sets δ=5.(2)Gδx,y=12πδ2exp−x2+y22δ2.The negative image extracted by the blocks in Figure2 is processed using the blocking rules in Figure 3, and the Gaussian function is used to count the positioning weld area. Figure 4 is a visual display of statistical positioning output, in which the blue line represents the Gaussian statistical results.Figure 4
Statistical positioning of welding seam output rendering. (a–e) The local images extracted from the block area in Figure2 according to Figure 3, and the result of the statistical output of the welding seam.
(a)(b)(c)(d)(e)Looking for the coordinates of the intersection of the Gaussian curve and the horizontal axis, where the left coordinate is the longitudinal coordinate of the upper coordinate of the weld in the local area and the right coordinate is the longitudinal coordinate of the lower coordinate, further processing can accurately locate the effective long weld area; Figure5 shows the intuitive visual output effect diagram of coordinate positioning, in which the green dots represent the local wave crests and the blue cross lines represent the weld positioning coordinates.Figure 5
Weld positioning output rendering. (a–e) The intuitive output diagrams of the statistical location of the weld in Figure4, where “×” represents the boundary point of the local weld area and “·” represents the local extrema of the statistical output curve.
(a)(b)(c)(d)(e)


## 2.3. Siamese Neural Network Model Construction

The Siamese neural network contains two subnetworks, each of which receives an input, maps it to a high-dimensional feature space, and outputs the corresponding representation. By calculating the distance between two representations, such as the Euclidean distance, the user can compare the similarity of the two inputs [22–24]. The main architecture of the twin neural network constructed in this paper is shown in Figure 6.Figure 6
The basic framework of the Siamese neural network.LetX1and X2 be the inputs of a Siamese neural network, and the output Y is the binary label of whether X1 and X2 match with Y∈0,1. If X1 and X2 are similar, Y=0. And if they are not, Y=1. The cost function adopted is in the following form:(3)Lw,y,x1,x2=121−yDw2+12ymax0,m−Dw2,where Dw is the Euclidean distance between two characteristic vectors transmitted by the Siamese neural network and DwX1,X2=GwX1−GwX2. Gw says the Siamese neural network will enter X1 and X2 mapped to their characteristic vector. The m value is used to define a boundary on Gw, made only from within the scope of the negative samples having impact on the loss function. For all the training samples, the overall loss function is(4)Lw=1N∑i=1NLw,y,x1,x2i.This paper uses the neural network structure as a simple VGG network [25], with 105 ∗ 105 as input; the backbone network mainly includes five convolution layers, as shown in Table 1.Table 1
The backbone of model parameter table in this paper.
Conv2DKernel sizeMaxPooling2DOutput channelConv13 × 3 × 22 × 2 × 164Conv23 × 3 × 22 × 2 × 1128Conv33 × 3 × 32 × 2 × 1256Conv43 × 3 × 22 × 2 × 1512Conv53 × 3 × 22 × 2 × 1512


## 2.4. Construction of Fake Film Evaluation Function

The obtained similarity probability value is weighted with the weights defined in this article one by one, and the real similarity evaluation value is output. If it is greater than the similarity evaluation threshold, it is determined as a fake film.After a large number of experiments and data analysis, the five regions of interest extracted from the welding seam of the reference film and the to-be-discriminated film were compared in pairs. When the similarity of the region of interest in the middle part is higher, the probability of judging it as a fake film is also greater; therefore, this paper proposes to weight the similarity probability value and the custom weight value as the judgment output value. The output of the true evaluation of similarity is defined asSimA−B, and the operation expression is(5)SimA−B=∑i=15simAi−Bi·wAi−Bi.Among them,wAi−Bi is the custom weight and simAi−Bi is the similarity probability. When the output values of simA0−B0, simA1−B1, simA3−B3, and simA4−B4 are all between (0–0.05) and the output value of simA2−B2 is (0.45, 0.5), it is determined that the slice to be judged is the reference slice reversal diagram, that is, it is also determined to be similar.


## 3. Results and Discussion

### 3.1. Small Sample Data Set for the Judgment of Weld Similarity

The small sample similarity evaluation data set constructed in this paper is specially designed for the discrimination of industrial X-ray fake film [26]. By extracting the local area from the real weld area, the samples extracted from the same weld were taken as a class and the data of different samples were expanded by using reverse mirroring, noise addition, filtering, etc. Finally, JET and HSV codes were uniformly used for color processing. A total of 41 types of samples were constructed in this paper, with 40 samples in each category. Figure 7 is a schematic diagram of some samples constructed in this paper.Figure 7
Part of the sample data set graph.The construction algorithms in this paper are all built on PyTorch under the Python 3.6 environment, and they are developed and tested on the Window10 operating system, Intel(R) Core(TM) CPU i7-8700HQ 3.20 GHz 8G, graphics card RTX2070 Supercomputer platform.


### 3.2. Weld Positioning Test

Aiming at 342 X-ray images generated in actual industrial occasions, this paper uses the Gaussian function method to carry out a weld area positioning test. Table2 shows the quantitative analysis of the positioning test and time cost index of this method.Table 2
Weld positioning accuracy and time cost test.
Test listTest resultsTest sample number342Correct positioning325Accuracy95.03%Positioning time test0.004 sCombining the test data in Table2, it can be seen that the number of test samples is 342 images, of which the number showing accurate positioning is 325, the accuracy rate reaches 95.03%, and the positioning time per page is about 0.004 s. It can be seen that the algorithm proposed in this paper maintains high accuracy while taking into account efficiency and has strong applicability.


### 3.3. Similarity Discriminant Test

In order to verify the effectiveness of the algorithm, first PyTorch is used to build a twin network structure and a small fake identification data set is used for training. The training set and test set are divided in a ratio of 9 : 1, and 100 epochs are trained iteratively. Secondly, two samples are randomly selected and different processing methods such as the SSIM structural similarity measurement method, the cosine similarity method, the ORB feature matching method, histogram comparison method, average hash algorithms, different hash algorithm, perceptual hash algorithm, and the algorithm proposed in this paper are used to compare the similarity of different samples, the similarity of the same sample, the average accuracy test of various similarity algorithms, and the average accuracy test of false slice discrimination. The different processing methods are left and right image processing, up and down image processing, Gaussian noise processing, contrast enhancement processing, and brightness enhancement processing. The comparison is as follows.


#### 3.3.1. The Similarity Comparison of Different Algorithms for Different Samples and Different Processing Methods

In this paper, we input any two nonfake images and use different methods to determine whether they are nonfake films. In addition, in order to verify the robustness of the algorithm, the two input images are processed with left and right mirroring, up and down flipping, Gaussian noise, and brightness and contrast adjustment. The comparison accuracy of all methods in this comparison is between [0, 1], where the number closer to 1 represents the higher degree of similarity and the closer to 0 represents the lower degree of similarity.As can be seen from Figure8, for different samples with different processing methods, there are great differences in the similarity comparison accuracy of different algorithms. For different samples, the smaller the output value indicates, the greater the difference will be, and the discrimination accuracy of ORB and SSIM methods is high. However, hash methods have poor stability. In contrast, the method constructed in this paper can better realize the detection of dissimilar samples under various conditions. By processing the samples with pseudo-color and reiterative training, it can improve a certain detection accuracy.Figure 8
The similarity comparison of nonfake films using different processing methods and different algorithms. The “Proposed” is the algorithm proposed in this paper, and “Proposed+” is the algorithm proposed in this paper that constructs the pseudo-color processing sample data set.


#### 3.3.2. The Similarity Comparison of Different Algorithms for the Same Sample and Different Processes

We input two identical samples and simulate industrial fakes by flipping up and down, mirroring left and right, adding noise, changing brightness and contrast, etc., and using multiple algorithms to test the recognition rate of industrial fakes.It can be seen from Figure9 that the same sample is processed by different methods and the larger the output result, the smaller the difference between the two images. Among them, the cosine similarity method performs better, but the ORB algorithm is quite different. The algorithm constructed in this paper can better realize the discrimination of sample differences under various conditions.Figure 9
The similarity comparison of the same sample and different processes.


#### 3.3.3. The Similarity Comparison of Different Algorithms

According to the comparative analysis in Figures8 and 9, the similarity pair ratio of the ORB feature matching algorithm is higher when different samples are input. When the same sample is input, the accuracy of the cosine similarity algorithm is higher. Through comparative analysis, it is found that the discriminant accuracy of these two algorithms for the same sample or different samples is both too high and too low at the same time, while that of other traditional algorithms is not high or low at the same time, which is inconsistent with the actual situation. According to the proposed algorithm in this paper, the similarity ratio of different processing algorithms with different samples is generally low, close to zero, and the similarity ratio of different processing algorithms with same samples is generally high, close to 1, and it has high robustness. Therefore, the proposed algorithm has more superiority and practicability compared with other similarity comparison algorithms.As can be seen from the analysis in Table3, when the number of samples is the same, there is a big difference between other algorithms and the algorithm proposed in this paper in the comprehensive similarity comparison accuracy. The algorithm proposed in this paper guarantees 1589 successful samples out of 1640 test samples, and the accuracy is as high as 96.8902%, which is about 30% higher than other algorithms.Table 3
Average test accuracy of multiple similarity algorithms.
MethodsTest sample numberJudgment correct numberEvaluation accuracy (%)SSIM164028917.621Cosine164085552.134ORB164086752.865Histogram164069835.979aHash164079548.475dHash164091255.609pHash164098059.756Proposed1640146989.573Proposed+1640158996.890


#### 3.3.4. Sample Number Test of Weld Segmentation

In order to verify the similarity evaluation system in this paper, the influence of the number of weld segmentation samples on the final evaluation results is compared and the similarity comparison test and time cost test are carried out on the number of segmentation samples. The test samples are 6 identical samples divided into 1, 2, 3, 4, 5, and 6, as shown in Table4.It can be seen from the analysis in Table4 that when the number of welds is divided and the division scheme is one block, due to the large number of pixels in the industrial ray film and the large aspect ratio, it will be difficult to extract all the features and it will cause the problem of poor similarity comparison effect. When the segmentation scheme is 5 blocks, the similarity comparison accuracy rate has increased by about 18.1% and the improvement effect is more obvious; when the segmentation scheme is 6 blocks, the similarity comparison has increased by about 0.9% and the time overhead is 0.049 s, which improves the effect. Through the analysis of the test results, when the number of weld split comparison samples selected in this paper is 5, taking into account the best accuracy and time cost, it has the best solution.Table 4
Sample number test of weld segmentation.
TestAccuracy test (%)Time overhead test (s)10.7220.03220.7490.07730.7930.12540.8460.17850.9030.20260.9120.251


#### 3.3.5. Similarity Evaluation Weights

The similarity evaluation system is established through this paper, in which the number of weld segmentation samples is 5 and the weight values of the 5 samples arewA1−B1=0.125, wA2−B2=0.125, wA3−B3=0.5, and wA5−B5=0.125. In order to explore the impact of weights on the similarity evaluation results, this section compares the similarity evaluation accuracy of input samples under different weights, as shown in Table 5. Table 5 expresses the weight directly as a set of numbers (in parentheses).Table 5
Weighting scheme test.
ProgramTest countAccurate discrimination timesAccuracy (%)(0.1, 0.1, 0.6, 0.1, 0.1)12010083.333(0.2, 0.2, 0.2, 0.2, 0.2)1208570.833(0.125, 0.125, 0.5, 0.125, 0.125)12010990.833(0.15, 0.15, 0.4, 0.15, 0.15)12010184.167(0.2, 0.3, 0.3, 0.1, 0.1)1207360.833(0.175, 0.175, 0.3, 0.175, 0.175)1208873.333By analyzing Tables4 and 5, it can be concluded that when a reference film and a radiographic film to be discriminated are input for similarity evaluation, the accuracy is higher when each weld image is divided into 5 pieces for comparison; after the weight test and the similarity comparison test, the position of the weld center is obtained. After the weight setting comparison, it is concluded that the weight settings of 1, 2, 4, and 5 are the same, and it has higher accuracy when the third block weight is set larger, with a minimum of 73.333%; when each block is set to (0.15, 0.15, 0.4, 0.15, 0.15), the accuracy rate is 84.167%; when each block is set to (0.1, 0.1, 0.6, 0.1, 0.1), the accuracy is 83.333%, which means the accuracy rate has not improved; when each block is set to (0.125, 0.125, 0.5, 0.125, 0.125), the accuracy rate reaches 90.833%, compared with 6.667% and 7.500%, respectively. It is the best solution to meet actual needs.


#### 3.3.6. Industrial X-Ray Fake Film Discrimination Test

We mixed several industrial fake films and ordinary radiographic negatives in the same folder and checked whether there were industrial fake films in the folder by successive comparison. To verify the effectiveness of the constructed similarity discrimination algorithm, multiple processed industrial fake film samples were mixed into the test sample to verify whether the industrial fake film could be accurately identified.From the analysis in Figure10, it can be concluded that when performing different processing, taking into account the output of different samples and the same sample, the algorithm proposed in this paper has a better discrimination effect. Among them, the accuracy of the sample test with Gaussian noise is less than 90%, and the similarity comparison between samples processed with various processing methods and unprocessed samples is higher than 90%. Among them, the sample similarity test after brightness enhancement processing has the highest accuracy rate, reaching 93.458%, which is higher than other processing methods.Figure 10
Average test accuracy of fake film discrimination.When the weld area in the test sample is relatively similar, it will be judged as an industrial fake, as shown in Figure11.Figure 11
Schematic diagram of the error detection sample. (a–d) Weld areas are similar to each other, and they are judged as industrial fakes.
(a)(b)(c)(d)


## 3.1. Small Sample Data Set for the Judgment of Weld Similarity

The small sample similarity evaluation data set constructed in this paper is specially designed for the discrimination of industrial X-ray fake film [26]. By extracting the local area from the real weld area, the samples extracted from the same weld were taken as a class and the data of different samples were expanded by using reverse mirroring, noise addition, filtering, etc. Finally, JET and HSV codes were uniformly used for color processing. A total of 41 types of samples were constructed in this paper, with 40 samples in each category. Figure 7 is a schematic diagram of some samples constructed in this paper.Figure 7
Part of the sample data set graph.The construction algorithms in this paper are all built on PyTorch under the Python 3.6 environment, and they are developed and tested on the Window10 operating system, Intel(R) Core(TM) CPU i7-8700HQ 3.20 GHz 8G, graphics card RTX2070 Supercomputer platform.


## 3.2. Weld Positioning Test

Aiming at 342 X-ray images generated in actual industrial occasions, this paper uses the Gaussian function method to carry out a weld area positioning test. Table2 shows the quantitative analysis of the positioning test and time cost index of this method.Table 2
Weld positioning accuracy and time cost test.
Test listTest resultsTest sample number342Correct positioning325Accuracy95.03%Positioning time test0.004 sCombining the test data in Table2, it can be seen that the number of test samples is 342 images, of which the number showing accurate positioning is 325, the accuracy rate reaches 95.03%, and the positioning time per page is about 0.004 s. It can be seen that the algorithm proposed in this paper maintains high accuracy while taking into account efficiency and has strong applicability.


## 3.3. Similarity Discriminant Test

In order to verify the effectiveness of the algorithm, first PyTorch is used to build a twin network structure and a small fake identification data set is used for training. The training set and test set are divided in a ratio of 9 : 1, and 100 epochs are trained iteratively. Secondly, two samples are randomly selected and different processing methods such as the SSIM structural similarity measurement method, the cosine similarity method, the ORB feature matching method, histogram comparison method, average hash algorithms, different hash algorithm, perceptual hash algorithm, and the algorithm proposed in this paper are used to compare the similarity of different samples, the similarity of the same sample, the average accuracy test of various similarity algorithms, and the average accuracy test of false slice discrimination. The different processing methods are left and right image processing, up and down image processing, Gaussian noise processing, contrast enhancement processing, and brightness enhancement processing. The comparison is as follows.


### 3.3.1. The Similarity Comparison of Different Algorithms for Different Samples and Different Processing Methods

In this paper, we input any two nonfake images and use different methods to determine whether they are nonfake films. In addition, in order to verify the robustness of the algorithm, the two input images are processed with left and right mirroring, up and down flipping, Gaussian noise, and brightness and contrast adjustment. The comparison accuracy of all methods in this comparison is between [0, 1], where the number closer to 1 represents the higher degree of similarity and the closer to 0 represents the lower degree of similarity.As can be seen from Figure8, for different samples with different processing methods, there are great differences in the similarity comparison accuracy of different algorithms. For different samples, the smaller the output value indicates, the greater the difference will be, and the discrimination accuracy of ORB and SSIM methods is high. However, hash methods have poor stability. In contrast, the method constructed in this paper can better realize the detection of dissimilar samples under various conditions. By processing the samples with pseudo-color and reiterative training, it can improve a certain detection accuracy.Figure 8
The similarity comparison of nonfake films using different processing methods and different algorithms. The “Proposed” is the algorithm proposed in this paper, and “Proposed+” is the algorithm proposed in this paper that constructs the pseudo-color processing sample data set.


### 3.3.2. The Similarity Comparison of Different Algorithms for the Same Sample and Different Processes

We input two identical samples and simulate industrial fakes by flipping up and down, mirroring left and right, adding noise, changing brightness and contrast, etc., and using multiple algorithms to test the recognition rate of industrial fakes.It can be seen from Figure9 that the same sample is processed by different methods and the larger the output result, the smaller the difference between the two images. Among them, the cosine similarity method performs better, but the ORB algorithm is quite different. The algorithm constructed in this paper can better realize the discrimination of sample differences under various conditions.Figure 9
The similarity comparison of the same sample and different processes.


### 3.3.3. The Similarity Comparison of Different Algorithms

According to the comparative analysis in Figures8 and 9, the similarity pair ratio of the ORB feature matching algorithm is higher when different samples are input. When the same sample is input, the accuracy of the cosine similarity algorithm is higher. Through comparative analysis, it is found that the discriminant accuracy of these two algorithms for the same sample or different samples is both too high and too low at the same time, while that of other traditional algorithms is not high or low at the same time, which is inconsistent with the actual situation. According to the proposed algorithm in this paper, the similarity ratio of different processing algorithms with different samples is generally low, close to zero, and the similarity ratio of different processing algorithms with same samples is generally high, close to 1, and it has high robustness. Therefore, the proposed algorithm has more superiority and practicability compared with other similarity comparison algorithms.As can be seen from the analysis in Table3, when the number of samples is the same, there is a big difference between other algorithms and the algorithm proposed in this paper in the comprehensive similarity comparison accuracy. The algorithm proposed in this paper guarantees 1589 successful samples out of 1640 test samples, and the accuracy is as high as 96.8902%, which is about 30% higher than other algorithms.Table 3
Average test accuracy of multiple similarity algorithms.
MethodsTest sample numberJudgment correct numberEvaluation accuracy (%)SSIM164028917.621Cosine164085552.134ORB164086752.865Histogram164069835.979aHash164079548.475dHash164091255.609pHash164098059.756Proposed1640146989.573Proposed+1640158996.890


### 3.3.4. Sample Number Test of Weld Segmentation

In order to verify the similarity evaluation system in this paper, the influence of the number of weld segmentation samples on the final evaluation results is compared and the similarity comparison test and time cost test are carried out on the number of segmentation samples. The test samples are 6 identical samples divided into 1, 2, 3, 4, 5, and 6, as shown in Table4.It can be seen from the analysis in Table4 that when the number of welds is divided and the division scheme is one block, due to the large number of pixels in the industrial ray film and the large aspect ratio, it will be difficult to extract all the features and it will cause the problem of poor similarity comparison effect. When the segmentation scheme is 5 blocks, the similarity comparison accuracy rate has increased by about 18.1% and the improvement effect is more obvious; when the segmentation scheme is 6 blocks, the similarity comparison has increased by about 0.9% and the time overhead is 0.049 s, which improves the effect. Through the analysis of the test results, when the number of weld split comparison samples selected in this paper is 5, taking into account the best accuracy and time cost, it has the best solution.Table 4
Sample number test of weld segmentation.
TestAccuracy test (%)Time overhead test (s)10.7220.03220.7490.07730.7930.12540.8460.17850.9030.20260.9120.251


### 3.3.5. Similarity Evaluation Weights

The similarity evaluation system is established through this paper, in which the number of weld segmentation samples is 5 and the weight values of the 5 samples arewA1−B1=0.125, wA2−B2=0.125, wA3−B3=0.5, and wA5−B5=0.125. In order to explore the impact of weights on the similarity evaluation results, this section compares the similarity evaluation accuracy of input samples under different weights, as shown in Table 5. Table 5 expresses the weight directly as a set of numbers (in parentheses).Table 5
Weighting scheme test.
ProgramTest countAccurate discrimination timesAccuracy (%)(0.1, 0.1, 0.6, 0.1, 0.1)12010083.333(0.2, 0.2, 0.2, 0.2, 0.2)1208570.833(0.125, 0.125, 0.5, 0.125, 0.125)12010990.833(0.15, 0.15, 0.4, 0.15, 0.15)12010184.167(0.2, 0.3, 0.3, 0.1, 0.1)1207360.833(0.175, 0.175, 0.3, 0.175, 0.175)1208873.333By analyzing Tables4 and 5, it can be concluded that when a reference film and a radiographic film to be discriminated are input for similarity evaluation, the accuracy is higher when each weld image is divided into 5 pieces for comparison; after the weight test and the similarity comparison test, the position of the weld center is obtained. After the weight setting comparison, it is concluded that the weight settings of 1, 2, 4, and 5 are the same, and it has higher accuracy when the third block weight is set larger, with a minimum of 73.333%; when each block is set to (0.15, 0.15, 0.4, 0.15, 0.15), the accuracy rate is 84.167%; when each block is set to (0.1, 0.1, 0.6, 0.1, 0.1), the accuracy is 83.333%, which means the accuracy rate has not improved; when each block is set to (0.125, 0.125, 0.5, 0.125, 0.125), the accuracy rate reaches 90.833%, compared with 6.667% and 7.500%, respectively. It is the best solution to meet actual needs.


### 3.3.6. Industrial X-Ray Fake Film Discrimination Test

We mixed several industrial fake films and ordinary radiographic negatives in the same folder and checked whether there were industrial fake films in the folder by successive comparison. To verify the effectiveness of the constructed similarity discrimination algorithm, multiple processed industrial fake film samples were mixed into the test sample to verify whether the industrial fake film could be accurately identified.From the analysis in Figure10, it can be concluded that when performing different processing, taking into account the output of different samples and the same sample, the algorithm proposed in this paper has a better discrimination effect. Among them, the accuracy of the sample test with Gaussian noise is less than 90%, and the similarity comparison between samples processed with various processing methods and unprocessed samples is higher than 90%. Among them, the sample similarity test after brightness enhancement processing has the highest accuracy rate, reaching 93.458%, which is higher than other processing methods.Figure 10
Average test accuracy of fake film discrimination.When the weld area in the test sample is relatively similar, it will be judged as an industrial fake, as shown in Figure11.Figure 11
Schematic diagram of the error detection sample. (a–d) Weld areas are similar to each other, and they are judged as industrial fakes.
(a)(b)(c)(d)


## 3.3.1. The Similarity Comparison of Different Algorithms for Different Samples and Different Processing Methods

In this paper, we input any two nonfake images and use different methods to determine whether they are nonfake films. In addition, in order to verify the robustness of the algorithm, the two input images are processed with left and right mirroring, up and down flipping, Gaussian noise, and brightness and contrast adjustment. The comparison accuracy of all methods in this comparison is between [0, 1], where the number closer to 1 represents the higher degree of similarity and the closer to 0 represents the lower degree of similarity.As can be seen from Figure8, for different samples with different processing methods, there are great differences in the similarity comparison accuracy of different algorithms. For different samples, the smaller the output value indicates, the greater the difference will be, and the discrimination accuracy of ORB and SSIM methods is high. However, hash methods have poor stability. In contrast, the method constructed in this paper can better realize the detection of dissimilar samples under various conditions. By processing the samples with pseudo-color and reiterative training, it can improve a certain detection accuracy.Figure 8
The similarity comparison of nonfake films using different processing methods and different algorithms. The “Proposed” is the algorithm proposed in this paper, and “Proposed+” is the algorithm proposed in this paper that constructs the pseudo-color processing sample data set.


## 3.3.2. The Similarity Comparison of Different Algorithms for the Same Sample and Different Processes

We input two identical samples and simulate industrial fakes by flipping up and down, mirroring left and right, adding noise, changing brightness and contrast, etc., and using multiple algorithms to test the recognition rate of industrial fakes.It can be seen from Figure9 that the same sample is processed by different methods and the larger the output result, the smaller the difference between the two images. Among them, the cosine similarity method performs better, but the ORB algorithm is quite different. The algorithm constructed in this paper can better realize the discrimination of sample differences under various conditions.Figure 9
The similarity comparison of the same sample and different processes.


## 3.3.3. The Similarity Comparison of Different Algorithms

According to the comparative analysis in Figures8 and 9, the similarity pair ratio of the ORB feature matching algorithm is higher when different samples are input. When the same sample is input, the accuracy of the cosine similarity algorithm is higher. Through comparative analysis, it is found that the discriminant accuracy of these two algorithms for the same sample or different samples is both too high and too low at the same time, while that of other traditional algorithms is not high or low at the same time, which is inconsistent with the actual situation. According to the proposed algorithm in this paper, the similarity ratio of different processing algorithms with different samples is generally low, close to zero, and the similarity ratio of different processing algorithms with same samples is generally high, close to 1, and it has high robustness. Therefore, the proposed algorithm has more superiority and practicability compared with other similarity comparison algorithms.As can be seen from the analysis in Table3, when the number of samples is the same, there is a big difference between other algorithms and the algorithm proposed in this paper in the comprehensive similarity comparison accuracy. The algorithm proposed in this paper guarantees 1589 successful samples out of 1640 test samples, and the accuracy is as high as 96.8902%, which is about 30% higher than other algorithms.Table 3
Average test accuracy of multiple similarity algorithms.
MethodsTest sample numberJudgment correct numberEvaluation accuracy (%)SSIM164028917.621Cosine164085552.134ORB164086752.865Histogram164069835.979aHash164079548.475dHash164091255.609pHash164098059.756Proposed1640146989.573Proposed+1640158996.890


## 3.3.4. Sample Number Test of Weld Segmentation

In order to verify the similarity evaluation system in this paper, the influence of the number of weld segmentation samples on the final evaluation results is compared and the similarity comparison test and time cost test are carried out on the number of segmentation samples. The test samples are 6 identical samples divided into 1, 2, 3, 4, 5, and 6, as shown in Table4.It can be seen from the analysis in Table4 that when the number of welds is divided and the division scheme is one block, due to the large number of pixels in the industrial ray film and the large aspect ratio, it will be difficult to extract all the features and it will cause the problem of poor similarity comparison effect. When the segmentation scheme is 5 blocks, the similarity comparison accuracy rate has increased by about 18.1% and the improvement effect is more obvious; when the segmentation scheme is 6 blocks, the similarity comparison has increased by about 0.9% and the time overhead is 0.049 s, which improves the effect. Through the analysis of the test results, when the number of weld split comparison samples selected in this paper is 5, taking into account the best accuracy and time cost, it has the best solution.Table 4
Sample number test of weld segmentation.
TestAccuracy test (%)Time overhead test (s)10.7220.03220.7490.07730.7930.12540.8460.17850.9030.20260.9120.251


## 3.3.5. Similarity Evaluation Weights

The similarity evaluation system is established through this paper, in which the number of weld segmentation samples is 5 and the weight values of the 5 samples arewA1−B1=0.125, wA2−B2=0.125, wA3−B3=0.5, and wA5−B5=0.125. In order to explore the impact of weights on the similarity evaluation results, this section compares the similarity evaluation accuracy of input samples under different weights, as shown in Table 5. Table 5 expresses the weight directly as a set of numbers (in parentheses).Table 5
Weighting scheme test.
ProgramTest countAccurate discrimination timesAccuracy (%)(0.1, 0.1, 0.6, 0.1, 0.1)12010083.333(0.2, 0.2, 0.2, 0.2, 0.2)1208570.833(0.125, 0.125, 0.5, 0.125, 0.125)12010990.833(0.15, 0.15, 0.4, 0.15, 0.15)12010184.167(0.2, 0.3, 0.3, 0.1, 0.1)1207360.833(0.175, 0.175, 0.3, 0.175, 0.175)1208873.333By analyzing Tables4 and 5, it can be concluded that when a reference film and a radiographic film to be discriminated are input for similarity evaluation, the accuracy is higher when each weld image is divided into 5 pieces for comparison; after the weight test and the similarity comparison test, the position of the weld center is obtained. After the weight setting comparison, it is concluded that the weight settings of 1, 2, 4, and 5 are the same, and it has higher accuracy when the third block weight is set larger, with a minimum of 73.333%; when each block is set to (0.15, 0.15, 0.4, 0.15, 0.15), the accuracy rate is 84.167%; when each block is set to (0.1, 0.1, 0.6, 0.1, 0.1), the accuracy is 83.333%, which means the accuracy rate has not improved; when each block is set to (0.125, 0.125, 0.5, 0.125, 0.125), the accuracy rate reaches 90.833%, compared with 6.667% and 7.500%, respectively. It is the best solution to meet actual needs.


## 3.3.6. Industrial X-Ray Fake Film Discrimination Test

We mixed several industrial fake films and ordinary radiographic negatives in the same folder and checked whether there were industrial fake films in the folder by successive comparison. To verify the effectiveness of the constructed similarity discrimination algorithm, multiple processed industrial fake film samples were mixed into the test sample to verify whether the industrial fake film could be accurately identified.From the analysis in Figure10, it can be concluded that when performing different processing, taking into account the output of different samples and the same sample, the algorithm proposed in this paper has a better discrimination effect. Among them, the accuracy of the sample test with Gaussian noise is less than 90%, and the similarity comparison between samples processed with various processing methods and unprocessed samples is higher than 90%. Among them, the sample similarity test after brightness enhancement processing has the highest accuracy rate, reaching 93.458%, which is higher than other processing methods.Figure 10
Average test accuracy of fake film discrimination.When the weld area in the test sample is relatively similar, it will be judged as an industrial fake, as shown in Figure11.Figure 11
Schematic diagram of the error detection sample. (a–d) Weld areas are similar to each other, and they are judged as industrial fakes.
(a)(b)(c)(d)


## 4. Conclusions

According to the X-ray characteristics of scarce UHR, a small sample image similarity discrimination model based on a twin neural network is proposed in this paper. The model extracts the weld area of the X-ray film image accurately and divides the extracted area into blocks. It builds a small sample data set. And by calculating the Euclidean distance between the reference film and the film to be discriminated, the final discrimination result is obtained and it is determined whether the discriminating film is a fake film. The image similarity judgment model proposed in this paper can complete the accurate detection of X-ray industrial fake films with high reliability and realize the scarce UHR even in the case of many image features and few data sets. It provides a reliable and accurate solution for fake film detection tasks in the field of nondestructive testing and also has important promotion and application value for related neural network algorithms and image similarity comparison tasks.



---

*Source: 3253190-2022-03-18.xml*