In the realm of manufacturing, casting stands as one of the most fundamental processes for product fabrication, with cast components finding extensive applications across diverse industries. However, casting defects are an inevitable occurrence during the casting process, severely impacting product performance and reliability. Therefore, in this study, we investigate a rapid method for judging and classifying casting defects by integrating digital image technology with neural network techniques. Specifically, we first explore the application of image signal processing methods to digitally process casting defect images collected via CCD cameras, extracting multiple characteristic parameters from these casting defects images. Through data sample processing, we obtain a substantial number of high-quality casting defect images suitable for analysis. Subsequently, we employ the principles of BP neural networks to classify and recognize the acquired casting defect images. After network training, we achieve a BP neural network with effective classification capabilities. The primary research methodology is illustrated below, emphasizing the systematic approach to handling casting defects.

Casting defects manifest in various forms due to influences from equipment, process, raw materials, and environmental factors during production. Among these, pinholes, cracks, and inclusions are three critical types of casting defects that significantly compromise component integrity. The primary causes for these casting defects are as follows. Pinholes arise when gases dissolved in the molten metal fail to fully escape before solidification, as gas solubility drops sharply with decreasing temperature during cooling. The presence of pinholes drastically reduces the strength of castings. Cracks often result from non-uniform cooling rates in specific sections of the casting, induced by mold walls or cores, leading to excessive stress between different regions near the solidification temperature. These casting defects, particularly cracks, severely diminish strength and ductility, while also promoting corrosion at crack sites. Inclusions stem from two sources: chemical reactions within the metal or between the metal and mold during pouring and solidification, and impurities dislodged from equipment or containers. Inclusion casting defects markedly lower the fatigue resistance of castings. Our focus is on leveraging digital image technology to process images of these casting defects, yielding优质 samples for BP neural network training.
To analyze and recognize casting defects, we first require numerous high-quality digital images of casting defects. We capture these images using a CCD camera under darkroom conditions with cold light illumination, employing an HP-480 color video image capture card for acquisition. The obtained raw images contain substantial noise and cannot be directly analyzed; thus, further algorithmic processing is essential. The key steps in digital image processing for casting defects are outlined below.
Given that noise in CCD lens imaging often follows a normal distribution, Gaussian filtering proves effective for image denoising. Gaussian filtering is a low-pass filtering method commonly used for image smoothing. The two-dimensional form of the Gaussian filter mask is expressed as:
$$ G(x,y) = \frac{1}{2\pi\sigma} \exp\left(-\frac{x^2 + y^2}{\sigma^2}\right) $$
where \(x\) and \(y\) represent distances from the pixel point, and \(\sigma\) is the distribution parameter. The shape of the Gaussian filter curve can be adjusted by altering \(\sigma\). After Gaussian filtering, image quality is significantly enhanced for casting defects analysis.
To increase image contrast and effectively distinguish white casting regions from black backgrounds, we apply a fuzzy enhancement algorithm to enhance edge details. The fuzzy operator \(k_{r}^{mn}\) is defined as:
$$ h_{t}^{mn} =
\begin{cases}
2^{(t-1)}(h_{mn})^r & \text{for } 0 \leq h_{mn} \leq 0.5 \\
1 – 2^{(t-1)}(1 – h_{mn})^r & \text{for } 0.5 \leq h_{mn} \leq 1
\end{cases} $$
where \(t\) denotes the number of grayscale fuzzy transformations, and experimental findings indicate optimal enhancement at \(r=4\). Here, \(h_{mn}\) represents the membership degree of image pixels. This operator amplifies grayscale values for pixels with membership above 0.5 and reduces them for those below 0.5. After \(t\) iterations of fuzzy enhancement, image quality is markedly improved for casting defects identification.
Threshold segmentation is a prevalent technique in image segmentation, utilizing grayscale histograms to determine optimal thresholds for dividing images into two regions of different grayscale levels. By selecting an optimal threshold, target regions can be separated from backgrounds, resulting in binary images. For casting defect images, the Laplacian operator is employed for boundary feature extraction due to its high定位 accuracy and good edge continuity, making it suitable for processing casting defects images. The sequential steps of Gaussian filtering, fuzzy enhancement, threshold segmentation, and Laplacian edge detection yield processed images ready for feature extraction, as demonstrated in the methodology for handling casting defects.
Machine recognition of casting defects necessitates descriptive features. Based on the image characteristics of cracks, pinholes, and inclusions, we select four feature parameters to describe these casting defects: aspect ratio, perimeter, elongation, and circularity. By examining the values of these parameters across different casting defects, we aim to achieve accurate classification. The aspect ratio is defined as the ratio of the major axis length to the minor axis length of the defect image. Elongation and circularity are calculated using the following formulas:
$$ T = \frac{a \times b}{S} $$
where \(S\) is the area of the target region, and \(a\) and \(b\) are the width and length of the minimum bounding rectangle enclosing the target region. This parameter helps distinguish approximately circular targets from elongated ones in casting defects.
$$ C = \frac{4\pi S}{L^2} $$
where \(S\) is the defect area, and \(L\) is the perimeter. Circularity \(C\) describes how closely the shape resembles a circle, with higher values indicating greater similarity to a circle (e.g., \(C=1\) for a perfect circle). These parameters are crucial for quantifying casting defects.
BP neural networks, or backpropagation neural networks, are improved neural networks capable of approximating any continuous function with arbitrary precision. They are well-suited for prediction and classification tasks. In this study, we utilize a BP neural network with casting defect images as the研究对象, using aspect ratio, perimeter, equivalent area, and circularity as judgment indicators to establish criteria for identifying casting defects types. From hundreds of digital images of casting defects collected via the described method, we select 12 sets as samples for BP network research. Using MATLAB, we compute the four feature parameters for each image, deriving the relationship between casting defects types and feature parameters, as summarized in the table below.
| Sample ID | Defect Type | Perimeter (mm) | Aspect Ratio | Elongation | Circularity |
|---|---|---|---|---|---|
| 1 | Pinhole | 1.2 | 1.12 | 0.86 | 0.91 |
| 2 | Crack | 4.2 | 3.2 | 0.12 | 0.081 |
| 3 | Inclusion | 3.2 | 1.63 | 0.51 | 0.53 |
| 4 | Pinhole | 1.1 | 1.16 | 0.82 | 0.92 |
| 5 | Crack | 4.8 | 2.88 | 0.14 | 0.12 |
| 6 | Inclusion | 2.9 | 1.75 | 0.44 | 0.58 |
| 7 | Crack | 5.1 | 3.54 | 0.75 | 0.132 |
| 8 | Inclusion | 2.8 | 2.56 | 0.41 | 0.48 |
| 9 | Pinhole | 1.3 | 1.14 | 0.83 | 0.88 |
| 10 | Crack | 3.7 | 3.34 | 0.09 | 0.57 |
| 11 | Pinhole | 1.5 | 1.15 | 0.84 | 0.952 |
| 12 | Inclusion | 2.9 | 1.68 | 0.45 | 0.56 |
We define the input and output sample data as follows. For input samples, we randomly select 8 sets (IDs: 1, 4, 5, 6, 8, 9, 11, 12) from the 12 groups, normalize the data, and input them into MATLAB. The output is encoded as a three-dimensional vector, with expected output vectors defined in the table below, representing different casting defects states.
| Class ID | Casting Defects State | Output Vector |
|---|---|---|
| 1 | Pinhole | [1 0 0] |
| 2 | Crack | [0 1 0] |
| 3 | Inclusion | [0 0 1] |
We construct a BP neural network with a single hidden layer. Given the input unit count of 4 (for the four feature parameters) and output unit count of 3 (for the three defect classes), the hidden layer node number is chosen based on empirical formulas, typically ranging from 3 to 12. Using a trial-and-error method, we plot the relationship between hidden layer nodes and mean squared error (MSE), finding the minimum MSE of 48 at 6 hidden nodes. Thus, we确定 the hidden layer node count as 6. The network structure and parameters are configured in MATLAB, with key transfer functions being ‘logsig’ and ‘newrb’, focusing on classifying casting defects.
We train the BP neural network using the input and output sample vectors in MATLAB, setting the desired error to \(1 \times 10^{-5}\). During training, the error reduction is monitored, and after 23 iterations, the network converges to the satisfactory error limit, indicating effective learning for casting defects recognition. Subsequently, we test the trained network with all 12 samples to evaluate its diagnostic performance. The normalized data from Table 1 are input into the network, and the output results are compiled, as shown in the table below. The network demonstrates good accuracy in judging casting defects types, though some samples (e.g., IDs 4 and 8) show misclassifications. To enhance accuracy, these samples can be incorporated into the training set for retraining, refining the network’s ability to handle casting defects.
| Sample ID | Actual State | Diagnostic Data | Diagnosed State | Result |
|---|---|---|---|---|
| 1 | Pinhole | [1.101, 0.032, -0.126] | Pinhole | Correct |
| 2 | Crack | [0.024, 0.981, 0.103] | Crack | Correct |
| 3 | Inclusion | [0.013, 0.184, 1.121] | Inclusion | Correct |
| 4 | Pinhole | [0.321, 0.031, 0.912] | Inclusion | Incorrect |
| 5 | Crack | [-0.062, 1.122, -0.041] | Crack | Correct |
| 6 | Inclusion | [0.031, -0.121, 1.210] | Inclusion | Correct |
| 7 | Crack | [0.012, 0.951, -0.103] | Crack | Correct |
| 8 | Inclusion | [0.922, 0.441, -0.031] | Pinhole | Incorrect |
| 9 | Pinhole | [1.010, 0.113, -0.143] | Pinhole | Correct |
| 10 | Crack | [0.132, 1.042, 0.131] | Crack | Correct |
| 11 | Pinhole | [0.921, 0.123, 0.032] | Pinhole | Correct |
| 12 | Inclusion | [0.024, 0.982, 0.031] | Inclusion | Correct |
To validate the generalization capability of the neural network model, we expand the training and validation sample sizes, observing changes in classification accuracy for casting defects. As shown in the table below, the correct judgment rate correlates with the proportion of training samples to validation samples, increasing as this ratio rises. Even with a sample size of 200, the network maintains a high accuracy of 96%, underscoring its reliability in identifying casting defects states.
| Training Sample Size | Validation Sample Size | Errors | Accuracy (%) |
|---|---|---|---|
| 10 | 20 | 3 | 85 |
| 20 | 50 | 4 | 92 |
| 50 | 100 | 6 | 94 |
| 100 | 200 | 7 | 96.5 |
In conclusion, casting is a vital manufacturing technique, and the quality of castings directly influences the safety and performance of final products. This study explores the integration of BP neural networks and digital image processing to analyze casting defect images. By leveraging characteristic parameters such as perimeter, aspect ratio, elongation, and circularity, we achieve accurate classification of different casting defects, addressing practical challenges in casting production. The research outcomes can serve as a foundation for real-time online diagnosis systems for casting defects, offering substantial practical value. Future work may involve refining the image processing algorithms, expanding the dataset to include more varied casting defects, and optimizing the neural network architecture for even higher accuracy in detecting casting defects. Ultimately, the continuous improvement of such methodologies will contribute to enhanced quality control in casting industries, minimizing the impact of casting defects on product reliability.
Throughout this investigation, we emphasize the importance of systematic approaches in handling casting defects, from image acquisition to neural network training. The use of Gaussian filtering, fuzzy enhancement, and threshold segmentation ensures that casting defect images are preprocessed effectively, while BP neural networks provide a robust framework for classification. By repeatedly focusing on casting defects, we highlight their significance in manufacturing contexts. The formulas and tables presented herein encapsulate key technical aspects, facilitating reproducibility and further research. As casting technologies evolve, so too must the methods for inspecting and mitigating casting defects, ensuring that cast components meet ever-higher standards of excellence. This work underscores the potential of combining traditional image processing with advanced machine learning to tackle persistent issues like casting defects, paving the way for more automated and reliable quality assurance in foundry operations.
