Abstract
In response to the problem of poor quantification ability and unclear feature correlation of pipeline defect magnetic flux leakage signals, a neural network is proposed to establish the relationship between the characteristic quantities of pipeline defect magnetic flux leakage signals and defect sizes. The characteristic quantities of pipeline defect magnetic flux leakage signals that measure the length, width and depth of pipeline defects are determined by combining the characteristic quantities of the radial and axial components of defect magnetic flux leakage signals in actual pipelines. A database of magnetic leakage signal characteristic quantities for pipeline defects is established by extracting and organizing the characteristic quantities of magnetic leakage signals. Moreover, a particle swarm optimization (PSO)–radial basis function (RBF) neural network model that combines the PSO algorithm and the RBF neural network to quantify pipeline defects is designed. Results show that the average quantification error of the PSO-RBF network model reached 21.08%, representing an improvement of 12.94% compared with that of the traditional RBF network model. The Pearson correlation analysis shows that these feature quantities are significantly positively correlated with the defect size, which provides a reliable feature basis for quantitative modeling.It meets the requirements of practical engineering applications for pipeline defect quantification and has a good application prospect in pipeline magnetic leakage internal detection technology.
Supplementary Information
The online version contains supplementary material available at 10.1038/s41598-025-34048-6.
Keywords: Magnetic flux leakage detection, Pipeline defects, Feature quantity, Defect quantification, PSO–RBF neural network
Subject terms: Energy science and technology, Engineering, Mathematics and computing
Introduction
Long-distance pipeline transportation has become an important form of oil and gas transportation at present1. Although pipeline transportation is highly efficient and cost effective, pipeline leakage accidents occur frequently because of aging, corrosion and external damage, causing substantial economic losses to the country and serious safety hazards to social production. Pipeline magnetic leakage internal detection technology2,3 has been widely used in pipeline defect detection because of its low cost and high sensitivity4.
The main goal of pipeline magnetic leakage internal detection is to measure the magnetic leakage signals generated by pipeline defects through detection equipment, process and study the signals and evaluate the severity of pipeline defects to timely grasp the safety and operating status of the tested pipeline5,6. Quantification of pipeline defects can be further achieved by studying the magnetic flux leakage signals obtained through internal detection technology and combining them with corresponding algorithms7,8. Pipeline defect quantification can accurately reflect the severity of dents, thus enabling timely and effective pipeline maintenance, avoiding serious leakage accidents and providing a reliable basis for pipeline safety evaluation, life prediction, maintenance and repair. In addition, using pipeline defect leakage signals to quantify pipeline defects can considerably reduce the workload of the leakage signal processing environment9, making the entire leakage signal processing process intelligent and convenient. Therefore, research on using pipeline defect leakage magnetic signals to quantify pipeline defects is particularly important.
This study investigates the feature quantities of the radial and axial components of the extracted actual pipeline defect magnetic flux leakage signal and determines the feature quantities of the pipeline defect magnetic flux leakage signal to measure the length, width and depth of the pipeline defect. Then, a neural network is used to establish the relationship between the magnetic flux leakage signal feature quantity and the size of the pipeline defect. A pipeline defect magnetic flux leakage signal feature quantity database is established after extracting and organizing the magnetic flux leakage signal feature quantities. A particle swarm optimization (PSO)–radial basis function (RBF) neural network model that combines the PSO algorithm and RBF neural network is designed to quantify pipeline defects. Then, the quantification results of pipeline defects derived by the PSO-RBF model are compared with those obtained by an ordinary RBF neural network, and error analysis is performed on the defect quantification results.
Generation of the leakage magnetic signal
Principle of leakage magnetic field formation
The principle of leakage magnetic field formation is that after a pipeline is magnetized, if the pipeline has no defects, the vast majority of magnetic induction lines will pass through the interior of the pipeline, and only a few of them will leak to the surface of the pipeline10. If the pipeline has defects, such as cutting magnetic field lines, caused by the magnetic permeability of ferromagnetic pipelines being greater than that of air, the magnetic induction lines will be distorted at the defect site, and some of them will leak into the air, forming a leakage magnetic field11,12. The leakage magnetic field of defects can be detected through Hall elements. The formation principle of the leakage magnetic field is shown in Fig. 1.
Fig. 1.
Pipeline defect leakage field formation principle.
Magnetic leakage signal of pipeline defects
The leakage magnetic field formed by pipeline defects is detected using a pipeline leakage magnetic field internal detector. The measurement section in the pipeline leakage magnetic field internal detector is responsible for detecting the leakage magnetic field signal formed by the defect13. The Hall sensor in the measurement section can obtain the leakage magnetic field flux at the defect on the surface of the pipeline wall, and the change in this flux is the leakage magnetic field signal. The leakage magnetic flux is converted into a digital quantity through the Hall sensor, which detects the leakage magnetic field components in three directions of the defect14, namely, axial, radial and circumferential components of the pipeline defect leakage magnetic signal. The diagram of the three leakage magnetic field signal components is shown in Fig. 2.
Fig. 2.

Diagram of the three components of the pipeline.
Quantification of pipeline defects mainly involves quantifying the length, width and depth of pipeline defects15. The length of the pipeline defect in Fig. 2 refers to the axial dimension of the pipeline defect. Defect width refers to the circumferential dimension of pipeline defects, and defect depth denotes the radial size of pipeline defects.
Assuming that the defect on this pipeline is rectangular16, for the axial component of the defect leakage magnetic field, when the leakage magnetic field diffuses along the axial direction, a maximum value is generated at the centre of the rectangular defect, and the magnetic flux of the leakage magnetic field is symmetrical on both sides17. For the radial component of the defect leakage magnetic field, when the direction of the leakage magnetic field diffuses radially, the magnetic flux of the defect leakage magnetic field reaches a positive maximum at the left edge of the defect and a negative minimum at the right edge of the defect. It is symmetrical about the centre of the defect18, and the magnetic flux at the centre of the defect is zero. Figure 3 shows the axial and radial components of the leakage magnetic field caused by pipeline defects.
Fig. 3.
Axial and radial components of the leakage field.
Given that the circumferential component of the leakage magnetic signal of pipeline defects does not change much when the defect size changes, this study mainly investigates the characteristic quantities of the axial and radial components of the leakage magnetic signal. Firstly, the leakage magnetic signal needs to be obtained. The leakage magnetic signal of pipeline defects can be derived through the Hall sensor in the measurement section of the pipeline leakage magnetic internal detector. The obtained leakage magnetic signal is stored in the computer section of the pipeline leakage magnetic internal detector. The leakage magnetic signal can be extracted through the program and presented in digital form.
Radial component characteristics of the pipeline defect leakage magnetic signal
A diagram of the characteristic quantities of the radial component of the leakage magnetic signal is shown in Fig. 4. The peak-to-valley values
and peak-to-valley spacing
of the radial component signal are mainly analysed. The
of the radial component of the defect leakage magnetic signal refers to the difference between the maximum value
and the minimum value
in the radial component of the leakage magnetic signal. The expression for the peak–valley value of the radial component of the leakage magnetic signal is as follows:
![]() |
1 |
Fig. 4.

Schematic of the radial component of the magnetic leakage signal.
Peak–valley spacing
of the radial component of the defect leakage magnetic signal refers to the absolute value of the difference between the maximum value
and the minimum value
of the radial component of the radial leakage magnetic signal at the corresponding points on the horizontal axis. The peak–valley values of the radial signal are approximately at the edges of the pipeline defect on both sides. The expression form of the peak–valley spacing of the radial component of the leakage magnetic signal is as follows:
![]() |
2 |
The following text examines the peak and valley values of the radial component of the leakage magnetic signal of pipelines with artificially made defects. By using the control variable method, the peak and valley values of the radial component of the leakage magnetic signal of defects are observed when the length and width of the defects are the same, and the depth of the defects changes. Table 1 shows the changes in the peak-to-valley values of the radial component of the defect leakage magnetic signal with varying defect depths when the length and width of the defect remain constant at 35 mm.
Table 1.
Peak and valley values of radial components at different depths.
| Defect depth(mm) | Peak–valley value of the radial component signal |
|---|---|
| 2 | 1.285 |
| 6 | 4.597 |
| 10 | 9.191 |
| 12 | 10.381 |
A linear relationship exists between the depth of defects and the peak-valley values of the radial components of defect leakage magnetic signals. When the width and length of a defect are constant, as the depth of the pipeline defect increases, the peak and valley values of the radial component of the defect leakage magnetic signal also increase. Therefore, the peak and valley values of the radial component of the pipeline defect leakage magnetic signal can be used as a characteristic quantity to measure the depth of the pipeline defect.
Further research is conducted on the peak-valley spacing of the radial component of the leakage magnetic signal for the produced pipeline defects. The width and depth are kept constant. The changes in the peak-valley spacing values of the radial component of the leakage magnetic signal when the defect length varies are shown in Table 2. Specifically, the table presents the changes in the peak-valley spacing values of the radial component of the leakage magnetic signal when the defect width is 20 mm, the depth is 11 mm and the defect length changes. A linear relationship also exists between the length of the defect and the peak-valley spacing of the radial component of the defect leakage magnetic signal. As the length of the defect increases, the peak-valley spacing of the radial component of the defect leakage magnetic signal also increases.
Table 2.
Radial component peak–valley distance with different lengths.
| Defect length(mm) | Peak–valley spacing of the radial component signal |
|---|---|
| 20 | 14 |
| 80 | 31 |
| 100 | 46 |
| 120 | 55 |
Axial component characteristic quantity of the pipeline defect leakage magnetic signal
A diagram of the characteristic quantities of the axial component of the leakage magnetic signal is shown in Fig. 5. The research variables for the characteristic quantities of the axial component of the defect leakage magnetic signal are signal peak-valley value
of the axial component, signal span
and differential signal peak-valley distance
, which are important indicators for quantifying defects by using pipeline defect leakage magnetic signals.
Fig. 5.
Diagram of the axial component of the magnetic leakage signal.
The peak–valley value of the axial component of the defect leakage magnetic signal,
, refers to the difference between maximum peak value
and minimum valley value
of the axial component of the leakage magnetic signal. The expression for the peak-valley value of the axial component is as follows:
![]() |
3 |
The span of the axial component of the defect leakage magnetic signal,
, refers to the absolute value of the difference between the minimum value of the leakage magnetic signal
adjacent to the maximum peak in the axial component of the leakage magnetic signal and the minimum value
adjacent to another peak in the axial component of the leakage magnetic signal at the corresponding point on the x axis. The expression for the span of the axial component is as follows:
![]() |
4 |
The peak-valley distance
of the differential signal of the axial component of the defect leakage magnetic signal refers to the distance between the maximum peak and minimum valley values obtained by differentiating the extracted axial component of the defect leakage magnetic signal; it is the peak valley distance of the differential signal of the axial component of the defect leakage magnetic signal.
The characteristic quantities of the axial component of the manually made defect leakage magnetic signal in the pipeline are analysed. On the basis of the control variable method, whether the peak and valley values of the axial component change with the defect width when the length and depth of the defect are the same is observed. Table 3 shows the changes in the peak and valley values of the axial component of the defect leakage magnetic signal when the defect length is 20 mm, the depth is 11 mm and remains unchanged and the defect width changes. Tables 4 and 5 present the variation in the axial signal span values and differential signal peak–valley distances when the defect width and depth are fixed and the defect length changes.
Table 3.
Peak and valley values of the axial components with different widths.
| Defect width(mm) | Peak–valley spacing of the axial component signal |
|---|---|
| 60 | 10.122 |
| 80 | 12.836 |
| 100 | 14.658 |
| 120 | 15.481 |
Table 4.
Axial component span value with different lengths.
| Defect length(mm) | Axial component signal span value |
|---|---|
| 30 | 29 |
| 50 | 34 |
| 80 | 57 |
| 100 | 60 |
Table 5.
Peak–valley distance of the axial component differential signal with different lengths.
| Defect length(mm) | Peak–valley distance of the axial component differential signal |
|---|---|
| 50 | 23 |
| 60 | 27 |
| 70 | 32 |
| 90 | 37 |
When the length and depth of the defect are constant, the change in defect width affects the peak and valley values of the axial component of the defect leakage magnetic signal. As the defect width increases, the peak and valley values of the axial component of the leakage magnetic signal also increase. When the width and depth of the defect are constant, changes in the length of the pipeline defect affect the axial component span and differential peak–valley spacing of the defect leakage magnetic signal. As the length of the defect increases, the span value of the axial component of the leakage magnetic signal also increases, and the peak–valley distance of the differential signal of the axial component is enlarged.
In order to verify the correlation between the five characteristic quantities and the length, width and depth of defects, and prevent accidental connection, Pearson correlation coefficient is introduced to analyze the correlation between the characteristic quantities of magnetic flux leakage signals and the length, width and depth of defects. First, mark the five characteristic quantities as F1-F5 and set them as independent variables. Then set the defect length, width and depth as dependent variables. Establish the relationship between independent variable and dependent variable. Pearson correlation coefficient formula and t-test formula of correlation coefficient are as follows:
![]() |
5 |
![]() |
6 |
F1: peak valley value of the radial component:
F2: peak valley spacing of the radial component;
F3: peak valley spacing of the axial component;
F4: axial component span value;
F5: peak valley distance of the axial component differential signal.
Establish the relationship, and then use the defect data detected in the later experiment to calculate the r value and t value for correlation verification.
Improvement of the defect quantification algorithm and establishment of a database
Radial basis function neural network
The RBF neural network is mainly composed of three parts: input, hidden and output layers19. A structure diagram of the RBF neural network is shown in Fig. 6. The RBF neural network needs to determine the basis functions of the network and learn the parameters. The steps for building the model are as follows:
Determine the basis functions of the network. The basis functions of the RBF neural network are nonlinear functions that monotonically change around the central point function value20. Given that basis functions map input data in the hidden layer, selecting appropriate basis functions for different data can determine the performance of the network to some extent.
Learn parameters. The centre, variance and output weights of the basis function are learned. The selection of the centre of the basis function in this design adopts the self-organization method. This method generally consists of two stages. The first stage is self-organizing learning, the goal of which is to focus on the centre and variance of the neural network basis functions. The second stage is supervised learning, whose main task is to obtain the output weights from the hidden layer to the output layer.
Fig. 6.

RBF neural network structure.
Initially, the network centre is calculated. The K-means clustering algorithm21 is used to select the centre of the basis function or cluster. Cluster centre M is initialized, which requires randomly selecting K data points from the input data as the starting data for the cluster centre.
The steps of this clustering algorithm are as follows:
Initialize cluster centre
(
= 1,2,…,
), which requires randomly selecting
data points from the input data as the starting data for the cluster centre.In accordance with the nearest neighbour principle, group the input data and assign
(
= 1,2,…,
) to input data cluster set
(
= 1,2,…,
) with the centre
(
= 1,2,…,
) and satisfy
=
||
-
||and
∈
, where
= 1,2,…,
;
= 1,2,…,
.- Select the cluster centres again and calculate the average value of the data in cluster set
, which is the cluster centre of
. The calculation formula is as follows:
7
In Eq. (7),
is the total amount of output data in
. The steps above are repeated until the distribution of cluster centres is stable and no longer changes. Then, the calculation is complete. The centre of the RBF neural network is the final calculated result
(
= 1,2,…,
).
Afterwards, the variance of the RBF neural network is calculated as follows:
![]() |
8 |
In Eq. (8),
= 1,2,…,
, where
is the number of network centres and
represents the distance between the two farthest centres. This can improve the smoothness of the Gaussian function.
The output weights can be calculated using the recursive least squares (RLS) method with the following formula:
![]() |
9 |
In Eq. (9),
= 1,2,…,
and
= 1,2,..
. Given the fixed number of centres in neural networks and the linear mapping between the hidden layer and the output layer, the output weights can be calculated using the RLS method or the simple Gaussian elimination method.
Due to the diversity of defect morphologies and the presence of local noise leading to a low signal-to-noise ratio (SNR) in magnetic flux leakage detection, Recursive Least Squares (RLS) possesses adaptive learning capabilities. For defects of different morphologies, it can achieve dynamic optimization of weights through iteration with real-time samples, thereby enhancing the generalization ability of the quantitative model. Meanwhile, RLS improves noise robustness by introducing the forgetting factor λ. Therefore, in scenarios such as online detection of long-distance pipelines and quantification of complex defect morphologies, RLS can significantly enhance the accuracy, real-time performance, and robustness of defect quantification. It is a superior choice for weight optimization in neural networks, which are currently used for intelligent defect quantification in MFL inspection. Thus, this paper selects RLS to calculate the output weights.
Particle swarm optimization algorithm
The PSO algorithm is a modern intelligent optimization algorithm22 that records the position information of each individual particle in the particle swarm as variable
and the velocity information as variable
.
represents the current direction of motion of the particle, and
denotes the current velocity of the particle. The optimization process of each particle in the PSO algorithm is independent the others, and each particle is unaffected by others. The initial result obtained from optimization is denoted as individual extremum
, and the optimal value of each individual particle is recorded. The optimization results of the other particles in the entire particle swarm are compared to find the optimal individual information in the entire particle swarm. This individual information is denoted as the optimal individual extremum information in the entire particle swarm or
. Then, with
as a reference, the speed and position of the individual are continuously updated to complete the optimization process. The updated expression for particle velocity in the PSO algorithm is as follows:
![]() |
10 |
The expression for updating particle positions by using the PSO algorithm is
![]() |
11 |
where
is the particle velocity,
is the current position of the particle,
and
are learning factors,
and
are random numbers between 0 and 1 and
is the inertia factor. The design and implementation of the PSO algorithm are as follows:
Initialize the information, set the population size to
and initialize the velocity and position information of the particles. Speed information
and position information
are randomly initialized within the set search space and speed interval. The dimension of each particle is equal to the number of optimal values to be found in the system.Calculate the fitness values of particles in each particle swarm during the evolution of each generation.
Find the individual extremum, compare fitness and update individual optimal value
if it is better than the individual extremum.Find the global optimal value, compare it with the individual extreme values, find the optimal individual, update global optimal value
and use the individual extreme value as the global optimal value.Continuously adjust the velocity and position information of the particles, and if the termination condition is reached, stop the iteration; otherwise, return to Step (2) and continue iterating until the conditions are met.
The termination condition of the PSO algorithm generally requires setting a maximum iteration number
or specifying that the difference between adjacent generations is within a specified range. The implementation process of the PSO algorithm is shown in Fig. 7.
Fig. 7.

Particle swarm optimization algorithm implementation process.
Based on the ability of Particle Swarm Optimization (PSO) to address the insufficient optimization of core parameters in Radial Basis Function (RBF) neural networks, the introduction of PSO can achieve global optimal matching of parameters. Simultaneously, the optimal forgetting factor is obtained through global search, enabling the weight update speed of Recursive Least Squares (RLS) to match the change rate of magnetic flux leakage (MFL) signals. In addition, the RBF parameters optimized by PSO can make the mean square error (MSE) of the RLS objective function smoother, reduce the risk of matrix ill-posedness, and improve the iteration convergence speed and weight estimation accuracy, thereby enhancing the dynamic adaptation capability of the RLS iterator. Therefore, this paper selects PSO to optimize the RBF neural network model iterated by RLS. By virtue of the dual advantages of "global parameter collaborative optimization + weight update", it not only solves the problems of unreasonable parameter configuration and weak generalization ability of traditional models but also strengthens the core requirements of magnetic flux leakage (MFL) detection for quantitative accuracy and adaptability.
Improved particle swarm optimization–radial basis function model construction
The performance of RBF neural network depends on three core parameters: the center vector, the width parameter, and the output layer weight. PSO can take these three parameters as an overall optimization objective. Through the collaborative search of the particle swarm and the update of individual and global optimal positions, it can achieve the global optimal matching of parameters.Meanwhile, PSO can incorporate the forgetting factor λ as an optimization variable, and through global search, find the optimal forgetting factor to match the weight update speed of RLS with the change rate of the leakage magnetic signal.Moreover, the RBF parameters optimized by PSO can make the mean square error of the RLS objective function smoother, reduce the risk of matrix ill-conditioning, and improve the convergence speed of the iteration and the accuracy of weight estimation.Therefore the PSO algorithm is adopted to improve and optimize the RBF neural network. Given the mutual sharing of information between particle populations in the PSO algorithm and the ability of particles to self correct, they can quickly approach the optimal position information through continuous correction. The PSO-RBF network model essentially utilizes the PSO algorithm to optimize the learning of clustering centres, output weights and variances in RBF neural networks.
The PSO-RBF neural network is used to build a pipeline defect quantification inversion algorithm model. The input layer of the model is responsible for receiving input data, which include the feature quantities of the axial and radial components of the defect leakage magnetic signal. In the study of the feature quantities, a total of 5 feature quantities are selected, so the number of nodes in the input layer is 5. The output is the length, width and depth dimensions of the defect, so the output node of the output layer is 1. The feature data need to be normalized before training the PSO-RBF neural network on the data. The formula for normalization processing is as follows:
![]() |
12 |
where
is the raw data of the
th data,
is the minimum value of the input data and Xmax is the maximum value of the input data. The specific improvement steps are as follows:
The number of nodes in the hidden layer is set. The initial number of hidden layer nodes in the PSO-RBF neural network is set to 30. After the numbers of input, hidden layer, and output layer nodes are set in the input layer, the PSO algorithm is used to optimize the neural network, and the iteration number, particle swarm number and fitness value are initialized. The initialized iteration number, iter_max, is 5,000 times. The particle swarm has 100 particles, and the initial fitness value is an array of all zeros.
The PSO algorithm is used to calculate centre point d, varianceσ(RBF neural network width) and output weight ɷ of the cluster centres. The three parameters to be optimized are ‘packaged’, and the dimensions are determined. The packaging operation requires setting the dimensions of the particles and the centre points of the cluster centres that need to be optimized, as well as the upper and lower bounds of the variance and output weights. The three neural network parameters are packaged to form a particle in the particle swarm group for optimization in the algorithm. After being used as particles, the parameters of the PSO algorithm are set to select the learning and inertia factors of the algorithm. Learning factors c1 and c2 have the same value of 2. Afterwards, the maximum value of inertia factor w is set to 0.9, and the minimum value is set to 0.2. Particle velocity v, particle position information x, initial particle optimal value Pbest and population particle optimal value Gbest need to be initialized and set.
After parameter initialization, the PSO algorithm can be used to optimize the particles in the particle swarm, that is, to optimize the centre points, variances and output weights of the clustering centres in the RBF neural network. On the basis of Eqs. (8) and (9), a program can be designed to update the velocity and position of the particles. Afterwards, the particles search for individual and group optimal values by moving. If the individual optimal value (fitness value) Pbest of the current particle is better than the individual optimal value of the particle at the previous position, the individual optimal value of the particle will be updated. Through continuous iteration, the individual optimal value constantly changes.
The global optimal value is determined and compared with the individual optimal value obtained in the individual extreme value search program to find the optimal value Gbest of the population. The optimal value Gbest of the group is also constantly updated. The measurement of the optimal value of the population also uses fitness values. The fitness values of the particles are calculated. If the current optimal value of the population for all particles is better than the previously obtained optimal value Gbest, the optimal value of the population will be updated. The optimal value of the group is obtained by continuously iterating and updating.
The obtained optimal value of the particle population is the optimal solution. The final optimized particle is transformed into the corresponding network parameters, namely, the centre point, variance and output weight of the clustering centre in the RBF neural network. After the RBF neural network is optimized using the PSO algorithm to obtain the optimal network parameters, the model construction of the improved PSO-RBF neural network is completed. Then, the input test set data can be used to test the neural network model. The training flowchart of the PSO-RBF neural network model is shown in. Fig. 8
Fig. 8.

Training flowchart of improved PSO-RBF neural network model.
Establishment of a defect leakage magnetic signal feature database
The database established in this research contains a dataset of axial and radial component feature quantities of defect leakage magnetic signals and is mainly used to train neural networks23. The source of the magnetic flux leakage signal for pipeline defects is the large-diameter pipeline ofΦ1016. The experimental pipeline ofΦ1016 has a total of 156 defects of different sizes. The size of pipeline defects in theΦ1016 pipeline is set in accordance with the method of controlling variables, with the lengths being 2, 5, 10 and 120 mm. The length and depth of the defects in the pipeline are controlled to be constant, and the width of the defects made are sequentially taken as integers (i.e. 2, 6, 10 and 120 mm). The length and width of the defects in the pipeline are controlled to be constant with depths of 1.35, 2.2 and 6.06 mm until the defects reached the wall thickness of the pipeline, that is, perforation defects. The radial component of the partial defect leakage magnetic signal obtained in the Φ1016 pipeline is shown in Fig. 9. The axial component of the defect leakage magnetic signal is given in Fig. 10.
Fig. 9.
Radial component of the Φ1016 pipeline defect magnetic leakage signal.
Fig. 10.
Axial component of the Φ1016 pipeline defect magnetic leakage signal.
The feature quantities of the axial and radial components of the defect leakage magnetic signal need to be extracted. Such feature quantity extraction is implemented in MATLAB software. Firstly, the peak–valley values and peak–valley distances of the radial component of the defect leakage magnetic signal are extracted. The numerical values of the radial component of the defect signal are read in Excel in a loop, and the maximum (peak) and minimum (valley) values of the signal are calculated. The program is reused to find the horizontal axis of the maximum and minimum values of the signal, and the maximum and minimum values are subtracted to obtain the peak and valley values of the signal. Subtracting the horizontal axis and taking the absolute value can obtain the peak valley distance of the defect. These values are calculated and extracted.
The signal span value of the axial component of the defect leakage magnetic signal is determined. The two peak values of the signal and the two adjacent valley values are obtained, and the horizontal coordinates of the two valley values of the signal are determined. The peak valley values of the axial component and the span of the axial component are then calculated. A differentiation operation is performed on the digital signal again, and diff() is used as the differentiation function in MATLAB. After the differential signal is obtained, its maximum (peak) and minimum (valley) values are derived, and the calculated value is the peak–valley distance of the differential signal.
The sorted defect magnetic leakage signal feature quantities are inputted into MATLAB software to generate a magnetic leakage signal feature quantity dataset, which is used to train and test neural networks. The dataset file format in MATLAB is .mat file. The partially prepared dataset is shown in Table 6.
Table 6.
Partially prepared dataset.
| Peak–valley value of the radial component | Radial component peak–valley distance | Peak–valley value of the axial component | Axial component span value | Axial differential peak–valley distance |
|---|---|---|---|---|
| 8.998 | 12 | 10.122 | 28 | 11 |
| 1.497 | 20 | 1.85 | 29 | 16 |
| 4.866 | 13 | 5.264 | 24 | 11 |
| 7.235 | 46 | 6.597 | 60 | 43 |
| 14.429 | 19 | 12.889 | 37 | 18 |
Experimental results and analysis
Experimental process
The experimental equipment uses a pipeline magnetic flux leakage internal detector to detect the large-diameter natural gas pipeline with a diameter of Φ1016. After the pipeline is fixed, the pipeline magnetic flux leakage internal detector is uniformly dragged from one end of the pipeline to the other by using a dragging device to obtain the pipeline magnetic flux leakage signal. The leakage magnetic detector and experimental pipeline used in the experiment are shown in Fig. 11.
Fig. 11.

Pipeline magnetic flux leakage internal detector and experimental pipeline.
The experimental data adopt the feature quantities of the axial and radial components of the magnetic leakage signal at the pipeline defect. Therefore, the first step is to extract the magnetic leakage signal of the pipeline defect detected by the detector. The extracted feature quantity data are made into a .mat file format dataset in MATLAB as the input of the neural network. The total number of feature quantities is 5. Therefore, the input data of the magnetic leakage signal for the radial and axial components of a defect is a 5 × 12D matrix.
Defect quantification results and error analysis
The total number of samples for all defects in the Φ1016 pipeline is 156. The leakage signal feature quantities of the first 146 defects are used as the training set for the PSO-RBF neural model to train the network model, and the 10 remaining defects do not participate in the training process of the PSO-RBF neural network model. After the training of the PSO-RBF network model is completed, the 10 pipeline defect leakage signal feature quantities are used as the test set to test the training effect of the model, thereby verifying the quantification ability of the pipeline defect quantification algorithm.
The data on the length, width and depth of the last 10 defects in the Φ1016 pipeline are shown in Table 7.
Table 7.
Size of 10 defects in test set in the Φ1016 pipeline.
| Defect ID | Length(mm) | Width(mm) | Depth(mm) |
|---|---|---|---|
| 147 | 20 | 50 | 9.05 |
| 148 | 20 | 20 | 3.17 |
| 149 | 60 | 60 | 4.13 |
| 150 | 20 | 20 | 8.17 |
| 151 | 30 | 20 | 9.05 |
| 152 | 20 | 60 | 9.01 |
| 153 | 20 | 122 | 8.98 |
| 154 | 6 | 6 | 7 |
| 155 | 20 | 20 | 6.19 |
| 156 | 60 | 60 | 6.06 |
The length, width and depth of defects in the Φ 1016 pipeline are quantified using the PSO-RBF neural network model. The neural network is trained for 5,000 rounds by using the input of defect leakage magnetic signal features to output the length, width and depth of pipeline defects. The number of nodes in the hidden layer is set to 35, 60 and 40. The improved PSO-RBF neural network model training iteration diagram is shown in Fig. 12.
Fig. 12.
Improved PSO-RBF neural network model training iteration diagram.
During the training process, the optimal value min of the model training set in length, width and depth quantification is 0.0082577, 0.14606 and 0.52942, respectively. After training, the corresponding feature values of the last 10 data points in Table 7 are tested. The following part tests the trained model on the data of the last 10 defect points and compares the results with the real values to observe the error situation.In order to more intuitively reflect the relationship between the quantitative value and the actual value, I also observed the three groups of data in a scatter diagram, and the X axis is the actual size; Y axis: predicted size, set a reference line: diagonal line of y = x, indicating perfect quantification. Clearly judge the performance: when the point falls above the diagonal, it indicates that the quantitative value of the model is < the actual value; If the point falls below the diagonal, it means that the quantitative value of the model is > the actual value. The observation shows that the 10 test data are evenly distributed on both sides of the diagonal, and some data are also on the diagonal, indicating that the quantification effect is better. It is consistent with the actual defect value.
The quantification results of defect length show that the PSO-RBF neural network model performs well in quantifying defect length. The maximum length quantification error is 5.44 mm, and the rest of the length quantification errors are between 0.5 and 4 mm. The minimum defect length quantification error is 0.5 mm.The comparison between the quantitative results of the length of pipe defects in the Φ 1016 pipe test set and the actual value is shown in the following Fig. 13a. 13b is the scatter diagram of the quantitative value of the length.The length of pipeline defects has important reference value, and the quantification accuracy of defect length in this model meets the requirements of practical engineering.
Fig. 13.
Comparison between quantitative results and actual values of defect length of Φ 1016 pipeline.
Figure 14a depicts a comparison between the quantitative results of defect width and the actual values for the Φ 1016 pipeline test set, whereas Fig. 14b illustrates the scatter diagram of width quantification values. Based on these quantitative results,the quantification results of pipeline defect width by the model have a larger error compared with the actual size. The prediction accuracy of the 20 mm size, which is small and numerous, is high in the test set and has an error within 0–3 mm. However, the quantification errors of the large pipeline defect width sizes, such as 50, 60 and 122 mm, are large. Particularly, the error of 122 mm reaches 60 mm. The main reason is that the number of defect samples for large pipeline widths is small, resulting in insufficient samples for large widths in the training set. Therefore, the quantification error for large widths is large.
Fig. 14.
Comparison between quantitative results and actual values of defect width of Φ 1016 pipeline.
Figure 15a shows the comparison between the quantitative results of the model on the depth of pipeline defects and the actual values, and Fig. 15b is the scatter diagram of the quantitative values of the depth. Compared with the true depth size error of the defects, the quantification error of most defect depths is between 0.4 and 3 mm, and the minimum quantification error is only 0.16 mm. Therefore, the model can accurately quantify the defect depth, and its quantification results for defect depth have certain reference value.
Fig. 15.
Comparison between quantitative results and actual values of defect depth of Φ 1016 pipeline.
Then, based on the 156 sets of defect data samples in the experiment, a correlation analysis was conducted to calculate the correlation coefficient r and the test t.
The P value was obtained by finding the t value. The P value is an indicator to eliminate the possibility of chance. When P < 0.05, it proves that the correlation is real and significant. When P > 0.05,it indicates that the correlation may be accidental. Therefore,to prove the correlation between the independent variable and the dependent variable, the corresponding r value and P value need to be calculated.
The correlation intensity is determined according to the absolute value of the correlation coefficient. When ∣r∣ < 0.3, there was no correlation; 0.3 ≤ ∣r∣ < 0.5, Weak correlation; 0.5 ≤ ∣r∣ < 0.8, Moderate correlation; ∣r∣ ≥ 0.8, Strong correlation.
After calculation:
Depth D and F1 : r = 0.92 (strong positive correlation);
Length L and F2 : r = 0.87 (strong positive correlation);
Width W and F3 : r = 0.65 (moderately positive correlation);
Length L and F4 : r = 0.83 (strong positive correlation);
Length L and F5 : r = 0.81 (strong positive correlation);
The P values of the five groups were all less than 0.001. All correlations were tested by statistical significance test, which showed that the linear correlation between the characteristic quantity and the defect parameter was real, not caused by random fluctuations.
After that, the width and axial peak valley value (F3) showed a moderate positive correlation. In the 156 groups of defect width, the proportion of small width defects (W < 30 mm) was very high, 107 groups, and only 49 groups of large width defects (w ≥ 30 mm). The width defect types are classified and calculated below. The correlation coefficients of small width defects and large width defects are calculated respectively.
The correlation coefficient r of small width defects is 0.82, and that of large width defects is 0.41. It can be seen that the small width defect is strongly correlated with the axial peak valley value (F3), and the characteristic quantity F3 has a strong ability to characterize the small width. However, the large width leads to insufficient model learning and weak correlation due to the small number of samples.It is demonstrated that the representation capability of large-width categories is insufficient, which is also consistent with the limited number of large-size and large-width samples observed in the width quantification results. Therefore, it is proved that the independent variables of these five MFL characteristics are strongly and positively correlated with the three dependent variables of defect length, width and depth.
Next, the optimization ability of the PSO algorithm is verified. For this purpose, an unoptimized RBF neural network model is used to learn and test the three feature quantities of length, width and depth in the Φ1016 pipeline test set, and the test results are compared with those of the improved PSO-RBF neural network model Fig. 16 Fig. 17 and Fig. 18 .
Fig. 16.

Comparison of the defect length errors quantified by the PSO-RBF and RBF models.
Fig. 17.

Comparison of the defect width errors quantified by the PSO-RBF and RBF models.
Fig. 18.

Comparison of the defect depth errors quantified by the PSO-RBF and RBF models.
To verify the enhanced quantification effect of the proposed optimized neural network model compared with the baseline model, using the test sample variance and average value to calculate the optimized and non optimized results. At the same time, in the comparison of the quantification of the last 10 defect positions, the maximum error difference between the UN optimized and optimized ones under the same defect is marked. The maximum error difference in length quantification is 9.1 mm; the maximum error difference in width quantification is 23.2 mm; and the maximum error difference in depth quantification is 3.5 mm.
Average error of test set:
![]() |
13 |
Test set variance:
![]() |
14 |
After calculation, statistics are made as shown in Table 8 below:
Table 8.
Comparison of defect quantification performance between the Optimized PSO-RBF Neural Network and the Non-Optimized RBF Neural Network.
| Quantitative dependent variable | Length | Width | Depth | |||
|---|---|---|---|---|---|---|
| Not optimized(RBF) |
Optimization (PSO-RBF) |
Not optimized(RBF) |
Optimization (PSO-RBF) |
Not optimized(RBF) |
Optimization (PSO-RBF) |
|
| Average error of test set | 4.75 mm | 2.92 mm | 23.99 mm | 15.52 mm | 3.93 mm | 2.53 mm |
| Test set variance | 8.905 | 5.289 | 697.65 | 328.54 | 1.388 | 1.305 |
Through the statistical analysis of the quantitative error data of length, width and depth, the results show that the average error of the optimized model is smaller than that of the non optimized model, and the sample variance of the corresponding dimension decreases synchronously. This indicates that the proposed optimization scheme not only effectively suppresses the overall quantification deviation of the system but also reduces error dispersion, thereby endowing the optimized model with higher stability and accuracy during the defect quantification process.
From the perspective of the mean quantification error of the last 10 defects, the overall quantification performance of the improved PSO-RBF algorithm model is superior to that of the unoptimized RBF network model. In terms of defect length quantification,the mean quantification error of the improved PSO-RBF neural network model is 8.2%, which is a significant improvement compared with the traditional RBF network model with a mean quantification error of 13.25%. In terms of width quantification, the improved model can achieve a mean quantification error of 35.43%, which is much lower than the 54.78% of the unoptimized model. In terms of depth quantification, the average error of the improved model is 19.62%, which is a significant improvement compared with the average error of 34.04% of the unoptimized model. The reason for the inaccurate width quantification is that there are not many samples with large widths in the training dataset, leading to significant errors in the test results.
The improved network model has improved the quantification accuracy of these three parameters, with an overall average quantification error of 21.08%. The average quantification error of the unoptimized RBF network model is 34.02%. representing an overall reduction of 12.94% points in quantification error. After training, the error of the improved model is almost similar to the true value, meeting the accuracy requirements of industrial inspection and improving the quantification level of pipeline defects.
Conclusion
With regard to the quantification method of pipeline magnetic leakage detection signals on the basis of neural networks, this study focused on the feature quantities related to defects in the axial and radial components of defect magnetic leakage signals and designed relevant algorithm programs to extract the defect feature quantities. Afterwards, the algorithm for quantifying defect size was studied, and a suitable neural network was selected to invert the defect size. An optimization algorithm for neural network optimization was also designed to improve the accuracy of neural network inversion of defect size. Then, the designed network model was used to quantify pipeline defects, and the accuracy of the pipeline defect quantification results was verified. The following conclusions were obtained.
The length, width and depth of pipeline defects are closely related to the characteristic quantities of axial and radial components of defect magnetic flux leakage signal. Through the study of the characteristic signals of axial and radial components of defect magnetic flux leakage signal, it is determined that the characteristic quantities related to defect size are five characteristic quantities such as the peak and valley values of radial components of defect magnetic flux leakage signal. The five characteristic quantities are strongly and positively correlated with the length, width and depth of pipeline defects.
The PSO algorithm was used to optimize the design of RBF neural network, and a PSO-RBF defect quantification model was constructed. The axial and radial components of the defect leakage magnetic signal were extracted, and a sample database of defect feature quantities was established in MATLAB software. This database is used as input for neural network models to quantify the size of pipeline defects.
Quantifying defects of different lengths, widths, and depths, experiments have shown that the improved PSO-RBF neural network model has high quantification accuracy in quantifying the length and depth dimensions of rectangular defects; The PSO-RBF network model achieves an average quantification error of 21.08%, representing a 12.94% improvement compared with the traditional RBF network model, and the optimization effect is better. Meet the requirements of industrial testing. However, its accuracy in partially quantifying defect width dimensions is relatively low. Therefore, this defect quantification model needs further improvement.
Supplementary Information
Author contributions
Guoqing Wang proposed a concept and developed methods; Shicheng Bei verified the experiment and conducted the experiment; Yantian Zuo searched for resources and organized data; Huakai Zhang was responsible for writing and editing. All authors reviewed the manuscript.
Funding
National Key Research and Development Program Project, 2022YFC3004802, State Administration for Market Regulation Science and Technology Plan Project, 2024-39/2023MK032.
Data availability
All data generated or analysed during this study are included in this published article [and its supplementary information files]. Thank you for the editor’s attention and recognition of our research work. We understand the data sharing requirements of SCI journals, but due to laboratory policies and confidentiality agreements. Unable to provide raw data, we have fully elaborated on the practical design, analysis results, and data processing process of the research. If editors and reviewers have doubts about the treatment of the given data. We will do our best to provide more detailed explanations.
Declarations
Competing interests
The authors declare no competing interests.
Footnotes
Publisher’s note
Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.
Guoqing Wang, Shicheng Bei, Yantian Zuo and Huakai Zhang contributed equally to this work.
References
- 1.Jiao, D. et al. Instrumentation of cross electromagnetic eddy current sensing for internal pipeline inspection. IEEE Sens. J.24, 22745–22757 (2024). [Google Scholar]
- 2.Lang, X. & Wang, Z. A multi-sensor feature fusion attention convolutional neural network for complex magnetic leakage. T-IM73, 2536509 (2024). [Google Scholar]
- 3.Liu, B. et al. Study of MFL signal identification in pipelines based on non-uniform magnetic charge distribution patterns. Meas. Sci. Technol.34, 044003 (2023). [Google Scholar]
- 4.Pan, J. & Gao, L. A novel method for defects marking and classifying in MFL inspection of pipeline. Int. J. Pres. Ves. Pip.202, 104892 (2023). [Google Scholar]
- 5.Gu, L. et al. Automated matching and visualisation of magnetic flux leakage data in shale gas pipeline based on ICP and DBSCAN algorithm. Nondestruct. Test. Eval.40, 3729–3753 (2025). [Google Scholar]
- 6.Liu, B. et al. Quantization of magnetic flux leakage internal detection signals for composite defects of gas and oil pipelines. Energy Rep.9, 5899–5914 (2023). [Google Scholar]
- 7.Atherton, D. L. Finite element calculations and computer measurements of magnetic flux leakage patterns for pits. Br. J. NDT5, 159 (1988). [Google Scholar]
- 8.Zhang, S. et al. Adaptive compressive sensing: An optimization method for pipeline magnetic flux leakage detection. Sustainability15, 14591 (2023). [Google Scholar]
- 9.Jaein, L. et al. Multisensor fusion for 3-D defect characterization using wavelet basis function neural networks. AIP Conf. Proc.557, 679–686 (2001). [Google Scholar]
- 10.Wang, R. et al. Analysis of the mechanism of leakage magnetic field generated by internal defects. J. Nondestruct. Eval.42, 31 (2023). [Google Scholar]
- 11.Li, X. et al. Magnetic charge model for leakage signals from surface defects in ferromagnetic material. Materials16, 3750 (2023). [DOI] [PMC free article] [PubMed] [Google Scholar]
- 12.Hu, B. et al. Leakage magnetic field variation induced by inner surface grooves during loading in geomagnetic environment. Int. J. Appl. Electrom.64, 1531–1538 (2020). [Google Scholar]
- 13.Gao, P. et al. Research on quantification methodof ellipsoidal defects based on leakage magnetic detection. IEEE Sens. J24, 14503–14518 (2024). [Google Scholar]
- 14.Atzlesberger, J. & Zagar, B. Magnetic flux leakage measurement setup for defect detection. Procedia Eng.5, 1401–1404 (2010). [Google Scholar]
- 15.Schifini, R. et al. Experimental verification of a finite element model used in a magntic flux leakage inverse problem. J. Phys. D Appl. Phys.38, 1875 (2005). [Google Scholar]
- 16.John, A. F. et al. A heuristic algorithm for the reconstruction and extraction of defect shape features in magnetic flux leakage testing. IEEE Trans. Instrum. Meas.69, 9062–9071 (2020). [Google Scholar]
- 17.Liu, B. et al. Quantitative study on MFL signal of pipeline composite defect based on improved magnetic charge model. Sensors21, 3412 (2021). [DOI] [PMC free article] [PubMed] [Google Scholar]
- 18.Liu, W., Ren, L. & Tian, G. Study on the impact of pole spacing on magnetic flux leakage detection under oversaturated magnetization. Sensors24, 5195 (2024). [DOI] [PMC free article] [PubMed] [Google Scholar]
- 19.Wang, X. et al. Dynamic reconstruction of electroencephalogram data using RBF neural networks. Front. Neurosci.19, 1557763 (2025). [DOI] [PMC free article] [PubMed] [Google Scholar]
- 20.Peng, R. et al. Practical consensus tracking control for networked Euler-Lagrange systems based on UDE integrated with RBF neural network. Neurocomputing583, 127554 (2024). [Google Scholar]
- 21.Aik, L. E., Hong, T. W. & Junoh, A. K. Distance weighted K-Means algorithm for center selection in training radial basis function networks. Int. J. Artif. Intell.8, 54–62 (2019). [Google Scholar]
- 22.Gong, C. et al. Quantum particle swarm optimization algorithm based on diversity migration strategy. Futur. Gener. Comput. Syst.157, 445–458 (2024). [Google Scholar]
- 23.Xu, L. et al. Intelligent identification of girth welds defects in pipelines using neural networks with attention modules. Eng. Appl. Artif. Intell.127, 107295 (2024). [Google Scholar]
Associated Data
This section collects any data citations, data availability statements, or supplementary materials included in this article.
Supplementary Materials
Data Availability Statement
All data generated or analysed during this study are included in this published article [and its supplementary information files]. Thank you for the editor’s attention and recognition of our research work. We understand the data sharing requirements of SCI journals, but due to laboratory policies and confidentiality agreements. Unable to provide raw data, we have fully elaborated on the practical design, analysis results, and data processing process of the research. If editors and reviewers have doubts about the treatment of the given data. We will do our best to provide more detailed explanations.






















