Defect Extraction in Sand Foundry Castings Based on Thresholding Segmentation

In the modern manufacturing industry, sand foundry defect detection plays a critical role in ensuring product quality and safety. Castings produced by sand casting methods often contain internal defects such as air holes, shrinkage cavities, and foreign objects, which directly affect the mechanical properties and service life of components. X-ray inspection combined with digital image processing provides an effective way to detect these defects automatically and objectively. In my master’s thesis, I focused on the problem of extracting typical sand foundry defects from X-ray images using thresholding segmentation techniques. This article presents the details of my research, including the methods, experimental results, and comparisons with existing approaches.

1. Introduction

The production of castings involves complex processes such as melting, pouring, solidification, and cooling. Due to the inherent limitations of sand casting technology, various internal defects may appear in the final product. These defects, including air holes, shrinkage cavities, and non-metallic inclusions, can significantly weaken the structural integrity of castings. Therefore, reliable inspection methods are essential. X-ray inspection is one of the most widely used nondestructive testing (NDT) techniques for sand foundry defect detection because it provides direct and intuitive images of internal structures. Traditional film radiography has several drawbacks: high cost, time-consuming processing, and subjective interpretation by human inspectors. With the rapid development of digital detectors and image processing algorithms, digital X-ray imaging systems have become increasingly popular. Such systems convert X-ray intensity into digital signals, allowing computer-based analysis. In the entire image processing pipeline, defect segmentation is the most critical step. The accuracy of subsequent feature extraction and classification heavily depends on the quality of segmentation.

However, X-ray images of sand foundry castings often suffer from low contrast, blurred edges, heavy noise, and uneven background illumination. These characteristics make it difficult to directly apply general-purpose segmentation algorithms. To address these challenges, I propose two thresholding methods based on the concept of a bound histogram (also called attribute histogram). The first method is a maximum fuzzy exponential entropy thresholding approach using a one-dimensional bound histogram. The second method is a maximum correlation criterion thresholding approach using a two-dimensional bound histogram with a fast recursive implementation. Both methods exploit prior knowledge to construct an attribute set, which removes irrelevant or interfering components from the original histogram. This enhances robustness and reduces computational complexity.

2. Background and Challenges in Sand Foundry Defect Images

In my research, I focused on three common types of sand foundry defects: air holes (gas porosity), shrinkage cavities, and foreign objects (inclusions). Air holes appear as circular bright spots in X-ray images, with slightly brighter centers. Shrinkage cavities typically exhibit irregular shapes with blurred boundaries. Foreign objects can be either brighter or darker than the background, depending on their material composition. Figure 1 shows a typical engine cylinder block, which is a common sand foundry product. The presence of internal defects can lead to catastrophic failures in automotive and aerospace applications, making reliable detection extremely important.

The X-ray imaging process introduces several degradations. First, the dynamic range of the detector and the scattering of X-rays reduce contrast. Second, the finite focal spot size and the geometric unsharpness blur the edges of defects. Third, the background intensity often varies smoothly due to variations in the thickness of the casting wall. These factors cause the gray-level histogram of a defect image to be unimodal or weakly bimodal, making simple thresholding methods ineffective. In addition, the presence of false defects such as background clouds, scratches, or density variations further complicates the segmentation task.

3. Attribute Histogram and Its Properties

To improve the segmentation of sand foundry defect images, I adopted the concept of an attribute histogram, originally proposed by Guo et al. An attribute histogram is a constrained histogram that only considers pixels satisfying a certain property. This property is defined by an attribute set, which is constructed based on prior knowledge of the specific problem. For example, if we know that defects of interest have gray levels within a certain range, we can exclude pixels outside that range. This operation eliminates interfering components and irrelevant information, making the histogram simpler and more reliable for threshold selection. In general, a one-dimensional attribute histogram is defined as:

$$ p_Q(k) = \frac{n_Q(k)}{N_Q}, \quad k=L_1, L_1+1, \ldots, L_2 $$

where $n_Q(k)$ is the number of pixels with gray level $k$ in the attribute set $Q$, and $N_Q$ is the total number of pixels in $Q$. The traditional histogram is a special case of the attribute histogram when $Q$ contains all pixels. For sand foundry defect images, I constructed attribute sets based on the results of a preliminary segmentation using a classical threshold method such as Otsu’s method. For air-hole and shrinkage defects, which appear as bright regions, the attribute set is defined as:

$$ Q_1 = \{(x,y) : s < g(x,y) \le L-1\} $$

where $s$ is the Otsu threshold and $g(x,y)$ is the gray level at pixel $(x,y)$. For foreign-object defects, which appear darker than the background, the attribute set is:

$$ Q_2 = \{(x,y) : 0 \le g(x,y) \le s\} $$

By applying these attribute sets, the resulting bound histograms show a much clearer separation between defect and background, as demonstrated in my experiments. Moreover, the reduced number of intensity levels speeds up the search for the optimal threshold.

4. Proposed Thresholding Methods

4.1 Maximum Fuzzy Exponential Entropy Thresholding Based on Attribute Histogram (MFEE-BH)

The Shannon entropy is widely used in thresholding, but it involves logarithmic operations that are computationally expensive and undefined at probability zero. To overcome this limitation, Pal and Pal introduced the exponential entropy. For a probability distribution $p_i$, the exponential entropy is defined as:

$$ H = \sum_{i} p_i \exp(1-p_i) $$

This definition is finite for all $p_i \in (0,1)$ and provides faster computation than entropy with logarithms. In my first method, I integrate exponential entropy with fuzzy set theory to handle the ambiguity present in low-contrast X-ray images. The proposed algorithm works on the one-dimensional attribute histogram. Let the gray level range in the attribute set be $\{L_1, L_1+1, \ldots, L_2\}$. I divide the pixels into two fuzzy classes: dark (background) and bright (defect). The membership functions are defined using Z-function and S-function:

$$ \mu_d(k;a,b) = \begin{cases} 1 & k \le a \\ 1 – 2\left(\frac{k-a}{b-a}\right)^2 & a < k \le \frac{a+b}{2} \\ 2\left(\frac{k-b}{b-a}\right)^2 & \frac{a+b}{2} < k \le b \\ 0 & k > b \end{cases} $$

$$ \mu_b(k;a,b) = 1 – \mu_d(k;a,b) $$

where $a$ and $b$ are parameters with $L_1 \le a < b \le L_2$. For a given threshold candidate, the probabilities of the dark and bright classes are calculated as:

$$ P_d = \sum_{k=L_1}^{L_2} p_Q(k) \mu_d(k;a,b), \quad P_b = \sum_{k=L_1}^{L_2} p_Q(k) \mu_b(k;a,b) $$

Then the fuzzy exponential entropies of the two classes are:

$$ H_d = \sum_{k=L_1}^{L_2} \frac{p_Q(k) \mu_d(k;a,b)}{P_d} \exp\left(1 – \frac{p_Q(k) \mu_d(k;a,b)}{P_d}\right) $$

$$ H_b = \sum_{k=L_1}^{L_2} \frac{p_Q(k) \mu_b(k;a,b)}{P_b} \exp\left(1 – \frac{p_Q(k) \mu_b(k;a,b)}{P_b}\right) $$

The total fuzzy exponential entropy is $H(a,b) = H_d + H_b$. The optimal parameters $a^*$ and $b^*$ are obtained by maximizing $H(a,b)$:

$$ (a^*, b^*) = \arg \max_{a,b} H(a,b) $$

Finally, the optimal threshold $t$ is computed as the point where the two membership functions intersect:

$$ t = \frac{a^* + b^*}{2} $$

This method is applied to the attribute histogram, which eliminates background noise and irrelevant peaks. In practice, I use a nested loop over $a$ and $b$ to find the maximum entropy. Because the attribute histogram has a much narrower range than the original histogram, the search is very fast.

4.2 Maximum Correlation Criterion Thresholding Based on Two-Dimensional Attribute Histogram (MCC-TBH)

One-dimensional thresholding methods consider only the gray-level information of each pixel, ignoring the spatial correlation between neighboring pixels. To incorporate spatial context, I also investigated a two-dimensional approach. The two-dimensional histogram is constructed by considering both the gray value of a pixel and the average gray value of its local neighborhood (e.g., $3 \times 3$). This provides better discrimination when the image contains noise or when the defect boundaries are blurred. In my method, I use the concept of maximum correlation criterion, which was proposed by Yen et al. as an alternative to entropy. For a discrete probability distribution $p_i$, the correlation measure is defined as:

$$ C = -\ln \left( \sum_{i} p_i^2 \right) $$

For the two-dimensional histogram with probabilities $p(i,j)$, the correlation becomes:

$$ C = -\ln \left( \sum_{i} \sum_{j} p^2(i,j) \right) $$

Let the two-dimensional attribute histogram be defined only for pixels in an attribute set $Q$, with gray level range $[L_1,L_2]$ and neighborhood average range $[L_3,L_4]$. A threshold vector $(s,t)$ divides this histogram into four regions: A (background) and B (defect), which are diagonally opposite, and C and D which represent noise and edges. The probabilities of A and B are:

$$ P_A(s,t) = \sum_{i=L_1}^{s} \sum_{j=L_3}^{t} p_Q(i,j), \quad P_B(s,t) = 1 – P_A(s,t) $$

After normalizing the probabilities within each class, the correlation measures for A and B are derived as:

$$ C_A(s,t) = -\ln \left( \sum_{i=L_1}^{s} \sum_{j=L_3}^{t} \left( \frac{p_Q(i,j)}{P_A(s,t)} \right)^2 \right) $$

$$ C_B(s,t) = -\ln \left( \sum_{i=s+1}^{L_2} \sum_{j=t+1}^{L_4} \left( \frac{p_Q(i,j)}{P_B(s,t)} \right)^2 \right) $$

The total correlation is $C(s,t) = C_A + C_B$. The optimal threshold vector is obtained by maximizing $C(s,t)$:

$$ (s^*, t^*) = \arg \max_{s,t} C(s,t) $$

Direct computation of $C(s,t)$ for every possible $(s,t)$ is computationally heavy. Therefore, I developed a recursive algorithm that significantly reduces the computation time. Let me define:

$$ G_A(s,t) = \sum_{i=L_1}^{s} \sum_{j=L_3}^{t} p_Q^2(i,j) $$

Then $C_A$ can be expressed as:

$$ C_A(s,t) = -\ln G_A(s,t) + 2 \ln P_A(s,t) $$

Similarly, $C_B$ can be expressed using the total sum of squares $G_{total} = \sum_{i=L_1}^{L_2} \sum_{j=L_3}^{L_4} p_Q^2(i,j)$ and $G_A(s,t)$:

$$ C_B(s,t) = -\ln \left( \frac{G_{total} – G_A(s,t)}{P_B^2(s,t)} \right) = -\ln \left( G_{total} – G_A(s,t) \right) + 2 \ln \left( 1 – P_A(s,t) \right) $$

Thus the total correlation becomes:

$$ C(s,t) = -\ln G_A(s,t) + 2 \ln P_A(s,t) – \ln \left( G_{total} – G_A(s,t) \right) + 2 \ln \left( 1 – P_A(s,t) \right) $$

Using dynamic programming, $P_A(s,t)$ and $G_A(s,t)$ can be updated incrementally. The initial values are:

$$ P_A(L_1,L_3) = p_Q(L_1,L_3), \quad G_A(L_1,L_3) = p_Q^2(L_1,L_3) $$

Then for the first row and column:

$$ P_A(L_1, t+1) = P_A(L_1, t) + p_Q(L_1, t+1) $$
$$ G_A(L_1, t+1) = G_A(L_1, t) + p_Q^2(L_1, t+1) $$
$$ P_A(s+1, L_3) = P_A(s, L_3) + p_Q(s+1, L_3) $$
$$ G_A(s+1, L_3) = G_A(s, L_3) + p_Q^2(s+1, L_3) $$

For the rest:

$$ P_A(s+1, t+1) = P_A(s, t+1) + P_A(s+1, t) – P_A(s, t) + p_Q(s+1, t+1) $$
$$ G_A(s+1, t+1) = G_A(s, t+1) + G_A(s+1, t) – G_A(s, t) + p_Q^2(s+1, t+1) $$

This recursion avoids re-summing from the beginning for each threshold. In my experiments, the recursive MCC-TBH algorithm is almost ten times faster than the exhaustive method, making it suitable for real-time sand foundry defect detection.

5. Experimental Results and Analysis

5.1 Experimental Setup

I tested the proposed methods on a set of X-ray images of sand foundry castings. The images contain three types of defects: air holes, shrinkage cavities, and foreign objects. Each image has a size of $200 \times 200$ pixels with 256 gray levels. I compared the proposed methods (MFEE-BH and MCC-TBH) with four existing thresholding methods: Otsu’s method, maximum entropy criterion (MEC), maximum fuzzy exponential entropy on the traditional histogram (MFEE), and maximum correlation criterion on the traditional two-dimensional histogram (MCC-T). For MFEE-BH, Otsu was used to construct the attribute set; for MCC-TBH, MEC was used because it provided a better initial threshold for the two-dimensional case. All algorithms were implemented in MATLAB 7.0 on a Pentium IV 3.06 GHz computer with 512 MB RAM.

5.2 Qualitative Comparison

Figures 2 to 4 show the segmentation results for representative air-hole, shrinkage cavity, and foreign-object images, respectively. (Note: the actual images are not reproduced here, but the qualitative conclusions are described.) For the air-hole images, the background contains cloud-like false defects. Otsu, MEC, MFEE, and MCC-T all failed to accurately extract the air holes; MCC-T produced the worst results with many false positives. In contrast, MFEE-BH and MCC-TBH clearly separated the true defects from the background. For shrinkage cavities, which have blurred and dispersed edges, the proposed methods again gave much cleaner segmentations. The results of MCC-TBH were particularly good, preserving the intricate boundaries of the shrinkage cavities. For foreign-object images, the background is brighter than the defects. Otsu performed reasonably on some images but produced large errors on others. MEC, MFEE, and MCC-T extracted many false scratches or failed to preserve the exact shape. The proposed methods consistently delivered clear, noise-free binary images with accurate defect boundaries.

5.3 Quantitative Evaluation

To provide a quantitative comparison, I recorded the threshold values selected by each method. Table 1 lists the thresholds for nine test images. Note that for MFEE-BH, the reported threshold $t$ is the final threshold computed from $a^*$ and $b^*$. For MCC-TBH, the threshold vector $(s,t)$ is given. The table clearly shows that the proposed methods often choose thresholds that are quite different from those of the classical methods, reflecting their ability to suppress background interferences.

Table 1: Selected thresholds for different methods
Image Otsu MFEE a* b* t (MFEE-BH) MEC MCC-T (s,t) MCC-TBH
Air1 138 121 138 224 181 114 [89,89] [193,202]
Air2 139 141 139 236 188 125 [114,114] [218,195]
Air3 87 133 87 211 149 132 [66,68] [197,200]
Shrinkage1 126 138 126 238 182 125 [109,109] [212,176]
Shrinkage2 106 148 108 229 169 131 [125,125] [175,208]
Shrinkage3 128 158 128 234 181 130 [130,127] [178,198]
Foreign1 160 204 44 157 101 205 [223,209] [94,94]
Foreign2 220 174 137 212 175 183 [211,174] [87,149]
Foreign3 141 202 41 138 90 200 [211,200] [114,107]

Table 2 shows the computation times (in seconds) for the two proposed methods and their counterparts. It is evident that the attribute-histogram-based methods are significantly faster than the traditional-histogram-based methods. For example, MFEE-BH is about ten times faster than MFEE. Similarly, MCC-TBH with the recursive algorithm is more than twenty times faster than the traditional MCC-T with exhaustive search, and even faster than the non-recursive version. These speed improvements are crucial for online sand foundry defect detection, where real-time processing is required.

Table 2: Computation time (seconds) for different methods
Image MFEE MFEE-BH MCC-T (exhaustive) MCC-T (recursive) MCC-TBH (exhaustive) MCC-TBH (recursive)
Air1 4.297 0.290 27.484 0.109 1.587 0.094
Air2 2.969 0.532 28.188 0.141 1.921 0.078
Air3 3.312 0.907 27.984 0.141 1.500 0.110
Shrinkage1 2.809 0.539 34.406 0.141 3.406 0.109
Shrinkage2 3.656 0.781 33.609 0.204 2.203 0.140
Shrinkage3 3.167 0.464 31.829 0.172 1.969 0.109
Foreign1 3.143 0.458 31.820 0.375 6.547 0.078
Foreign2 2.625 0.953 29.547 0.140 3.343 0.109
Foreign3 3.119 0.353 27.078 0.125 4.485 0.110

5.4 Discussion

The experimental results demonstrate the superiority of the proposed methods for sand foundry defect extraction. The key factors are: (1) the attribute histogram effectively removes irrelevant intensity levels and reduces the interference from the inhomogeneous background; (2) the fuzzy exponential entropy provides a robust criterion under uncertainty and is computationally efficient; (3) the two-dimensional correlation criterion takes spatial information into account, which helps to preserve the actual defect shape and suppress noise; and (4) the recursive implementation makes the two-dimensional method fast enough for practical use. However, I also observed that MFEE-BH tends to be more sensitive than MCC-TBH for very small defect regions, while MCC-TBH sometimes merges close but separate small defects. Thus, the choice between the two methods may depend on the specific inspection requirement: MFEE-BH is preferred when high sensitivity is needed (e.g., for small foreign objects), while MCC-TBH is more suitable when a clean background is essential (e.g., for larger shrinkage cavities).

6. Conclusion

In this paper, I presented two thresholding segmentation methods for the automated extraction of sand foundry defects from X-ray images. The first method combines fuzzy membership functions with exponential entropy and uses a one-dimensional attribute histogram to improve robustness. The second method extends the maximum correlation criterion to a two-dimensional attribute histogram and incorporates a fast recursive algorithm. Extensive experiments on air holes, shrinkage cavities, and foreign objects verified that both methods outperform classical techniques such as Otsu, maximum entropy, and their one-dimensional counterparts. The proposed methods yield accurate defect boundaries, effectively suppress background artifacts, and operate at high speed. Therefore, they are well-suited for real-time X-ray inspection systems in sand foundry manufacturing. In future work, I plan to integrate these segmentation methods into a complete automatic inspection system with feature extraction and classification modules for quantitative defect evaluation.

I sincerely hope that these contributions will benefit the field of nondestructive testing and assist in improving the quality control of sand foundry products.

Scroll to Top