In this thesis, I present a comprehensive study on the recognition of internal defects in aerospace light-alloy castings using X-ray imaging and machine learning techniques. The manufacturing environment of a sand foundry defect is often complex, and the resulting X-ray images contain irregular noise, uneven brightness, and diverse defect morphologies. The core challenge is to accurately identify defects such as shrinkage, porosity, cracks, and inclusions, which directly affect the safety and reliability of aerospace components. My research focuses on a systematic pipeline involving image preprocessing, segmentation, multi-feature extraction, feature selection, and ensemble classification. The ultimate goal is to build a robust model that can assist quality inspectors in real production lines, especially when the sand foundry defect patterns are subtle and highly variable.
1. Introduction and Motivation
Sand casting is one of the oldest and most widely used manufacturing processes for producing metal components. In the aerospace industry, light-alloy castings are essential for structural and functional parts. However, during the casting process, the interaction between molten metal, sand molds, and environmental conditions often leads to various internal defects. These defects, if not detected and remediated, can propagate into fatigue cracks or stress-corrosion cracks, leading to catastrophic failures. Therefore, non-destructive testing (NDT) is mandatory for safety-critical castings. X-ray radiography is one of the most effective NDT methods because it can reveal internal structures without damaging the part. Nevertheless, manual inspection of X-ray images is subjective, labor-intensive, and error-prone. This motivates the development of an automated machine-learning framework for detecting and classifying sand foundry defect types.
The main contributions of this work are as follows. First, I provide a detailed analysis of common defect categories found in sand castings, including their formation mechanisms and visual characteristics. Second, I design an image preprocessing and segmentation strategy that enhances defect visibility while suppressing noise. Third, I extract multiple feature groups—geometric, moment-based, local binary patterns, and histogram of oriented gradients—to capture the diverse properties of sand foundry defect regions. Fourth, I employ a support vector machine recursive feature elimination (SVM-RFE) algorithm to select the most discriminative features, reducing redundancy and improving computational efficiency. Finally, I construct an ensemble classifier based on the Adaboost algorithm with support vector machines as base learners, termed Adaboost-SVM, which significantly improves classification accuracy and generalization compared to single classifiers.
2. Defect Analysis in Sand Castings
In sand foundry processes, several typical defects can arise. Table 1 summarizes the primary defect types studied in this thesis, along with their causes and typical radiographic appearances.
| Defect Type | Formation Cause | Radiographic Appearance |
|---|---|---|
| Gas porosity | Trapped gas during pouring; gas evolved from mold or metal | Round or elliptical dark spots with smooth boundaries |
| Shrinkage | Inadequate feeding; solidification contraction | Sponge-like or dendritic dark regions |
| Hot tears / cracks | Non-uniform solidification; constrained contraction | Narrow, elongated dark lines, often with jagged edges |
| Inclusions / slag | Foreign particles entering the melt; mold erosion | Irregular bright or dark spots with varying density |
| Sand inclusion | Mold sand washed into the casting surface | Irregular patch with granular texture |
| Cold shut | Low pouring temperature; poor fluidity | Discontinuous seam or lap |
Each type of sand foundry defect presents different challenges for automated detection. For example, gas pores are usually small and round, while shrinkage areas are large and fuzzy. Cracks may be very thin and elongated, whereas inclusions can have arbitrary shapes and contrast levels. Therefore, a single feature extraction method is insufficient. My approach combines complementary descriptors to represent the rich information embedded in defect images.

3. Image Preprocessing and Segmentation
Raw X-ray images of castings often suffer from low contrast, non-uniform illumination, and random noise. To improve the quality for subsequent analysis, I first apply linear gray-level transformation to stretch the contrast. The transformation is defined as:
$$
f(i,j) = \frac{b’ – a’}{b – a} \big( g(i,j) – a \big) + a’
$$
where \(g(i,j)\) is the original pixel intensity, \(f(i,j)\) is the enhanced intensity, and \([a,b]\) and \([a’,b’]\) are the input and output intensity ranges, respectively. This operation makes defect regions more distinguishable from the background.
After contrast enhancement, I perform noise reduction using bilateral filtering. Bilateral filtering is a non-linear technique that preserves edges while smoothing homogeneous regions. The filtered pixel value is given by:
$$
\hat{I}(x) = \frac{1}{W_x} \sum_{y \in S} G_{\sigma_s}(\|x-y\|) \, G_{\sigma_r}(|I(x)-I(y)|) \, I(y)
$$
Here, \(G_{\sigma_s}\) and \(G_{\sigma_r}\) are Gaussian weighting functions in the spatial domain and intensity domain, respectively. This filter is particularly effective for sand foundry defect images because it reduces noise without blurring the fine boundaries of cracks or pores.
I compared several filtering methods, including mean, median, Gaussian, and bilateral filters. The visual results demonstrated that bilateral filtering provides the best trade-off between noise suppression and defect detail preservation. Table 2 lists the parameters used in my preprocessing stage.
| Algorithm | Parameter | Value |
|---|---|---|
| Bilateral filter | Kernel size | 5 × 5 |
| Spatial sigma \(\sigma_s\) | 20 | |
| Intensity sigma \(\sigma_r\) | 0.2 |
For segmentation, I use both edge detection and adaptive thresholding. Canny edge detection is applied to extract the contours of crack-like defects. The Canny operator involves gradient computation, non-maximum suppression, and hysteresis thresholding. The gradient magnitude and direction are computed as:
$$
G(x,y) = \sqrt{ G_x(x,y)^2 + G_y(x,y)^2 }
$$
$$
\theta(x,y) = \tan^{-1} \left( \frac{G_y(x,y)}{G_x(x,y)} \right)
$$
For porosity and shrinkage, adaptive thresholding is more suitable because these defects often appear as large, low-intensity regions. The threshold at each pixel is computed from the local mean of a \(15 \times 15\) neighborhood:
$$
T(h,w) = (1 – ratio) \cdot \text{mean}(f(h,w))
$$
with \(ratio = 0.15\). Then the binary image is obtained by:
$$
J(h,w) = \begin{cases} 255 & \text{if } f(h,w) < T(h,w) \\ 0 & \text{otherwise} \end{cases}
$$
Figure 1 shows the result of the adaptive threshold segmentation for a gas pore defect. The defect region is clearly separated from the background, which greatly facilitates feature extraction.
4. Feature Extraction
To comprehensively describe the characteristic of each sand foundry defect, I extract four complementary feature sets: geometric features, Hu moments, local binary patterns (LBP), and histograms of oriented gradients (HOG). These features capture shape, spatial distribution, texture, and edge orientation, respectively.
4.1 Geometric Features
Geometric features describe the shape and size of the segmented defect region. Let \(S\) be the area (number of pixels), \(L\) the perimeter, \(R\) the rectangularity, and \(E\) the elongation (length-to-width ratio). The sharpness \(P\) is computed as:
$$
P = \frac{S_1 + S_2}{S}
$$
where \(S_1\) and \(S_2\) are the areas at the two ends of the defect, and \(S\) is the total area. Other geometric features include the centroid, which is derived as:
$$
x_c = \frac{1}{S} \sum_{(x,y) \in R} x, \qquad y_c = \frac{1}{S} \sum_{(x,y) \in R} y
$$
I selected six geometric features: area, perimeter-area ratio, aspect ratio, rectangularity, sharpness, and average gray-level intensity. Table 3 provides example values for three defect classes.
| Defect | Area (pixels) | Perimeter/Area | Aspect Ratio | Rectangularity | Sharpness | Avg. Intensity |
|---|---|---|---|---|---|---|
| Crack | 289 | 6.12 | 16.23 | 0.43 | 0.87 | 122 |
| Porosity | 24 | 0.63 | 1.54 | 0.88 | 0.12 | 14 |
| Shrinkage | 1782 | 3.12 | 2.54 | 0.76 | 0.43 | 167 |
4.2 Hu Moments
Hu moments are seven descriptors that are invariant to translation, scaling, and rotation. They are derived from normalized central moments. For a digital image \(f(x,y)\) of size \(M \times N\), the \((p+q)\)-th order moment is:
$$
m_{pq} = \sum_{x=0}^{M-1} \sum_{y=0}^{N-1} x^p y^q f(x,y)
$$
The central moments are given by:
$$
\mu_{pq} = \sum_{x=0}^{M-1} \sum_{y=0}^{N-1} (x-\bar{x})^p (y-\bar{y})^q f(x,y)
$$
where \(\bar{x} = m_{10}/m_{00}\) and \(\bar{y} = m_{01}/m_{00}\). Then the first few Hu moments are:
$$
\phi_1 = \eta_{20} + \eta_{02}
$$
$$
\phi_2 = (\eta_{20} – \eta_{02})^2 + 4\eta_{11}^2
$$
These moments provide a compact representation of the overall shape of the defect region and are robust to minor variations in orientation and scale, which is common in sand foundry defect images.
4.3 LBP Texture Features
Local binary patterns are widely used for texture analysis. The original LBP operator labels the pixels of an image by thresholding the neighborhood of each pixel. The decimal value is computed as:
$$
LBP(x_c, y_c) = \sum_{p=0}^{P-1} s(i_p – i_c) 2^p
$$
where \(i_c\) is the gray value of the center pixel, \(i_p\) is the gray value of the \(p\)-th neighbor, and \(s(u)\) is a sign function:
$$
s(u) = \begin{cases} 1, & u \geq 0 \\ 0, & \text{otherwise} \end{cases}
$$
To improve efficiency, I use the “uniform” LBP variant that reduces the number of patterns from \(2^P\) to \(P(P-1)+2\). This captures the fundamental texture properties of defects such as the granular structure of shrinkage or the smooth surface of gas pores.
4.4 HOG Features and PCA Dimensionality Reduction
The histogram of oriented gradients (HOG) descriptor is computed by dividing the image into small cells, accumulating a histogram of gradient directions over the pixels of each cell, and normalizing across blocks. The gradient magnitude and orientation are computed as described in the edge detection section. The resulting feature vector can be very high-dimensional. To avoid excessive computational cost and redundancy, I apply Principal Component Analysis (PCA) to reduce the HOG feature dimension. PCA finds a linear projection \(M\) that maximizes the variance:
$$
\max_{M} \; \mathrm{tr}(M^T Q M) \quad \text{s.t. } M^T M = I
$$
where \(Q\) is the covariance matrix of the HOG features. The optimal \(M\) is composed of the eigenvectors corresponding to the largest eigenvalues. I retain a sufficient number of components to preserve \(99.99\%\) of the cumulative variance.
5. Feature Fusion and SVM-RFE Selection
After extracting the four feature groups, I concatenate them into a full information feature set. However, the concatenated vector contains redundant or irrelevant information that may degrade classifier performance and slow down training. Therefore, I apply a feature selection method based on Support Vector Machine Recursive Feature Elimination (SVM-RFE).
The SVM-RFE algorithm iteratively trains an SVM on the current feature set, computes the ranking criterion for each feature, and removes the feature with the smallest criterion. The criterion is based on the squared weight \(w_j^2\) of the linear SVM hyperplane. For a linear SVM, the decision function is:
$$
f(x) = w^T x + b
$$
and the feature importance is \(g_j = w_j^2\). In each iteration, the feature with the lowest \(g_j\) is eliminated. This process continues until the desired number of features is reached. In my experiment, I retained the top \(60\%\) of features as the final sensitive feature set. Table 4 compares different retention thresholds in terms of classification performance.
| Retention Ratio | Crack Accuracy | Porosity Accuracy | Shrinkage Accuracy |
|---|---|---|---|
| 10% | 0.894 | 0.891 | 0.905 |
| 20% | 0.902 | 0.908 | 0.900 |
| 30% | 0.924 | 0.905 | 0.923 |
| 40% | 0.921 | 0.913 | 0.920 |
| 50% | 0.932 | 0.918 | 0.931 |
| 60% | 0.961 | 0.921 | 0.943 |
| 70% | 0.942 | 0.915 | 0.934 |
| 80% | 0.931 | 0.906 | 0.921 |
| 90% | 0.926 | 0.891 | 0.929 |
| 100% | 0.894 | 0.892 | 0.918 |
The results demonstrate that selecting too few features loses important discriminative information, while retaining too many features introduces noise and redundancy. The \(60\%\) threshold achieves the best balance and is adopted for the final model.
6. Adaboost-SVM Classifier
Support Vector Machine (SVM) is a powerful supervised learning algorithm that works well for high-dimensional and small-sample problems. The primal optimization problem of SVM with soft margin can be written as:
$$
\min_{w,b,\xi} \; \frac{1}{2} \|w\|^2 + C \sum_{i=1}^{N} \xi_i
$$
$$
\text{s.t.} \quad y_i (w^T x_i + b) \geq 1 – \xi_i, \quad \xi_i \geq 0
$$
where \(C\) is the penalty parameter and \(\xi_i\) are slack variables. For non-linear classification, I use the Gaussian radial basis function (RBF) kernel:
$$
K(x_i, x_j) = \exp\left( -\gamma \|x_i – x_j\|^2 \right)
$$
The optimal \(\gamma\) and \(C\) were selected via grid search. In my experiments, \(\gamma = 1.01\) and \(C = 100\) gave the best validation performance.
Although SVM performs well, its generalization can be further improved by ensemble learning. AdaBoost (Adaptive Boosting) combines multiple weak classifiers to form a strong classifier. In each round \(t\), a new SVM is trained on reweighted training samples. The weights of misclassified samples are increased so that the next classifier focuses on the hard examples. The final prediction is a weighted majority vote:
$$
H(x) = \text{sign}\left( \sum_{t=1}^{T} \alpha_t h_t(x) \right)
$$
where \(h_t(x)\) is the \(t\)-th SVM classifier and \(\alpha_t\) is its weight, computed from the error rate \(\epsilon_t\):
$$
\alpha_t = \frac{1}{2} \ln\left( \frac{1 – \epsilon_t}{\epsilon_t} \right)
$$
The sample weights are updated according to the following rules for correctly and incorrectly classified samples, respectively:
$$
w_{t+1,i} = \frac{w_{t,i} e^{-\alpha_t}}{B_t} \quad \text{(correct)}
$$
$$
w_{t+1,i} = \frac{w_{t,i} e^{\alpha_t}}{B_t} \quad \text{(incorrect)}
$$
where \(B_t\) is a normalization factor ensuring that the sum of all weights equals one. The number of boosting iterations \(T\) was set to 1000 in my experiments.
7. Experimental Setup and Data
I collected X-ray images from a real sand foundry production line producing aft cabin castings. The original dataset contained 14 crack images, 14 porosity images, 14 shrinkage images, and 23 non-defect images. To increase the robustness of the model, I applied data augmentation techniques including rotation, flipping, mirroring, and noise addition. After augmentation, the dataset contained 112 images per defect class and 184 healthy images, for a total of 560 images. Table 5 shows the data distribution.
| Class | Original Count | Augmented Count |
|---|---|---|
| Crack | 14 | 112 |
| Porosity | 14 | 112 |
| Shrinkage | 14 | 112 |
| Healthy | 23 | 184 |
| Total | 38 | 560 |
I used 10-fold cross-validation to evaluate the model. The dataset was partitioned into 10 folds. In each iteration, nine folds were used for training and the remaining fold was used for testing. The final performance metrics are the average and variance across all folds.
A confusion matrix was used to evaluate the classification results. For a multi-class problem with four classes (crack, porosity, shrinkage, healthy), the confusion matrix is shown in Table 6.
| Predicted Crack | Predicted Porosity | Predicted Shrinkage | Predicted Healthy | |
|---|---|---|---|---|
| Actual Crack | TP11 | FP12 | FP13 | FN1 |
| Actual Porosity | FP21 | TP22 | FP23 | FN2 |
| Actual Shrinkage | FP31 | FP32 | TP33 | FN3 |
| Actual Healthy | FP1 | FP2 | FP3 | TN |
The accuracy and false negative rate for each defect class can be computed from this matrix. For example, the accuracy for class 1 (crack) is:
$$
\text{Accuracy}_1 = \frac{TP_{11}}{TP_{11} + FP_{12} + FP_{13} + FN_1}
$$
and the false negative rate is:
$$
\text{FN Rate}_1 = \frac{FN_1}{TP_{11} + FP_{12} + FP_{13} + FN_1}
$$
8. Results and Discussion
8.1 Overall Performance of the Proposed Method
Table 7 presents the mean results of the 10-fold cross-validation for each defect class using the proposed Adaboost-SVM model.
| Defect Class | Accuracy Mean | Accuracy Variance | False Negative Mean |
|---|---|---|---|
| Crack | 0.961 | 0.0302 | 0.022 |
| Porosity | 0.921 | 0.0352 | 0.046 |
| Shrinkage | 0.943 | 0.0311 | 0.034 |
| Overall | 0.941 | 0.0321 | 0.034 |
These results indicate that the proposed method achieves high recognition rates for all sand foundry defect types. The crack defect has the highest accuracy of \(96.1\%\), while porosity has the lowest accuracy of \(92.1\%\) due to its similarity to small shrinkage pores. The overall false negative rate of \(3.4\%\) is acceptable for industrial inspection, as it ensures that the vast majority of defective parts are correctly identified.
8.2 Comparison of Feature Extraction Methods
To validate the advantage of the multi-feature fusion with SVM-RFE selection, I compared the proposed feature set with individual feature groups. Table 8 summarizes the classification results using the same Adaboost-SVM classifier.
| Feature Type | Crack Acc. | Porosity Acc. | Shrinkage Acc. | Crack FN | Porosity FN | Shrinkage FN |
|---|---|---|---|---|---|---|
| Geometric | 0.938 | 0.902 | 0.921 | 0.030 | 0.052 | 0.039 |
| HOG | 0.943 | 0.912 | 0.913 | 0.039 | 0.051 | 0.041 |
| LBP | 0.921 | 0.891 | 0.901 | 0.041 | 0.075 | 0.048 |
| Hu Moments | 0.912 | 0.899 | 0.897 | 0.039 | 0.069 | 0.049 |
| Proposed Fusion | 0.961 | 0.921 | 0.943 | 0.022 | 0.046 | 0.034 |
The fused feature set consistently outperforms every single feature type across all defect classes, confirming that complementary information is essential for distinguishing the complex and varied sand foundry defect patterns.
8.3 Comparison of Classifiers
To further demonstrate the effectiveness of the Adaboost-SVM ensemble, I compared it with two commonly used classifiers: BP neural network and random forest, using the same sensitive feature set. The BP network had one hidden layer with 5 neurons, sigmoid activation, and SGD optimizer. The random forest used 30 decision trees with a maximum depth of 40. The comparison results are shown in Table 9.
| Classifier | Crack Acc. | Porosity Acc. | Shrinkage Acc. | Overall Acc. | Overall Var. | Overall FN |
|---|---|---|---|---|---|---|
| BP Neural Network | 0.937 | 0.913 | 0.924 | 0.924 | 0.0526 | 0.050 |
| Random Forest | 0.891 | 0.881 | 0.902 | 0.891 | 0.0841 | 0.045 |
| Adaboost-SVM | 0.961 | 0.921 | 0.943 | 0.941 | 0.0340 | 0.034 |
The proposed Adaboost-SVM model improves the overall accuracy by \(1.7\%\) over BP neural network and by \(5.0\%\) over random forest. Moreover, the variance of accuracy is the lowest, indicating better stability and generalization. The false negative rate is also reduced to \(3.4\%\), which is highly desirable in safety-critical applications.
8.4 Discussion on Key Challenges
Despite the promising results, some challenges remain in sand foundry defect recognition. Porosity and small shrinkage regions are notoriously difficult to distinguish because they share similar low-intensity, irregular morphologies. In my experiments, the porosity class achieved the lowest accuracy. This issue could be alleviated by incorporating additional contextual information or using deep learning methods when more data becomes available. Moreover, the current dataset is relatively small due to the low-volume production of these aerospace castings. Data augmentation helped, but it cannot fully replace real-world variability. As more X-ray images are collected, the model can be retrained and further improved.
9. Conclusion and Future Work
In this thesis, I presented a machine-learning-based approach for the automatic recognition of sand foundry defects in X-ray images of aerospace light-alloy castings. The main steps include image preprocessing with linear gray-level transformation and bilateral filtering, segmentation using Canny edge detection and adaptive thresholding, multi-feature extraction including geometric, Hu moments, LBP, and HOG descriptors, feature selection via SVM-RFE, and classification using an Adaboost-SVM ensemble. The experimental results on real production data show that the proposed method achieves an overall accuracy of \(94.1\%\) with a false negative rate of \(3.4\%\), outperforming both BP neural networks and random forests. The integration of multi-feature fusion and SVM-RFE proves to be effective in selecting the most discriminative features, while the Adaboost-SVM improves robustness and generalization.
Future work will focus on several aspects. First, expanding the dataset by collecting more defect images from the production line to reduce the impact of data scarcity. Second, optimizing the algorithm for real-time deployment, as current offline processing may not meet the speed required for high-throughput manufacturing. Third, developing an integrated detection system that couples X-ray imaging, automated defect marking, and repair verification workflows to further assist quality inspectors. Finally, exploring deep learning models, such as convolutional neural networks, which may learn even more powerful representations directly from raw images and potentially eliminate the need for handcrafted features. These advancements will bring the automated sand foundry defect recognition system closer to practical industrial use, ultimately improving product quality and production efficiency.
