In the realm of advanced manufacturing, the casting industry serves as a cornerstone for producing critical components across sectors such as automotive, aerospace, and machinery. Among various casting techniques, sand casting remains prevalent due to its adaptability for complex geometries and cost-effectiveness, especially for large-scale production. The surface quality of sand casting parts is paramount, directly influencing functional attributes like wear resistance, fatigue strength, and noise vibration. Surface roughness, quantified by Ra values typically ranging from 3.2 to 50 μm for sand casting parts, is a key metric for assessing this quality. Traditional evaluation methods, including tactile profilometers and visual comparison with standard specimens, are fraught with limitations: contact-based tools are restricted in measurement range and spatial access, while comparative approaches are subjective and time-consuming. Consequently, there is an urgent demand for non-contact, rapid, and objective measurement systems tailored for sand casting parts. Leveraging advancements in machine vision and artificial intelligence, this study presents an integrated framework that combines image processing with deep learning to automate surface roughness detection for sand casting parts, offering a scalable solution for industrial quality control.
Our approach centers on capturing digital images of sand casting parts surfaces, processing them to extract salient features, and employing a convolutional neural network (CNN) enhanced with attention mechanisms to classify roughness levels. The methodology unfolds in several phases: image acquisition and preprocessing, dataset construction, neural network architecture design, training, and validation on both standard specimens and actual sand casting parts. By focusing on sand casting parts, we address a niche yet critical need in foundry operations, where surface imperfections can lead to downstream failures. The subsequent sections detail each phase, underpinned by mathematical formulations and empirical data, to elucidate the robustness of our system.
Image acquisition constitutes the first step, where consistency is vital to ensure reliable inputs. We engineered a custom module using a DYVCAM-W20246 V22 macro camera with a CMOS sensor, capable of outputting 640×480 pixel images. To mitigate ambient light variations, we incorporated unilateral LED sidelighting and encased the setup in a 3D-printed black resin housing, which minimizes reflections and stray light. This module connects via USB to a computing unit, enabling real-time image capture. For sand casting parts, which often exhibit irregular textures, the fixed focal length and lighting arrangement standardize the imaging conditions, reducing external noise. The raw images, however, require preprocessing to enhance discriminative texture patterns and normalize inputs for neural network consumption.
Preprocessing involves a sequence of operations: cropping, grayscale conversion, contrast enhancement, and noise reduction. Initially, images are cropped to 480×480 pixels to eliminate peripheral blurring inherent to macro lenses. Grayscale conversion simplifies the data by collapsing RGB channels into a single intensity channel, as color information is negligible for roughness assessment in sand casting parts. The transformation follows the luminance formula:
$$ f(i,j) = 0.30R(i,j) + 0.59G(i,j) + 0.11B(i,j) $$
Here, $f(i,j)$ denotes the grayscale value at pixel coordinates $(i,j)$, while $R$, $G$, and $B$ represent the red, green, and blue channel intensities, respectively. This step reduces computational overhead and aligns with the textural focus for sand casting parts surfaces. Next, contrast-limited adaptive histogram equalization (CLAHE) is applied to ameliorate non-uniform illumination and boost local contrast. Unlike global histogram equalization, which can exaggerate brightness disparities, CLAHE operates on tile-based regions with a clip limit to curb noise amplification. For our sand casting parts images, we set a clip limit of 200 and tile size of $8 \times 8$, yielding enhanced texture visibility without artifacts. The discrete histogram equalization for a tile can be expressed as:
$$ s_k = T(r_k) = (L-1) \sum_{j=0}^{k} P_r(r_j) = \frac{L-1}{MN} \sum_{j=0}^{k} n_j $$
where $MN$ is the total pixel count in the tile, $n_j$ is the number of pixels with gray level $j$, $P_r(r_j)$ is the probability of occurrence of gray level $j$, $L=256$ for 8-bit images, and $T$ maps input gray level $r_k$ to output $s_k$. Following CLAHE, median filtering with a kernel size of 7 is employed to suppress random noise while preserving edge details crucial for sand casting parts textures. The median filter output for a window $W$ centered at $(i,j)$ is given by:
$$ \text{median}(W) = \text{middle value of sorted } \{ f(x,y) : (x,y) \in W \} $$
This preprocessing pipeline transforms raw images into normalized, feature-rich representations, as illustrated in Table 1, which summarizes the operations and their parameters for sand casting parts surfaces.
| Step | Description | Parameters/Formula | Purpose for Sand Casting Parts |
|---|---|---|---|
| Cropping | Extract central region | Size: 480×480 pixels | Remove blurry edges |
| Grayscale Conversion | RGB to intensity | $f(i,j) = 0.30R + 0.59G + 0.11B$ | Reduce dimensionality, emphasize texture |
| CLAHE | Adaptive contrast enhancement | Clip limit: 200, Tiles: 8×8 | Normalize illumination, enhance local features |
| Median Filtering | Noise reduction | Kernel size: 7 | Suppress noise while retaining edges |
With preprocessing established, we curated a dataset using standard roughness specimens emulating sand casting parts surfaces. These specimens, categorized into iron-sand type (for ferrous sand casting parts) and aluminum-zinc-magnesium type (for non-ferrous sand casting parts), cover five Ra grades: 3.2, 6.3, 12.5, 25, and 50 μm. We captured 3,478 images in total, followed by horizontal flipping augmentation to double the dataset to 6,956 images, thereby improving generalization. The dataset was partitioned into training, validation, and test sets, ensuring no overlap between splits. Table 2 delineates the distribution, highlighting the balance across roughness levels and specimen types relevant to sand casting parts.
| Subset | Specimen Type | Ra 3.2 μm | Ra 6.3 μm | Ra 12.5 μm | Ra 25 μm | Ra 50 μm | Total Images |
|---|---|---|---|---|---|---|---|
| Training Set | Iron-Sand Type | 484 | 492 | 484 | 492 | 504 | 2,456 |
| Al-Zn-Mg Type | 484 | 516 | 484 | 484 | 492 | 2,460 | |
| Validation Set | Iron-Sand Type | 104 | 104 | 104 | 104 | 104 | 520 |
| Al-Zn-Mg Type | 104 | 104 | 104 | 104 | 104 | 520 | |
| Test Set | Iron-Sand Type | 100 | 100 | 100 | 100 | 100 | 500 |
| Al-Zn-Mg Type | 100 | 100 | 100 | 100 | 100 | 500 |
The core of our detection system is a deep learning model that maps preprocessed images to roughness classes. We adopted a residual convolutional neural network (ResNet) architecture, specifically ResNet50, due to its efficacy in handling hierarchical features through skip connections that mitigate vanishing gradients. To further refine feature learning for sand casting parts textures, we integrated squeeze-and-excitation (SE) attention modules into the residual blocks. Each SE module performs channel-wise feature recalibration by first squeezing global spatial information via global average pooling, then exciting through a gating mechanism with sigmoid activation. Mathematically, for an input feature map $\mathbf{U} \in \mathbb{R}^{H \times W \times C}$, the squeeze operation computes channel-wise statistics:
$$ z_c = \frac{1}{H \times W} \sum_{i=1}^{H} \sum_{j=1}^{W} u_c(i,j) $$
where $z_c$ is the squeezed output for channel $c$. This is followed by excitation using two fully connected layers with ReLU and sigmoid activations to produce channel weights $\mathbf{s} = \sigma(\mathbf{W}_2 \delta(\mathbf{W}_1 \mathbf{z}))$, where $\delta$ denotes ReLU, $\sigma$ is sigmoid, and $\mathbf{W}_1, \mathbf{W}_2$ are learnable weights. The final output is obtained by scaling $\mathbf{U}$ with $\mathbf{s}$. This attention mechanism enables the network to emphasize informative texture channels pertinent to sand casting parts surfaces, enhancing discrimination among Ra grades. The overall network, termed SE-ResNet-50, comprises convolutional layers, SE-enhanced residual blocks, and a fully connected layer for 5-class classification. We trained the model using the Adam optimizer, which adapts learning rates based on moment estimates, with an initial learning rate $\eta = 0.1$. The loss function is categorical cross-entropy, defined as:
$$ \mathcal{L} = -\frac{1}{N} \sum_{n=1}^{N} \sum_{c=1}^{C} y_{n,c} \log(\hat{y}_{n,c}) $$
where $N$ is batch size, $C=5$ is the number of roughness classes, $y_{n,c}$ is the ground-truth label, and $\hat{y}_{n,c}$ is the predicted probability for sand casting parts images. Training hyperparameters are summarized in Table 3, tailored for efficient learning on sand casting parts datasets.
| Hyperparameter | Value/Description | Role in Sand Casting Parts Detection |
|---|---|---|
| Optimizer | Adam (β₁=0.9, β₂=0.999) | Adaptive learning for texture features |
| Initial Learning Rate | 0.1 | Balances convergence speed and stability |
| Batch Size | 64 | Utilizes GPU memory efficiently |
| Epochs | 2,000 (with early stopping) | Prevents overfitting on limited sand casting parts data |
| Loss Function | Categorical Cross-Entropy | Penalizes misclassification of roughness levels |
| Data Augmentation | Horizontal Flipping | Increases variability in sand casting parts textures |
Training proceeded until convergence, monitored via validation accuracy on sand casting parts specimens. The model achieved peak validation accuracies of 99.04% and 99.23% for iron-sand and Al-Zn-Mg types, respectively, after approximately 90 epochs. We evaluated the final model on the held-out test sets, obtaining confusion matrices that underscore its proficiency. Table 4 aggregates the classification results, demonstrating near-perfect accuracy across Ra grades for both specimen types, which bodes well for generalizing to actual sand casting parts.
| Specimen Type | Ra 3.2 μm Accuracy | Ra 6.3 μm Accuracy | Ra 12.5 μm Accuracy | Ra 25 μm Accuracy | Ra 50 μm Accuracy | Overall Accuracy |
|---|---|---|---|---|---|---|
| Iron-Sand Type | 99.0% | 98.0% | 100.0% | 99.0% | 99.0% | 99.00% |
| Al-Zn-Mg Type | 100.0% | 99.0% | 100.0% | 100.0% | 99.0% | 99.60% |
To transition from controlled specimens to real-world scenarios, we developed a software application that encapsulates the trained SE-ResNet-50 model. The software interfaces with the image acquisition module, performs real-time preprocessing, and outputs roughness predictions within seconds. We validated the system on actual sand casting parts, including a stainless steel pump casing and an aluminum alloy volute casing, which exemplify typical sand casting parts in industrial settings. These components exhibit varied surface textures due to mold conditions and material properties, providing a rigorous testbed. We selected 16 points on each casting, ensuring coverage of diverse regions, and compared our machine vision predictions with manual assessments using standard specimen comparison—the prevailing method for sand casting parts in foundries.

The results, tabulated in Table 5, reveal a strong correlation between the two methods. Out of 32 measurements on sand casting parts, 28 aligned perfectly, translating to an accuracy of 87.5%. The discrepancies, occurring at Ra 3.2 μm and Ra 25 μm boundaries, may stem from subtle texture similarities or lighting artifacts during image capture for sand casting parts. Notably, the average inference time per image was 0.086 seconds, underscoring the system’s suitability for high-throughput inspection of sand casting parts. This performance highlights the practicality of our approach for on-line quality control, where speed and objectivity are paramount for sand casting parts manufacturing.
| Sample Point | Sand Casting Part Type | Standard Method (Ra μm) | Our Method (Ra μm) | Deviation | Correct? |
|---|---|---|---|---|---|
| 1 | Stainless Steel Pump Casing | 6.3 | 6.3 | 0.0 | Yes |
| 2 | Stainless Steel Pump Casing | 12.5 | 12.5 | 0.0 | Yes |
| 3 | Stainless Steel Pump Casing | 6.3 | 6.3 | 0.0 | Yes |
| 4 | Stainless Steel Pump Casing | 6.3 | 6.3 | 0.0 | Yes |
| 5 | Stainless Steel Pump Casing | 3.2 | 3.2 | 0.0 | Yes |
| 6 | Stainless Steel Pump Casing | 3.2 | 3.2 | 0.0 | Yes |
| 7 | Stainless Steel Pump Casing | 3.2 | 6.3 | +3.1 | No |
| 8 | Stainless Steel Pump Casing | 12.5 | 12.5 | 0.0 | Yes |
| 9 | Stainless Steel Pump Casing | 12.5 | 12.5 | 0.0 | Yes |
| 10 | Stainless Steel Pump Casing | 12.5 | 12.5 | 0.0 | Yes |
| 11 | Stainless Steel Pump Casing | 6.3 | 12.5 | +6.2 | No |
| 12 | Stainless Steel Pump Casing | 6.3 | 6.3 | 0.0 | Yes |
| 13 | Stainless Steel Pump Casing | 6.3 | 6.3 | 0.0 | Yes |
| 14 | Stainless Steel Pump Casing | 6.3 | 6.3 | 0.0 | Yes |
| 15 | Stainless Steel Pump Casing | 12.5 | 12.5 | 0.0 | Yes |
| 16 | Stainless Steel Pump Casing | 12.5 | 12.5 | 0.0 | Yes |
| 17 | Aluminum Alloy Volute Casing | 50 | 50 | 0.0 | Yes |
| 18 | Aluminum Alloy Volute Casing | 50 | 50 | 0.0 | Yes |
| 19 | Aluminum Alloy Volute Casing | 50 | 50 | 0.0 | Yes |
| 20 | Aluminum Alloy Volute Casing | 25 | 25 | 0.0 | Yes |
| 21 | Aluminum Alloy Volute Casing | 12.5 | 12.5 | 0.0 | Yes |
| 22 | Aluminum Alloy Volute Casing | 12.5 | 12.5 | 0.0 | Yes |
| 23 | Aluminum Alloy Volute Casing | 25 | 50 | +25.0 | No |
| 24 | Aluminum Alloy Volute Casing | 50 | 50 | 0.0 | Yes |
| 25 | Aluminum Alloy Volute Casing | 50 | 50 | 0.0 | Yes |
| 26 | Aluminum Alloy Volute Casing | 50 | 50 | 0.0 | Yes |
| 27 | Aluminum Alloy Volute Casing | 50 | 50 | 0.0 | Yes |
| 28 | Aluminum Alloy Volute Casing | 25 | 50 | +25.0 | No |
| 29 | Aluminum Alloy Volute Casing | 25 | 25 | 0.0 | Yes |
| 30 | Aluminum Alloy Volute Casing | 12.5 | 12.5 | 0.0 | Yes |
| 31 | Aluminum Alloy Volute Casing | 25 | 25 | 0.0 | Yes |
| 32 | Aluminum Alloy Volute Casing | 25 | 25 | 0.0 | Yes |
The effectiveness of our machine vision system for sand casting parts stems from several synergistic factors. The preprocessing pipeline, particularly CLAHE, mitigates illumination variances common in industrial environments, while median filtering preserves texture integrity. The SE-ResNet-50 architecture excels at capturing multi-scale features inherent to sand casting parts surfaces, with attention mechanisms prioritizing salient channels. From a computational standpoint, the model’s efficiency—evidenced by sub-second inference—makes it viable for integration into production lines for sand casting parts. However, limitations persist: the accuracy dip on actual sand casting parts versus specimens suggests sensitivity to surface conditions like oxidation or residual sand, which could be addressed by training on more diverse real-world images of sand casting parts. Additionally, the system assumes planar surfaces; curved or recessed areas on sand casting parts might require multi-angle imaging. Future enhancements could incorporate transfer learning from broader surface texture datasets or employ generative adversarial networks to synthesize augmented data for sand casting parts. Moreover, extending the Ra range beyond 50 μm would cater to rougher sand casting parts, such as those from large-scale molds.
In summary, we have demonstrated a comprehensive machine vision framework for non-contact surface roughness detection of sand casting parts. By fusing image processing algorithms with a deep residual network augmented by attention, we achieved high classification accuracy on standard specimens and robust performance on actual sand casting parts. The system’s speed, objectivity, and ease of use present a significant advancement over traditional methods, promising enhanced quality assurance for sand casting parts manufacturing. As industries increasingly adopt Industry 4.0 paradigms, such automated inspection tools will become indispensable for maintaining competitiveness and reducing human error. Continued refinement through larger datasets and real-time optimization will further solidify the applicability of this approach across diverse sand casting parts production scenarios.
