Assisting Microscopic Defect Assessment in Investment Castings: Random Forest and CNN Compared
Published:
2025-05-20
Using production micrographs of casting sections, this study compares Random Forest and convolutional neural networks and examines resolution, dataset preparation and overfitting. The CNN achieved 98% test accuracy as an operator-assistance tool.
Figure 3: Examples of different defects in microscopic examination.
Building a Comparable Study from Production Micrographs
After cleaning and post-processing, the internal quality of investment castings cannot be judged solely by surface appearance. The inspection part of this paper is to cut the casting section and observe it under microscope, then the inspector decides whether there is defect in the image. This link belongs to destructive inspection, which deals with the obtained cross-section microscopic images, rather than directly seeing through the castings with ordinary cameras. The study hopes to add a data-driven basis for review while preserving human judgment.
The objects to be identified are classified into pores and micropores, larger gas pockets, cracks and surface chemical reactions. The visible characteristics of different defects vary significantly: cracks appear as continuous thin lines, pores may have only a small local area, and reaction areas may be close to the edge. Instead of establishing classification rules for multiple defects, the task is limited to two categories, i.e., a microscopic image contains defects or does not contain defects. This task boundary determines what subsequent accuracy means.
The process shown in Figure 1 places the model after the operator's initial evaluation: the model may support the original judgment or may present inconsistent results for re-examination. It does not change microscope hardware and does not cancel section preparation. The focus of the study is to determine what kind of learning methods are suitable for such images, rather than claiming to have built a set of whole-line detection equipment that can operate unattended.

The data came from the historical image database of daily quality inspection of enterprises, with a total of 2249 original microscopic images, of which 1787 contained defects and 462 did not contain defects. The same defect is recorded repeatedly with different magnification, scale or corner in the image containing defect. If these highly similar records are indiscriminately trained and tested, the model may encounter defects that have already been seen. Therefore, the author selects and labels images first, rather than treating the original number as an independent sample number.
Most of the original images are 2080×1544 pixels, and the pretreatment is first cut into squares with sides of 1544 pixels to highlight the observation area. The author selects 500 images from the records containing defects, covers different defects, and uses industry professionals to complete the labeling, so as to avoid the same image repeatedly appearing in training, verification and testing. There are 462 images without defects, and 500 images are enhanced after part of them. Finally, two kinds of balanced data sets with 500 images each and 1000 images in total are formed.
The raw data are not all at the same resolution. There are 14 images with defects and 3 images without defects with 1040×772 pixels, which are attributed to the magnification and recording conditions in the actual microscopic examination. Figure 5 shows an example of retaining original and enhanced images, illustrating that data consolidation is not only about adjusting file size, but also about whether defects are still clear after cropping, and whether different recording conditions can enter the same evaluation process.

The traditional machine learning component starts with random forests. For this approach, which uses image pixels as input features, increasing the image resolution quickly increases the number of features. For a sample size of 1000, the author limits the test range to no more than 31 pixels per side and changes the resolution step by step. In the initial scan, 29×29 pixels achieved 89.3% classification accuracy, and then random forest parameters were adjusted at this resolution.
But pressing 1544 pixels to 29 pixels doesn't just make the image look fuzzy. Figure 7 shows that some small pores are difficult to distinguish after downsampling, and the image with small defects may be very close to the intact image. Such errors may be directional, meaning that the model consistently classifies small defects as defect-free, rather than randomly making errors between the two classes. Therefore, higher overall accuracy must also be understood in conjunction with the degree of retention of minor defects.

The convolutional neural network part tested 50, 100, 150, 200, and 250 pixel sides, comparing the benefits of retaining more detail with the risk of overfitting. Figure 8 shows the performance of different defects at various resolutions side by side: when the side length reaches 100 pixels, the morphological information of small defects is much clearer than that of 29 pixels. Instead of using maximum resolution directly, the study continued to observe whether there was an increasing performance gap between the training and validation sets.

The data were divided into training, validation and test sets by 70%, 15%, and 15%. After the images are converted into tensors, the spatial structure is preserved, 32 images are grouped into batches, and the input order is disturbed. The training set is used to learn model parameters, the validation set is used to compare resolution and training state, and the test set is used for final evaluation. The three sets have different functions, and the image performance that has been contacted in the training process cannot be regarded as the recognition effect that has not seen the data in the end.
The network contains two convolutional blocks. Each block uses two convolutional layers, each with 32 filters of size 3×3 and padding 1, ReLU activation, and a max-pooling layer with kernel size 2 and stride 2. A dropout rate of 0.1 follows pooling to reduce overfitting. The resulting feature maps are flattened and passed to a fully connected layer with two output classes: faulty and non-faulty. Figure 9 shows this architecture; the study did not simply adopt a larger general-purpose image network.

Changing the input resolution also changes the number of flattened features. Original Equation (1) gives input_features = 32 × [resolution / 2^(num_maxpool_layers)]², where resolution is the image side length and num_maxpool_layers is the number of max-pooling layers. Thus input size affects the size of the classification layer as well as retained defect detail and model capacity.
Each model was trained for 50 epochs, using cross-entropy loss to measure the difference between predictions and labels, and parameter updates were performed with Adam Optimizer. During the training process, the correction weights are back-propagated, and the accuracy and loss of training and validation are recorded. In the evaluation phase, SoftMax converts the output of the network into category probabilities, and then calculates the accuracy rate according to the proportion of correctly classified images. The paper compares the two recognition methods in this complete process, rather than showing only a few images that seem successful.
Classification Results, Resolution and Inspection Practice
Random forest further tested the number of trees at 29×29 pixels, and the final accuracy was 90% at 70 estimators. The authors also compared decision trees, Gaussian processes, and support vector machines on the same dataset with accuracy rates of 80%, 69.3%, and 68.6%, respectively. Fig. 12. Accuracy is combined with the number of correct and incorrect judgments. The correspondence confusion matrix is used to distinguish correctly identified defects, correctly identified intact images, and false positives from missed detections.

This set of comparisons shows that random forest is the best performing scheme among the traditional classifiers tested in this study, but 90% does not eliminate information loss under low-resolution conditions. For a pore with a small cross-section, it is difficult to recover the lost details by increasing the number of decision trees when the input image itself lacks recognizable features. The paper therefore uses random forest as a control and focuses on CNN which can learn spatial features.
CNN's resolution comparison checks for three indicators simultaneously: whether training accuracy is significantly higher than validation accuracy, whether there is a large gap between training and validation losses, and whether validation losses stop falling or turn up as training losses continue to fall. The author finally chose 100×100 pixels. Figures 13 and 14 show that the gap between training and validation begins to widen as the resolution increases to 150 pixels and above, indicating that more pixels do not automatically lead to more reliable generalization at this data size and network structure.


The 100-pixel input retained details such as microporosity while keeping training and validation losses close. The final CNN test accuracy was 98%, and validation accuracy was 95%. These figures refer to different datasets. Figure 16 compares the CNN and Random Forest confusion matrices: the CNN made more correct predictions, supporting the improvement beyond a few selected example images.

The authors also pulled new images from industrial databases that had not been previously entered into the model to show predictions for both defective and defect-free instances. Figure 17 illustrates that the model can handle new inspection records, but this figure is an example validation and cannot be otherwise inferred as having completed independent large-scale validation across enterprises, equipment, or materials. The 98% in the paper should still correspond to its set of tests, rather than directly as the quality pass rate of all investment castings.

The difference between the two methods is related to the way the image features are organized. Methods such as random forest mainly receive pixel features associated with specific locations; CNN extracts spatial morphology through local convolution and pooling, so that similar defects can still be identified when they appear in different positions. Dropout further constrains the model's dependence on training sample details. This explanation corresponds to the resolution experiment: it is valuable to retain spatial information, but the model capacity must still match the sample size.
Down to the test site, the study retains the judgment role of the operator. If the model results disagree with the initial estimate, the personnel can review the original microscopic image to check whether the disagreement is caused by micropores, cracks or local reaction areas. The goal of this framework is to enhance consistency of judgment and reduce omissions and bias in single-person inspections. It does not further translate image classification into acceptance levels for each defect in product drawings or material standards.
The paper also clearly points out that the current model still needs to be manually used by the operator, only to judge whether there are defects, and the percentage of defects in the cross section has not been calculated. Continuous operation, improvement of processing speed, classification of defect types, and establishment of links with specific manufacturing conditions are all follow-up research directions. The enterprise data used in the study is not public, so reuse cannot assume that the same training set and all field validation conditions have been obtained at the same time.
For casting quality links where it is desired to introduce auxiliary identification, the core basis provided by this work is traceable data collation, appropriate image resolution, and a clear division of labor between training, validation, and testing. What really supports its effectiveness is the comparison results under these conditions. If the magnification, illumination, section treatment or defect category are changed, it is still necessary to reconfirm whether the input characteristics and judgment results are consistent, so that the model can become an effective supplement in the inspection process.
Antonia Antoniadou、Amare Desalegn Fentaye、Ioanna Aslanidou、Konstantinos Kyprianidis; The International Journal of Advanced Manufacturing Technology,138,3277–3291; DOI:10.1007/s00170-025-15616-6。 This article is compiled according to the original text, the original number of the drawings is retained, and the CC BY 4.0 authorization is adopted.Original Paper · PDF · CC BY 4.0 ·
Related News