In my work on automated inspection, the central problem I address is how to detect a casting defect reliably when the image of the part under inspection is not perfectly aligned with a reference image. A casting defect can appear as a gas pore, inclusion, crack, shrinkage cavity, thin wall, or other internal irregularity, and any such casting defect can reduce the mechanical integrity of a component. Because castings are widely used in vehicle wheels, chassis parts, industrial machinery, and safety-critical structures, the presence of a casting defect must be identified with high accuracy before the part enters service. X-ray nondestructive testing is one of the most important tools for this task, but in many production environments the interpretation of X-ray images still depends on human inspectors. Manual inspection is slow, tiring, and subjective, and it can easily miss a small casting defect or mark a harmless variation as a defect. Therefore, I focus on a registration-based strategy that aligns a test casting image with a template casting image and then uses digital subtraction to reveal a casting defect.

My motivation is simple: if the test image and the template image are not spatially aligned, digital subtraction produces false edges and ghost contours, and those artifacts can be mistaken for a casting defect. In real acquisition, the casting may be placed with a small translation, a small rotation, or a local elastic distortion. Translation and rotation are rigid deformations, while local bending, stretching, and warping are elastic deformations. A robust casting defect detection method must therefore handle both rigid and elastic misalignment. I propose a framework in which rigid registration is performed first, elastic registration is performed second, and subtraction with thresholding is performed last. The output is a marked image in which a casting defect is localized and highlighted.
Image registration principle. I begin from the standard registration relationship between a template image and a test image. Let the template image be \(f_1(x,y)\) and the test image be \(f_2(x,y)\). Registration seeks a spatial mapping and an intensity relationship such that
$$ f_1(x,y) = g\left(f_2(\phi(x,y))\right), $$
where \(\phi(x,y)\) is a two-dimensional coordinate transformation and \(g\) is an intensity transformation. In the common case where intensity changes are ignored, I search for
$$ (x’,y’) = \phi(x,y), $$
so that corresponding anatomical or structural points in the two casting images occupy the same coordinates. For casting defect detection, the template image represents an acceptable casting, and the test image may contain a casting defect. The better the alignment, the more reliable the subtraction result and the more accurate the casting defect localization.
Registration transformations. I summarize the main transformation families that are relevant to casting defect inspection. Rigid transformation preserves shape and size, affine transformation preserves parallelism, projective transformation allows perspective effects, and nonlinear or elastic transformation allows local warping. The casting images I study usually require rigid transformation followed by elastic transformation, because the part can be rotated or translated on the fixture, and the imaging geometry or part thickness can introduce local nonrigid variation.
| Transformation type | Reversal | Rotation | Translation | Scaling | Projection | Warping |
|---|---|---|---|---|---|---|
| Rigid | Yes | Yes | Yes | No | No | No |
| Affine | Yes | Yes | Yes | Yes | No | No |
| Projective | Yes | Yes | Yes | Yes | Yes | No |
| Nonlinear or elastic | Yes | Yes | Yes | Yes | Yes | Yes |
The rigid transformation of a point \((x,y)\) can be written 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 translations. An affine transformation is
$$ \begin{bmatrix} x’ \\ y’ \\ 1 \end{bmatrix} = \begin{bmatrix} a_{11} & a_{12} & t_x \\ a_{21} & a_{22} & t_y \\ 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ 1 \end{bmatrix}. $$
A projective transformation is
$$ \begin{bmatrix} x’ \\ y’ \\ 1 \end{bmatrix} = \begin{bmatrix} a_{11} & a_{12} & a_{13} \\ a_{21} & a_{22} & a_{23} \\ a_{31} & a_{32} & a_{33} \end{bmatrix} \begin{bmatrix} x \\ y \\ 1 \end{bmatrix}. $$
A second-order nonlinear transformation can be represented as
$$ x’ = a_{00}+a_{10}x+a_{01}y+a_{20}x^2+a_{11}xy+a_{02}y^2+\cdots, $$
$$ y’ = b_{00}+b_{10}x+b_{01}y+b_{20}x^2+b_{11}xy+b_{02}y^2+\cdots. $$
For casting defect detection, elastic transformation is especially important because small local distortions can create large subtraction residuals even when the global position is correct.
Registration categories. I also considered the common categories used to describe registration algorithms. These categories help me select the right method for casting defect inspection. The table below summarizes the categories and my interpretation for casting images.
| Category | Subtypes | Meaning in my casting defect study |
|---|---|---|
| Application area | Natural image, computer vision, medical image, industrial image | Industrial X-ray casting image registration for casting defect detection |
| Acquisition mode | Point cloud, 2D image, 3D image, video | Two-dimensional X-ray projection images of castings |
| Interaction | Manual, automatic, semi-automatic | Automatic registration is preferred for high throughput |
| Transformation region | Global, local | Global rigid alignment followed by local elastic correction |
| Transformation function | Parametric, non-parametric | Rigid parameters plus a dense displacement field for elastic deformation |
Basic registration pipeline. In my implementation, the registration pipeline contains feature space, search space, search strategy, image interpolation, and similarity measurement. I use a dense intensity-based strategy for the elastic stage because a casting defect may not correspond to a reliable corner or edge feature. I use phase correlation and inertia ellipse features for the rigid stage because translation and rotation can be estimated efficiently and accurately from global image information.
| Pipeline component | Role | My choice for casting defect detection |
|---|---|---|
| Feature space | Information used for matching | Phase information and inertia ellipse for rigid stage; intensity and gradient for elastic stage |
| Search space | Range of possible transformations | Translation, rotation, and dense local displacement field |
| Search strategy | Optimization method | Phase correlation, ellipse axis matching, iterative Demons updates |
| Image interpolation | Resampling of transformed pixels | Linear and Gaussian-smoothed interpolation |
| Similarity measure | Quality of alignment | MSE, PSNR, CC, RV, SSIM, and normalized mutual information |
Similarity measures. I use several objective measures to evaluate registration quality before I trust the detected casting defect. Let \(f(x,y)\) and \(r(x,y)\) be the template and registered images, and let \(\Omega\) be the image domain. The mean squared error is
$$ \mathrm{MSE} = \frac{1}{|\Omega|}\sum_{(x,y)\in\Omega}\left(f(x,y)-r(x,y)\right)^2. $$
The normalized cross-correlation is
$$ \mathrm{CC} = \frac{\sum_{(x,y)\in\Omega}(f(x,y)-\bar f)(r(x,y)-\bar r)} {\sqrt{\sum_{(x,y)\in\Omega}(f(x,y)-\bar f)^2}\sqrt{\sum_{(x,y)\in\Omega}(r(x,y)-\bar r)^2}}. $$
The peak signal-to-noise ratio is
$$ \mathrm{PSNR} = 10\log_{10}\left(\frac{255^2}{\frac{1}{|\Omega|}\sum_{(x,y)\in\Omega}(f(x,y)-r(x,y))^2}\right). $$
The residual mean is
$$ \mathrm{RV} = \frac{1}{|\Omega|}\sum_{(x,y)\in\Omega}\left|f(x,y)-r(x,y)\right|. $$
The structural similarity is
$$ \mathrm{SSIM}(f,r) = \frac{(2\mu_f\mu_r+c_1)(2\sigma_{fr}+c_2)}{(\mu_f^2+\mu_r^2+c_1)(\sigma_f^2+\sigma_r^2+c_2)}, $$
where \(\mu_f,\mu_r\) are means, \(\sigma_f,\sigma_r\) are standard deviations, \(\sigma_{fr}\) is covariance, and \(c_1,c_2\) are small constants. In my casting defect experiments, a lower MSE and RV indicate better alignment, while higher PSNR, CC, and SSIM indicate better alignment.
| Measure | Desired direction | Interpretation for casting defect detection |
|---|---|---|
| MSE | Lower is better | Small residual energy after registration |
| PSNR | Higher is better | Less distortion between template and registered test image |
| CC | Higher is better | Strong linear relationship between aligned images |
| RV | Lower is better | Small average residual that could hide a casting defect |
| SSIM | Higher is better | Preserved structure after alignment |
| NMI | Higher is better | Strong statistical dependence used in my improved elastic stage |
Nonrigid registration methods. I reviewed feature-based, intensity-based, spatial-transformation-based, and physical-model-based nonrigid registration. For casting defect detection, intensity-based and physical-model-based methods are the most practical because they can produce a dense deformation field without requiring explicit landmarks. A physical-model method is especially suitable when the casting image contains smooth local deformation caused by placement or imaging geometry.
| Nonrigid family | Main idea | Strength | Limitation for casting defect detection |
|---|---|---|---|
| Feature-based | Match points, lines, or regions | Interpretable and efficient when features are reliable | A small casting defect may not provide stable features |
| Intensity-based | Optimize a similarity measure over intensities | Uses all image information | Can be sensitive to intensity variation and noise |
| Spatial transformation | Polynomial or spline mapping | Flexible global and local modeling | Control point selection affects smoothness and accuracy |
| Physical model | Elastic or optical flow deformation | Dense displacement field and smooth deformation | Parameters must be tuned carefully |
Rigid registration for casting images. I use phase correlation to estimate translation and an inertia ellipse to estimate rotation. For translation, if
$$ f_2(x,y) = f_1(x-x_0,y-y_0), $$
then the 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)}, $$
and its inverse Fourier transform gives a sharp peak at \((x_0,y_0)\). This peak directly provides the translation that aligns the test casting image with the template casting image. The phase correlation plane is robust to illumination variation and is computationally efficient for large casting images.
For rotation, I construct an inertia ellipse from the grayscale distribution. If the image is treated as a planar rigid body, the moment of inertia about an axis \(L\) is
$$ I = \sum_i m_i r_i^2. $$
With direction cosines \(\alpha,\beta,\gamma\), the inertia is
$$ I = A\alpha^2+B\beta^2+C\gamma^2-2F\beta\gamma-2G\gamma\alpha-2H\alpha\beta, $$
where
$$ A=\sum_i m_i(y_i^2+z_i^2),\quad B=\sum_i m_i(z_i^2+x_i^2),\quad C=\sum_i m_i(x_i^2+y_i^2), $$
$$ F=\sum_i m_i y_i z_i,\quad G=\sum_i m_i z_i x_i,\quad H=\sum_i m_i x_i y_i. $$
The inertia ellipsoid is
$$ A x^2+B y^2+C z^2-2F y z-2G z x-2H x y = 1. $$
For a two-dimensional image, the principal axis slopes can be computed as
$$ k = \frac{1}{2H}\left[(A-B)-\sqrt{(A-B)^2+4H^2}\right], $$
$$ l = \frac{1}{2H}\left[(A-B)+\sqrt{(A-B)^2+4H^2}\right]. $$
By taking the arctangent of these slopes, I obtain the rotation angle between the test casting image and the template casting image. This rigid preprocessing is essential because it removes the dominant global pose difference before elastic registration. Without it, the elastic stage would have to compensate for a large rigid displacement, which reduces stability and may create a false casting defect after subtraction.
Demons elastic registration. After rigid alignment, I apply an elastic registration method based on the Demons algorithm. The original Demons update uses the template gradient as the driving force:
$$ \frac{\partial u}{\partial t} = (m-f)\frac{\nabla f}{|\nabla f|^2}, $$
where \(m\) is the moving or test image after rigid registration and \(f\) is the fixed or template image. To avoid instability when the gradient is small, the normalized form is commonly written as
$$ \frac{\partial u}{\partial t} = \frac{(m-f)\nabla f}{|\nabla f|^2+(m-f)^2}. $$
The Active Demons method introduces the moving image gradient as an additional force:
$$ \frac{\partial 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}. $$
Here \(\alpha\) controls the strength and smoothness of the deformation. A larger \(\alpha\) can suppress excessive local motion, while a smaller \(\alpha\) allows more aggressive warping. In my rigid-elastic framework, I first use phase correlation and inertia ellipse matching, then I use Active Demons to correct local elastic deformation, then I apply digital subtraction.
| Stage | Operation | Purpose for casting defect detection |
|---|---|---|
| 1 | Translation estimation by phase correlation | Remove global shift of the casting |
| 2 | Rotation estimation by inertia ellipse | Remove global rotation of the casting |
| 3 | Active Demons elastic registration | Correct local elastic distortion |
| 4 | Digital subtraction | Reveal intensity differences caused by a casting defect |
| 5 | Threshold segmentation | Remove small registration residuals and mark a casting defect |
Digital subtraction and thresholding. After registration, the template image \(f\) and the registered test image \(m’\) have the same spatial coordinates. I compute the subtraction image
$$ D(x,y) = m'(x,y)-f(x,y). $$
If the casting is acceptable in a local region, \(D(x,y)\) should be close to zero. If a casting defect is present, the local intensity difference is larger. I then apply a threshold \(T\):
$$ B(x,y) = \begin{cases} 1, & D(x,y) > T, \\ 0, & D(x,y) \le T. \end{cases} $$
The binary image \(B(x,y)\) marks candidate casting defect regions. A threshold that is too low keeps registration noise and creates false casting defect marks; a threshold that is too high misses a low-contrast casting defect. In my experiments, I set the threshold by considering the residual distribution after registration and by validating against manual annotations. The threshold step is simple but critical: it converts a continuous residual image into a decision about the presence or absence of a casting defect.
My rigid-elastic casting defect detection method. I designed the first version of my method to address a gap in existing registration-based inspection: many approaches consider only rigid deformation, but real casting images also contain elastic deformation. My method combines rigid registration with Active Demons elastic registration. The algorithm proceeds as follows. First, I estimate translation using phase correlation and rotation using the inertia ellipse. Second, I apply the rigid transformation to the test casting image. Third, I use Active Demons to refine the alignment and obtain a dense displacement field. Fourth, I subtract the registered test image from the template image. Fifth, I threshold the subtraction image and mark candidate casting defect regions on the test image.
| Algorithm element | Specification |
|---|---|
| Input | Template casting image and test casting image |
| Rigid translation | Phase correlation peak |
| Rigid rotation | Inertia ellipse principal axis |
| Elastic deformation | Active Demons iterative displacement field |
| Defect evidence | Digital subtraction residual |
| Decision | Threshold segmentation and connected region marking |
| Output | Marked casting defect locations |
First experimental evaluation. I evaluated the rigid-elastic method on large casting images with a size of \(3072\times3072\). The template was formed by registering and averaging multiple acceptable casting images. I compared rigid registration alone, Active Demons alone, rigid plus B-spline elastic registration, and my rigid plus Active Demons method. The subjective result showed that rigid-only and Active-Demons-only methods left visible misalignment, which produced false casting defect marks. Rigid plus elastic methods reduced false marks. My rigid plus Active Demons method gave the most accurate casting defect localization among these four options.
| Method | MSE | PSNR | CC | RV | SSIM |
|---|---|---|---|---|---|
| Rigid registration | 50.50 | 19.59 | 0.9409 | 5.16 | 0.9357 |
| Active Demons elastic registration | 38.33 | 20.21 | 0.9962 | 1.96 | 0.9744 |
| Rigid plus B-spline elastic registration | 9.46 | 21.89 | 0.9972 | 1.78 | 0.9910 |
| My rigid plus Active Demons method | 8.59 | 23.53 | 0.9987 | 1.31 | 0.9942 |
These values support my conclusion that rigid preprocessing followed by elastic correction is necessary for accurate casting defect detection. The lower MSE and RV, together with higher PSNR, CC, and SSIM, indicate that my registration produced a subtraction image with fewer false residuals. In visual comparisons, my method detected more of the true casting defect regions and produced fewer false marks in the dense defect areas.
Improved Demons registration using direction fields. Although Active Demons performed well, I found that it mainly uses gradient information and does not fully exploit the orientation information in the casting image. A casting image contains intensity, gradient, direction, and frequency fields. The gradient field points along the normal to an edge, while the direction field is related to the tangent of the edge. For a casting defect, the local edge and boundary orientation can carry useful information for spatial deformation. Therefore, I replaced the Active Demons stage with a Demons elastic registration method that introduces a direction field.
For an image \(I\), I compute the gradients
$$ dI_x(i,j)=I(i+1,j)-I(i,j), $$
$$ dI_y(i,j)=I(i,j+1)-I(i,j). $$
I then compute the direction field components
$$ V_x = 2 dI_x dI_y, $$
$$ V_y = dI_x^2 – dI_y^2, $$
$$ O_I = \frac{1}{2}\tan^{-1}\left(\frac{V_x}{V_y}\right). $$
The direction field provides a tangent orientation that complements the gradient direction. In the direction-field Demons method, I define two auxiliary angles for the template \(R\) and the moving image \(F\):
$$ \theta_R = \arctan\left(\frac{eO_R \cdot \nabla R}{k(R-F)}\right), $$
$$ \theta_F = \arctan\left(\frac{eO_F \cdot \nabla F}{k(R-F)}\right), $$
where \(eO_R\) and \(eO_F\) are unit vectors along the direction fields, and \(k\) is a normalization factor. The corresponding sine terms are
$$ \sin 2\theta_F = \frac{2k\nabla F(R-F)}{k^2|\nabla F|^2+(R-F)^2}, $$
$$ \sin 2\theta_R = \frac{2k\nabla R(R-F)}{k^2|\nabla R|^2+(R-F)^2}. $$
The displacement update is
$$ \frac{\partial u}{\partial t} = \frac{1}{2k}\left(\sin 2\theta_F eO_F + \sin 2\theta_R eO_R\right). $$
This update uses both gradient and direction information, which improves the estimation of local deformation around a casting defect and along casting boundaries. However, the direction-field method still requires manual adjustment of the normalization factor \(k\) or \(\alpha\). Manual tuning is time-consuming and not suitable for automated casting defect inspection.
| Information field | Definition | Role in my casting defect registration |
|---|---|---|
| Intensity field | Gray level of each pixel | Provides the basic subtraction signal |
| Gradient field | Spatial derivative of intensity | Drives edge-normal deformation |
| Direction field | Tangent orientation from gradients | Adds orientation constraints around casting defect boundaries |
| Frequency field | Local frequency content | Can describe texture and density intervals |
Mutual information for adaptive normalization. To remove manual tuning, I introduce mutual information and normalized mutual information into the direction-field Demons update. Mutual information measures the statistical dependence between the template casting image and the moving casting image. If the two images are well aligned, their mutual information is high. If they are poorly aligned, their mutual information is low. For a random variable \(X\), entropy is
$$ H(X) = -\sum_x p(x)\log p(x). $$
For the template image \(F\) and moving image \(M\), the marginal entropies are
$$ H(F) = -\sum_r p_F(r)\log p_F(r), $$
$$ H(M) = -\sum_t p_M(t)\log p_M(t). $$
The joint entropy is
$$ H(M,F) = -\sum_{r,t} p_{M,F}(r,t)\log p_{M,F}(r,t). $$
Mutual information is
$$ I(M,F) = H(M)+H(F)-H(M,F). $$
I use normalized mutual information because it is more stable when the overlapping region changes during iterative registration:
$$ \mathrm{NMI}(M,F) = \frac{H(M)+H(F)}{H(M,F)}. $$
In my improved method, \(\mathrm{NMI}(M,F)\) replaces the manually tuned factor in the direction-field Demons equations. The modified angle estimates are
$$ \theta_R = \arctan\left(\frac{eO_R \cdot \nabla R}{k\,\mathrm{NMI}(M,F)(R-F)}\right), $$
$$ \theta_F = \arctan\left(\frac{eO_F \cdot \nabla F}{k\,\mathrm{NMI}(M,F)(R-F)}\right). $$
The modified sine terms are
$$ \sin 2\theta_F = \frac{2k\,\mathrm{NMI}(M,F)\nabla F(R-F)}{k^2|\nabla F|^2+(R-F)^2}, $$
$$ \sin 2\theta_R = \frac{2k\,\mathrm{NMI}(M,F)\nabla R(R-F)}{k^2|\nabla R|^2+(R-F)^2}. $$
The adaptive displacement update becomes
$$ \frac{\partial u}{\partial t} = \frac{\sin 2\theta_F eO_F + \sin 2\theta_R eO_R}{2k\,\mathrm{NMI}(M,F)}. $$
This modification has a clear intuitive meaning. At the beginning of registration, the misalignment is large, the normalized mutual information is relatively low, and the update allows a larger deformation. As the images become better aligned, the normalized mutual information increases, and the update becomes more conservative and more precise. In this way, the algorithm adapts the deformation strength automatically and avoids repeated manual adjustment of \(\alpha\) or \(k\).
| Quantity | Meaning | Effect in my improved method |
|---|---|---|
| \(H(M)\) | Entropy of moving casting image | Measures uncertainty of the test image |
| \(H(F)\) | Entropy of template casting image | Measures uncertainty of the reference image |
| \(H(M,F)\) | Joint entropy | Measures combined uncertainty |
| \(I(M,F)\) | Mutual information | Similarity measure for registration |
| \(NMI(M,F)\) | Normalized mutual information | Adaptive control of elastic update strength |
My improved casting defect detection workflow. The improved workflow keeps the rigid stage and changes the elastic stage. First, I use phase correlation to estimate translation and inertia ellipse analysis to estimate rotation. Second, I apply the rigid transform to the test casting image. Third, I use the direction-field Demons method with normalized mutual information to estimate a dense elastic displacement field. Fourth, I resample the test casting image and compute the subtraction image. Fifth, I threshold the subtraction image and mark candidate casting defect regions. Sixth, I validate the result using several objective similarity measures.
| Step | Operation | Output |
|---|---|---|
| 1 | Phase correlation translation estimation | Translation parameters |
| 2 | Inertia ellipse rotation estimation | Rotation angle |
| 3 | Rigid transformation of test image | Rigidly aligned casting image |
| 4 | Direction-field Demons with NMI | Elastic displacement field |
| 5 | Digital subtraction | Residual image |
| 6 | Threshold segmentation | Candidate casting defect mask |
| 7 | Marking on test image | Final casting defect localization |
Second experimental evaluation. I tested the improved method on three groups of casting images. Each image had a size of \(3072\times3072\). I compared B-spline elastic registration, Active Demons elastic registration, and my improved direction-field Demons registration with normalized mutual information. All methods used the same rigid preprocessing. I evaluated MSE, PSNR, CC, RV, and SSIM. The results showed that my improved method consistently produced the best values across the three groups.
| Group | Method | MSE | PSNR | CC | RV | SSIM |
|---|---|---|---|---|---|---|
| First | B-spline elastic | 9.46 | 21.89 | 0.9972 | 1.78 | 0.9910 |
| First | Active Demons | 8.59 | 23.53 | 0.9987 | 1.31 | 0.9942 |
| First | My improved method | 6.87 | 26.05 | 0.9992 | 1.17 | 0.9983 |
| Second | B-spline elastic | 9.37 | 21.77 | 0.9928 | 2.05 | 0.9902 |
| Second | Active Demons | 9.02 | 23.11 | 0.9978 | 1.93 | 0.9926 |
| Second | My improved method | 6.50 | 25.94 | 0.9994 | 1.76 | 0.9985 |
| Third | B-spline elastic | 14.40 | 21.06 | 0.9864 | 2.46 | 0.9894 |
| Third | Active Demons | 10.45 | 22.46 | 0.9982 | 2.08 | 0.9937 |
| Third | My improved method | 8.38 | 25.74 | 0.9989 | 1.64 | 0.9979 |
In the first group, my improved method reduced MSE from 9.46 to 6.87 relative to B-spline elastic registration and from 8.59 to 6.87 relative to Active Demons. It increased PSNR from 21.89 to 26.05 and from 23.53 to 26.05. The residual mean decreased from 1.78 to 1.17 and from 1.31 to 1.17. The structural similarity increased from 0.9910 to 0.9983 and from 0.9942 to 0.9983. These improvements indicate that the normalized mutual information term successfully adapts the elastic deformation and reduces residual error that could be misinterpreted as a casting defect.
In the second group, the same trend appeared. My improved method achieved the lowest MSE and RV and the highest PSNR, CC, and SSIM. This is important because the second group contained different casting geometries and defect distributions, which shows that the improvement is not limited to a single sample. In the third group, which had the largest residuals overall, my method still achieved the best scores. The third group is especially informative because a weaker registration method produced many false residual regions, while my method suppressed those residuals and retained the true casting defect evidence.
Subjective comparison of casting defect localization. I also compared the marked casting defect regions. In the first group, B-spline elastic registration missed some casting defect regions and produced incomplete marks. Active Demons detected more of the casting defect, but some defects were still missed. My improved method detected the largest number of true casting defect regions and produced the fewest false marks. In the second group, the same pattern was observed: B-spline elastic registration had clear missed detections, Active Demons was better, and my improved method was best. In the third group, B-spline elastic registration produced partial false detections and missed defects, Active Demons improved the detection but still missed a small casting defect, and my improved method gave the most accurate localization.
| Method | False casting defect marks | Missed casting defect regions | Localization accuracy |
|---|---|---|---|
| Rigid only | High | High | Low |
| Active Demons only | Medium | Medium | Medium |
| Rigid plus B-spline elastic | Low to medium | Medium | Medium |
| Rigid plus Active Demons | Low | Low to medium | High |
| My improved direction-field Demons with NMI | Lowest | Lowest | Highest |
Why the improved method works for casting defect detection. The improvement has three main reasons. First, rigid registration removes global translation and rotation, so the elastic stage starts from a much better initial condition. Second, the direction field supplies tangent orientation information that is not available in the gradient alone, which helps the algorithm align casting edges and boundaries near a casting defect. Third, normalized mutual information adapts the deformation strength automatically. When the alignment is poor, the method permits larger correction; when the alignment is good, the method becomes more conservative. This adaptive behavior reduces overshoot and prevents the creation of artificial residuals that could be mistaken for a casting defect.
| Component | Contribution to casting defect detection |
|---|---|
| Phase correlation | Fast and accurate global translation removal |
| Inertia ellipse | Global rotation removal using shape information |
| Direction field | Additional tangent orientation for elastic alignment |
| Demons iteration | Dense local displacement field estimation |
| Normalized mutual information | Automatic adaptation of deformation strength |
| Digital subtraction | Direct visualization of intensity difference caused by a casting defect |
| Threshold segmentation | Reduction of false residuals and final casting defect marking |
Parameter behavior and convergence. In my implementation, the iterative elastic update is smoothed after each iteration to keep the displacement field continuous. If the update is not smoothed, the displacement field can become irregular and produce a false casting defect. I initialize the displacement field to zero and iterate until the similarity measure stops improving or a maximum iteration count is reached. The normalized mutual information term changes during iteration. At the early stage, it is relatively small, so the update is stronger. At the later stage, it is relatively large, so the update is weaker. This is similar to a coarse-to-fine behavior without requiring an explicit multiresolution schedule.
I can summarize the convergence condition as
$$ \left| \mathrm{NMI}^{(t+1)}(M,F) – \mathrm{NMI}^{(t)}(M,F) \right| < \epsilon, $$
or
$$ t \ge N_{\max}, $$
where \(\epsilon\) is a small tolerance and \(N_{\max}\) is the maximum number of iterations. In my experiments, the method usually reaches a stable alignment before the maximum iteration count when the casting image has moderate elastic distortion. When the casting has a large local deformation, more iterations are needed, but the adaptive term prevents excessive warping.
Comparison with other elastic registration choices. I also considered why I did not rely only on B-spline elastic registration or only on Active Demons. B-spline registration controls deformation through a control grid. A sparse grid produces a smooth but less accurate deformation, while a dense grid produces a more accurate but less smooth deformation. Refining the grid globally can be computationally expensive, and a local registration error can propagate. Active Demons is simple and effective, but it mainly uses gradient information and requires parameter tuning. My improved method combines the dense deformation ability of Demons with direction-field information and adaptive normalized mutual information. This combination is well suited to casting defect detection because it can handle local elastic distortion while preserving the global alignment established by the rigid stage.
| Method | Deformation model | Information used | Parameter tuning | Suitability for casting defect detection |
|---|---|---|---|---|
| B-spline elastic | Control grid | Intensity and smoothness | Grid spacing and regularization | Good for smooth deformation, weaker for local defects |
| Original Demons | Optical flow | Template gradient | Iteration and smoothing | Fast but sensitive to large deformation |
| Active Demons | Optical flow with two forces | Template and moving gradients | \(\alpha\) | Better for local deformation but still manual tuning |
| Direction-field Demons | Optical flow with orientation | Gradient and direction | Normalization factor | More accurate but manual tuning |
| My improved method | Adaptive direction-field Demons | Gradient, direction, and NMI | Automatic adaptation | Best among the compared methods in my experiments |
Defect detection sensitivity. The final goal of registration is not only a high similarity score but also a reliable casting defect decision. A high similarity score alone does not guarantee that a small casting defect is detected, because a small local intensity difference can be averaged into a low global residual. I therefore evaluate the subtraction image locally and mark connected residual regions. I also compare the marked regions with manual annotations. In my experiments, the improved registration reduced false residuals around the casting boundary and around internal structures, which allowed the threshold to be set more effectively. As a result, the casting defect detection sensitivity improved without a large increase in false positives.
I can express the local residual contrast for a candidate casting defect region \(R_d\) as
$$ C_d = \frac{1}{|R_d|}\sum_{(x,y)\in R_d} |D(x,y)| – \frac{1}{|R_b|}\sum_{(x,y)\in R_b} |D(x,y)|, $$
where \(R_b\) is a nearby background region without a casting defect. A larger \(C_d\) means that the casting defect stands out more clearly from the registration background. Better registration reduces the background residual, so \(C_d\) increases and the casting defect becomes easier to detect.
Practical implementation details. I implemented the method in a high-level programming environment and processed large casting images. The main computational cost comes from iterative elastic registration, not from phase correlation or inertia ellipse estimation. Phase correlation uses the fast Fourier transform and is very efficient. Inertia ellipse estimation requires moment calculations and principal axis computation, which are also efficient. The Demons iterations require gradient computation, displacement field update, Gaussian smoothing, image interpolation, and normalized mutual information evaluation. The normalized mutual information evaluation adds some cost, but it removes the need for repeated manual parameter search, so the total practical cost is reduced in an automated workflow.
| Operation | Computational character | Practical note for casting defect inspection |
|---|---|---|
| Phase correlation | FFT-based | Fast global translation estimation for large casting images |
| Inertia ellipse | Moment-based | Fast rotation estimation |
| Demons update | Iterative pixel-wise | Dominant cost, but parallelizable |
| Gaussian smoothing | Local convolution | Keeps displacement field regular |
| NMI evaluation | Histogram-based | Removes manual tuning and improves automation |
| Threshold segmentation | Pixel-wise | Fast final casting defect decision |
Discussion of limitations. Although my method improves casting defect detection, I recognize several limitations. First, the method assumes that a reliable template casting image is available. If the template contains a casting defect or if the production process changes, the template must be updated. Second, the threshold for the subtraction image still requires attention. A single global threshold may not be optimal for all casting regions, especially when thickness varies strongly. Third, the method is validated on two-dimensional X-ray projection images. Three-dimensional casting data would require an extension of the deformation model. Fourth, the normalized mutual information term improves automation, but it also adds histogram computation to each iteration. For very large image sets, a multiresolution or GPU implementation would be beneficial.
| Limitation | Effect on casting defect detection | Possible improvement |
|---|---|---|
| Template dependence | A defective or outdated template can cause false results | Use robust template synthesis and periodic template updating |
| Global threshold | May fail when local contrast varies | Use local adaptive thresholding or statistical region decisions |
| 2D projection only | Depth information is limited | Extend to 3D X-ray computed tomography |
| Iterative cost | Slower than simple rigid registration | Use multiresolution, parallel computing, or GPU acceleration |
| Residual noise | Small residuals may remain after registration | Combine with morphological filtering and shape analysis |
Future research directions. I see several promising directions for improving registration-based casting defect detection. One direction is to optimize Demons registration for texture and edge preservation. Another is to study which similarity measure is most appropriate for different casting image types, because MSE, PSNR, CC, RV, SSIM, and NMI emphasize different aspects of image similarity. A third direction is to improve computational speed with multiresolution pyramids, parallel processing, or hardware acceleration. A fourth direction is to integrate casting defect classification after detection, so that a detected casting defect can be labeled as a pore, inclusion, crack, or shrinkage cavity. A fifth direction is to extend the method from two-dimensional projection images to three-dimensional volumetric images.
| Future direction | Reason | Expected benefit for casting defect detection |
|---|---|---|
| Texture and edge preservation | Demons can blur fine structures | Better localization of small casting defects |
| Similarity measure selection | Different measures behave differently | More robust registration for varied casting images |
| Acceleration | Iterative elastic registration is costly | Higher throughput for industrial inspection |
| Defect classification | Detection alone does not identify type | More informative quality control |
| 3D extension | Projection images lose depth information | Improved detection of internal casting defects |
Conclusion. In my study, I developed a registration-based framework for casting defect detection. I first addressed the problem of rigid misalignment using phase correlation and inertia ellipse analysis. I then addressed elastic misalignment using Demons elastic registration. I found that rigid plus elastic registration greatly improves digital subtraction and reduces false casting defect marks. I further improved the elastic stage by introducing a direction field, which adds orientation information to the gradient-based Demons force. Finally, I introduced normalized mutual information to adapt the deformation strength automatically, eliminating the need for manual adjustment of a normalization factor. Across multiple groups of large casting images, my improved method achieved lower MSE and RV and higher PSNR, CC, and SSIM than B-spline elastic registration and Active Demons elastic registration. In subjective comparisons, my method detected more true casting defect regions and produced fewer false marks. These results show that image registration is not merely a preprocessing step for casting defect detection; it is a decisive component that determines whether digital subtraction can reveal a true casting defect or produce a misleading artifact. My work supports the use of rigid-elastic registration with adaptive direction-field Demons and normalized mutual information as an effective approach for automated casting defect inspection.
