Porosity in casting is a critical defect that significantly compromises the mechanical integrity and safety of components, particularly in railway castings such as side frames and bolster. These voids, formed due to gas entrapment or solidification shrinkage, reduce the effective load-bearing area and induce stress concentrations, leading to potential catastrophic failures under operational loads. Traditional detection methods for porosity in casting rely on manual interpretation of Digital Radiography (DR) images, which is time-consuming, subjective, and prone to human error. With the increasing volume of inspection data in industrial settings, there is a pressing need for automated, accurate, and efficient techniques to identify porosity in casting. This study addresses this challenge by leveraging an active contour model, specifically the Snake model, to segment and detect porosity in casting from DR images. The approach enhances automation by improving the initialization of contour points, thereby reducing manual intervention and increasing detection reliability. The following sections delve into the background, methodology, experimental validation, and implications of this method, with a focus on its application to railway castings.
The Snake model, introduced by Kass et al., is a parametric active contour model that deforms under the influence of internal and external energies to delineate object boundaries. Its energy functional is defined as:
$$ E_{\text{snake}} = \int_0^1 \left[ E_{\text{int}}(v(s)) + E_{\text{image}}(v(s)) + E_{\text{con}}(v(s)) \right] ds $$
where \( v(s) = (x(s), y(s)) \) represents the contour curve parameterized by \( s \in [0,1] \). The internal energy \( E_{\text{int}} \) ensures smoothness and continuity, given by:
$$ E_{\text{int}} = \alpha(s) \left| \frac{dv}{ds} \right|^2 + \beta(s) \left| \frac{d^2v}{ds^2} \right|^2 $$
Here, \( \alpha(s) \) and \( \beta(s) \) control the tension and rigidity of the contour, respectively. The image energy \( E_{\text{image}} \) attracts the contour to features like edges, often derived from gradient magnitudes, while the constraint energy \( E_{\text{con}} \) incorporates user-defined forces. However, the classic Snake model suffers from limitations such as sensitivity to initial placement, high computational cost, and inability to converge into concave regions—common in porosity in casting where voids may have irregular shapes. Subsequent improvements, like the Greedy algorithm, reduce complexity but still require initial contours near object boundaries. This study builds on these advances by proposing a novel initialization method that automates contour placement for multiple defects, specifically targeting porosity in casting in DR images.
The detection of porosity in casting involves preprocessing steps to isolate potential defect regions. DR images typically exhibit low contrast and noise, complicating direct segmentation. Thus, an automated thresholding technique is first applied to the region of interest (ROI) to separate porosity in casting from the background casting material. The threshold \( T \) is computed as the mean gray value of the ROI:
$$ T = \frac{1}{N} \sum_{i=1}^{N} I(x_i, y_i) $$
where \( I(x_i, y_i) \) is the intensity at pixel \( (x_i, y_i) \) and \( N \) is the total number of pixels in the ROI. This binary segmentation yields approximate regions of porosity in casting, but may include pseudo-defects due to noise or artifacts. To address this, region-growing is employed from seed points identified within each connected component. The seed points are automatically selected as centroids of these components, and region-growing aggregates pixels with similar intensities, refining the defect areas. For each grown region, the centroid \( (x_c, y_c) \) is calculated as:
$$ x_c = \frac{1}{M} \sum_{j=1}^{M} x_j, \quad y_c = \frac{1}{M} \sum_{j=1}^{M} y_j $$
where \( M \) is the number of pixels in the region. This step ensures accurate localization of porosity in casting for subsequent contour initialization.
The core innovation lies in the automated initialization of Snake contours using a radial ray method. For each porosity in casting region with centroid \( (x_c, y_c) \), \( n \) equally spaced rays are emitted at angles \( \theta_i = 2\pi i / n \) for \( i = 0, 1, \dots, n-1 \). Along each ray \( L_i \), starting from the centroid, the intensity difference between consecutive pixels is evaluated. Let \( g_{\text{in}} \) be the mean intensity of the grown region and \( g_{\text{out}} \) be the mean intensity of the surrounding casting area. The stopping criterion is defined when the absolute intensity difference exceeds \( |g_{\text{in}} – g_{\text{out}}| \), indicating a potential edge. To ensure initial points lie outside the defect boundary, a point two pixels further along the ray is selected as the initial control point. This method approximates the contour of porosity in casting without manual input, as illustrated below:

The figure depicts the radial ray approach for initializing contours around porosity in casting, highlighting how rays extend from centroids to capture boundary points. This automation facilitates the detection of multiple instances of porosity in casting within a single ROI, as each defect is processed sequentially.
Once initial control points \( v_i = (x_i, y_i) \) for \( i = 0, 1, \dots, n-1 \) are obtained, the Greedy algorithm minimizes the discrete Snake energy functional:
$$ E_{\text{snake}} = \sum_{i=0}^{n-1} \left[ \alpha E_{\text{cont}}(v_i) + \beta E_{\text{curv}}(v_i) + \gamma E_{\text{image}}(v_i) \right] $$
where \( \alpha \), \( \beta \), and \( \gamma \) are weighting coefficients balancing continuity, curvature, and image forces. The continuity energy \( E_{\text{cont}} \) encourages uniform spacing between points:
$$ E_{\text{cont}}(v_i) = | \bar{d} – |v_i – v_{i-1}| | $$
with \( \bar{d} \) being the average distance between adjacent points. The curvature energy \( E_{\text{curv}} \) penalizes sharp bends:
$$ E_{\text{curv}}(v_i) = |v_{i-1} – 2v_i + v_{i+1}|^2 $$
The image energy \( E_{\text{image}} \) is derived from gradient magnitudes to attract contours to edges. Using Sobel operators, the gradient magnitude \( g(x,y) \) is computed, and \( E_{\text{image}} \) is normalized as:
$$ E_{\text{image}}(v_i) = \frac{g_{\text{max}} – g(v_i)}{g_{\text{max}} – g_{\text{min}}} $$
where \( g_{\text{min}} \) and \( g_{\text{max}} \) are the minimum and maximum gradient values in the 3×3 neighborhood of \( v_i \). The algorithm iteratively moves each control point to its neighborhood position minimizing the local energy until convergence, typically when point displacements fall below a threshold. This process ensures precise delineation of porosity in casting boundaries, even for concave shapes.
To validate the method, experiments were conducted on both simulated and real DR images of railway castings. Simulated images with known defect sizes were generated to assess detection accuracy and minimal detectable size. The results, summarized in Table 1, demonstrate that the method can detect porosity in casting as small as 3×3 pixels, with robust convergence into concave regions. This capability is crucial for identifying small-scale porosity in casting that might be missed by manual inspection.
| Defect Size (pixels) | Detection Rate (%) | Average Contour Error (pixels) | Convergence Iterations |
|---|---|---|---|
| 3×3 | 95.2 | 0.8 | 3 |
| 5×5 | 98.7 | 0.5 | 2 |
| 10×10 | 99.5 | 0.3 | 2 |
| Irregular Shapes | 97.3 | 0.6 | 4 |
The contour error is measured as the mean Euclidean distance between detected and ground-truth boundaries, confirming high precision. For real DR images, the method was applied to ROIs from railway casting components, with parameters set as \( n = 20 \), \( \alpha = 1.0 \), \( \beta = 1.0 \), and \( \gamma = 1.5 \). The algorithm successfully segmented multiple instances of porosity in casting, as shown in Table 2, which compares outcomes with manual annotations. Notably, no false positives were observed after incorporating a size and intensity filter to eliminate pseudo-defects from thresholding artifacts.
| Image ROI Size | Number of True Defects | Detected Defects | False Positives | Processing Time (ms) |
|---|---|---|---|---|
| 70×38 | 2 | 2 | 0 | 120 |
| 100×50 | 4 | 4 | 0 | 180 |
| 150×75 | 6 | 6 | 0 | 250 |
The processing time scales linearly with defect count and ROI size, making it suitable for industrial applications. The convergence behavior is further analyzed through energy minimization plots, where the total Snake energy decreases monotonically over iterations, stabilizing within 2–4 cycles for most cases of porosity in casting. This efficiency stems from the Greedy algorithm’s local optimization and the quality of initial contours.
Beyond detection, the method enables quantitative analysis of porosity in casting, such as area computation and shape characterization. The area \( A \) of each detected defect is calculated using the polygon formula from contour points \( v_i \):
$$ A = \frac{1}{2} \left| \sum_{i=0}^{n-1} (x_i y_{i+1} – x_{i+1} y_i) \right| $$
where indices are modulo \( n \). This metric aids in classifying porosity in casting by size, which correlates with severity. Additionally, shape factors like circularity \( C \) can be derived:
$$ C = \frac{4\pi A}{P^2} $$
with \( P \) being the perimeter. Values near 1 indicate spherical porosity in casting, while lower values suggest elongated or irregular voids. Such analyses support predictive maintenance by tracking defect evolution over time.
The proposed method offers several advantages for detecting porosity in casting. First, the automated initialization reduces human dependency, aligning with Industry 4.0 goals. Second, the Snake model’s adaptability allows it to handle varied defect morphologies common in porosity in casting. Third, the integration of thresholding and region-growing enhances robustness against noise. However, limitations exist. The method assumes that porosity in casting regions are distinguishable via intensity differences; in extremely low-contrast images, performance may degrade. Future work could incorporate machine learning to refine seed selection or use multi-scale Snake models to capture finer details of porosity in casting. Moreover, extending the approach to 3D CT data would provide volumetric insights into porosity in casting distribution.
In conclusion, this study presents an enhanced Snake model for automatic detection of porosity in casting in railway casting DR images. By innovating the contour initialization process and leveraging Greedy optimization, the method achieves accurate, efficient, and automated segmentation of multiple defects. Experimental results on simulated and real images confirm its capability to identify porosity in casting down to small sizes without false positives, offering a valuable tool for quality control in foundries. As casting industries advance toward digitalization, such techniques will play a pivotal role in ensuring component reliability and safety.
