Progress in Casting Defect Detection Algorithms

As an engineer and researcher working on intelligent inspection for cast components, I have observed that casting defects remain one of the most persistent barriers to achieving reliable, high-performance metal parts. The presence of porosity, shrinkage, cracks, inclusions, and cold shuts directly degrades mechanical properties, fatigue life, and service safety. Consequently, the detection of casting defects is not merely a quality control step but a critical enabler for process optimization, defect tracing, and structural integrity assessment. In this article, I systematically review the research progress in casting defect detection algorithms over the past two decades, organizing the discussion around five major task categories: defect recognition and classification, defect localization and detection, defect segmentation and quantitative evaluation, defect prediction, and defect image generation for data augmentation. I also summarize common challenges and corresponding optimization pathways, and I offer a forward-looking perspective on future directions. Throughout this review, I emphasize that casting defects are diverse in morphology, weak in feature contrast, scarce in labeled samples, and subject to stringent real-time requirements in industrial settings.

1. Task Taxonomy and Data Modalities

I begin by clarifying the scope of casting defect detection algorithms. The field has evolved from simple binary classification of whether a defect exists to a multi-task ecosystem that includes localization, pixel-level segmentation, quantitative rating, process-based prediction, and synthetic data generation. Table 1 summarizes the major tasks, their typical data modalities, output forms, mainstream technical routes, and research goals. This taxonomy helps me structure the subsequent review and highlights the growing complexity of the problem.

Detection Task Common Data Modalities Typical Output Mainstream Technical Routes Research Goal
Defect recognition Visible light images, X-ray images, CT slices, metallographic images Defect class CNN, ResNet, SVM, feature engineering Automatically identify defect types
Defect localization X-ray images, industrial images, CT slices Bounding boxes Faster R-CNN, YOLO, FPN, DETR Obtain spatial positions of defects
Defect segmentation 2D images, 3D volumetric data, metallographic images Masks Mask R-CNN, DeepLabV3+, U-Net, 3D CNN Fine-grained region extraction
Defect prediction Process parameters, simulation data, multi-source industrial data Defect probability, quality parameters ANN, random forest, data–physics fusion Process optimization and quality prediction
Data augmentation Real images, synthetic images, multimodal data Synthetic training samples GAN, diffusion, SMOTE, physical modeling Mitigate sample scarcity

I note that the data sources have expanded from single X-ray images to surface images, DR images, CT images, process parameters, and simulation outputs. This multimodal nature makes the detection of casting defects a rich but challenging research area. In the following sections, I discuss each task in detail, highlighting representative methods and their limitations.

2. Defect Recognition and Classification Algorithms

Defect recognition and classification aim to determine whether a sample contains casting defects and, if so, to assign the correct defect type. This task is often used for rapid screening and quality diagnosis. I categorize the technical routes into four directions: traditional feature engineering, feature fusion and ensemble learning, deep learning, and lightweight deployment.

2.1 Traditional Feature Engineering

Early work relied on handcrafted features. For example, mathematical morphology combined with genetic algorithm optimization achieved over 99% accuracy in a mixed-part production line. Another study used an improved Laplacian-of-Gaussian edge detector to extract eight geometric attributes such as area, perimeter, and compactness, and then fed them into a two-layer feedforward neural network for classification. This method reached about 90% accuracy in offline tests, but it required manual presetting of edge detection sensitivity and zero-crossing thresholds, and it was sensitive to illumination and surface oil contamination. In my assessment, traditional methods are highly reliable in controlled industrial environments with standardized lighting, fixed workpiece pose, and stable imaging conditions, but they struggle when the grayscale difference between casting defects and background is weak or when noise is present.

2.2 Feature Fusion and Ensemble Learning

To handle complex backgrounds and internal defects, researchers introduced multi-feature fusion and feature selection. One approach fused 22 handcrafted features from texture, grayscale, and geometry, applied PCA-ReliefF for dimensionality reduction, and used an improved K-Means++ clusterer for three-class classification of porosity, cracks, and slag inclusions. However, as a single unsupervised model, it could not use label information to distinguish structural edges from defect edges, and standard defect samples required manual cropping. Another study introduced the Relief algorithm to select sensitive features and improved the classifier to an Adaboost-SVM ensemble for binary detection of internal cracks. This enhanced sensitivity to weak cracks and robustness to noise and complex backgrounds, but the detection object was limited to a single defect type. A further extension used a wrapper feature selection algorithm and an Adaboost-RF ensemble classifier for four-class classification of cracks, segregation, porosity, and defect-free, achieving over 96% multi-class accuracy while maintaining computational efficiency. I find that such methods extract more information in the feature space but do not expand the expressive power of the features themselves. They are more suitable for industrial radiographic inspection scenarios where defect samples are limited or where the grayscale distributions of casting defects and background are clearly separable.

2.3 Deep Learning

Convolutional neural networks (CNNs) enable end-to-end learning and automatic extraction of deep features from casting defects. One early work trained a Caffenet model on 4,000 X-ray images and achieved 100% defect sample detection rate, though a 4.5% false positive rate remained due to insufficient defect-free samples. Subsequently, a deep convolutional network named BX-Net introduced bilinear pooling to capture second-order statistics between feature maps, improving recognition accuracy by at least ten percentage points over traditional machine learning. However, it struggled to capture effective semantic differences when casting defects had weak texture features and overlapping visual characteristics. To address this, recursive attention mechanisms were embedded into convolutional networks, allowing dynamic focus on key regions and improving recognition under strong background interference. For tiny casting defects in complex backgrounds, a method fusing feature clustering and image reconstruction mined more weak defect information from low-quality images, enhancing adaptability to extreme imaging conditions. I observe that deep learning methods require no manual feature design and are applicable to various detection scenarios, especially for industrial radiographic images with variable defect morphology, complex backgrounds, or low contrast.

2.4 Lightweight and Efficient Deployment

With the increasing demand for online inspection, computational efficiency and deployment feasibility have become key research focuses. One method combined CNN with a machine vision system using image partitioning and multi-label classification, dividing the original image into sub-regions for independent classification, thereby processing high-resolution surface images at low per-patch inference cost. Another study introduced a CBAM attention module and replaced the backbone with MobileNetV3, improving detection accuracy by 5.13% over MobileNetV3-large while maintaining low parameter count and fast inference. To address scarce defect samples in real production lines, a hybrid quantum–classical neural network achieved 93.8% accuracy on the GDXray Castings dataset with only 144 trainable parameters. Ablation experiments showed that removing the quantum variational layer decreased accuracy by about 5 percentage points, indicating a positive effect of quantum feature transformation on classification of casting defects. These studies focus on computational efficiency and deployment feasibility, suitable for industrial online inspection scenarios with tight production cycles and limited computing and storage resources.

In summary, the recognition and classification of casting defects has gradually shifted toward deep feature self-learning, with detection objects extending from regular surface defects to complex internal defects. Convolutional networks, attention mechanisms, and lightweight models are currently core research directions.

3. Defect Localization and Detection Algorithms

Defect localization goes beyond recognition by locking the specific spatial position of casting defects. The output typically includes defect class, bounding box, and confidence. This task has received significant attention in the field of casting defect detection algorithms.

3.1 Handcrafted Features and Physical Priors

Before deep learning, localization relied on handcrafted image features and physical prior models. Casting defects usually appear as local grayscale mutations, irregular edges, or texture discontinuities. A typical pipeline involved enhancing contrast between casting defects and background, applying segmentation algorithms to extract defects, and performing morphological post-processing. One method combined image registration with a difference-image method: after aligning the test piece with a standard template, grayscale residuals were extracted directly, and defects were marked via morphological reconstruction. However, this method demanded high template quality and registration accuracy; structural artifacts could significantly reduce reliability. Another approach combined Butterworth low-pass filtering, USM sharpening, and iterative threshold segmentation to localize tiny casting defects using only image grayscale statistics. Yet manually set filter parameters and threshold initial values had poor generalization, and segmentation accuracy dropped sharply when external factors changed. For aerospace titanium alloy castings, selective search generated candidate regions, followed by size statistics and edge curvature filtering, achieving 99.7% recall and 91.76% precision. Some studies introduced prior geometric knowledge and dynamic observation. For instance, a human visual attention mechanism was used to quickly screen salient regions via grayscale differencing, followed by Harris corner and SIFT feature matching across frames, and finally spatial coordinates of casting defects were solved using translational parallax. This elevated static detection to dynamic 3D, but required stable workpiece translation during imaging, which is difficult in real production lines. Another method used the STL 3D model of a casting to produce defect-free X-ray images as reference standards and compared them with actual inspection images to localize casting defects. The localization effect depended on the consistency between the model and the real object. In my view, handcrafted feature and prior model methods are computationally lightweight and can achieve stable rapid screening when the grayscale difference between casting defects and background is obvious or the casting structure is relatively fixed. However, performance varies greatly under different imaging conditions.

3.2 Two-Stage and One-Stage CNN Detectors

With the development of deep convolutional networks, data-driven representation learning has been applied to localization of casting defects. Current CNN-based detection research mainly follows two-stage and one-stage object detection paradigms. Two-stage algorithms first propose candidate regions, then perform classification and regression, achieving higher accuracy. One study introduced a feature pyramid network (FPN) into Faster R-CNN, fusing multi-scale features through top-down pathways and lateral connections, enhancing representation and localization of internal casting defects at different scales, with mAP around 0.514. One-stage algorithms skip candidate region generation and directly predict classes and regress anchors on feature maps, resulting in faster detection. To address tiny casting defects being lost in deep networks in X-ray images, one study added coordinate attention (CA) and multi-head self-attention modules to YOLOv5 and used a Focal-EIoU loss to increase gradient contribution of hard samples, raising overall recall from 78.8% to 84.2%. Another study replaced YOLOv3’s Darknet53 backbone with EfficientNet, added depthwise separable convolution and Soft-NMS post-processing, and compressed model size by about 83% while maintaining detection accuracy. A further study replaced YOLOX’s Darknet53 with ShuffleNetv2-plus, combining channel shuffling and depthwise separable convolution to reduce computational complexity, validating the feasibility of channel shuffling architectures in die-casting defect detection.

Although lightweight backbones reduce computation, they often sacrifice feature representation capability, leading to decreased localization accuracy for tiny casting defects and blurred textures. To address this, one study introduced a global attention mechanism to reallocate feature weights across channel and spatial dimensions, and designed a multi-scale feature enhancement module to expand the receptive field, repairing feature loss caused by backbone compression while maintaining lightweight design. Another study targeted tiny casting defects that easily blend with background under reflections and oil contamination by adding a dedicated detection head for small objects in YOLOv11 and introducing a normalized Wasserstein distance loss to solve gradient vanishing during small object regression. Some studies focused on neck and head structure optimization. One improved the detection head of YOLOv8 to a task-aligned dynamic head structure and simultaneously lightweighted the downsampling and feature extraction modules, reducing parameters by 43.5% compared to the baseline while improving accuracy by 8.5%. Another added knowledge distillation and feature enhancement modules to a lightweight detection network and developed a surface defect detection system, advancing application from model validation to system integration. I note that deep convolutional network methods enable autonomous feature learning and joint optimization of feature extraction and bounding box regression, but their performance depends heavily on the scale and annotation quality of training data. They are more suitable for scenarios with diverse casting defect morphologies and sufficient training samples. Two-stage structures remain the first choice for high-precision localization in complex backgrounds, while one-stage structures dominate online inspection scenarios with tight production cycles and limited hardware resources.

3.3 Transformer-Based Detectors

Transformer architectures have natural advantages in global modeling and end-to-end processing due to self-attention mechanisms. Since the introduction of DETR in 2020, some researchers have attempted to apply DETR-like models to localization of casting defects. To address low small-object recognition accuracy and slow convergence, one study added dynamic anchors and multi-scale deformable attention modules to DETR, and used an SIoU loss to optimize bounding box regression, achieving mAP of 0.837 on a self-built dataset. Another study proposed supervised enhancement and attention distillation based on Deformable DETR, duplicating labels to strengthen training and raising defect recall to 97.7%. A further study optimized DETR’s attention structure, matching strategy, and bounding box learning logic, and built a real-time detection system based on PyQT6. Results showed that single-frame detection time remained stable at around 90 ms under four different environments, with detection accuracy of 91.2%. Although Transformers can bypass anchor presetting and non-maximum suppression post-processing, they rely heavily on large-scale annotated data and high computing power, making them more suitable for scenarios requiring high-precision analysis and complex, variable casting defect morphologies.

In summary, deep object detection methods have improved the ability to recognize small objects, complex backgrounds, and low-contrast casting defects, while Transformers provide new approaches to avoid anchor design and post-processing parameter tuning. The two types of methods are not mutually exclusive; how to achieve complementary fusion while preserving their respective advantages may be a promising direction for the next stage.

4. Defect Segmentation and Quantitative Evaluation Algorithms

Defect segmentation and quantitative evaluation represent the core transition from “finding casting defects” to “evaluating casting defects.” The goal is to extract quantitative indicators for quality judgment from segmentation results.

4.1 Traditional Segmentation Methods

Traditional segmentation methods are generally based on grayscale distribution and region connectivity, combining filtering, contrast enhancement, threshold segmentation, edge detection, and morphological processing. One study systematically compared second-order derivative combined morphology, adaptive thresholding, and 2D wavelet transform, finding that 2D wavelet transform had good adaptability to porosity, inclusions, and shrinkage cavities, but required manual presetting of multi-level decomposition layers and was susceptible to background interference. To address this, one study introduced prior constraints into threshold selection and constructed an attribute histogram, using a fuzzy index entropy criterion to obtain the optimal segmentation threshold, effectively suppressing background interference. Another study combined attribute histograms with maximum fuzzy index entropy and set grayscale retention intervals for three types of casting defects, showing significantly better adaptability to low-contrast images than classical Otsu and maximum entropy methods. Since a single threshold struggles to segment casting defects with severe background grayscale fluctuations, one study proposed adaptive thresholding combined with morphological reconstruction, first suppressing pseudo-defects via dual thresholds and then recovering complete defect regions via morphological reconstruction, achieving accurate extraction of internal casting defects in wheels. These traditional segmentation algorithms share advantages of strong physical interpretability and low computational cost, but false positives and missed detections increase significantly when dealing with complex background defect images or blurred defect edges. Therefore, they are more suitable for industrial scenarios with fixed defect types and guaranteed image quality.

4.2 Deep Learning Segmentation

With the accumulation of pixel-level annotated data and the development of deep learning models, instance segmentation and semantic segmentation have entered the field of casting defect detection. One study combined Mask R-CNN with guided filter enhancement to perform region-based instance segmentation of bubbles and porosity in railway casting DR images, setting five defect grades and achieving integrated segmentation and grading. When defect categories increase, small inter-class differences and large intra-class differences easily arise. One study improved DeepLabV3+ by introducing a multi-scale feature fusion model and combining Focal Loss with Lovász-Softmax hybrid loss to alleviate sample imbalance, achieving 96.34% pixel accuracy on seven-class internal defect segmentation. Another study followed the DeepLabV3+ architecture but designed a D_DenseASPP module to strengthen multi-scale context perception, and introduced StyleGAN for generative data augmentation to address small-sample issues. The improved model achieved mIoU of 60.21% with only 11.81% of the original parameters. A further study proposed a semantic segmentation method based on improved U-Net for surface porosity, cracks, sand holes, and slag inclusions in castings. It first used median filtering to suppress noise, then enhanced edge feature preservation via attention mechanisms and residual connections, and finally extracted geometric features such as position, area, and perimeter in post-processing, achieving pixel-level segmentation and recognition of surface casting defects. Results showed 96.2% overall detection accuracy on 500 casting samples, with five times higher efficiency than manual inspection. Deep learning models can autonomously learn boundary and semantic features of casting defects, achieving higher segmentation accuracy under complex backgrounds and low contrast. Moreover, performance does not fluctuate drastically across different batches and illumination conditions.

4.3 3D Segmentation and Quantitative Evaluation

2D image segmentation can only extract parameters such as area and perimeter, but for internal casting defects like porosity, shrinkage, and cracks, these indicators cannot reflect the true volume and connectivity inside the casting, making it difficult to accurately judge mechanical properties. Therefore, in recent years, researchers have extended segmentation algorithms from 2D images to 3D voxel space. For complex and irregular 3D structures of casting defect regions, one study proposed a 3D CNN-based instance segmentation framework. It first performed fine voxel-level segmentation of defect regions, then quantified extracted geometric features via nonlinear topological dimensions, and finally established an empirical model based on experimental data to inversely estimate 3D features and microscopic performance parameters of casting defects. However, the experiment required extensive manual annotation of 3D metallographic and CAD fusion data and high imaging quality. Another study proposed a 3D semantic segmentation model trained entirely on simulated CT data. It first generated synthetic samples with precise voxel labels, then used transfer learning to train on real industrial CT data, significantly reducing the labor cost of 3D voxel annotation. Although 3D segmentation can provide more sufficient data support for mechanical property evaluation of casting defects, the high cost of acquiring high-quality CT data, the difficulty of voxel-wise annotation, and the computational load far exceeding 2D models limit its large-scale application in routine casting inspection. At present, such methods are more suitable for precision inspection and quality assessment of high-value castings.

The ultimate purpose of defect segmentation is to provide quantitative geometric parameters for quality evaluation. One research group systematically studied feature extraction and rating of casting defects in aluminum alloy X-ray images. They compared multiple filtering, enhancement, and threshold segmentation methods, and used connected component labeling and edge tracking on binary images to automatically calculate area and perimeter of porosity, slag inclusions, and other casting defects. They further embedded this parameter extraction method into a defect rating task, using defect area as the core indicator and referencing standard atlases to establish quantitative grading criteria for porosity, inclusions, shrinkage cavities, and shrinkage porosity, integrated into an automatic rating system, making feature extraction truly serve quality judgment in practical inspection. In my view, research on defect segmentation and quantitative evaluation is shifting from “finding casting defects” to “quality evaluation.” 2D parameterization methods have high computational efficiency, low hardware thresholds, and good compatibility with existing standards, and will remain mainstream for some time. 3D analysis can more truly reflect the spatial distribution, aggregation degree, and shape complexity of casting defects, but how to effectively incorporate this information into quality evaluation frameworks and establish a 3D evaluation index system is a key direction for future breakthrough.

5. Defect Prediction Algorithms

Defect prediction algorithms use casting process data, material parameters, simulation results, or quality records to predict the probability and specific categories of casting defects in advance. They focus more on analyzing the causes and subsequent development trends of casting defects.

5.1 Early BP and Expert Systems

Early work constructed a three-layer BP neural network for five common casting defects in gray cast iron and ductile iron. The network input was production process parameters, and the output was the occurrence probability of five defect types. Genetic algorithms were introduced to optimize initial weights, and defect prediction software was developed. Validation on 40 training samples and 20 test samples achieved 93% prediction accuracy. However, due to the black-box nature of the network, the output was only a probability value, and it could not determine the location or cause of casting defects. Another study integrated temperature gradient methods, new mountain criterion methods, and expert systems into a unified defect analysis system. It first performed solidification simulation to obtain temperature field and temperature gradient distributions, then used criteria to predict the locations of shrinkage cavities and porosity, and the knowledge base could perform defect cause reasoning and recommend prevention measures. Early casting defect algorithm research linked defect prediction with casting mechanisms and engineering experience, but the model structure, data scale, and evaluation system were relatively simple.

5.2 Data-Driven Prediction

In recent years, with the accumulation of production process data in casting enterprises, purely data-driven defect prediction models have emerged. One study collected 6,276 groups of process data for steering axle castings, including 18 input features such as pouring temperature, chemical composition, and sand properties. It compared random forest, K-nearest neighbors, support vector machines, and neural networks for casting defect prediction. The random forest model achieved 97.1% accuracy on the test set, with recall rates for all defect types exceeding 90%. The same team later introduced the Gini coefficient into the same model and combined Monte Carlo simulation to optimize the distribution of key parameters such as pouring temperature and inoculation amount. Such methods can automatically exploit hidden complex correlations when handling high-dimensional, nonlinear process data. However, casting defects are the result of multiple process parameters acting together. Random forests can give the importance of each feature but cannot explain the interaction relationships between parameters. Therefore, once working conditions change, model prediction accuracy drops.

5.3 Data–Physics Fusion

To break through the limitations of purely physical criteria or purely data-driven approaches, one study proposed a data–physics fusion-driven defect prediction framework. It first performed orthogonal solidification simulation in CAE software, then constructed a dataset mapping pouring temperature, shell temperature, and pouring time to defect quantity and defect volume, and finally established multiple regression models and BP neural network prediction models. Comparing the two models, multiple regression achieved high fitting accuracy for shrinkage cavity volume with R² of 0.995, but its ability to predict shrinkage porosity quantity was clearly insufficient, with R² of only 0.471. In contrast, the neural network model performed better on all four prediction targets. Data and physics fusion prediction methods retain the mechanistic basis of simulation results while leveraging the nonlinear fitting advantages of neural networks, making them very suitable for complex high-value castings. In my assessment, data-driven methods represented by random forests and neural networks have shown excellent performance. As data–physics fusion methods mature, future research is expected to maintain high prediction accuracy while giving models stronger explanatory power for casting physical mechanisms, thereby better combining prediction performance and process credibility.

6. Defect Image Generation and Data Augmentation Algorithms

In actual production, most collected samples are qualified parts. The proportion of casting defects is low and irregular, resulting in limited defect samples, especially for severe defects that are even harder to collect. Therefore, defect image generation has gradually become an important auxiliary direction in the field of casting defect detection, mainly addressing issues of insufficient or imbalanced defect samples.

6.1 Physical and Geometric Modeling

For casting defects, especially dendritic shrinkage porosity, real X-ray inspection samples are extremely difficult to obtain. One study proposed a defect image generation framework based on semantic description, transforming dendritic shrinkage porosity into a skeleton structure with time weights, first simulating the diffusion process with Gaussian filtering, then adding grayscale and fusing edges based on grayscale statistics of real wheel hub backgrounds. However, this method could not simulate the real imaging mechanism of X-rays, resulting in obvious artificial traces at the edges of generated casting defects. Another study proposed a virtual inspection image generation method entirely based on geometric and physical imaging models. It established a casting coordinate dimensionality reduction mapping and a ray–triangle intersection model, and converted penetration thickness into grayscale values according to Beer’s law, generating more realistic virtual inspection images. Such methods relying on physical models or geometric modeling benefit from interpretability and controllability, making them reliable sample supplements in detection scenarios with fixed defect morphology and clear imaging mechanisms. However, because they require prior modeling or rule definition, costs increase when defect types multiply.

To reduce the cost and complexity of physical modeling, one study used an improved Diamond-Square algorithm to generate random elevation data, obtained simulated shrinkage cavity defect images through grayscale mapping, and then applied thresholding, grayscale stretching, and Gaussian filtering to make the grayscale distribution and texture of simulated defects closer to real shrinkage cavities. This method skips complex ray attenuation calculations and geometric intersections, making implementation simpler, but it still relies on manually set process parameters.

6.2 Generative Adversarial Networks

With the development of generative deep learning, GAN models and their variants have been introduced into casting defect image generation tasks. To address the difficulty of training deep learning models due to scarce defect samples in light alloys, one study designed an interpolated deep convolutional generative adversarial network (I-DCGAN). The generator first outputs a low-resolution image (64×64), then restores it to the original high resolution (416×416) via upsampling. The discriminator first downsamples the original high-resolution image to low resolution before discrimination. This effectively reduces computational burden and network depth and generates diverse high-resolution defect samples. Another study proposed a synthetic defect generation method based on a scalable conditional Wasserstein generative adversarial network (SCWGAN). It embeds SCWGAN-generated defect regions into real defect-free X-ray images and adaptively adjusts network layers and tensor sizes according to input image resolution to accommodate different defect sizes. On the GDXray castings dataset, adding 650 synthetic images to the training set increased mAP@IoU=0.5:0.95 from 67.0% to 84.0%. A further study used GAN to enhance low-quality images with severe noise and blurred details. Through adversarial training between generator and discriminator, the reconstructed images showed significantly improved texture realism. The reconstructed high-quality images were then input into a CNN-FC model for defect recognition, achieving 99.37% recognition accuracy. GAN methods can generate richer defect morphologies and texture features and have strong adaptability to complex scenes. However, in scenarios with very few samples, the generated sample types tend to be monotonous, and the training process is unstable.

In summary, the introduction of models like GAN has improved the diversity of defect samples and enhanced adaptability to complex scenes. At present, the research focus is not only on the quality of generated images but also on the actual gain that generated samples bring to casting defect detection. However, there is still no unified evaluation standard for the realism and physical plausibility of generated images, which may be an important issue for future research. Table 2 compares data modalities, technical routes, and research goals for casting defect detection tasks.

Detection Task Common Data Modalities Typical Output Mainstream Technical Routes Research Goal
Defect recognition Visible light images, X-ray images, CT slices, metallographic images Defect class CNN, ResNet, SVM Automatically identify defect types
Defect localization X-ray images, industrial images, CT slices Bounding boxes Faster R-CNN, YOLO, FPN Obtain spatial positions of casting defects
Defect segmentation 2D images, 3D volumetric data, metallographic images Masks Mask R-CNN, 3D CNN Fine-grained region extraction
Defect prediction Process parameters, simulation data, multi-source industrial data Defect probability, quality parameters ANN, RF, data–physics fusion Process optimization and quality prediction
Data augmentation Real images, synthetic images, multimodal data Synthetic training samples GAN, diffusion, SMOTE Mitigate sample scarcity

7. Common Difficulties and Optimization Pathways

Across the tasks reviewed above, I identify three common difficulties: weak feature representation of casting defects, loss of small and multi-scale casting defects, and sample insufficiency with class imbalance. I now summarize the optimization pathways that have emerged in complex casting defect detection.

7.1 Weak Feature Enhancement

The most common difficulty in casting defect detection is that the features of casting defects are often not highly distinguishable. Whether it is fine cracks, pits, or sand holes in surface images, or porosity, inclusions, and shrinkage porosity in X-ray or DR images, these defect regions mostly have blurred boundaries, small grayscale differences, and obvious texture fluctuations. If the image preprocessing and feature extraction stages fail to fully capture defect information, subsequent processing cannot stably separate defect regions from the background. Therefore, how to enhance the distinguishability of defect regions and improve the model’s ability to express weak features has long been an important issue in the field of casting defect detection.

The root cause of the weak feature problem is that the distinction between casting defects and background is too small. On one hand, casting imaging is affected by scattering noise, quantization errors, and equipment imaging quality. On the other hand, complex internal structures of castings form numerous textures and grayscale variations in radiographic images. These background messages superimpose with defect features, further increasing recognition difficulty.

Casting images often contain a large amount of redundant features and irrelevant information, which directly affects the accuracy and reliability of casting defect detection and increases the risk of false positives and missed detections. One study first used grayscale transformation, bilateral filtering, and adaptive threshold segmentation to highlight defect regions, then extracted HOG features, LBP texture features, and invariant moment features to construct a full-information feature set. It then used the Relief algorithm to evaluate the weight of each feature and selected the top 10% sensitive features as input to an Adaboost-SVM model. Test results showed an average accuracy of 0.8033, accuracy variance of 0.0342, and missed report rate of 0.0666, better than using HOG, LBP, or invariant moment features alone in terms of accuracy and stability.

In X-ray and DR images, weak features often coexist with image noise, insufficient contrast, and blurred edges. To address low contrast and noise that make casting defects difficult to identify in aluminum casting radiographic images, one study used two mixed noise removal methods, LSM-NLR and WESNR, to enhance casting radiographic images in the GDX-ray dataset. Results showed that both methods made internal structures and defect regions clearer, with LSM-NLR achieving better enhancement. Another study proposed a hierarchical detection model using a two-level structure. It first extracted overall structural features via a general feature network (GFN), then used a subtle feature network (SFN) embedded with a self-attention guidance module (SGM) to focus on defect regions. The SGM computed long-range dependencies between positions within features to generate attention weights, making defect regions more prominent while suppressing background noise. The residual structure designed in the SFN protected defect edge details, and the model achieved 91.17% detection accuracy on the test set.

Although the methods for solving weak feature problems differ, the underlying idea is consistent: first improve the contrast between casting defects and background through denoising and contrast enhancement, then use feature selection or attention mechanisms to make the model focus on these enhanced regions while suppressing background interference. The common effect of these processes is to increase the distance between casting defects and background in the feature space. Therefore, in weak feature defect detection tasks, the primary constraint on performance lies not in the classifier or detection head but in whether the feature expression stage can provide sufficiently reliable discriminative basis for subsequent judgment.

7.2 Small Object and Multi-Scale Defect Preservation

Small casting defects such as porosity, inclusions, and microcracks occupy a very small pixel proportion, and their edge contours are very similar to background textures. After layer-by-layer downsampling in deep convolutional networks, spatial details decay rapidly, causing small objects to be lost in high-level feature extraction, with recall far lower than regular-sized casting defects. Therefore, how to improve detection capability for small casting defects while extracting semantic features in deep networks is key to improving performance.

To address small casting defect sizes in X-ray images, one study designed a C3CA module based on YOLOv5s6. This module uses coordinate attention to capture cross-channel, direction-aware, and positional information, allowing the model to better preserve defect position information when extracting local features. At the same time, multi-head self-attention was introduced into the backbone, and Focal-EIoU loss was used to enhance small object detection. The improved model achieved AP50 of 90.2% and F1 score of 87.8%.

In DR images of aluminum and magnesium alloy castings, complex structural backgrounds, random noise, low brightness, and insufficient contrast all interfere with small casting defect detection. One study introduced a CAA (Context Anchor Attention) mechanism into YOLOv8 to capture long-distance contextual information. It also added a P2 small object detection layer in the detection head, leveraging richer edge and texture information in shallow features to prevent tiny casting defects such as porosity and inclusions from being weakened in deep networks. Experimental results showed precision, recall, and mAP of 92.7%, 98.5%, and 92.4%, respectively, with detection speed up to 138 FPS.

For X-ray images where background textures are highly similar to tiny casting defects, one study designed a bidirectional small object detail enhancement structure called BiSDE. It added bidirectional cross-layer connections at the encoding end to enhance information flow between different levels, and used Hadamard products at the decoding end for pointwise fusion of multi-scale feature maps to restore spatial details of small objects as much as possible. In addition, it replaced traditional IoU-based losses with an NWD loss based on Wasserstein distance, making the model more tolerant to positional deviations. Results showed that this model surpassed existing models such as YOLOv8, FasterNet, and DETR in mAP, with about 5% mAP improvement over YOLOv8 and only about 3.9% FPS decrease.

Another study targeted tiny casting defects in CT images. Based on YOLOv5n, it added a small object detection layer and introduced CA attention and Triplet Attention mechanisms to better capture the position and spatial correlation of tiny casting defects. It also used data augmentation methods such as grayscale adjustment, noise addition, and multi-scale cropping to enhance model robustness to tiny objects under different imaging conditions. Results showed that the unmodified YOLOv5n had precision of 0.763 and recall of 0.733; after adding CA attention, these metrics improved to 0.844 and 0.832; with Triplet Attention, they reached 0.833 and 0.830.

In summary, existing enhancement methods for small casting defect detection essentially rebuild an information channel between deep semantic extraction and shallow detail preservation, so that tiny details that are easily diluted can bypass low-level loss and directly participate in final discrimination.

7.3 Sample Insufficiency and Class Imbalance

Sample insufficiency and class imbalance are common difficulties in research, affecting the entire process from data collection and model training to performance evaluation. Therefore, it is necessary to discuss them as independent difficult problems.

To address this issue, some studies start from the feature space and use oversampling strategies for data augmentation. One study collected production data from a sand casting complex casting enterprise, including 5,848 defect-free data records, while cold shut, porosity, sand hole, and shrinkage cavity defect data were only 274, 399, 359, and 148 records, respectively. The data volume gap between defect categories and defect-free data was large. Therefore, SMOTE was used to synthesize new minority class samples, expanding porosity, cold shut, sand hole, and shrinkage cavity defect samples to about 6,000 records each, building a relatively balanced training dataset. After data preprocessing, the defect prediction model accuracy improved to 97.91%. On this basis, the same team further applied the method to defect prediction for a 6DM cylinder block casting, effectively solving the serious shortage of porosity and sand hole samples, with prediction accuracy reaching 99.37%.

In summary, these methods for addressing sample insufficiency, whether in image space or feature space, use prior knowledge to fill data gaps. The difference lies in the source of the prior. The stronger the prior, the better the physical plausibility of generated samples, but the more limited the sample diversity. The weaker the prior, the richer the sample diversity, but the easier it is for the generator’s own bias to be learned as defect features. There is no optimal solution among different methods; it depends on the specific detection task’s tolerance for missed detections versus false positives. Table 3 summarizes common difficulties and major optimization pathways in casting defect detection.

Common Difficulty Main Causes Typical Impact Main Optimization Pathways Common Methods/Techniques
Weak feature expression of casting defects Small grayscale difference between casting defects and background, blurred boundaries, imaging noise and structural texture interference Missed detections and false positives; model struggles to stably extract effective defect features Image enhancement, feature selection, background suppression, attention modeling Bilateral filtering, adaptive thresholding, Relief feature selection, self-attention
Small objects and multi-scale casting defects easily lost Tiny porosity, inclusions, cracks occupy few pixels; multi-layer downsampling causes spatial detail decay Decreased detection accuracy for small casting defects; increased bounding box localization deviation Shallow feature preservation, multi-scale fusion, small object detection head, bounding box loss optimization FPN/PAN, multi-scale feature fusion, P2 detection layer, NWD loss, coordinate attention
Complex background and low contrast interference Casting structural edges, texture variations, noise, reflections, and occlusions superimpose with defect features Difficulty distinguishing defect regions from background; decreased model generalization Structural prior introduction, context modeling, attention enhancement, feature reconstruction 3D model-assisted differencing, global attention, supervised enhancement, knowledge distillation
Sample insufficiency and class imbalance Low incidence of industrial casting defects; normal samples far outnumber defect samples Model biased toward majority class; decreased recall for minority class casting defects Oversampling, data synthesis, defect image generation, task-driven evaluation SMOTE, Diamond-Square simulation, GAN generation, synthetic sample validation

8. Mathematical Formulations of Key Metrics and Losses

To make the review more rigorous, I present the key mathematical definitions used in casting defect detection algorithms. These formulas are widely adopted in recognition, localization, segmentation, and prediction tasks.

Precision, recall, and F1 score are fundamental for evaluating classification and detection of casting defects:

$$ Precision = \frac{TP}{TP + FP} $$

$$ Recall = \frac{TP}{TP + FN} $$

$$ F1 = \frac{2 \cdot Precision \cdot Recall}{Precision + Recall} $$

Intersection over Union (IoU) measures the overlap between predicted and ground-truth bounding boxes or masks:

$$ IoU = \frac{Area(A \cap B)}{Area(A \cup B)} $$

Mean Average Precision (mAP) aggregates precision across classes and IoU thresholds:

$$ mAP = \frac{1}{N} \sum_{i=1}^{N} AP_i $$

For segmentation tasks, the Dice coefficient is often used:

$$ Dice = \frac{2 |X \cap Y|}{|X| + |Y|} $$

Focal Loss addresses class imbalance in casting defect detection:

$$ L_{Focal} = -\alpha_t (1 – p_t)^\gamma \log(p_t) $$

EIoU Loss improves bounding box regression for small casting defects:

$$ L_{EIoU} = 1 – IoU + \frac{\rho^2(b, b^{gt})}{c^2} + \frac{\rho^2(w, w^{gt})}{C_w^2} + \frac{\rho^2(h, h^{gt})}{C_h^2} $$

NWD Loss based on Wasserstein distance enhances tolerance to positional deviations of tiny casting defects:

$$ L_{NWD} = \exp\left(-\frac{W_2^2(\mathcal{N}_p, \mathcal{N}_g)}{C}\right) $$

These formulations provide a common language for comparing different algorithms and for designing task-specific optimization objectives for casting defect detection.

9. Future Perspectives

With the development of intelligent manufacturing and the industrial internet, casting production is gradually evolving toward digitalization, networking, and intelligence. Although current research has made progress in deep model design, multi-task expansion, and engineering adaptation, complex industrial scenarios place higher demands on detection accuracy, real-time performance, and generalization ability. The existing technical system still needs further optimization. Based on my review of the current research status and development trends, I believe the following directions are worth breakthrough in the field of casting defect detection.

(1) In terms of data, research focus will shift away from costly manual annotation toward self-supervised or contrastive learning pre-training using massive unlabeled or weakly labeled multimodal industrial data. On the other hand, high-quality, balanced training datasets will be constructed so that models can learn general representations of casting structures and casting defects, reducing dependence on annotated data for downstream specific detection tasks.

(2) Defect detection algorithms will focus on multi-task collaborative learning and physical mechanism fusion. Unified multi-task network architectures will be built to share multimodal feature encoding, allowing localization, segmentation, and quantitative rating tasks to reinforce each other and improve overall efficiency and accuracy.

(3) GANs have already been used for casting defect sample generation and data augmentation. In the future, diffusion models, visual generative large models, and multimodal generative models can further optimize the quality of defect sample generation and enable controllable generation of casting defect morphology, size, position, and category.

(4) Rather than limiting efforts to model lightweighting, deep collaborative design of algorithms, specialized hardware, and compilation tools should be advanced simultaneously, so that high-performance detection models can achieve optimal energy efficiency on resource-constrained industrial edge devices. This will lower the threshold and cycle for deploying advanced detection technologies and meet the strict real-time and stability requirements of high-speed production lines.

10. Concluding Remarks

In this review, I have systematically examined the research progress of casting defect detection algorithms from five perspectives: recognition and classification, localization and detection, segmentation and quantitative evaluation, prediction, and image generation. I have shown that convolutional neural networks and object detection frameworks have become mainstream for localization and classification of casting defects. Lightweight designs and attention mechanisms are driving models toward industrial online scenarios. Defect segmentation is expanding into 3D voxel space to support mechanical property inversion and quality rating. Defect prediction has evolved from BP networks relying solely on process parameters to data–physics fusion-driven multi-target prediction frameworks. Generative models such as GANs have demonstrated practical effectiveness in defect image synthesis and data augmentation, but the physical plausibility and evaluation standards of generated samples remain open issues. I have also summarized common challenges in weak feature enhancement, small object detection, sample imbalance, and complex background interference, along with corresponding optimization pathways. Looking forward, multi-task collaborative modeling, integration of generative artificial intelligence, and intelligent detection system deployment for industrial scenarios represent key directions worthy of breakthrough. The ultimate goal is not only to detect casting defects but also to provide reliable evidence for quality judgment, defect tracing, and process optimization, thereby ensuring the service reliability and safety of cast components.

Scroll to Top