Sand Foundry Defect Extraction via Thresholding Segmentation

As a researcher in industrial inspection, I have devoted significant effort to developing robust methods for extracting internal defects in sand foundry defects. The manufacturing of castings is a complex process, and unavoidable imperfections in the production chain often lead to defective products. These defects, such as air holes, shrinkage cavities, and foreign inclusions, can severely compromise the mechanical integrity of the final component. Therefore, reliable nondestructive testing is essential. In this work, I focus on the application of X-ray imaging combined with digital image processing to automatically detect these typical defects. The central challenge lies in the fact that X-ray images of castings suffer from low contrast, blurred edges, and significant background noise. To address these issues, I propose two novel thresholding segmentation methods based on the concept of attribute histograms. The first method utilizes a fuzzy exponential entropy criterion, while the second employs a maximal correlation criterion on a two-dimensional attribute histogram. Through extensive experiments, I demonstrate that both methods achieve accurate and rapid extraction of sand foundry defects, outperforming classical thresholding techniques in both segmentation quality and computational efficiency.

X-ray inspection has long been a standard tool for evaluating the internal quality of castings. Traditional film-based radiography, although reliable, is labor-intensive and difficult to automate. With advancements in digital detector technology, real-time X-ray imaging now provides high-resolution digital images that can be processed automatically. The goal of my research is to create a fully automated pipeline that eliminates the subjectivity of human inspectors and enables consistent, quantitative evaluation. A typical digital X-ray inspection system consists of an X-ray source, a conversion screen, a CCD camera, and an image processing unit. The resulting grayscale image carries information about the internal structure of the casting, where regions with defects exhibit distinct intensity variations. However, these variations are often subtle, and the images contain noise and uneven illumination, making defect extraction a nontrivial task. To this end, I have developed segmentation algorithms that exploit both the gray-level distribution and spatial context of pixels, while incorporating prior knowledge to suppress irrelevant background information.

In the following sections, I first review the existing literature on defect extraction and thresholding techniques. Then, I introduce the concept of attribute histograms and present my two proposed methods in detail. Next, I describe the experimental setup and compare the results with several state-of-the-art approaches. Finally, I discuss the implications of my findings and outline potential directions for future work.

1. Background and Motivation

Castings are produced by pouring molten metal into a mold, and they are widely used in industries such as automotive, aerospace, and heavy machinery. Despite advances in process control, defects are inevitable due to factors like gas entrapment, solidification shrinkage, or foreign material contamination. The most common defects include air holes (spherical voids), shrinkage cavities (irregular voids caused by volume contraction), and foreign inclusions (embedded particles). These internal flaws can lead to catastrophic failure if not detected. Consequently, 100% inspection is often mandatory in safety-critical applications. X-ray radiography is the preferred method because it provides direct visual evidence of internal discontinuities. However, manual interpretation of radiographs is slow, error-prone, and subject to operator variability. Therefore, automated image analysis is highly desirable.

Digital image processing for X-ray inspection involves several stages: preprocessing, segmentation, feature extraction, and classification. Segmentation is the most crucial step because its accuracy directly influences subsequent defect identification and sizing. The goal is to separate defect regions from the background. Given the inherent limitations of X-ray images—low contrast, blurred boundaries, and noise—conventional segmentation methods often fail. For instance, edge detection techniques are sensitive to noise, while region growing methods require careful seed selection. Thresholding is a simple and effective approach when the object and background have distinct gray levels. However, in sand foundry defects, the gray-level histograms often show overlapping peaks, making global thresholding insufficient. To overcome these challenges, I propose to use attribute histograms, which discard irrelevant histogram components based on prior knowledge. This not only improves robustness but also reduces computational complexity.

2. Related Work

Numerous techniques have been developed for defect extraction in radiographic images. Background subtraction methods attempt to estimate a defect-free reference image and then subtract it from the original, but obtaining a reliable reference is difficult. Feature-based methods compute local statistics and classify pixels using neural networks or support vector machines, yet they require extensive training and feature engineering. Morphological and edge-based techniques have also been explored, but they are often insufficient for low-contrast defects. Among the various approaches, thresholding remains a popular choice due to its simplicity and speed. Classical thresholding algorithms include Otsu’s method, minimum error thresholding, moment preservation, and entropy-based methods.

Entropy-based thresholding, rooted in information theory, has been widely studied. Pun proposed maximizing the posterior entropy to obtain the threshold, and Kapur et al. developed the famous KSW entropy method, which selects the threshold that maximizes the sum of entropies of the object and background classes. However, these methods rely on logarithmic computations, which are computationally expensive and suffer from undefined values when probabilities approach zero. To address these issues, Pal and Pal introduced an exponential entropy measure that avoids logarithmic singularities. Yen et al. proposed the maximum correlation criterion (MCC), which uses a quadratic measure of information and has been shown to be effective. Another limitation of one-dimensional thresholding is that it ignores spatial information. To incorporate pixel neighborhood information, two-dimensional (2D) histograms were introduced. Abutaleb extended the maximum entropy method to 2D, and Brink modified it to use the minimum of class entropies. The 2D Otsu method was also developed. These 2D methods improve segmentation accuracy but at the cost of increased computation.

Fuzzy set theory provides a powerful framework for handling the uncertainty inherent in image segmentation. Several authors have proposed fuzzy thresholding methods that optimize fuzzy measures such as fuzzy entropy or index of fuzziness. In my work, I integrate these ideas with attribute histograms to create robust segmentation algorithms that are both accurate and efficient.

3. Attribute Histogram

An attribute histogram is a restricted histogram that only considers pixels satisfying a predefined attribute set. This concept was introduced by Guo and colleagues to suppress interfering components in sonar image segmentation. The attribute set is constructed using prior knowledge about the specific problem. For example, if we know that the defects of interest correspond to bright regions, we can set the attribute to include only pixels whose gray values exceed a certain threshold. This way, the histogram no longer contains contributions from irrelevant dark background structures. Formally, for a grayscale image of size \(M \times N\) with gray levels ranging from \(0\) to \(L-1\), an attribute set \(Q\) can be defined as:

\[
Q = \{(x,y) \mid L_1 \le g(x,y) \le L_2, 1 \le x \le M, 1 \le y \le N\},
\]

where \(g(x,y)\) is the gray value at pixel \((x,y)\), and \(L_1\) and \(L_2\) define the intensity interval of interest. The attribute histogram \(p_Q(k)\) is then given by:

\[
p_Q(k) = \frac{n_Q(k)}{N_Q},
\]

where \(n_Q(k)\) is the number of pixels in \(Q\) with gray value \(k\), and \(N_Q\) is the total number of pixels in \(Q\). It is easy to see that when \(Q\) contains all pixels, the attribute histogram reduces to the standard histogram. The power of this concept lies in its flexibility: by choosing different attributes, we can tailor the histogram to the specific segmentation task.

3.1 Two-Dimensional Attribute Histogram

To incorporate spatial context, I extend the attribute histogram to two dimensions. For each pixel, I also compute the average gray value over a small neighborhood (e.g., \(3\times 3\)). Let \(g(x,y)\) be the gray value and \(h(x,y)\) be the neighborhood average. The 2D attribute histogram is defined over pairs \((i,j)\), where \(i\) is the gray level and \(j\) is the average gray level. The attribute set \(Q\) can now be specified in terms of both \(i\) and \(j\):

\[
Q = \{(x,y) \mid L_1 \le g(x,y) \le L_2, L_3 \le h(x,y) \le L_4\}.
\]

The resulting 2D attribute histogram is an \((L_2-L_1+1) \times (L_4-L_3+1)\) matrix, where each entry \(p_Q(i,j)\) represents the fraction of pixels in \(Q\) with gray level \(i\) and neighborhood average \(j\). By selectively including only the relevant intensity and average-intensity ranges, we can effectively remove noisy or unwanted pixels, leading to clearer class separation.

4. Proposed Segmentation Methods

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

The first method I propose combines the exponential entropy measure with fuzzy set theory, operating on a one-dimensional attribute histogram. Exponential entropy, as defined by Pal and Pal, has the form:

\[
H = \sum_{i} p_i \exp(1 – p_i),
\]

where \(p_i\) is the probability of the \(i\)-th event. Unlike Shannon entropy, this measure is well-defined for all \(p_i \in [0,1]\), and it avoids the expensive logarithmic operations. To handle the ambiguity present in X-ray images, I introduce a fuzzy partition of the grayscale range. Let \(Q\) be an attribute set. For a given threshold pair \((a,b)\) with \(L_1 \le a < b \le L_2\), I define two fuzzy membership functions: a Z-function for the dark class (defects) and an S-function for the bright class (background), as follows:

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

Here, \(k\) is the gray level in \(Q\). The parameter \(b\) is the threshold \(t\), which separates the two classes. The probability of the dark class \(E_d\) and the bright class \(E_b\) are calculated as:

\[
P_d = \sum_{k \in Q} p_Q(k) \mu_d(k; a,b), \qquad P_b = \sum_{k \in Q} p_Q(k) \mu_b(k; a,b).
\]

Then, the fuzzy exponential entropy for each class is defined by:

\[
H_d = \sum_{k \in Q} \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 \in Q} \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^*, b^*)\) are obtained by maximizing \(H(a,b)\):

\[
(a^*, b^*) = \arg\max_{L_1 \le a < b \le L_2} H(a,b).
\]

Once the optimal parameters are found, the threshold \(t\) is chosen as \(t = (a^* + b^*)/2\), because it corresponds to the crossover point where \(\mu_d = \mu_b = 0.5\). Finally, pixels with gray value less than or equal to \(t\) are classified as defects, and the rest as background.

To construct the attribute set for sand foundry defects, I first apply Otsu’s method to the original image to obtain a preliminary threshold \(s\). For air holes and shrinkage cavities, which appear as bright regions, the attribute set is defined as:

\[
Q_1 = \{(x,y) \mid s < g(x,y) < L-1\}.
\]

For foreign inclusions, which appear as dark regions, the attribute set is:

\[
Q_2 = \{(x,y) \mid 0 < g(x,y) \le s\}.
\]

This preliminary classification can be done based on the histogram shape: images with early peaks (low gray values) correspond to bright defects, while those with late peaks correspond to dark defects. Using an attribute histogram in this way not only removes irrelevant background but also narrows the search range for the threshold, greatly reducing computation time.

4.2 Maximum Correlation Criterion Based on 2D Attribute Histogram (MCC-TBH)

The second method I propose extends the maximum correlation criterion to a two-dimensional attribute histogram. The correlation measure for a probability distribution \(X\) is defined as:

\[
C_X = – \ln \sum_{i} p_i^2.
\]

For an image, the 2D correlation is defined over the joint probabilities \(p(i,j)\) of gray level \(i\) and neighborhood average \(j\). In the 2D attribute histogram, given a threshold vector \((s,t)\), we divide the histogram into four quadrants. The two quadrants along the diagonal correspond to background (A) and object (B), while the off-diagonal quadrants represent edges and noise, which are neglected. The class probabilities are:

\[
P_A(s,t) = \sum_{i=L_1}^{s} \sum_{j=L_3}^{t} p_Q(i,j), \qquad P_B(s,t) = \sum_{i=s+1}^{L_2} \sum_{j=t+1}^{L_4} p_Q(i,j) = 1 – P_A(s,t).
\]

After normalizing the probabilities within each class, the correlation for class A is:

\[
C_A(s,t) = – \ln \sum_{i=L_1}^{s} \sum_{j=L_3}^{t} \left( \frac{p_Q(i,j)}{P_A(s,t)} \right)^2 = \ln P_A^2(s,t) – \ln \sum_{i=L_1}^{s} \sum_{j=L_3}^{t} p_Q^2(i,j).
\]

Similarly, for class B:

\[
C_B(s,t) = \ln P_B^2(s,t) – \ln \sum_{i=s+1}^{L_2} \sum_{j=t+1}^{L_4} p_Q^2(i,j).
\]

The total correlation is \(C(s,t) = C_A(s,t) + C_B(s,t)\). To simplify the expression, I define \(G_A(s,t) = \sum_{i=L_1}^{s} \sum_{j=L_3}^{t} p_Q^2(i,j)\). Then \(C(s,t)\) can be written as:

\[
C(s,t) = 2\ln P_A(s,t) + 2\ln(1-P_A(s,t)) – \ln G_A(s,t) – \ln (G_{\text{total}} – G_A(s,t)),
\]

where \(G_{\text{total}} = \sum_{i=L_1}^{L_2} \sum_{j=L_3}^{L_4} p_Q^2(i,j)\) is a constant. The optimal threshold vector \((s^*, t^*)\) maximizes \(C(s,t)\):

\[
(s^*, t^*) = \arg\max_{(s,t)} C(s,t).
\]

To avoid repetitive summation for every \((s,t)\), I derive a recursive algorithm. Let \(P_A(s,t)\) and \(G_A(s,t)\) be updated incrementally. The first point is \(P_A(L_1,L_3) = p_Q(L_1,L_3)\), \(G_A(L_1,L_3) = p_Q^2(L_1,L_3)\). Then, for the first row and first column:

\[
P_A(s+1,L_3) = P_A(s,L_3) + p_Q(s+1,L_3), \quad G_A(s+1,L_3) = G_A(s,L_3) + p_Q^2(s+1,L_3),
\]
\[
P_A(L_1,t+1) = P_A(L_1,t) + p_Q(L_1,t+1), \quad G_A(L_1,t+1) = G_A(L_1,t) + p_Q^2(L_1,t+1).
\]

Then, for any \((s+1,t+1)\), we have:

\[
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 recursive computation reduces the time complexity from \(O(L_2^2 L_4^2)\) to \(O(L_2 L_4)\), enabling real-time processing. In the MCC-TBH method, the attribute set for bright defects is similarly based on a preliminary threshold \(th\) obtained from the maximum entropy criterion. The attribute sets are:

\[
Q_1 = \{(x,y) \mid th \le g(x,y) \le L-1, th \le h(x,y) \le L-1\},
\]

and for dark defects:

\[
Q_2 = \{(x,y) \mid 0 \le g(x,y) \le th, 0 \le h(x,y) \le th\}.
\]

These choices ensure that only pixels with consistent gray level and neighborhood average are included, effectively suppressing isolated noise points.

5. Experimental Results and Analysis

5.1 Dataset and Setup

I evaluated both proposed methods on a set of X-ray images containing three common types of sand foundry defects: air holes, shrinkage cavities, and foreign inclusions. Each image had a size of \(200 \times 200\) pixels with 256 gray levels. The images exhibited typical characteristics: low contrast, blurred edges, and a background with uneven intensity and occasional fake defects (e.g., cloud-like patterns and scratches). I compared my methods against four existing algorithms: Otsu’s method, Kapur’s maximum entropy criterion (MEC), one-dimensional fuzzy exponential entropy without attribute histogram (MFEE), and the two-dimensional maximum correlation criterion without attribute histogram (MCC-T). The experiments were conducted in MATLAB 7.0 on a Pentium IV 3.06 GHz with 512 MB RAM.

5.2 Attribute Histogram Construction

For MFEE-BH, I used Otsu’s threshold to construct the attribute set as described in Section 3. For MCC-TBH, I used MEC’s threshold for the same purpose. The attribute histograms were then computed for each image. Figures (not shown here) illustrate that the attribute histograms have a much narrower distribution compared to the original histograms, effectively removing the background interference and also reducing the search space. This directly contributes to both higher accuracy and faster computation.

5.3 Qualitative Segmentation Results

The segmentation results for representative images are summarized qualitatively. For air hole images, the classical methods (Otsu, MEC, MFEE, MCC-T) often misclassified background cloud-like artifacts as defects. In particular, MCC-T produced a high number of false positives. In contrast, both MFEE-BH and MCC-TBH clearly extracted the air hole regions with minimal background noise. For shrinkage cavities, whose edges are fuzzy and scattered, the improvement was even more noticeable. The classical methods produced incomplete or noisy segmentations, whereas both proposed methods accurately outlined the cavities, with MCC-TBH giving the cleanest results. For foreign inclusions, which are darker than the background, the proposed methods also performed well. Otsu worked well on some images but failed on others, indicating instability. MFEE-BH and MCC-TBH consistently produced clear, accurate defect shapes without spurious detections.

5.4 Quantitative Evaluation

Table 1 lists the threshold values obtained by each method for nine test images (three of each defect type). The columns for MFEE-BH show the optimal parameters \(a^*\) and \(b^*\), and the final threshold \(t = (a^*+b^*)/2\). For MCC-TBH, the threshold vector \((s,t)\) is shown. It can be observed that the proposed methods yield very different thresholds compared to the classical ones, reflecting their ability to focus on the defect regions.

Table 1: Segmentation thresholds for different methods
Image Otsu MFEE MFEE-BH MFEE-BH MFEE-BH MEC MCC-T MCC-TBH
a* b* t
Fig. A (air hole) 138 121 138 224 181 114 [89,89] [193,202]
Fig. B (air hole) 139 141 139 236 188 125 [114,114] [218,195]
Fig. C (air hole) 87 133 87 211 149 132 [66,68] [197,200]
Fig. D (shrinkage) 126 138 126 238 182 125 [109,109] [212,176]
Fig. E (shrinkage) 106 148 108 229 169 131 [125,125] [175,208]
Fig. F (shrinkage) 128 158 128 234 181 130 [130,127] [178,198]
Fig. G (inclusion) 160 204 44 157 101 205 [223,209] [94,94]
Fig. H (inclusion) 220 174 137 212 175 183 [211,174] [87,149]
Fig. I (inclusion) 141 202 41 138 90 200 [211,200] [114,107]

5.5 Computational Efficiency

Table 2 reports the execution times for each method. The MFEE-BH method was approximately ten times faster than the classical MFEE method, thanks to the reduced histogram range. For MCC-TBH, I also implemented the recursive algorithm and compared it with the exhaustive search. The recursive version reduced the time from several seconds to less than 0.15 s in most cases. Overall, both proposed methods completed in under one second for all tested images, easily satisfying real-time inspection requirements.

Table 2: Segmentation time (in seconds)
Image MFEE MFEE-BH MCC-T (exhaustive) MCC-T (recursive) MCC-TBH (exhaustive) MCC-TBH (recursive)
Fig. A 4.297 0.290 27.484 0.109 1.587 0.094
Fig. B 2.969 0.532 28.188 0.141 1.921 0.078
Fig. C 3.312 0.907 27.984 0.141 1.500 0.110
Fig. D 2.809 0.539 34.406 0.141 3.406 0.109
Fig. E 3.656 0.781 33.609 0.204 2.203 0.140
Fig. F 3.167 0.464 31.829 0.172 1.969 0.109
Fig. G 3.143 0.458 31.820 0.375 6.547 0.078
Fig. H 2.625 0.953 29.547 0.140 3.343 0.109
Fig. I 3.119 0.353 27.078 0.125 4.485 0.110

5.6 Comparison of the Two Proposed Methods

Both MFEE-BH and MCC-TBH successfully extract sand foundry defects, but they have complementary strengths. MCC-TBH, which uses spatial context, is particularly effective for larger defects like air holes and shrinkage cavities because it removes small irrelevant details and yields cleaner background. In contrast, MFEE-BH is more sensitive to small defects, making it suitable for foreign inclusions that occupy only a few pixels. In terms of speed, MCC-TBH with the recursive algorithm is the fastest, often completing in under 0.1 s. MFEE-BH, while slightly slower, still easily meets real-time requirements. The choice between the two methods depends on the specific defect type and the acceptable level of false positives.

6. Discussion

The success of the proposed methods hinges on the careful construction of attribute sets. By using a classical threshold to pre-segment the image and restricting the histogram to the region of interest, I effectively filter out background disturbances that would otherwise mislead the thresholding criterion. This approach is particularly powerful in X-ray inspection of sand foundry defects, where the background often contains false indications. Another important factor is the chosen information measure. The exponential entropy formula, although less conventional than Shannon entropy, avoids undefined logarithmic values and yields faster computations. The maximum correlation criterion similarly avoids logarithms and naturally emphasizes the class separability.

One limitation of my methods is that they require a preliminary threshold to define the attribute set. In my implementation, I used Otsu and MEC for this purpose. These preliminary thresholds need not be perfectly accurate; they only need to place the resulting attribute interval around the defect gray levels. This two-stage strategy, sometimes called “divide and conquer”, has proven robust across many images. Nevertheless, there may be cases where the preliminary threshold fails, leading to a poorly chosen attribute set. Future work could explore adaptive methods for attribute construction, possibly using local statistics or fuzzy clustering.

7. Conclusion

In this paper, I have presented two thresholding segmentation methods for the automatic extraction of sand foundry defects from X-ray images. The first method, termed MFEE-BH, combines attribute histogram pruning with a fuzzy exponential entropy criterion. The second method, MCC-TBH, utilises a two-dimensional attribute histogram and a maximum correlation criterion, along with a fast recursive algorithm. Through extensive experiments on air holes, shrinkage cavities, and foreign inclusions, I demonstrated that both methods significantly outperform classical thresholding techniques in terms of segmentation accuracy, robustness, and computation speed. The use of attribute histograms effectively suppresses background noise and reduces the search space, while the chosen entropy or correlation measures provide reliable separation of defects from the background. These characteristics make the methods highly suitable for on-line quality control in foundry environments. Future research will focus on integrating these segmentation algorithms with feature extraction and classification modules to achieve a fully automated inspection system for sand foundry defects.

References

  1. Wang, Y., Sun, Y., Lv, P., et al. Detection of line weld defects based on multiple thresholds and support vector machine. NDT & E International, 2008, Doi:10.1016/j.ndteint.2005.05.004.
  2. Kapur, J. N., Sahoo, P. K., Wong, A. K. C. A new method for gray-level picture thresholding using the entropy of the histogram. Computer Vision, Graphics and Image Processing, 1985, 29: 273-285.
  3. Pal, N. R., Pal, S. K. Entropy: A new definition and its applications. IEEE Transactions on Systems, Man and Cybernetics, 1991, 21(5): 1260-1270.
  4. Yen, J. C., Chang, F. J., Chang, S. Y. A new criterion for automatic multilevel thresholding. IEEE Transactions on Image Processing, 1995, 4(3): 370-378.
  5. Otsu, N. A threshold selection method from gray-level histogram. IEEE Transactions on Systems, 1979, 9: 62-66.
  6. Guo, H., Sun, D., Tian, T. Attribute histogram and its application in sonar image fuzzy enhancement. Journal of Electronics and Information Technology, 2002, 24(9): 1287-1290.
  7. Guo, H., Tian, T., Wang, L., et al. Image segmentation based on maximum entropy using two-dimensional attribute histogram. Acta Optica Sinica, 2006, 26(4): 506-509.
  8. Chen, X., Hu, Y., Huang, Y. Image threshold segmentation based on two-dimensional maximum correlation criterion. Journal of Infrared and Millimeter Waves, 2005, 24(5): 397-400.
Scroll to Top