A Study on Casting Defect Detection Using Image Registration Technology

1. Introduction

In modern industrial manufacturing, castings play a vital role because of their flexibility in producing complex shapes and their cost-effectiveness. The quality of casting components directly affects the safety and reliability of entire products. For instance, defective castings used in automotive wheel hubs or chassis can lead to catastrophic consequences for drivers and passengers. Therefore, ensuring 100% quality in casting production is mandatory. However, during actual casting processes, defects such as gas pores, inclusions, cracks, and thin-wall regions are inevitably introduced due to process variations. X-ray nondestructive testing has become a standard technique for inspecting internal defects in castings. Nevertheless, the interpretation of X-ray images is still heavily dependent on human experts. This manual inspection process is labor-intensive, time-consuming, and prone to subjectivity and misjudgment. The development of intelligent and automated defect detection systems is therefore of great significance.

Image registration technology, which aligns two or more images geometrically, has advanced rapidly in recent years. It offers a promising solution for automatic defect detection in industrial castings. In real-world applications, the casting to be inspected is often placed with slight positional deviations from the reference template. Consequently, the acquired X-ray image of the inspected casting exhibits both rigid and elastic deformations relative to the template image. Direct digital subtraction between the inspected image and the template image is not feasible because misalignments create false contours that obscure real defects. By precisely registering the inspected image to the template image, the two images can be spatially aligned, enabling accurate digital subtraction to extract defect information. Thus, image registration is an indispensable preprocessing step for casting defect detection.

The work presented in this thesis focuses on developing robust image registration methods specifically tailored for casting defect detection. In the current literature, many registration-based defect detection methods assume only rigid transformations, which are insufficient for real casting images that also suffer from local elastic distortions. To address this limitation, I propose a hierarchical approach that combines rigid registration with non-rigid elastic registration using the Active Demons algorithm. This method first corrects global translation and rotation using phase correlation and inertial ellipse orientation. Next, it refines the alignment using an elastic deformation model to compensate for local shape variations. After registration, digital subtraction and threshold segmentation are applied to locate defects accurately.

However, I further observe that the Active Demons algorithm only utilizes gradient information, neglecting the directional information embedded in the image structure. To enhance registration accuracy, I introduce an improved Demons algorithm that integrates orientation fields into the deformation computation. This approach leverages both gradient and orientation information to better characterize local image geometry. Moreover, I address the manual tuning issue of the normalization parameter in the orientation-based Demons method by incorporating mutual information as an adaptive similarity measure. The proposed adaptive strategy automatically adjusts the deformation strength, thereby improving both efficiency and precision. Experimental results on real industrial casting images demonstrate that the proposed methods outperform conventional registration approaches in terms of defect localization accuracy.

2. Fundamentals of Image Registration

Image registration is the process of transforming different images of the same scene into a common coordinate system. Mathematically, let the template image be \( f_1(x,y) \) and the reference to be aligned (floating image) be \( f_2(x,y) \). A spatial transformation \( g(x,y) \) maps points from \( f_2 \) to \( f_1 \) such that the similarity between \( f_1 \) and the transformed \( f_2 \) is maximized. The relation can be written as:

$$ f_1(x,y) \approx f_2(g(x,y)). $$

The transformation \( g \) can be rigid (translation, rotation), affine (also includes scaling and shearing), projective, or nonlinear (elastic). The choice of transformation depends on the type of deformation present in the images. Table 1 summarizes common transformation types and their preserved properties.

Table 1: Image Transformation Types
Transformation Reflection Rotation Translation Scaling Projection Distortion
Rigid
Affine
Projective
Nonlinear

Rigid transformations preserve distances and angles, and can be represented for a point \( (x,y) \) as:

$$ \begin{bmatrix} x’ \\ y’ \\ 1 \end{bmatrix} = \begin{bmatrix} \cos\theta & -\sin\theta & t_x \\ \sin\theta & \cos\theta & t_y \\ 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ 1 \end{bmatrix}, $$

where \( \theta \) is the rotation angle and \( (t_x,t_y) \) are translation offsets. Affine transformations add scaling and shearing parameters. Projective transformations allow perspective changes. Nonlinear (elastic) transformations permit local deformations and are essential for modeling physical distortions in casting images.

The general image registration framework consists of four main components: feature space, search space, search strategy, and similarity measure. The feature space defines the information used for matching, such as pixel intensities, edges, corners, or other landmarks. The search space represents the set of possible transformations to be explored. The search strategy determines how to find the optimal transformation within the search space, often using optimization algorithms. The similarity measure quantifies how well the transformed floating image matches the template. In this work, several similarity metrics are employed to evaluate registration quality, including Mean Square Error (MSE), Peak Signal-to-Noise Ratio (PSNR), Cross-Correlation (CC), Residual Variance (RV), and Structural Similarity Index (SSIM). They are defined as follows:

$$ \mathrm{MSE} = \frac{1}{|\Omega|} \sum_{(x,y)\in\Omega} \left[ f_1(x,y) – f_2′(x,y) \right]^2, $$

$$ \mathrm{PSNR} = 10 \log_{10} \left( \frac{255^2 |\Omega|}{\sum_{(x,y)\in\Omega} \left[ f_1(x,y) – f_2′(x,y) \right]^2} \right), $$

$$ \mathrm{CC} = \frac{\sum (f_1 – \bar{f}_1)(f_2′ – \bar{f}_2′)}{\sqrt{\sum (f_1 – \bar{f}_1)^2 \sum (f_2′ – \bar{f}_2′)^2}}, $$

$$ \mathrm{RV} = \frac{1}{|\Omega|} \sum_{(x,y)\in\Omega} \left| f_1(x,y) – f_2′(x,y) \right|, $$

$$ \mathrm{SSIM} = \frac{(2\mu_{f_1}\mu_{f_2′} + c_1)(2\sigma_{f_1 f_2′} + c_2)}{(\mu_{f_1}^2 + \mu_{f_2′}^2 + c_1)(\sigma_{f_1}^2 + \sigma_{f_2′}^2 + c_2)}. $$

Lower MSE and RV indicate better registration, while higher PSNR, CC, and SSIM correspond to higher similarity.

Non-rigid registration methods can be classified into feature-based, intensity-based, transformation-model-based, and physical-model-based approaches. Feature-based methods extract landmarks or features from both images and estimate deformation using correspondences. Intensity-based methods directly optimize a similarity measure over the entire image. Transformation-model-based methods model deformation using parametric functions such as polynomials or splines. Physical-model-based methods treat the image as an elastic body or a fluid, simulating physical deformation processes. Among these, the Demons algorithm is a popular intensity-based approach that computes a displacement field based on image gradients and intensity differences. It is closely related to the optical flow method. The original Demons algorithm was inspired by Maxwell’s demon thought experiment and was introduced by Thirion in 1998. The core update equation for the displacement field is:

$$ \vec{v} = \frac{(m(\mathbf{x}) – f(\mathbf{x})) \nabla f(\mathbf{x})}{\|\nabla f(\mathbf{x})\|^2 + (m(\mathbf{x}) – f(\mathbf{x}))^2}, $$

where \( f \) is the template image, \( m \) is the floating image, and \( \nabla f \) is the gradient of the template. The algorithm iteratively applies this displacement and smooths the field with a Gaussian filter. However, the original Demons method is only suitable for small deformations and relies solely on the gradient of the template. To improve robustness, the Active Demons algorithm incorporates the gradient of the floating image as well, yielding:

$$ \vec{v} = \frac{(m-f)\nabla f}{\|\nabla f\|^2 + \alpha^2 (m-f)^2} + \frac{(m-f)\nabla m}{\|\nabla m\|^2 + \alpha^2 (m-f)^2}, $$

where \( \alpha \) is a normalization factor that controls the deformation step size. This formulation provides a bidirectional driving force and can handle larger deformations than the original approach.

3. Rigid-Elastic Registration for Casting Defect Detection

In the acquisition of industrial casting X-ray images, rigid misalignments arise from translational and rotational positioning errors of the casting, while elastic distortions originate from variations in the manufacturing process and imaging geometry. Most existing registration-based defect detection approaches only account for rigid misalignments, leading to false defects when elastic deformation is present. To overcome this problem, I propose a hierarchical registration framework that first corrects rigid deformation and then performs elastic registration using the Active Demons algorithm. The complete flowchart of the proposed casting defect detection system is depicted in the following figure, which illustrates the integration of rigid registration, elastic refinement, digital subtraction, and thresholding.

3.1 Rigid Registration Using Phase Correlation and Inertia Ellipse

The first stage aims to remove translation and rotation between the inspected casting image and the template image. Translational offset is estimated using the phase correlation method, which relies on the Fourier shift property. If the floating image is a translated version of the template, such as \( f_2(x,y)=f_1(x-x_0, y-y_0) \), then their Fourier transforms satisfy:

$$ F_2(\xi,\eta) = e^{-j2\pi(\xi x_0 + \eta y_0)} F_1(\xi,\eta). $$

The normalized cross-power spectrum is:

$$ \frac{F_1^*(\xi,\eta) F_2(\xi,\eta)}{|F_1^*(\xi,\eta) F_2(\xi,\eta)|} = e^{-j2\pi(\xi x_0 + \eta y_0)}. $$

Taking the inverse Fourier transform of this expression yields a delta function centered at \( (x_0,y_0) \). The peak location gives the translation vector between the images.

For rotation correction, I use the inertia ellipse method. In gray-level images, the inertia ellipse describes the spatial distribution of pixel intensities. The orientation of the principal axis of the inertia ellipse is computed from the moments of inertia. For a two-dimensional image, the moment of inertia around the \( x \)- and \( y \)-axes are given by:

$$ A = \sum_i (y_i^2 + z_i^2), \quad B = \sum_i (z_i^2 + x_i^2), \quad C = \sum_i (x_i^2 + y_i^2), $$

and the products of inertia are \( F = \sum y_i z_i \), \( G = \sum z_i x_i \), \( H = \sum x_i y_i \). In the 2D case, the orientation angle of the inertia ellipse is obtained from:

$$ k = \frac{(A-B) – \sqrt{(A-B)^2 + 4H^2}}{2H}, \quad l = \frac{(A-B) + \sqrt{(A-B)^2 + 4H^2}}{2H}. $$

The angle between the principal axis and the horizontal axis is then \( \theta = \tan^{-1}(k) \). By computing the angles of the template image and the floating image, the rotation angle is determined. The floating image is subsequently rotated to align its principal axis with that of the template.

3.2 Active Demons Elastic Registration

After rigid registration, residual local deformations remain. To correct these, the Active Demons algorithm is applied. The deformation field between the rigidly registered inspected image \( m \) and the template image \( f \) is iteratively updated using the bidirectional force formula:

$$ \frac{\partial \mathbf{u}}{\partial t} = \frac{(m-f)\nabla f}{\|\nabla f\|^2 + \alpha^2 (m-f)^2} + \frac{(m-f)\nabla m}{\|\nabla m\|^2 + \alpha^2 (m-f)^2}, $$

where \( \alpha \) controls the maximum step size of deformation. In each iteration, the displacement field \( \mathbf{u} \) is updated, and then Gaussian smoothing is applied to maintain spatial regularity. The iteration continues until the similarity between \( m \) and \( f \) reaches a predefined threshold or the maximum number of iterations is reached (typically 300). The parameter \( \alpha \) is chosen empirically; in my experiments I set \( \alpha = 1.5 \). This elastic registration effectively compensates for local shape differences caused by casting distortions.

3.3 Defect Extraction and Threshold Segmentation

Once the inspected image is accurately aligned with the template, digital subtraction is performed to obtain a difference image. Since the template is assumed to be defect-free, any significant intensity difference indicates a potential defect. However, due to interpolation artifacts and residual registration errors, small intensity differences may appear even in non-defective regions. Therefore, thresholding is used to suppress these false positives. The threshold is set to 15 gray levels, meaning that pixels with absolute intensity difference greater than 15 are considered defect candidates. The defect locations are then marked on the original inspected image. The overall process is summarized in the following table.

Table 2: Procedure of Proposed Rigid-Elastic Registration for Casting Defects
Step Description
1 Load template image and inspected casting image
2 Estimate translation using phase correlation
3 Estimate rotation using inertia ellipse orientation
4 Apply rigid transformation to correct global alignment
5 Run Active Demons elastic registration to refine local deformations
6 Compute subtraction image between registered inspected image and template
7 Apply threshold segmentation to remove false defects
8 Mark defect regions on the inspected image

3.4 Experimental Results and Discussion

To evaluate the effectiveness of the proposed method, experiments were conducted on real X-ray images of industrial castings. The image size was 3072×3072 pixels. The template image was obtained by averaging ten registered images of defect-free castings. The experiments were performed in Microsoft Visual Studio 2012 with an Intel Core i7-9700K CPU and 32 GB RAM. Four registration combinations were compared: (1) rigid registration alone, (2) Active Demons alone, (3) rigid registration followed by B-spline elastic registration, and (4) the proposed rigid registration followed by Active Demons elastic registration. The defect detection results were evaluated both subjectively and objectively.

Subjective evaluation involved visual inspection of the marked defect regions. The proposed method yielded fewer false positives and missed detections than the rigid-only and Active-Demons-only approaches. The combination of rigid and B-spline registration showed improved performance but still missed some defects in local areas, whereas the proposed method successfully detected almost all true defects. Figure 1 presented earlier illustrates the marking results for the compared methods.

For objective evaluation, I computed the five similarity metrics discussed previously. Table 3 shows the average registration results over the tested images.

Table 3: Registration Results for Different Methods in Casting Defect Detection
Method MSE PSNR (dB) CC RV SSIM
Rigid only 50.50 19.59 0.9409 5.16 0.9357
Active Demons only 38.33 20.21 0.9962 1.96 0.9744
Rigid + B-spline 9.46 21.89 0.9972 1.78 0.9910
Proposed (rigid + Active Demons) 8.59 23.53 0.9987 1.31 0.9942

The proposed method achieved the lowest MSE (8.59) and RV (1.31), and the highest PSNR (23.53 dB), CC (0.9987), and SSIM (0.9942). These results confirm that the rigid-elastic registration pipeline provides superior alignment accuracy, which directly contributes to more accurate casting defect detection. The improvement over rigid-only registration is substantial, demonstrating the necessity of handling elastic deformations in casting images.

4. Improved Demons Registration for Casting Defects

Although the Active Demons algorithm is effective for elastic registration, it only exploits gradient information. The direction of image structures, such as edges and textures, contains valuable complementary information that can further improve registration accuracy. In this chapter, I describe an improved non-rigid registration method that incorporates orientation fields into the Demons framework. The method is based on the work by Lan et al., but I enhance it with an adaptive mechanism using mutual information to eliminate manual tuning of the normalization factor.

4.1 Orientation Field and Gradient Field Representation

An image can be characterized by several fields, including intensity, gradient, orientation, and frequency. The gradient field \( \nabla I = (dI_x, dI_y) \) measures the rate of intensity change, while the orientation field \( O_I \) describes the direction of maximum variation. The gradient components are computed by:

$$ dI_x(i,j) = I(i+1,j) – I(i,j), \quad dI_y(i,j) = I(i,j+1) – I(i,j). $$

The orientation field can be derived from the structure tensor. One common formulation uses the following variables:

$$ V_x = 2 dI_x dI_y, \quad V_y = dI_x^2 – dI_y^2, $$

and the orientation angle is given by:

$$ O_I = \frac{1}{2} \tan^{-1}\left( \frac{V_x}{V_y} \right). $$

This angle represents the local edge orientation. In the context of Demons registration, combining the gradient and orientation fields provides a more complete description of local image geometry, thereby improving the estimation of deformation vectors.

4.2 Orientation-Based Demons Algorithm

The orientation-based Demons algorithm extends the classical Demons force by adding directional components. Let \( R \) and \( F \) denote the template and floating images, respectively. The unit orientation vectors for both images are computed as:

$$ \vec{e}_{O_R} = \frac{\nabla R}{|\nabla R|}, \quad \vec{e}_{O_F} = \frac{\nabla F}{|\nabla F|}. $$

The displacement field is then computed using the following equations, which incorporate both gradient and orientation information:

$$ \sin 2\theta_F = \frac{2 \alpha k \nabla F \cdot (R-F)}{\|\nabla F\|^2 + \alpha^2 (R-F)^2}, $$

$$ \sin 2\theta_R = \frac{2 \alpha k \nabla R \cdot (R-F)}{\|\nabla R\|^2 + \alpha^2 (R-F)^2}. $$

The update of the displacement field becomes:

$$ \frac{\partial \mathbf{u}}{\partial t} = \frac{1}{2} \left( \sin 2\theta_F \, \vec{e}_{O_F} + \sin 2\theta_R \, \vec{e}_{O_R} \right). $$

This formulation uses both the gradient magnitudes and the orientation directions, allowing the deformation to follow the natural geometry of the images. However, the parameter \( \alpha \) and \( k \) need to be chosen carefully. In the original implementation, \( \alpha \) is adjusted manually, which is laborious and may not be optimal for different images.

4.3 Mutual Information Adaptive Parameter Adjustment

To overcome the manual tuning issue, I propose to use the normalized mutual information (NMI) between the template and floating images as an adaptive indicator for controlling the deformation strength. Mutual information is a powerful similarity measure that quantifies statistical dependence between two images. The entropy of an image \( I \) is:

$$ H(I) = -\sum_{k} p(k) \log p(k), $$

where \( p(k) \) is the probability of intensity value \( k \). The joint entropy of template \( R \) and floating \( F \) is:

$$ H(R,F) = -\sum_{r}\sum_{f} p(r,f) \log p(r,f). $$

The mutual information is:

$$ I(R,F) = H(R) + H(F) – H(R,F). $$

The normalized mutual information is defined as:

$$ \mathrm{NMI}(R,F) = \frac{H(R) + H(F)}{H(R,F)}. $$

In my modified Demons algorithm, I replace the constant \( \alpha \) with a function of NMI. Specifically, the equations become:

$$ \sin 2\theta_F = \frac{2 k \cdot \mathrm{NMI}(R,F) \nabla F \cdot (R-F)}{\|\nabla F\|^2 + (R-F)^2}, $$

$$ \sin 2\theta_R = \frac{2 k \cdot \mathrm{NMI}(R,F) \nabla R \cdot (R-F)}{\|\nabla R\|^2 + (R-F)^2}. $$

The displacement update is:

$$ \frac{\partial \mathbf{u}}{\partial t} = \frac{1}{2} \left( \sin 2\theta_F \, \vec{e}_{O_F} + \sin 2\theta_R \, \vec{e}_{O_R} \right). $$

Here, \( \mathrm{NMI}(R,F) \) changes adaptively during the iterative process. At the early stages, when the images are far apart and NMI is small, the deformation step is modest, allowing stable convergence. As registration progresses and NMI increases, the algorithm can fine-tune the alignment with larger steps in subtle regions. This adaptive behavior eliminates the need for manual parameter tuning and improves both speed and accuracy.

4.4 Defect Detection Pipeline with Improved Demons

The complete defect detection procedure using the improved Demons method follows the same pipeline as described in the previous chapter, with the elastic registration step replaced by the orientation-based adaptive Demons method. The main steps are listed in Table 4.

Table 4: Steps of Defect Detection with Improved Demons Registration
Step Description
1 Acquire template and inspected casting images
2 Perform rigid registration (translation + rotation)
3 Compute NMI between rigidly aligned image and template
4 Run orientation-based Demons registration with adaptive NMI
5 Apply digital subtraction between the elastically registered image and the template
6 Apply threshold segmentation to identify defect regions
7 Visualize defects on the inspected casting image

4.5 Experimental Evaluation

I evaluated the improved method on three independent sets of casting X-ray images. Each set consisted of a template image and an inspected image containing various defects. The images were 3072×3072 pixels. The proposed method was compared with two representative non-rigid registration approaches: B-spline elastic registration and Active Demons registration. All methods were preceded by the same rigid registration preprocessing. Subjective and objective evaluations were performed on the resulting defect detection maps.

4.5.1 Subjective Analysis

For the first image set, the defect detection results are shown in Figure 2 of the original thesis. The green rectangles indicate regions of interest for close-up inspection. In the magnified views, the B-spline based method failed to detect several defects in the left region, while the Active Demons method detected most of them but missed a few small ones. In contrast, the proposed improved Demons method accurately located nearly all true defects, with fewer false positives and missed detections. Similar trends were observed for the second and third image sets. The use of orientation information clearly improved the alignment of thin edges and small structures, which are critical for detecting fine cracks and pores.

In the second image set, the B-spline method suffered from apparent missed defects in the center region. The Active Demons improved the situation but still left some defects undetected at the boundaries. The proposed method successfully detected these defects, as evidenced by the highlighted marks corresponding to the manual inspection. For the third image set, the B-spline approach produced several false positives due to inaccurate registration in high-texture areas. The Active Demons method reduced false positives but missed a few real defects. The proposed method achieved a balanced performance with high recall and precision.

4.5.2 Objective Analysis

Quantitative metrics were computed for each image set to verify the superiority of the proposed method. Tables 5, 6, and 7 list the MSE, PSNR, CC, RV, and SSIM values for the three image sets.

Table 5: Registration Results for Image Set 1
Method MSE PSNR (dB) CC RV SSIM
Rigid + B-spline 9.46 21.89 0.9972 1.78 0.9910
Rigid + Active Demons 8.59 23.53 0.9987 1.31 0.9942
Rigid + Improved Demons 6.87 26.05 0.9992 1.17 0.9983
Table 6: Registration Results for Image Set 2
Method MSE PSNR (dB) CC RV SSIM
Rigid + B-spline 9.37 21.77 0.9928 2.05 0.9902
Rigid + Active Demons 9.02 23.11 0.9978 1.93 0.9926
Rigid + Improved Demons 6.50 25.94 0.9994 1.76 0.9985
Table 7: Registration Results for Image Set 3
Method MSE PSNR (dB) CC RV SSIM
Rigid + B-spline 14.40 21.06 0.9864 2.46 0.9894
Rigid + Active Demons 10.45 22.46 0.9982 2.08 0.9937
Rigid + Improved Demons 8.38 25.74 0.9989 1.64 0.9979

Across all three image sets, the improved Demons method consistently achieved the lowest MSE and RV values and the highest PSNR, CC, and SSIM values. This indicates that the incorporation of orientation fields and adaptive NMI leads to more precise image alignment, which directly translates into more reliable casting defect detection. The improvements are especially notable in images with complex textures and small defects, where orientation information plays a crucial role.

5. Conclusion and Future Work

In this thesis, I have addressed the problem of automatic defect detection in industrial castings using image registration techniques. The inherent rigid and elastic deformations in casting images necessitate robust registration methods before digital subtraction can be applied. I first proposed a hierarchical combination of rigid registration and Active Demons elastic registration. This method effectively corrects global and local deformations, leading to accurate defect localization. Experimental results confirmed its superiority over rigid-only, elastic-only, and rigid-B-spline approaches.

Recognizing the limitation of gradient-only Demons force, I developed an improved non-rigid registration algorithm that integrates orientation fields with Demons displacement computation. Furthermore, I introduced normalized mutual information as an adaptive parameter to automatically regulate the deformation strength, eliminating manual tuning. The improved method was evaluated on three casting image sets and consistently outperformed both B-spline and Active Demons methods in terms of registration accuracy and defect detection precision. The proposed algorithm is not only more accurate but also more efficient since no manual intervention is required.

Despite these advancements, several challenges remain for future research. First, the Demons-based methods still have limitations in handling images with very weak gradients or significant noise. Future work could incorporate texture descriptors or deep learning features to enhance robustness. Second, the selection of an appropriate similarity measure for non-rigid registration is still an open question. Different applications may require different metrics, and a universal criterion is lacking. I plan to investigate adaptive similarity measures that can be dynamically selected based on image content. Third, the computational efficiency of elastic registration is crucial for real-time industrial inspection. The current algorithm is implemented in MATLAB and Visual Studio; however, optimization using parallel computing or GPU acceleration would substantially reduce processing time. Moreover, the evaluation of casting defect detection should be extended to a larger dataset with ground truth annotations to statistically validate the performance. Finally, the proposed framework could be adapted to other non-destructive testing modalities, such as ultrasonic or thermographic imaging, to broaden its applicability.

In conclusion, the work presented in this thesis demonstrates that a well-designed image registration pipeline, combining rigid and elastic transformations with orientation and mutual information cues, can significantly improve the accuracy of casting defect detection. The methods contribute to the ongoing effort toward intelligent and automated quality control in industrial manufacturing.

Scroll to Top