Casting X-ray image defect detection method based on SAHI algorithm

By employing the SAHI algorithm to perform overlapping slicing of X-ray images of castings and a two-stage trained deep learning network model, the problems of false detection and missed detection in X-ray image defect detection of castings are solved, thereby improving detection accuracy and efficiency.

CN121998955APending Publication Date: 2026-05-08WUHAN UNIV OF TECH
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
WUHAN UNIV OF TECH
Filing Date
2026-01-29
Publication Date
2026-05-08

AI Technical Summary

Technical Problem

Existing methods for detecting defects in castings using X-ray images ignore the inherent characteristics of the X-ray defect images themselves, resulting in high false positive and false negative rates. In particular, they are not very effective in identifying small-sized defects and defects with small inter-class differences but large intra-class differences.

Method used

The SAHI algorithm was used to perform overlapping slicing on the X-ray images of the castings. A two-stage deep learning network model was constructed. First, the global semantic context was learned through the initial dataset. Then, the local detail features were trained through the sliced ​​dataset. Combined with denoising and contrast enhancement, the YOLO11-seg network was used for defect detection.

Benefits of technology

It improves the accuracy and precision of identifying internal defects in castings, reduces the GPU memory required for training, improves model training efficiency, and enhances the model's generalization ability and robustness.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121998955A_ABST
    Figure CN121998955A_ABST
Patent Text Reader

Abstract

The invention provides a casting X-ray image defect detection method based on an SAHI algorithm, and the method comprises the steps: carrying out the defect marking of an obtained casting X-ray image, and obtaining an initial data set; slicing the initial data set based on an overlapping image cutting algorithm, and adjusting and marking to obtain an image cutting data set; constructing a deep learning network model, performing pre-training on the deep learning network model based on the initial data set to obtain a pre-training model, and performing fine tuning on the pre-training model based on the cut graph data set to obtain a target network model; segmenting the X-ray image of the casting to be detected into a plurality of overlapped image blocks based on an SAHI algorithm; and performing defect detection on the plurality of image blocks based on the target network model to obtain a plurality of detection results, mapping the detection results back to an image coordinate system of the X-ray image of the casting to be detected, and fusing the detection results to obtain a defect detection result. According to the method, the calculation cost during model training is reduced, the training efficiency is improved, and the detection precision of the internal defects of the casting is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of casting defect detection technology, specifically to a method for detecting casting defects using X-ray images based on the SAHI algorithm. Background Technology

[0002] Large and complex castings are key components in major equipment in aerospace, energy, and petrochemical industries, and their performance directly affects the service life of the entire equipment. During the manufacturing process, influenced by multiple factors such as process parameters and the production environment, large and complex castings are prone to internal defects such as shrinkage cavities, porosity, inclusions, and gas porosity, which reduce product performance to varying degrees and can even lead to catastrophic accidents in severe cases. Accurate and efficient casting defect detection technology can effectively avoid economic losses and safety accidents caused by defective castings. Currently, large and complex castings mainly rely on X-ray inspection technology for non-destructive testing, and defects are identified by manually interpreting X-ray images. This method suffers from low efficiency, significant subjective influence on inspection quality, and a high rate of missed detections.

[0003] With the development of intelligent manufacturing and machine vision technologies, deep learning has become a research hotspot in the field of target detection due to its powerful learning capabilities, wide adaptability, and good portability. To improve the accuracy of target recognition, various optimized deep learning target detection algorithms and network module improvement methods have been proposed. These methods have improved the accuracy of target recognition to some extent, but most deep learning algorithms perform well in natural scenes, while their performance in detecting internal defects in castings is poor. Specifically, most existing research on intelligent detection of casting defects is based directly on training with acquired X-ray images, focusing primarily on improving deep learning network models, while neglecting the false positives and false negatives caused by the characteristics of the casting X-ray defect images themselves. Specifically, internal defects in castings (such as porosity and shrinkage) typically appear as small targets in X-ray images, with small inter-class differences and large intra-class differences. Traditional methods usually compress the high-resolution original image before inputting it into the network, resulting in the destruction of key details of small targets and severe loss of spatial information, seriously affecting detection accuracy.

[0004] Therefore, there is an urgent need to provide a defect detection method for castings based on the SAHI algorithm, which can adapt to the characteristics of casting X-ray images and improve the accuracy of defect detection. Summary of the Invention

[0005] In view of this, it is necessary to provide a defect detection method for casting X-ray images based on the SAHI algorithm to solve the technical problem of false positives and false negatives caused by ignoring the characteristics of the casting X-ray defect images themselves in the existing technology.

[0006] To address the aforementioned technical problems, in a first aspect, the present invention provides a method for detecting defects in X-ray images of castings based on the SAHI algorithm, comprising:

[0007] Acquire X-ray images of the casting and annotate the defects in the X-ray images of the casting to obtain an initial dataset; The initial dataset is sliced ​​and the labels are adjusted based on the overlapping slicing algorithm to obtain a sliced ​​dataset. A deep learning network model for detecting internal defects in castings is constructed. The deep learning network model is pre-trained based on the initial dataset to obtain a pre-trained model. The pre-trained model is then fine-tuned based on the tiling dataset to obtain the target network model. The SAHI algorithm is used to segment the X-ray image of the casting under test into multiple overlapping image blocks; Based on the target network model, defect detection is performed on the multiple image patches to obtain multiple detection results that correspond one-to-one with the multiple image patches; The detection results are mapped back to the image coordinate system of the X-ray image of the casting under test and fused to obtain the defect detection results.

[0008] In one possible implementation, before marking defects in the X-ray image of the casting, the method further includes: The X-ray image of the casting is subjected to noise reduction and contrast enhancement processing.

[0009] In one possible implementation, the denoising process employs a nonlocal mean filtering algorithm, and the contrast enhancement process employs a contrast-limited adaptive histogram equalization method.

[0010] In one possible implementation, the initial dataset is sliced ​​based on an overlapping slicing algorithm, including: The initial dataset is sliced ​​based on a preset first overlap rate and a preset first size to obtain multiple slice regions; Determine whether the size of the cropping region located at the edge of the image in the initial dataset is smaller than the first size; If so, the initial dataset is reverse-cut starting from the image edge so that the size of each cut region is the same as the preset size.

[0011] In one possible implementation, after obtaining the tiling dataset, the following is also included: Delete the image blocks in the plot dataset that do not contain defects.

[0012] In one possible implementation, the pre-trained model includes a backbone network, a neck network, and a detection head; fine-tuning the pre-trained model based on the slice dataset to obtain the target network model includes: Freeze the backbone network, and train the neck network and the detection head based on the plot dataset to obtain the transition network model; Unfreeze the backbone network, train the transition network model based on the plotted dataset, and obtain the target network model.

[0013] In one possible implementation, the SAHI-based algorithm is used to segment the X-ray image of the casting under test into multiple overlapping image blocks, including: The X-ray image of the casting under test is divided into multiple overlapping image blocks based on the SAHI algorithm, a preset second overlap rate, and a preset second size; The first overlap rate and the second overlap rate are equal, and the first size and the second size are equal.

[0014] In one possible implementation, after mapping each of the detection results back to the image coordinate system of the X-ray image of the casting under test and fusing them, the method further includes: The defect detection results are redundancy removed based on the nonmaximum suppression algorithm.

[0015] In one possible implementation, the target network model is YOLO11-seg.

[0016] The beneficial effects of this invention are as follows: The SAHI algorithm-based method for detecting defects in X-ray images of castings provided by this invention sets the target network model training process to a two-stage training based on an initial dataset and a slice dataset. This allows the target network model to first learn the global semantic context of the initial dataset and then train based on the slice dataset. This increases the relative size of defects in the image, enabling the model to focus more on learning the local detailed features of defects. This effectively solves the problem of difficult identification and detection caused by small defect size, small inter-class differences, and large intra-class differences, and improves the accuracy of identifying internal defects in castings.

[0017] Furthermore, by slicing the initial dataset, this invention can transform large-size images into multiple small-size image patches for training, significantly reducing the GPU memory required for a single training run. This makes it possible to train high-resolution image models with limited hardware resources and accelerates the efficiency of model training iterations. Attached Figure Description

[0018] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0019] Figure 1 A schematic flowchart of an embodiment of the casting X-ray image defect detection method based on the SAHI algorithm provided by the present invention; Figure 2 This is a schematic diagram of an embodiment of the overlapping slicing algorithm for slicing an initial dataset provided by the present invention; Figure 3 A schematic diagram illustrating an embodiment of the implementation process of the overlapping image slicing algorithm provided by the present invention; Figure 4 This is a schematic flowchart of an embodiment of the present invention for fine-tuning a pre-trained model; Figure 5 This is a detailed implementation process diagram of S105 provided by the present invention; Figure 6 A comparison chart of detection results using plotted data to fine-tune the model versus not using plotted data; Figure 7 This is a comparison of the detection results using the uniform tiling method and the overlapping tiling algorithm. Detailed Implementation

[0020] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of the present invention, and not all of them. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention without creative effort are within the scope of protection of the present invention.

[0021] It should be understood that the schematic drawings are not drawn to scale. The flowcharts used in this invention illustrate operations implemented according to some embodiments of the invention. It should be understood that the operations in the flowcharts may be implemented out of order, and steps without logical contextual relationships may be reversed or performed simultaneously. Furthermore, those skilled in the art, guided by the content of this invention, may add one or more other operations to the flowcharts, or remove one or more operations from the flowcharts. Some block diagrams shown in the drawings are functional entities and do not necessarily correspond to physically or logically independent entities. These functional entities may be implemented in software, in one or more hardware modules or integrated circuits, or in different network and / or processor devices and / or microcontroller devices.

[0022] In this document, the term "embodiment" means that a particular feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of the invention. The appearance of this phrase in various places throughout the specification does not necessarily refer to the same embodiment, nor is it a mutually exclusive, independent, or alternative embodiment. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.

[0023] This invention provides a method for detecting defects in X-ray images of castings based on the SAHI algorithm, which will be described in detail below.

[0024] Figure 1 This is a schematic flowchart of an embodiment of the casting X-ray image defect detection method based on the SAHI algorithm provided by the present invention, as shown below. Figure 1 As shown, the defect detection method for castings based on SAHI algorithm X-ray images includes: S101. Obtain X-ray images of the casting and annotate the defects in the X-ray images of the casting to obtain the initial dataset.

[0025] Specifically, the process of annotating defects in X-ray images of castings is as follows: the labelme tool is used to outline the defect contours in the X-ray images of castings using polygons to achieve defect annotation. Then, the annotated image is saved as a JSON file, and the initial dataset is determined based on this JSON file and the X-ray images of castings.

[0026] S102. The initial dataset is sliced ​​and the labels are adjusted based on the overlapping slicing algorithm to obtain the sliced ​​dataset.

[0027] It should be understood that the image patch dataset includes multiple image patches, and the field of view of each image patch is smaller than that of the X-ray image of the casting.

[0028] Specifically, adjusting annotations refers to modifying the position and size of annotations in the initial dataset. For example, if a defect image is sliced ​​into two parts, the size of the defect in the sliced ​​image dataset will differ from that in the original image. Adjusting the annotations can improve the accuracy of the annotations in the sliced ​​image dataset.

[0029] S103. Construct a deep learning network model for detecting internal defects in castings. Pre-train the deep learning network model based on the initial dataset to obtain a pre-trained model. Fine-tune the pre-trained model based on the tiling dataset to obtain the target network model.

[0030] Specifically, the deep learning network model is the YOLO series network, and preferably, the deep learning network model is YOLO11-seg.

[0031] S104. Based on the SAHI algorithm, the X-ray image of the casting to be tested is divided into multiple overlapping image blocks.

[0032] The SAHI (Slicing Aided Hyper Inference) algorithm's specific segmentation process is as follows: A sliding window of a preset size slides across the X-ray image of the casting under test with a certain overlap rate, dividing the entire image into multiple overlapping image blocks. This overlapping segmentation mechanism ensures that regardless of where the defect is located in the image, it can appear in at least one image block in a complete or near-complete form, thus avoiding target breakage or loss of edge information due to segmentation.

[0033] S105. Based on the target network model, perform defect detection on multiple image blocks to obtain multiple detection results that correspond one-to-one with the multiple image blocks; S106. Map each detection result back to the image coordinate system of the X-ray image of the casting to be tested and fuse them to obtain the defect detection result.

[0034] It should be noted that, in order to ensure the performance of the target network model, the target network model can be evaluated based on multiple evaluation metrics before performing defect detection on multiple image blocks. When the evaluation results meet the requirements, defect detection can then be performed on multiple image blocks.

[0035] Specifically, evaluation metrics include, but are not limited to, precision, recall, and mean precision (mAP) across all classes. Precision is the proportion of samples that were actually predicted as positive by the model; recall is the proportion of samples that were actually positive that were correctly predicted as positive by the model; and mAP is the average AP value for all classes. The specific calculation formulas for these three evaluation metrics will not be elaborated here.

[0036] It should be understood that the casting X-ray image defect detection method based on the SAHI algorithm in this embodiment of the invention can be implemented in any device based on the casting X-ray image defect detection method based on the SAHI algorithm, such as electronic equipment like a casting X-ray image defect detection device based on the SAHI algorithm. Specifically, the casting X-ray image defect detection method based on the SAHI algorithm is stored in the aforementioned device as a pre-programmed program. When the device is started, the program is invoked, and the casting X-ray image defect detection method based on the SAHI algorithm is implemented.

[0037] Compared with existing technologies, the casting X-ray image defect detection method based on the SAHI algorithm provided in this invention sets the target network model training process as a two-stage training based on an initial dataset and a slice dataset. This allows the target network model to first learn the global semantic context of the initial dataset and then train based on the slice dataset. This increases the relative size of defects in the image, enabling the model to focus more on learning the local detailed features of defects. This effectively solves the problem of difficult identification and detection caused by small defect size, small inter-class differences, and large intra-class differences, and improves the accuracy of identifying internal defects in castings.

[0038] Furthermore, by slicing the initial dataset, the embodiments of the present invention can transform large-size images into multiple small-size image patches for training, which significantly reduces the GPU memory required for a single training session, making it possible to train high-resolution image models with limited hardware resources and accelerating the efficiency of model training iterations.

[0039] In practical applications, directly acquired X-ray images of castings often contain significant noise interference (such as Gaussian noise and speckle noise) and have low overall contrast, resulting in blurred defect outlines and minimal grayscale difference between the defect and the background. This raw image quality severely restricts the efficiency of subsequent steps: on the one hand, it makes it difficult to accurately define defect boundaries manually or semi-automatically, affecting the accuracy of the initial dataset's annotation; on the other hand, using poor-quality raw images directly for model training forces the model to expend a large amount of resources learning noise features and makes it difficult to capture subtle grayscale changes, thereby reducing the deep learning network's ability to learn the essential features of defects and its generalization performance, becoming a fundamental bottleneck restricting overall detection accuracy.

[0040] To address this technical problem, in some embodiments of the present invention, before marking defects in the X-ray image of the casting, the following steps are also included: The X-ray images of the castings were subjected to noise reduction and contrast enhancement.

[0041] The noise reduction process employs a nonlocal mean filtering algorithm, while the contrast enhancement process uses a contrast-limited adaptive histogram equalization method.

[0042] In a specific embodiment of the present invention, the process of denoising using a nonlocal mean filtering algorithm is as follows: First, a large search window and a small neighborhood window are defined. The center pixel of the search window is taken as the target. The neighborhood window slides in the search window. The similarity between each pixel in the search window and the neighborhood window of the target pixel is calculated and used as a weight value. The pixel values ​​of all pixels in the search window are weighted and averaged to replace the pixel value of the target pixel. This reduces noise interference while preserving image details and edge information.

[0043] The contrast enhancement process using the contrast-limited adaptive histogram equalization method is as follows: The X-ray image of the casting is divided into multiple local regions, and histogram equalization is performed independently on each region. When the histogram of a certain region exceeds a preset contrast threshold, the excess histogram data is cropped, and the cropped gray levels are evenly distributed to other effective gray level ranges to balance contrast enhancement and noise suppression. Finally, bilinear interpolation is used to perform weighted fusion on four adjacent local regions to eliminate unnatural transitions at the boundaries of each region.

[0044] This invention first utilizes a nonlocal mean filtering algorithm to effectively suppress image noise while preserving the edge and structural details of defects to the greatest extent possible, avoiding edge blurring caused by traditional filtering methods. Then, a contrast-limited adaptive histogram equalization method is employed to enhance the local contrast of the image, significantly improving the grayscale difference between the defect area and the surrounding background, making the originally blurred defect outline clear and prominent. The synergistic application of these two methods provides high-quality, high-reliability input for subsequent defect annotation, improving the quality of the initial dataset construction. Simultaneously, it provides deep learning models with more distinct features and less noise, enabling the model to focus more on learning the essential morphological features of defects, laying a crucial preliminary data foundation for achieving high accuracy in the entire detection method.

[0045] It should be noted that the X-ray image of the casting to be tested also has the technical problem of low image quality. Therefore, when executing step S104, it is also necessary to perform noise reduction and contrast enhancement processing on the X-ray image of the casting to be tested. The processing process is the same as that of the X-ray image of the casting, and will not be described in detail here.

[0046] When performing overlapping image cropping, the original image size is often not divisible by integer multiples of the overlapping image cropping algorithm, resulting in incomplete remaining portions at the image edges. Discarding these remaining portions directly will lose potential defect information within that area, creating a detection blind spot and reducing overall recall. Forcibly scaling or padding to a preset size will introduce unrealistic image deformations or invalid pixels, distorting the true geometric features and spatial context of defects, misleading the deep learning model, affecting its learning of the true shape and scale of defects, and ultimately impairing the model's detection accuracy and robustness in practical applications.

[0047] To address the aforementioned technical problems, in some embodiments of the present invention, such as... Figure 2 As shown, step S102 involves slicing the initial dataset based on the overlapping slicing algorithm, including: S201. Slice the initial dataset based on the preset first overlap rate and preset first size to obtain multiple slice regions; S202. Determine whether the size of the cropping region located at the edge of the image in the initial dataset is smaller than the first size; S203. If so, then starting from the image edge, reverse cut the initial dataset so that the size of each cut region is the same as the preset size.

[0048] It should be noted that reverse cropping refers to cutting out a complete patch of the first size from the edge of the image inward, so as to ensure that every pixel region (including the edge) of the original image is effectively and without distortion covered in a training sample of a certain standard size.

[0049] This invention, by setting a reverse cutting method when the size of the image edge's cropping region is smaller than a first size, not only eliminates the detection blind zone caused by discarding edges and ensures the spatial completeness of the training data, but also ensures that the cropping regions maintain realistic and consistent physical dimensions and spatial proportions. This allows the target network model to learn defect representations based on real geometric features in all regions of the entire image, improving the detection capability of the target network model and further enhancing the detection accuracy of internal defects in castings.

[0050] The initial image dataset generated by the overlapping image tiling algorithm contains a large number of pure background image patches that are completely free of any defects. The introduction of these pure negative samples will directly lead to a severe imbalance between positive and negative samples in the training data. This forces the model to process a far greater amount of background information than positive samples during training, causing the model to tend to learn background features rather than the core features of the target, thus reducing the model's recognition accuracy and generalization ability.

[0051] To address this technical problem, in some embodiments of the present invention, after obtaining the image tiling dataset, the method further includes: Remove image patches from the cropping dataset that do not contain defects.

[0052] It should be understood that the annotation information corresponding to the image patch without defects should also be removed from the JSON file constructed above.

[0053] This invention constructs a dataset with denser positive samples and more prominent targets by deleting image patches without defects. This effectively alleviates the problem of imbalance between positive and negative samples, allowing the model to focus more on learning the essential features of defects and enhancing the model's generalization ability and robustness.

[0054] In a specific embodiment of the present invention, the implementation process of the overlapping tiling algorithm is as follows: Figure 3As shown, the first size is 640×640, and the first overlap rate is 20%. Then, cutting begins from the top left corner of the image. Due to the 20% overlap rate, the horizontal starting size of the second slice is 512. When the remaining portion on the other side is insufficient, a pre-defined size image is cut out starting from the other side boundary. During cutting, defect annotation information is modified simultaneously, such as its position, size, and shape in the image. After cutting, all the segmented small images are obtained. Finally, defect-free small images are detected, and those with pure background are removed, along with their information in the annotation file, resulting in a sample of all small images without pure background, thus establishing the slice dataset.

[0055] When fine-tuning a pre-trained model based on a slice dataset, directly retraining all parameters of the model without differentiation can easily destroy the generalized basic features learned from the initial dataset during the pre-training stage, which have strong generalization capabilities. Furthermore, the distribution of the slice dataset differs significantly from the initial dataset; direct global fine-tuning may lead to catastrophic forgetting or optimization oscillations during the adaptation process to new data. This makes it difficult to stably and efficiently achieve accurate transfer of capabilities from global semantic understanding to local detail discrimination, thus affecting the stability and upper limit of the model's final convergence.

[0056] To address this technical problem, in some embodiments of the present invention, the pre-trained model includes a backbone network, a neck network, and a detection head; thus, as follows... Figure 4 As shown, step S103, which involves fine-tuning the pre-trained model based on the image-tipped dataset to obtain the target network model, includes: S401. Freeze the backbone network, and train the neck network and detection head based on the slice dataset to obtain the transition network model.

[0057] In step S401, the condition for ending the training is reaching the set number of training rounds.

[0058] S402. Unfreeze the backbone network and train the transition network model based on the slice dataset to obtain the target network model.

[0059] Similarly, the condition for ending training in step S402 is reaching the set number of training rounds. The number of training rounds in steps S401 and S402 can be the same or different.

[0060] It should be understood that stochastic gradient descent is used during training in steps S401 and S402.

[0061] This invention employs a two-stage training strategy of freezing and unfreezing. In the first stage, the backbone network is frozen, and only the neck network and detection head are trained. This allows the high-level structure of the model to quickly adapt to the statistical characteristics of the slice data and the task requirements, while firmly preserving the general basic features extracted by the backbone network. In the second stage, the backbone network is unfrozen for overall training. This allows for gentle, task-specific calibration and optimization of the feature extraction network within the pre-adapted framework. This training strategy effectively balances feature preservation and feature adaptation, ensuring the stability and efficiency of the training process, and ultimately enabling the model to integrate powerful general representation capabilities and accurate discrimination capabilities for casting defects.

[0062] In some embodiments of the present invention, step S104 includes: The X-ray image of the casting under test is divided into multiple overlapping image blocks based on the SAHI algorithm, the preset second overlap rate, and the preset second size. The first overlap rate and the second overlap rate are equal, and the first size and the second size are equal.

[0063] Specifically, using the second dimension as the size of the sliding window, this sliding window starts from the upper left corner of the X-ray image of the casting under test, and slides sequentially to the right and down based on the sliding step length calculated based on the second overlap rate. Each slide cuts out an image block. When sliding to the edge of the image, if the remaining width or height is less than a complete sliding step length, the window position is adjusted to ensure that the size of the finally cut image blocks remains consistent, until the sliding window covers the entire area of ​​the X-ray image of the casting under test, thereby generating multiple image blocks.

[0064] This invention ensures that the physical scale, spatial context, and possible cut-off shape of each image block processed by the model when inferring from the X-ray image of the casting under test are completely matched with the data distribution repeatedly learned and optimized by the model during the fine-tuning stage by setting the overlap rate and size of the overlapping image cutting algorithm and the SHAI algorithm. This eliminates the performance degradation of the model caused by input condition mismatch, allows the model to perform at its best, and further improves the accuracy of detecting internal defects in castings.

[0065] In some embodiments of the present invention, after mapping each detection result back to the image coordinate system of the X-ray image of the casting to be tested and fusing them, the method further includes: Redundancy removal is performed on the defect detection results based on the nonmaximum suppression algorithm.

[0066] Specifically, the detection process of three image patches will be used as an example for illustration, such as... Figure 5As shown, the image includes three image blocks: P1, P2, and P3. After detecting each image block, three detection results corresponding to P1, P2, and P3 are obtained. Then, the three detection results are mapped back to the image coordinate system of the X-ray image of the casting under test and merged. Then, the non-maximum suppression (NMS algorithm) is used to remove redundancy from the merged detection results to obtain the defect detection results.

[0067] Specifically, the nonmaximum suppression algorithm eliminates detection results where the IOU is greater than a set value.

[0068] To verify the effectiveness of the casting X-ray image defect detection method based on the SAHI algorithm proposed in this embodiment of the invention, the method of this embodiment of the invention was verified using a hardware configuration of Intel Core i7-14650HX CPU, NVIDIA GeForce RTX5060 GPU, and an experimental development environment based on Windows 11 operating system, Python version 3.8, PyTorch version 2.3.1, and CUDA version 11.8.

[0069] Specifically: Nonlocal mean filtering algorithm is used to reduce image noise interference in the pre-acquired X-ray images of castings. In the nonlocal mean filtering algorithm, the large search window is defined as 21×21 and the small neighborhood window is defined as 7×7. Then, the contrast-limited adaptive histogram equalization algorithm is used to improve the image contrast. The local region is defined as 10×10 and the contrast threshold is set to 2.

[0070] Defects in the enhanced image were annotated with polygons using labelme, and the corresponding annotation information JSON file was generated to form the initial dataset, in which the training set and validation set were divided in a ratio of 8:2.

[0071] The overlapping image slicing algorithm is used to slice the images in the training and validation sets respectively. The slice size is uniformly set to 640×640 and the overlap rate is 20%. The image annotation information is modified simultaneously, and each sliced ​​image is detected. The sliced ​​image dataset is obtained by deleting the defective image and its information from the annotation file.

[0072] A deep learning network model for detecting internal defects in castings was constructed. First, the model was pre-trained using the initial dataset with original images. The initial learning rate was set to 0.005, the total number of epochs was 20, and the batch size was 4. Then, the optimal weights of the pre-trained model were loaded, and the model was fine-tuned using a sliced ​​dataset with a total number of epochs of 80. The backbone network (the first ten layers) was frozen and trained for 15 epochs with an initial learning rate of 0.002. The backbone network was then unfrozen and trained for 65 epochs with the initial learning rate lowered to 0.0004. The batch size was set to 4 for both epochs. After pre-training with original images and fine-tuning with sliced ​​images, the image recognition and segmentation model was obtained.

[0073] Based on the SAHI algorithm, the X-ray image of the casting under test (resolution of 2156×1772) is divided into several overlapping small regions by a sliding window. The size of the sliding window is the same as the preset size of the cut image. During the sliding process, the small regions that the sliding window passes through are guaranteed to have an overlap with the preset overlap rate of the cut image, until the entire image area is covered.

[0074] Defect detection is performed on each small region by loading the target network model, and the defect detection results for each small region are obtained. The defect detection results of each small region are mapped to the original casting X-ray image and fused. Then, the NMS method is used to filter overlapping detection results with an IOU threshold greater than a set value of 0.2, and the defect detection results of the casting X-ray image are output.

[0075] In contrast, instead of fine-tuning the model based on the image-slicing dataset, the model was trained using only the initial dataset as input to the deep learning network. The initial learning rate was 0.005, and the epoch was set to 100. Furthermore, the SAHI algorithm was not used to assist in inference during detection; instead, the trained model was used to directly detect the original X-ray image of the casting to be tested. The comparison results are as follows: Figure 6 As shown, Figure 6 The red, green, and blue colors represent shrinkage porosity, shrinkage pores, and air pockets, respectively. Figure 6 It can be seen that the casting X-ray image defect detection method based on the SAHI algorithm proposed in this invention has higher identification and segmentation accuracy and detection rate for small target defects such as shrinkage porosity and gas pores.

[0076] To further demonstrate the gain effect of training deep learning network models using the present invention, the performance metrics of the target network models trained using the present invention and traditional methods are quantitatively compared. The results are shown in Table 1 (Box in Table 1 represents defect localization, and Mask represents shape segmentation). The training models used were all based on YOLO11-seg. The initial dataset used for model training and validation consisted of 150 X-ray images of castings, divided into training and validation sets in an 8:2 ratio. Traditional methods directly use the initial dataset, resulting in 120 images for the training set and 30 images for the validation set. Using the method of the present invention, the initial dataset undergoes overlapping and cropping processing, resulting in 922 small images for the training set and 183 small images for the validation set.

[0077] Table 1 Comparison of performance metrics of target network models

[0078] As shown in Table 1, compared with traditional methods, the target network model trained using this invention improves the mAP@0.5 on the Box by 25.7% and the mAP@0.5 on the Mask by 22.7%, proving that this invention can significantly improve the detection accuracy of the trained target network model.

[0079] For further comparison, instead of using an overlapping slicing algorithm, a uniform slicing algorithm was employed to process the initial dataset when creating the sliced ​​image dataset. Specifically, the uniform slicing algorithm was used to slice the images in both the training and validation sets, with a uniform slice size of 975×975 pixels and no overlap (i.e., no overlapping portions between the slices). If the remaining portion was insufficient, it was simply cut into smaller slices with a single side size of 975 pixels. Similarly, the image annotation information needed to be modified, and each sliced ​​slice was inspected. Slices without defects and their corresponding annotation information were then removed from the dataset to obtain the uniformly sliced ​​image dataset.

[0080] Figure 7 To compare the defect detection results obtained by the uniform slicing method and the method of the present invention, Figure 7 The red, green, and blue colors represent shrinkage porosity, shrinkage pores, and air pockets, respectively. Figure 7 It can be seen that although the detection rate of shrinkage and porosity defects in the uniform slicing method is roughly the same as that of the method of the present invention, it will cause larger target defects at the boundary to be cut off and lose complete feature information. The detection rate and segmentation accuracy of shrinkage defects are significantly reduced compared with the method of the present invention.

[0081] To further demonstrate the gain effect of training the network segmentation model using the method of this invention, the performance metrics of the image recognition segmentation models trained using the method of this invention and the uniform image slicing method are quantitatively compared, and the results are shown in Table 2. The initial dataset used for model training and validation consisted of 150 X-ray images of castings, divided into training and validation sets in an 8:2 ratio. When training using the uniform image slicing method, the initial dataset was uniformly sliced, resulting in 318 small images in the training set and 62 small images in the validation set. When training using the method of this invention, the initial dataset was overlapped and sliced, resulting in 551 small images in the training set and 104 small images in the validation set.

[0082] Table 2 Comparison of performance metrics of target network models obtained using different graph cutting algorithms

[0083] As shown in Table 2, compared with the uniform slicing method, the target network model trained using the present invention improves the mAP@0.5 on the Box by 16.3% and the mAP@0.5 on the Mask by 11.2%, proving that the present invention can significantly improve the detection accuracy of the trained image recognition and segmentation model.

[0084] In summary, the X-ray image defect detection method for castings based on the SAHI algorithm proposed in this invention employs a nonlocal mean filtering algorithm and a contrast-limited adaptive histogram equalization algorithm to reduce image noise while improving image contrast. It applies an overlapping image-cutting training strategy to the field of defect recognition and detection in X-ray images of large and complex castings. The method utilizes a YOLO11-seg network segmentation model, first pre-training on the original image and then fine-tuning it through image cutting to obtain an image recognition segmentation model. Finally, the SAHI algorithm is used to detect the acquired X-ray images of large and complex castings, greatly improving model training efficiency and defect recognition accuracy. This method has significant application value in the intelligent detection of internal defects in castings.

[0085] Those skilled in the art will understand that all or part of the processes of the methods described in the above embodiments can be implemented by a computer program instructing related hardware (such as a processor, controller, etc.), and the computer program can be stored in a computer-readable storage medium. The computer-readable storage medium may be a disk, optical disk, read-only memory, or random access memory, etc.

[0086] The present invention provides a detailed description of a method for detecting defects in X-ray images of castings based on the SAHI algorithm. Specific examples have been used to illustrate the principle and implementation of the present invention. The description of the above embodiments is only for the purpose of helping to understand the method and core idea of ​​the present invention. At the same time, those skilled in the art will know that there will be changes in the specific implementation and application scope based on the idea of ​​the present invention. Therefore, the content of this specification should not be construed as a limitation of the present invention.

Claims

1. A method for detecting defects in X-ray images of castings based on the SAHI algorithm, characterized in that, include: Acquire X-ray images of the casting and annotate the defects in the X-ray images of the casting to obtain an initial dataset; The initial dataset is sliced ​​and the labels are adjusted based on the overlapping slicing algorithm to obtain a sliced ​​dataset. A deep learning network model for detecting internal defects in castings is constructed. The deep learning network model is pre-trained based on the initial dataset to obtain a pre-trained model. The pre-trained model is then fine-tuned based on the tiling dataset to obtain the target network model. The SAHI algorithm is used to segment the X-ray image of the casting under test into multiple overlapping image blocks; Based on the target network model, defect detection is performed on the multiple image patches to obtain multiple detection results that correspond one-to-one with the multiple image patches; The detection results are mapped back to the image coordinate system of the X-ray image of the casting under test and fused to obtain the defect detection results.

2. The method for detecting defects in castings using X-ray images based on the SAHI algorithm according to claim 1, characterized in that, Before marking defects in the X-ray image of the casting, the process also includes: The X-ray image of the casting is subjected to noise reduction and contrast enhancement processing.

3. The method for detecting defects in castings using X-ray images based on the SAHI algorithm according to claim 2, characterized in that, The denoising process employs a nonlocal mean filtering algorithm, and the contrast enhancement process employs a contrast-limited adaptive histogram equalization method.

4. The method for detecting defects in castings using X-ray images based on the SAHI algorithm according to claim 1, characterized in that, The initial dataset is sliced ​​based on an overlapping slicing algorithm, including: The initial dataset is sliced ​​based on a preset first overlap rate and a preset first size to obtain multiple slice regions; Determine whether the size of the cropping region located at the edge of the image in the initial dataset is smaller than the first size; If so, the initial dataset is reverse-cut starting from the image edge so that the size of each cut region is the same as the preset size.

5. The method for detecting defects in castings using X-ray images based on the SAHI algorithm according to claim 1 or 4, characterized in that, After obtaining the tiling dataset, the following is also included: Delete the image blocks in the plot dataset that do not contain defects.

6. The method for detecting defects in castings using X-ray images based on the SAHI algorithm according to claim 1, characterized in that, The pre-trained model includes a backbone network, a neck network, and a detection head; the pre-trained model is fine-tuned based on the slice dataset to obtain the target network model, including: Freeze the backbone network, and train the neck network and the detection head based on the plot dataset to obtain the transition network model; Unfreeze the backbone network, train the transition network model based on the plotted dataset, and obtain the target network model.

7. The method for detecting defects in castings using X-ray images based on the SAHI algorithm according to claim 4, characterized in that, The method of segmenting the X-ray image of the casting under test into multiple overlapping image blocks based on the SAHI algorithm includes: The X-ray image of the casting under test is divided into multiple overlapping image blocks based on the SAHI algorithm, a preset second overlap rate, and a preset second size; The first overlap rate and the second overlap rate are equal, and the first size and the second size are equal.

8. The method for detecting defects in castings using X-ray images based on the SAHI algorithm according to claim 1, characterized in that, After mapping and fusing the detection results back to the image coordinate system of the X-ray image of the casting to be tested, the method further includes: The defect detection results are redundancy removed based on the nonmaximum suppression algorithm.

9. The method for detecting defects in castings based on SAHI algorithm according to any one of claims 1-8, characterized in that, The target network model is YOLO11-seg.