Method for detecting and analyzing internal shrinkage cavity defects of die casting based on machine vision

By constructing a dual-branch deep learning network and pixel-level sensitivity heatmap technology, the problem of weak interpretability in uncertainty assessment during the detection of shrinkage cavities in die castings was solved. Automatic identification of noise sources and generation of causal labels were achieved, improving the interpretability and practicality of the detection system.

CN121883472AInactive Publication Date: 2026-04-17DONGGUAN YIHAN HARDWARE PRODUCTS CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
DONGGUAN YIHAN HARDWARE PRODUCTS CO LTD
Filing Date
2026-01-21
Publication Date
2026-04-17
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

Existing machine vision inspection systems suffer from a problem in the detection of shrinkage defects inside die castings: while the uncertainty assessment technology is highly consistent, its interpretability is weak. It is difficult to understand the specific causes of misjudgments or omissions, which limits the improvement of model weaknesses and production line response capabilities.

Method used

A machine vision-based method for detecting shrinkage cavities in die-cast parts is adopted. The method acquires the original visual image and records the imaging condition label, performs grayscale normalization and nonlocal mean denoising, and uses a dual-branch deep learning network with attention gating structure to generate multi-granular feature response distribution map. Combined with pixel-level sensitivity heatmap and superpixel segmentation, potential interference sources are identified and interpretable causal labels are generated.

Benefits of technology

It significantly improves the interpretability and engineering usability of uncertainties, can automatically identify noise sources such as uneven lighting and surface reflection, generate clear cause labels, support process parameter adjustment and dataset optimization, reduce on-site debugging costs, and enhance the practicality and robustness of the detection system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121883472A_ABST
    Figure CN121883472A_ABST
Patent Text Reader

Abstract

The invention provides a method for detecting and analyzing internal shrinkage cavity defects of a die casting based on machine vision, which comprises the following steps of: introducing process environment parameters and multi-stage response characteristics, and combining multi-dimensional superpixel characteristics with noise template matching to realize spatial positioning of high-uncertainty defect instances and cause labeling of typical interference sources; according to the method, the robustness and traceability of shrinkage cavity defect detection are effectively enhanced, and reliable data support is provided for die casting quality management and intelligent abnormal decision making.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of machine vision and die casting defect detection technology, and in particular to a machine vision-based method for detecting and analyzing internal shrinkage cavities in die castings. Background Technology

[0002] Currently, internal defect detection technology for die-cast parts has been widely applied in industrial manufacturing quality control, especially in microstructural analysis scenarios such as shrinkage cavities. Machine vision inspection systems utilize image information obtained from X-rays or industrial CT equipment, and automatically identify and locate defects through deep learning models, greatly improving inspection efficiency and accuracy. The mainstream technical approaches include automated inspection schemes based on deep learning structures such as Convolutional Neural Networks (CNNs) and Region Proposal Networks (RPNs). These networks typically integrate classification and localization functions, demonstrating high accuracy in both laboratory and industrial environments. Meanwhile, to enhance model reliability, some studies have introduced model uncertainty quantification methods based on probability output (such as Softmax posterior probability), Monte Carlo sampling, or Bayesian networks to help determine the confidence level of model predictions. These technologies lay the foundation for achieving large-scale online inspection and intelligent sorting, and have been initially validated in actual production lines. Nevertheless, existing uncertainty assessment techniques generally suffer from the limitation of "strong consistency but weak interpretability." Currently, the uncertainty output in most machine vision inspection systems mainly focuses on black-box probability values, variance scores, or global entropy measurements. System operators can only obtain numerical feedback on confidence levels, but find it difficult to understand the specific causes of misjudgments or missed judgments. For example, when the inspection system produces high uncertainty results, the feedback only indicates "insufficient confidence" or "algorithm discrepancy," lacking clear indications of specific factors leading to unstable predictions, such as abnormal local image features, imaging environment fluctuations, blurred boundaries, or surface reflections. This limits targeted improvements to the model's weaknesses and makes it difficult for the inspection process to quickly respond to production line changes and external disturbances. Summary of the Invention

[0003] In order to solve the above-mentioned technical problems, the present invention provides a machine vision-based method for detecting and analyzing internal shrinkage cavities in die-cast parts.

[0004] The technical solution of this invention is implemented as follows: a machine vision-based method for detecting and analyzing internal shrinkage cavities in die-cast parts, comprising: S1: Acquire the original visual image of the shrinkage cavity defect inside the die casting, and record the ambient light intensity and sensor position information during image acquisition to construct an input dataset containing imaging condition labels; S2: Perform grayscale normalization and nonlocal mean denoising on the original visual image to suppress imaging interference caused by uneven illumination and surface reflection, and generate a preprocessed image with stable contrast characteristics. S3: Input the preprocessed image into a dual-branch deep learning network with an attention gating structure, wherein the main branch performs the task of classifying and locating the pinhole defects, and the auxiliary branch simultaneously extracts the gradient weighted class activation map of the multi-scale convolutional layer to form a multi-granularity feature response distribution map. S4: Based on the multi-granularity feature response distribution map, the feature gradient of each key convolutional layer relative to the final predicted output is calculated using the backpropagation algorithm, and a pixel-level sensitivity heatmap is generated by combining the attention weights, which serves as a spatial mapping representation for model decision-making. S5: Perform superpixel segmentation on the original visual image to obtain a set of image blocks with local consistency texture attributes, and map the response intensity of the pixel-level sensitivity heatmap to each superpixel block, and select the top K highest response regions to form a potential interference source candidate set; S6: For each superpixel block in the potential interference source candidate set, extract its texture complexity, edge blurring and grayscale contrast low-order visual features, and perform similarity matching with reference features in the standard normal region template library to identify interference regions that conform to typical noise patterns. S7: Determine whether there is a detection result that meets the high uncertainty judgment condition. If there is, generate the corresponding interpretable cause label according to the identified typical noise pattern type, and form a composite output result package containing defect location, category, uncertainty score and cause label. S8: Transmit the composite output result package to the quality decision system to support the selection of anomaly handling strategies and the optimization of process parameters. At the same time, store the cause labels and corresponding original image fragments in the historical case database to provide unlabeled supervision signals for subsequent model iterations.

[0005] The machine vision-based method for detecting and analyzing internal shrinkage cavities in die-cast parts provided by this invention has the following advantages: (1) This invention significantly improves the interpretability and engineering usability of uncertainty by constructing a reverse tracing mechanism from the model decision space to the input image space. Under the dual-branch network architecture, classification and localization results and multi-scale gradient weighted class activation maps (Grad-CAM) are acquired simultaneously, and backpropagation is initiated to generate pixel-level sensitivity heatmaps when high uncertainty is triggered, thus achieving precise locking of key response regions. Combined with superpixel segmentation, the thermal response is mapped to semantically clear local blocks, and low-order visual features such as texture complexity, edge blurring, and grayscale contrast are extracted for pattern matching. The system can automatically identify typical noise sources such as uneven illumination, surface reflection, and microcrack interference, and then generate cause labels with clear physical meaning. This mechanism breaks through the limitations of traditional "black box" uncertainty feedback, so that the model output not only includes "whether it is credible", but also answers "why it is not credible", effectively supporting process parameter adjustment and dataset optimization, and significantly reducing on-site debugging costs.

[0006] (2) By introducing an attention-gated structure and a lightweight, decoupled tracing process, this invention ensures high-precision defect identification while achieving compatibility between interpretable analysis and real-time detection systems, significantly enhancing the practicality and robustness of the method in industrial online scenarios. Compared to traditional methods that require additional training of interpretive models or rely on a large number of manually labeled uncertain samples, this technology can complete attribution analysis without special labeling, lowering the deployment threshold. Its modular design based on mainstream convolutional networks also has good portability and can be seamlessly integrated into lightweight detection frameworks such as YOLO and SSD, meeting the millisecond-level response requirements of high-speed production lines. At the same time, by limiting the tracing scope to high-uncertainty samples, the waste of resources caused by full-scale computation is avoided, balancing efficiency and in-depth analysis requirements. The generated composite result package—covering defect location, category, uncertainty score, and cause label—provides quality inspectors with complete decision-making basis, strengthening the trust foundation in human-machine collaboration. In addition, the system's ability to identify typical interference patterns provides a directional optimization direction for subsequent data augmentation strategies and model retraining, promoting the detection system to form a closed-loop evolution path of "perception—evaluation—interpretation—optimization". Attached Figure Description

[0007] Figure 1 This is a flowchart of the machine vision-based method for detecting and analyzing internal shrinkage cavities in die castings according to the present invention. Figure 2 This is a sub-flowchart of the machine vision-based method for detecting and analyzing internal shrinkage cavities in die castings according to the present invention. Figure 3 This is another sub-flowchart of the machine vision-based method for detecting and analyzing internal shrinkage cavities in die castings according to the present invention. Detailed Implementation

[0008] Embodiments of the present invention are described in detail below, examples of which are shown in the accompanying drawings, wherein the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention, and should not be construed as limiting the present invention.

[0009] The following disclosure provides many different embodiments or examples for implementing different structures of the invention. To simplify the disclosure, specific examples of components and arrangements are described below. Of course, these are merely examples and are not intended to limit the invention. Furthermore, reference numerals and / or letters may be repeated in different examples; such repetition is for simplification and clarity and does not in itself indicate a relationship between the various embodiments and / or arrangements discussed.

[0010] like Figure 1 As shown, this invention provides a machine vision-based method for detecting and analyzing internal shrinkage cavities in die-cast parts, specifically including: S1: Acquire the original visual image of the shrinkage cavity defect inside the die casting, and record the ambient light intensity and sensor position information during image acquisition to construct an input dataset containing imaging condition labels; S2: Perform grayscale normalization and nonlocal mean denoising on the original visual image to suppress imaging interference caused by uneven illumination and surface reflection, and generate a preprocessed image with stable contrast characteristics. S3: Input the preprocessed image into a dual-branch deep learning network with an attention gating structure, wherein the main branch performs the task of classifying and locating the pinhole defects, and the auxiliary branch simultaneously extracts the gradient weighted class activation map of the multi-scale convolutional layer to form a multi-granularity feature response distribution map. S4: Based on the multi-granularity feature response distribution map, the feature gradient of each key convolutional layer relative to the final predicted output is calculated using the backpropagation algorithm, and a pixel-level sensitivity heatmap is generated by combining the attention weights, which serves as a spatial mapping representation for model decision-making. S5: Perform superpixel segmentation on the original visual image to obtain a set of image blocks with local consistency texture attributes, and map the response intensity of the pixel-level sensitivity heatmap to each superpixel block, and select the top K highest response regions to form a potential interference source candidate set; S6: For each superpixel block in the potential interference source candidate set, extract its texture complexity, edge blurring and grayscale contrast low-order visual features, and perform similarity matching with reference features in the standard normal region template library to identify interference regions that conform to typical noise patterns. S7: Determine whether there is a detection result that meets the high uncertainty judgment condition. If there is, generate the corresponding interpretable cause label according to the identified typical noise pattern type, and form a composite output result package containing defect location, category, uncertainty score and cause label. S8: Transmit the composite output result package to the quality decision system to support the selection of anomaly handling strategies and the optimization of process parameters. At the same time, store the cause labels and corresponding original image fragments in the historical case database to provide unlabeled supervision signals for subsequent model iterations.

[0011] Step S1: Acquire the original visual image of the shrinkage cavity defect inside the die-cast part, and record the ambient light intensity and sensor position information during image acquisition to construct an input dataset containing imaging condition labels. Specifically, this includes: S1.1: Obtain the original visual image of the die casting under X-ray or industrial CT imaging device as the initial input object, wherein the original visual image is stored in grayscale image form with a resolution of 1024×1024 pixels or higher and a bit depth of 16 bits to retain the detailed information of the internal micro shrinkage cavity structure. The acquisition and control system of the die-casting imaging device calls the preset X-ray or industrial CT imaging command (parameters: voltage range 120kV-150kV, exposure time 200ms-500ms) to realize full-field scanning of the internal structure of the workpiece and transmit the scanning data to the cache module of the acquisition terminal in real time. Furthermore, the raw pixel matrix output by the CT detector or flat panel detector is read through the hardware interface driver of the image acquisition module (parameter: single pixel size does not exceed 50μm) to achieve high-precision internal defect signal capture and obtain the raw array of grayscale signals expressed in two-dimensional matrix form; Furthermore, the 16-bit grayscale encoding function of the image storage component is called (parameter: grayscale range 0-65535) to achieve lossless quantization encoding of the light intensity value of each pixel in the original pixel matrix and generate a grayscale image file with a uniform resolution of 1024×1024 pixels or higher to ensure the detail resolution capability of the tiny pinholes. Furthermore, a dynamic range detection algorithm (parameters: peak value, mean value, and variance of the statistical histogram) is used to verify the sampling quality of the current grayscale image file and generate quality labeling parameters to ensure that subsequent input data meets the preset requirements of the deep learning model for the quality of the input image. The grayscale image file obtained in the previous step is stably written into the high-speed solid-state storage medium of the acquisition terminal through the temperature control and shockproof control system of the imaging device, so as to achieve stable preservation of the original visual image and ensure data integrity. For example, in a workstation for detecting shrinkage cavities inside die-cast parts, the operator performs a scanning task using an industrial CT imaging device (detector resolution of 2048×2048 pixels, single pixel size of 45μm). The scanning tube voltage is set to 140kV, the exposure time to 300ms, and the number of loop scans to 3. The system calls the detector driver program, reads the output two-dimensional pixel matrix after each scan, and maps the light intensity range [0, 60000] to the interval 0-65535 according to a 16-bit grayscale encoding function, generating a grayscale image file with a resolution of 2048×2048. A dynamic range detection algorithm is applied, and the mean of the grayscale histogram is calculated. The variance is The quality status was determined to be acceptable. Finally, the grayscale image file was saved in the date-indexed directory of a high-speed solid-state drive to ensure no signal loss during imaging. This enabled the acquisition of refined raw visual images of minute pinhole defects, providing reliable visual input data for subsequent binding of illumination intensity and sensor position information. S1.2: Based on the timestamp of the image acquisition time, extract the corresponding ambient light intensity value from the production line environment monitoring system, use the Modbus protocol to read the analog signal output by the illuminance sensor, convert it into a standard lux unit value, and generate an ambient light intensity parameter as a quantitative indicator to characterize external optical interference. Based on the timestamp parameter of the image acquisition time, the data interface of the production line environment monitoring system is called to match the real-time output signal of the environmental illuminance sensor of the current working section with millisecond-level time accuracy, ensuring that the illuminance data strictly corresponds to the image acquisition event and realizing the synchronous measurement of environmental optical conditions. The Modbus RTU communication protocol (parameters: baud rate 9600bps, data bits 8 bits, stop bits 1 bit, parity bits none) is adopted to establish a serial bus connection between the main controller and the illuminance sensor. The analog output register value of the sensor is read periodically and cached in the sensor data buffer of the acquisition node to ensure the stability and real-time performance of signal acquisition. Furthermore, the voltage signal output by the illuminance sensor is converted into a digital quantity through the A / D conversion module (parameters: sampling accuracy 16 bit, sampling rate 1 kHz). The numerical calibration operation is performed using the coefficients of the sensor calibration curve to realize the mapping of the digital signal to the physical illuminance value and obtain the raw illuminance data without unit normalization. Furthermore, a unit normalization algorithm (parameter: target unit lux, mapping relationship based on international illuminance standards) is used to calculate the standard lux value using the following formula:

[0012] in, Illuminance value (lux) This is the voltage value after A / D conversion. This is the reference voltage for the sensor at zero illumination. This is the voltage-illuminance ratio coefficient, ensuring that the collected values ​​from different sensor models are uniformly converted to the standard reference system; Furthermore, the above standard lux value sequence is smoothed by a numerical filtering algorithm (parameters: sliding window width of 5 frames, filter type weighted moving average) to suppress high-frequency noise fluctuations caused by instantaneous illumination flicker and generate ambient light intensity parameters with improved stability. Through the above processing method, the original analog signal is converted into standardized lux value data, realizing a quantifiable characterization of external optical interference, and providing accurate illumination index support for the subsequent construction of imaging condition labels. For example, in a die-casting production line inspection scenario, the image acquisition timestamp is 1622548795123 ms, corresponding to an illuminance sensor model of TCS34725, a calibration coefficient k of 0.45 lux / mV, and a zero-illuminance reference voltage. The value is 220 mV. The analog register value read via the Modbus RTU protocol, after A / D conversion, is 356 mV. Substituting this value into the above formula yields the illuminance value. After weighted averaging via a sliding window, the output stable illumination intensity is: lux. This value, along with the original image file reference and corresponding timestamp, is recorded as the illumination field in the imaging condition label and used for subsequent sample screening and uncertainty source analysis based on environmental context. During the inspection process of different batches, when the production line illumination fluctuates due to workstation switching, the standardized output of this step can significantly improve the consistency of feature extraction for subsequent defect identification across batch samples; S1.3: Based on the device ID of the image acquisition device, call the spatial coordinate information recorded by its built-in encoder to obtain the position offset of the sensor relative to the center point of the die casting, including three-dimensional coordinate data of the horizontal direction (X-axis), vertical direction (Y-axis) and focal length direction (Z-axis), to form sensor position information for subsequent geometric distortion correction and viewing angle consistency analysis. Based on the device ID of the image acquisition device, the spatial coordinate information recorded by its built-in encoder is called as the initial input condition. The real-time position register value of the encoder is read using the device communication interface to obtain the uncorrected raw spatial coordinate dataset. The coordinate decoding algorithm provided by the device driver library (parameters: encoder pulse count / revolution, zero offset constant) is used to convert the original spatial coordinate data into three-dimensional coordinate values ​​with physical meaning, including the horizontal direction (X-axis), vertical direction (Y-axis) and focal length direction (Z-axis), and obtain preliminary position data in millimeters. Furthermore, by calling the geometric transformation algorithm (parameters: rotation matrix R, translation vector T) through the sensor calibration parameter table, the coordinate transformation from the local coordinate system of the equipment to the reference coordinate system of the center point of the die casting is realized, and a normalized three-dimensional position vector for subsequent calculations is generated. Furthermore, by using a precision measurement compensation method (parameters: temperature drift coefficient, mechanical runout correction value), the accuracy of the normalized three-dimensional position vector is optimized, and a compensated set of spatial position parameters is generated to reduce the impact of environmental changes and mechanical clearances on position accuracy. Furthermore, a location data consistency verification algorithm (parameter: sampling frequency) is used. Time window This enables the analysis of sensor position stability during a continuous acquisition period and generates standard deviation indices for each coordinate dimension, which serve as input conditions for subsequent viewpoint consistency analysis. Through the above coordinate decoding, geometric transformation and accuracy compensation processing, the original encoder data from the previous step is transformed into calibrated and corrected three-dimensional position parameters, thereby realizing high-precision sensor position information for geometric distortion correction and viewpoint consistency analysis. For example, in an industrial CT image acquisition environment, the encoder parameters corresponding to the device ID are 4096 pulses per revolution, the zero-point offset constant is 15 pulses, the rotation matrix R is obtained from a calibration sphere array experiment, and the translation vector T is... millimeters, temperature drift coefficient is mm / ℃, mechanical runout correction value Millimeters. The encoder pulse values ​​are converted into three-dimensional physical coordinates through coordinate decoding, and then mapped onto the die-cast part's center point reference system through geometric transformation. After introducing temperature and mechanical runout compensation, the stability verification results of the three-dimensional coordinates show that within a 2-second sampling window and a sampling frequency of [missing information - likely a value or value], [missing information - likely a value or value]. Under Hz conditions, the standard deviations in the X, Y, and Z directions are respectively millimeters millimeters Millimeters. The fluctuation amplitude of the final output sensor position information during dynamic acquisition is significantly reduced, providing a stable and high-precision spatial parameter input for subsequent geometric distortion correction; S1.4: The original visual image, ambient light intensity parameters and sensor location information are time-aligned and field-bound. Multi-source data fusion operation is performed based on a unified timestamp to generate a structured data record, which includes image file reference, illumination value, three-dimensional coordinates and work order number, forming a basic data unit with imaging condition label; S1.5: The structured data records are written in batches to the original data warehouse directory in the distributed file system, the storage path is organized according to the 'date-batch number' naming rule, and a metadata index database is established to support the subsequent screening of sample sets according to imaging conditions and the generation of input datasets with environmental context annotations.

[0013] Step S2: Perform grayscale normalization and nonlocal mean denoising on the original visual image to suppress imaging interference caused by uneven illumination and surface reflection, generating a preprocessed image with stable contrast characteristics. Specifically, this includes: S2.1: Obtain the original visual image of the shrinkage cavity defect inside the die casting as the input object. Based on its pixel intensity distribution characteristics, perform grayscale space mapping transformation to convert the original RGB three-channel image into a single-channel grayscale image and generate preliminary grayscale image data to eliminate the interference of color channel redundancy on subsequent feature analysis. Based on the original visual image data matrix of shrinkage defects inside die castings, a grayscale space mapping transformation method (parameter: mapping model type is ITU-R BT.601 standard weighted coefficient) is used to realize the mapping transformation from the original RGB three-channel pixel values ​​to single-channel grayscale values, so as to eliminate the redundant interference of color information on subsequent feature analysis. Furthermore, the grayscale component of each pixel is calculated using a weighted summation formula, specifically:

[0014] in, For pixel grayscale values, , , These are the red, green, and blue component values ​​of the input image pixels, respectively, with the coefficient values ​​determined based on the human eye perception sensitivity model. Furthermore, by combining the pixel intensity distribution characteristics of the input image, a normalization processing algorithm (parameter: normalization range [0,255]) is used to dynamically adjust the grayscale value, and preliminary grayscale matrix data that can be used to unify subsequent brightness correction is obtained; Furthermore, a bit depth preservation mechanism (parameter: original bit depth is 16 bits) is adopted to maintain the original quantization accuracy of the input pixels during the conversion process, avoiding the loss of detail caused by truncation or rounding, thereby obtaining high-fidelity preliminary grayscale image data. Through the above grayscale space mapping transformation and normalization processing, the RGB input image result from the previous step is transformed into a single-channel high-precision grayscale image, achieving the expected technical effect of suppressing color noise and channel redundancy. For example, in the scenario of detecting shrinkage cavities in die-cast parts, the input image resolution is 2048×2048 pixels, the bit depth of each RGB channel is 16 bits, and the grayscale value of the first pixel is calculated using the ITU-R BT.601 grayscale mapping model. The numerical values ​​are precisely maintained within the 16-bit range. The entire image is normalized to the [0, 255] interval. In low-light areas, the original grayscale values ​​are concentrated in the [1000, 5000] range, and after normalization, they are mapped to [12, 65], significantly improving detail contrast. The final output single-channel high-precision grayscale image serves as the input for subsequent dynamic range stretching and non-local mean denoising, effectively reducing the interference of the original color data on the identification of pinhole defects. The model's detection performance in mixed low-light and high-reflectivity environments is greatly improved. S2.2: Perform histogram statistical analysis on the preliminary grayscale image data, calculate the global pixel intensity cumulative distribution function, perform dynamic range stretching operation based on the distribution function, optimize the overall image contrast, and generate an enhanced grayscale image with balanced brightness distribution to improve the visibility of details in low-light areas. S2.3: Based on the enhanced grayscale image, a weighted kernel function is constructed using local neighborhood pixel blocks. A non-local means denoising algorithm is used to perform self-similarity matching filtering on high variance regions in the image affected by surface reflection, suppressing the pseudo-edge structure caused by specular reflection, generating a preliminary denoised image, and preserving the real defect boundary information. A local neighborhood pixel block model is constructed based on the enhanced grayscale image. According to the preset parameters of the neighborhood window radius r and the attenuation control factor h, the neighborhood of each target pixel is weighted by a weighted kernel function to realize the initial construction of the local similarity measurement. Furthermore, a nonlocal mean denoising algorithm (parameters: search window size S, neighborhood block size T, decay factor h) is used to calculate the weighted Euclidean distance between any two neighboring pixels in the image, and a similarity weight matrix is ​​generated based on the distance to measure the structural similarity between pixels. Furthermore, for high-variance regions affected by surface reflection, a self-similarity matching filter is performed using a weight matrix. The gray values ​​of neighboring blocks are weighted and summed according to similarity weight coefficients to generate a filtered center pixel value, thereby suppressing the false edge structure caused by specular reflection and reducing the interference intensity of local high-frequency noise. Furthermore, by combining the spatial distribution of the high variance region, the filtering results are locally reconstructed, and the gray values ​​of the edge region are constrained and adjusted using the loss minimization criterion to ensure that the boundary contour information of the real shrinkage defect is preserved while removing the reflective pseudostructure. Through the above nonlocal mean denoising process, the enhanced grayscale image from the previous step is transformed into a preliminary denoised image, achieving stable preservation of defect boundary features under conditions of uneven illumination and surface reflection. For example, in the scenario of detecting shrinkage cavities in die-cast parts, an enhanced grayscale image with a resolution of 1024×1024 pixels is selected, the neighborhood window radius r is set to 3 pixels, the search window size S is set to a 21×21 pixel block, and the attenuation factor h is set to 12. For pixel p, its non-local mean filter value... Calculate using the following formula:

[0015] in, Let q be the original grayscale value of the candidate pixel. The search window is centered on p. For similarity weights, according to the formula

[0016] in, This represents the neighborhood block centered at p. This represents the neighborhood block centered at q. As the attenuation factor, is the Euclidean norm of the pixel block grayscale difference. Under this setting, specular reflection noise in high-variance regions is significantly suppressed, and the generated preliminary denoised image retains continuous gradient transitions at the real defect boundaries, which significantly improves the edge localization accuracy of subsequent texture consistency verification and feature extraction; S2.4: Perform local texture consistency verification on the preliminary denoised image, calculate the gradient direction entropy value in the neighborhood of each pixel through a sliding window, identify and mark texture disordered areas, and dynamically adjust the search window radius and attenuation parameter of the nonlocal mean algorithm based on these marking results to optimize the denoising intensity, so as to balance the performance of noise suppression and edge preservation. S2.5: Perform global grayscale mean and variance standardization on the adaptively optimized denoised image, uniformly mapping its pixel intensity to the [0,1] interval, generating a preprocessed image output with uniform scale characteristics, which serves as the input data for the subsequent dual-branch deep learning network, ensuring that the model has stable feature extraction capabilities under different imaging conditions.

[0017] like Figure 2As shown, step S3 involves inputting the preprocessed image into a dual-branch deep learning network with an attention-gated structure. The main branch performs the classification and localization of pinhole defects, while the auxiliary branch simultaneously extracts gradient-weighted class activation maps from multi-scale convolutional layers, forming a multi-granularity feature response distribution map. Specifically, this includes: S3.1: Construct the input tensor of a dual-branch deep learning network based on preprocessed images, and use the normalized pixel matrix as the input data of the convolutional neural network to ensure that the feature extraction process of each level is carried out in a unified numerical domain, thereby generating a standardized input tensor. Based on the preprocessed image output from step S2.5, a two-dimensional matrix normalization method (parameter: pixel intensity range [0,1]) is used to achieve uniformity of pixel value values ​​in order to eliminate the grayscale distribution differences between images from different batches. Furthermore, by using the channel expansion method (parameter: converting single-channel grayscale to three-channel copy), structural alignment with the expected number of channels in the input layer of the dual-branch convolutional neural network is achieved, and a three-channel normalized matrix is ​​obtained; Furthermore, by using a batch dimensionality standardization method (parameter: batch size B≥8), statistical consistency of multi-sample matrices within a batch processing unit is achieved, and a batch input tensor structure is generated. Furthermore, a tensor shape reconstruction method is adopted (parameters: shape specifications are B×C×H×W, C is the number of channels, H and W are the image height and width) to realize the matching relationship between the memory layout of the input data and the network forward computation graph, and generate a standardized four-dimensional input tensor; Through the above normalization and structuring processes, the preprocessed image from the previous step is transformed into standardized tensor data that meets the input requirements of a dual-branch deep convolutional network, achieving a unified numerical domain and structural compatibility in the feature extraction stage. For example, in the scenario of detecting shrinkage cavities inside die-cast parts, a pre-processed image with a resolution of 1024×1024 and a single channel is linearly mapped to pixel intensity using a normalization method. The interval is used to obtain the normalized matrix. The channel expansion method is applied to copy it to a three-channel structure, forming a single-sample four-dimensional tensor of shape 1×3×1024×1024. In batch processing mode, samples are loaded with a batch size B=16, and batch normalization calculation is performed to ensure that the mean and variance of each channel satisfy the following conditions: and The set conditions are as follows. After shape reconstruction, the tensor size is 16×3×1024×1024. After the network input layer receives this structure, the memory access latency in the forward inference stage is significantly reduced, and the stability of feature calculation of convolutional kernels for multiple batches of data is greatly improved, ensuring that the subsequent main and auxiliary branches can achieve consistent feature response extraction under different acquisition conditions. S3.2: Deploy the residual convolution module and the region proposal network (RPN) in the main branch to perform multi-level spatial convolution and non-linear activation operations on the standardized input tensor to extract deep semantic features and generate candidate defect regions, and output preliminary detection results including location box coordinates and category confidence. Based on the normalized input tensor output by S3.1, a residual convolution module (parameters: kernel size 3×3, stride 1, channel number increment strategy is to double the number of channels after every two residual blocks) is used to realize cross-layer feature transfer and gradient mitigation functions. Furthermore, by batch normalization and ReLU nonlinear activation operation (parameters: momentum coefficient 0.9, activation threshold 0), tensor feature distribution is balanced, and nonlinear discriminative ability is introduced to obtain a preliminary deep feature map sequence. Furthermore, a multi-level spatial convolution strategy is adopted (parameters: shallow convolutional groups are used to capture local textures, and high-level convolutional groups are used to extract global morphology) to achieve hierarchical feature representation of shrinkage defects at different scales and obtain a multi-scale feature map set. Furthermore, the Region Proposal Network (RPN) is invoked (parameters: anchor box scale 32, 64, 128 pixels, aspect ratio 1:1, 1:2, 2:1) to perform sliding window scanning and feature mapping scoring operations on the multi-scale feature map set, generate a list of anchor box proposals for candidate defect regions, and assign target / background binary labels and position regression offsets to each anchor box; Furthermore, non-maximum suppression (parameter: IoU threshold 0.7) is used to process the anchor box proposal list, eliminating redundant and overlapping candidate regions, and generating a simplified set of candidate defect regions, including location box coordinates and preliminary foreground confidence scores; Furthermore, based on the simplified candidate set, the classification sub-network is called (parameters: 1024 and 512 nodes in the fully connected layer, softmax output category = shrinkage defect / background) to realize the category discrimination of each candidate region and obtain the category confidence value and the optimized bounding box coordinates; By using a combined detection processing method of residual convolution and RPN, the standardized input tensor output from the previous step is transformed into a preliminary detection result containing the location box coordinates and category confidence, thereby achieving the preliminary identification effect of locating and classifying shrinkage defects inside die castings. For example, in the CT image detection of a die-cast part, the input tensor size is 1024×1024×1. After processing by the residual convolution module, the number of channels is 64, 128, and 256 respectively, corresponding to three sets of multi-scale feature maps. The Region Proposal Network (RPN) generates approximately 1500 anchor box proposals on each scale feature map, which are filtered down to less than 200 candidate regions by non-maximum suppression. The classification subnetwork outputs the confidence score of shrinkage defects for each candidate region at the softmax layer, for example, the confidence score range is from... arrive The positioning coordinate accuracy reaches the single-pixel level. In this scenario, the cross-layer feature fusion of the residual convolutional network significantly improves the detection capability of small shrinkage holes. The multi-scale anchor box configuration of the RPN effectively covers defect areas of different sizes. Finally, the preliminary detection results can provide spatial location input for the interpretable feature response analysis of the auxiliary branch, improving the pertinence and accuracy of subsequent uncertainty assessment. S3.3: Integrate an attention gating mechanism in the auxiliary branch. Based on the feature map sequence output by each key convolutional layer in the main branch, use gradient backpropagation to calculate the weight coefficients corresponding to each type of shrinkage defect and generate a multi-scale gradient weighted class activation map (Grad-CAM) as a spatial response representation of the model's region of interest. In the auxiliary branch, a sequence of feature maps associated with the residual convolution module of the main branch is loaded. An attention gating mechanism is used (parameters: initial value of channel attention weight is 0.5, initial value of spatial attention weight is 0.5) to jointly adjust the channel and spatial dimensions of the feature maps at each scale. Furthermore, by using the gradient backpropagation algorithm (parameter: automatic differentiation accuracy of 1e-6), the class score vector of the main branch and the corresponding key convolutional layer feature map tensor are input to calculate the gradient signal matrix of each type of shrinkage defect and obtain the channel-level gradient weight coefficient matrix. Furthermore, based on the gradient weight coefficient matrix of each type of shrinkage defect, a weighted linear combination method (parameter: weight normalization is L1 normalization) is used to weight the feature maps at different scales according to the channel dimension, generating a multi-scale gradient weighted class activation map, which is used as the response intensity distribution of the model's region of interest in the input space. Furthermore, to ensure the spatial information consistency of the response map across multiple scales, a scale-aligned interpolation algorithm (parameters: bilinear interpolation, target resolution of 256×256) is used to unify the resolution of the gradient-weighted activation maps at each scale, and to generate multi-scale Grad-CAM response maps optimized by the attention gating mechanism. By combining the attention gating mechanism with the gradient backpropagation algorithm, the result of the previous step is transformed into a multi-scale gradient weighted activation map with spatial local and global features, thereby realizing the visualization of the spatial response of the model’s focus area and improving the accuracy of subsequent feature fusion. For example, for a 1024×1024 grayscale preprocessed image of a die-cast part, a channel attention module and a spatial attention module are introduced in the auxiliary branch. The input to the channel attention module is the feature map of the third convolution layer of the main branch, and the input to the spatial attention module is the feature map of the fifth convolution layer of the main branch. The initial channel weight vector length is 64, and the initial spatial weight map size is 32×32. The gradient signal matrix of category "shrinkage defect 1" is calculated using an automatic differentiation algorithm to obtain the gradient mean of each channel. For example, the gradient mean of channel c=12 is...

[0018] As normalized weighting coefficients, these coefficients are combined with feature maps of different scales to form a preliminary Grad-CAM response map. Bilinear interpolation is then used to adjust all response maps to a resolution of 256×256. An attention gating mechanism adjusts the channel weights to the channel corresponding to the maximum response value (e.g., c=27) by increasing the weight by 0.2, and the spatial weights in the highest response region by 0.15, resulting in an optimized multi-scale Grad-CAM map. This map significantly highlights the blurred areas and texture difference areas at the pinhole edges during visualization verification, providing high-quality spatial response evidence for subsequent uncertainty tracing. S3.4: The multi-scale gradient weighted activation maps are weighted and fused along the channel dimension to generate a multi-granularity feature response distribution map with hierarchical consistent response intensity, which is used to characterize the difference in the degree of attention of the model to local image regions at different scales. Based on the multi-scale gradient weighted activation map set output by S3.3, a channel-dimensional weighted fusion algorithm is adopted (the weight parameters are set according to the mean of the normalized response energy of the feature maps at each scale) to achieve unified intensity merging of spatial attention information output by different convolutional layers; Furthermore, the normalized weighting coefficient calculation method (parameter: mean pixel response within the channel) is used. with standard deviation This enables adaptive allocation of channel weights for feature maps at various scales, and yields optimized channel weight vectors. Furthermore, a channel-by-channel linear combination strategy is adopted (parameter: channel weight vector). Gradient-weighted class activation graphs at corresponding scales This enables cross-scale response fusion and generates an intermediate fusion result matrix. Its element values ​​in the range [0,1] reflect the intensity of the fusion response; Furthermore, a hierarchical consistency regularization method is used (parameter: fusion result matrix). Global response variance threshold This suppresses local intensity anomalies caused by differences in scale resolution, ensuring that the response intensity of the fusion results is consistent across different levels. Furthermore, smooth convolution kernel filtering (parameters: kernel size 3×3, standard deviation 0.8) is used to optimize the spatial continuity of the fusion result and generate the final multi-granularity feature response distribution map to characterize the differences in the model's attention to local image regions at different scales. Through the above fusion processing method, the original distribution of the multi-scale gradient weighted activation map is transformed into a spatial response map with a uniform intensity ratio, thereby realizing the integration and intensity consistency of multi-granularity attention information. For example, in the scenario of detecting shrinkage cavities inside die-cast parts, channel-weighted fusion is performed on gradient-weighted activation maps from three different convolutional layers (corresponding to feature maps with receptive field sizes of 32×32, 64×64, and 128×128 pixels, respectively), and the channel weight vectors are... The calculation formula is:

[0019] in, This is the normalized mean response of the channel. This represents the normalized standard deviation of the channel's response. This is the smoothing regularization constant. When the number of channels is 64, calculate the value for each channel separately. The values ​​are then normalized until their sum equals 1. The normalized weight vectors are then linearly combined channel-by-channel with the corresponding feature maps to obtain the fusion result matrix. Its global response variances at the three scales were 0.0021, 0.0024, and 0.0020, respectively, which were below the threshold. The hierarchical consistency requirement is met. After smoothing with a 3×3 convolution kernel, the response intensity of the final multi-granularity feature response distribution map is significantly improved in the actual defect location region, and significantly reduced in the response intensity in the typical noise interference region, verifying the effectiveness of the fusion strategy in improving interpretability and suppressing background noise; S3.5: The defect classification and localization results of the main branch and the multi-granularity feature response distribution map generated by the auxiliary branch are output simultaneously. The two constitute a joint decision output, which provides a dual-modal input basis for subsequent pixel-level sensitivity analysis and uncertainty cause tracing based on backpropagation. The candidate defect location boxes and their category confidence results output by the main branch are encapsulated using a structured data encapsulation method (parameters: location box coordinate quadruples, confidence scores, category index) to generate a standardized storage format for the detection results. Furthermore, through the multi-granularity feature response distribution map generation module of the auxiliary branch (parameters: fusion weight matrix, scale index sequence), channel-weighted fusion of response features of different convolutional layers is achieved, and a response intensity matrix with consistent spatial resolution is obtained; Furthermore, the standardized detection results of the main branch and the response intensity matrix of the auxiliary branch are subjected to a joint index matching method (parameters: spatial resampling scale, location matching threshold) to achieve cross-referencing of defect location boxes and their corresponding high-response region index pairs, and generate a binary association data structure; Furthermore, a dual-modal output encapsulation mechanism (parameters: detection result data stream, feature response data stream) is adopted to encapsulate candidate defects and their multi-granularity response maps into a unified joint decision output unit, ensuring that subsequent steps obtain complete spatial localization and feature attention information in a single interface; By using a joint decision-making output encapsulation processing method, the detection results and feature response maps of the previous step are transformed into dual-modal input data with synchronous spatial index and response intensity annotation, thereby achieving the input preparation effect for subsequent backpropagation pixel-level sensitivity analysis and uncertainty cause tracing. For example, in the task of detecting shrinkage cavities in die castings, the coordinates of the bounding box output by the main branch are (128, 256, 192, 320), with a corresponding class confidence of 0.78 and a class index of 2. The spatial resolution of the multi-granularity feature response distribution matrix generated by the auxiliary branch is uniformly 256×256 pixels, and the fusion weight matrix is ​​set to [0.3, 0.5, 0.2] corresponding to three layers of convolutional features. The scale index sequence is [1, 2, 3] representing shallow, medium, and deep features, respectively. During the joint index matching process, the position matching threshold is configured to 5 pixels to ensure that the spatial deviation between the mapped area of ​​the bounding box and the high-intensity area of ​​the response matrix does not exceed this threshold. In the binary association data structure generated after matching, the average response intensity value associated with the bounding box and the response area is 0.64. Through dual-modal encapsulation, the above detection results and response map are compressed into two synchronous data stream fields contained in a unified JSON structure and passed to step S4 for backpropagation sensitivity analysis. The verification in this scenario shows that dual-modal output encapsulation can significantly improve the spatial alignment accuracy and response intensity consistency when tracing the source of uncertainty, thus ensuring the stability of the technical effect of causal analysis.

[0020] like Figure 3 As shown, step S4 involves: based on the multi-granularity feature response distribution map, calculating the feature gradients of each key convolutional layer relative to the final predicted output using the backpropagation algorithm, and generating a pixel-level sensitivity heatmap in conjunction with attention weights, serving as a spatial mapping representation for model decision-making. Specifically, this includes: S4.1: Based on the multi-scale convolutional layer gradient weighted class activation map (Grad-CAM) output by the auxiliary branch, the feature map tensor of the corresponding layer in the backbone network and the class score of the classification task are obtained as the initial input conditions for backpropagation calculation; the class score is backpropagated relative to the feature map of each key convolutional layer using an automatic differentiation mechanism to calculate the gradient signal matrix of each layer, so as to capture the sensitive response regions of the model to input changes at different levels of abstraction; Based on the multi-scale convolutional layer gradient-weighted activation map (Grad-CAM) output by auxiliary branches, a tensor indexing retrieval method is used (parameter: convolutional layer identifier = set of key layer IDs of the backbone network) to achieve a one-to-one spatial mapping between the multi-scale response map and the tensor of the feature map of the convolutional layer of the backbone network. Furthermore, through the category score calculation module of the classification task (parameter: category index = the defect category ID to which the current detection target belongs), the corresponding category score scalar is extracted from the Softmax output vector of the main branch and used as the target output of the backpropagation calculation; Furthermore, an automatic differentiation mechanism (parameters: framework=TensorFlow / PyTorch, computational precision=float32) is adopted to realize the gradient backpropagation process of the category score relative to the feature maps of each key convolutional layer, and to generate the gradient signal matrix of each convolutional layer, capturing the sensitive regions of the model to input changes at different semantic abstraction layers. Furthermore, a tensor caching operation with feature channel preservation is performed on the gradient signal matrix (parameter: cache mode = layer number index) to enable repeated calls to subsequent gradient aggregation and channel weighting; Through the above gradient calculation process, the Grad-CAM output of the auxiliary branch and the feature gradient of the main branch are combined to form dual-path feature correlation data, thereby realizing the input preparation work for cross-scale sensitivity analysis. For example, when processing the original CT image of a die-cast part with a resolution of 1024×1024 and a grayscale bit depth of 16 bits, the 3rd, 5th, and 7th convolutional layers in the backbone network are first selected as key layers using the tensor indexing retrieval method, resulting in tensor dimensions of 256×256×64, 128×128×128, and 64×64×256 for the feature maps of each layer, respectively. Subsequently, the softmax output value of the target class ID=2 is extracted through the class score calculation module. = During automatic differentiation, this score is used as input to the loss function to calculate the gradient signal matrix of each key layer. For example, the gradient matrix of the 3rd layer has a dimension of 256×256×64, and the matrix element range is... The data is cached in an in-memory index table for subsequent S4.2 calls. This process effectively obtains the sensitive response distribution data of the model in shallow, medium, and deep feature spaces, significantly improving the spatial accuracy of subsequent sensitivity heatmap construction; S4.2: Perform global average pooling on the gradient signal matrix of each key convolutional layer to obtain the gradient weight coefficient corresponding to each channel; perform a weighted linear combination operation on the feature map of the corresponding layer based on the gradient weight coefficient to generate a preliminary class-independent feature response map as a coarse-grained spatial localization result of the model's region of interest. S4.3: Perform element-wise multiplication on the preliminary class-independent feature response map and the channel-space joint attention weight map output by the attention gating module in the main branch to fuse the feature selection preference guided by the attention mechanism; optimize the spatial focusing ability of the response map through this fusion operation, suppress background redundant response, generate an enhanced feature response map, and improve the sensitivity consistency to potential defect edge regions. Based on the preliminary class-independent feature response map output by S4.2 and the channel-spatial joint attention weight map of the main branch attention gating module, an element-wise multiplication operation is used to fuse the response map in the spatial and channel domains. This operation uses the position index as the registration reference, multiplying the response value at the same pixel coordinate with the channel weight value corresponding to that position, thereby preserving local spatial features while embedding the guidance of the attention mechanism for feature selection. Furthermore, by using a weighted normalization algorithm (parameter: L1 norm constraint of the channel weight vector), the numerical standardization of the fused response map is achieved, eliminating the response offset introduced by the difference in the weight scale of different channels, and obtaining a balanced enhanced response map matrix to improve the stability of subsequent spatial analysis. Furthermore, a local variance suppression algorithm (parameter: window radius r = 3 pixels) is used to suppress low variance regions in the enhanced response map matrix, reducing the response values ​​of background or texture-smooth regions, thereby achieving spatial focusing optimization of the target region; Furthermore, by using the edge gradient enhancement algorithm (parameter: Sobel operator scale=1), the gradient magnitude of the response intensity at the defect edge is increased on the enhanced response map, so that the edge of the potential shrinkage defect appears as a continuous and significant high response band in the response map, thereby improving the consistency of boundary sensitivity. Through the above fusion and optimization process, the preliminary feature response map of the previous step is transformed into an enhanced feature response map with spatial focusing capability and sensitivity consistency, so as to achieve the expected technical effect of background interference suppression and defect area response enhancement. For example, in a set of CT grayscale images of die-cast parts with a resolution of 1024×1024 pixels, the main branch attention gating module outputs a channel-spatial joint weight map with 64 channels, each with a weight ranging from 0.05 to 0.12. The initial class-independent feature response map has a response value range of 0-4.7. Element-wise multiplication is performed on both to obtain a fusion matrix with a response value range of 0-0.56. After L1 norm normalization of the fusion matrix, the response value range is unified to 0-1. A local variance suppression algorithm with a window radius of 3 pixels is used to attenuate the response value by 50% in low variance (<0.008) regions, reducing the background region response to below 0.2. Gradient enhancement is performed using the Sobel operator with a scale of 1, increasing the response value from 0.75 to 0.9 at the defect edge to achieve boundary strengthening. The final output of the enhanced feature response map shows that the edge response of the shrinkage defect is continuous and the brightness is concentrated in the subsequent upsampling and heatmap generation steps, which significantly improves the stability and interpretability of edge recognition. S4.4: Perform bilinear interpolation upsampling on the enhanced feature response map to restore its resolution to the original input image size; then perform ReLU nonlinear activation and L2 normalization to generate a pixel-level sensitivity heatmap with spatial alignment characteristics, which serves as a continuous intensity representation of key visual evidence on which the model decision depends. S4.5: The pixel-level sensitivity heatmap is overlaid and registered with the original visual image after channel expansion to generate a heatmap visualization intermediate product with transparency encoding; this product is used for cross-modal mapping analysis with superpixel segmentation results in subsequent steps, forming an interpretable bridge between the internal decision logic of the model and the external observable image structure.

[0021] Step S5: Perform superpixel segmentation on the original visual image to obtain a set of image patches with local consistency texture attributes, and map the response intensity of the pixel-level sensitivity heatmap to each superpixel patch, selecting the top K highest response regions to form a candidate set of potential interference sources. Specifically, this includes: S5.1: Based on the original visual image, superpixel segmentation is performed using the Simple Linear Iterative Clustering (SLIC) algorithm to over-segment the image while maintaining local texture consistency, generating an image block set consisting of N compact and uniformly distributed superpixel blocks, where the number of segments N is between 1000 and 3000, and each superpixel block represents a group of pixel units with similar colors and spatial proximity. S5.2: Perform the same spatial grid alignment operation as the superpixel segmentation result on the pixel-level sensitivity heatmap to ensure that the response intensity value of each pixel position in the heatmap can be accurately mapped to its superpixel block, forming a spatially registered heatmap response distribution; For the pixel-level sensitivity heatmap obtained by step S4.5, a spatial grid registration algorithm (parameters: resolution = original visual image size, grid cell boundary = superpixel block pixel set) is used to achieve physical spatial consistency between the heatmap coordinate system and the superpixel segmentation result; Furthermore, by using the coordinate index mapping method (parameters: pixel index table, superpixel block ID table), the response intensity value of each heatmap pixel is accurately mapped to its superpixel block, and a registration-level pixel response matrix is ​​obtained. Furthermore, a bidirectional neighborhood search algorithm (parameter: row and column neighborhood size = 1 pixel) is used to perform edge correction on the mapping results, ensuring that pixels located at the superpixel boundary are assigned to the superpixel block of the most similar texture category according to the spatial proximity principle, thereby generating a boundary-optimized response mapping matrix; Furthermore, by using a unified scale normalization method (parameter: normalization range = [0,1]), the heatmap response intensity is standardized across the global pixel range, forming a unified response distribution that is suitable for subsequent average response calculation. The above spatial grid alignment algorithm transforms the pixel-level sensitivity heatmap result from the previous step into a spatially registered superpixel block response distribution, achieving a consistent mapping effect between superpixels and thermal responses. For example, in a die-casting defect detection scenario, the original visual image has a resolution of 2048×2048 pixels. After being segmented into 2000 superpixel blocks using the SLIC algorithm, the resulting pixel-level sensitivity heatmap is the same size as the original image. The spatial grid registration algorithm sets the unit boundary as the pixel set of the superpixel block, matching each heatmap pixel to its corresponding superpixel block ID, forming a 2000×P response distribution matrix, where P is the number of pixels contained in each block. For pixels located at the boundary, a bidirectional neighborhood search algorithm compares the texture entropy value and grayscale gradient of neighboring pixels, determines the most similar texture category, and adjusts the classification. After correction, the boundary mismatch rate is significantly reduced. During normalization, the response intensity of each pixel is mapped to the [0,1] interval, and the average response intensity is used as the input for subsequent calculation units, ensuring the comparability of response intensities across different superpixel blocks. After this superpixel-heatmap spatial registration process, the output response distribution maintains strict consistency with the model's region of interest in both position and intensity, providing a high-precision input basis for the superpixel-level sensitivity vector calculation of S5.3; S5.3: For each superpixel block, calculate the average response intensity value of all pixels contained therein in the registered heatmap, and use it as the overall sensitivity response score of the superpixel block. Generate a superpixel-level sensitivity vector composed of N response scores to characterize the contribution of each local region of the image to the uncertainty of the model decision. S5.4: Based on the superpixel-level sensitivity vector, the top K superpixel blocks with the highest response scores are selected using a descending sorting strategy. These blocks are considered as key regions that have the greatest impact on the uncertainty of the current detection results, forming a potential interference source candidate set for subsequent low-order visual feature extraction and noise pattern matching analysis. Based on the superpixel-level sensitivity vector obtained from S5.3, a descending sorting algorithm (parameter: sorting key is sensitivity response score, stability is guaranteed by using a stable sorting method) is used to arrange the response intensity of all N superpixel blocks from high to low. Furthermore, by using the threshold-index truncation method (parameter: K value depends on the preset upper limit of the candidate region), the index of the first K superpixel blocks of the sorting result is extracted, and the corresponding region number and sensitivity score are obtained; Furthermore, by normalizing the response scores (parameters: interval [0,1], method: maximum and minimum value normalization), the scale of sensitivity scores among multiple samples is unified, and a standardized sensitivity matrix adapted for cross-image comparison analysis is generated. Furthermore, by using a region feature combination method (parameters: retaining superpixel spatial labels and shape descriptors), the spatial information and response intensity of candidate superpixel blocks are jointly encapsulated, and a candidate region description set with spatial semantic orientation is generated. Through the above sorting, filtering and feature encapsulation processes, the superpixel-level sensitivity vector of the previous step is transformed into a candidate set of potential interference sources, enabling rapid localization and structured output of the key regions that contribute the most to the uncertainty in the current detection results, providing accurate input for the next step of low-order visual feature extraction and noise pattern matching analysis; For example, in an X-ray inspection scenario of a die-cast part, N is 150, and the sensitivity response score ranges from 0.12 to 0.97. After sorting in descending order, K=10 superpixel blocks are selected as candidate regions. The sorting algorithm uses quicksort combined with a stable index to maintain the original sequence position attributes. Normalization maps the highest score of 0.97 to 1.0, the lowest score of 0.12 to 0.0, and the remaining scores are mapped linearly. The region number and coordinate label include the shape compactness parameter (values ​​from 0.83 to 0.95) and spatial location label (e.g., center coordinates (X:245, Y:512)) during encapsulation. The execution effect shows that the candidate set covers all high-sensitivity regions, most of which are located at the edge of shrinkage defects or in areas where reflective interference occurs. Subsequent low-order feature analysis verifies that the matching success rate of this candidate set with typical noise patterns is significantly improved. During model iteration, this candidate set provides high-quality causal origin training samples, effectively improving the accuracy and operational controllability of the explanation of uncertain causes. S5.5: Establish a spatial index mapping relationship between each superpixel block in the potential interference source candidate set and its corresponding local region of the original image, and generate a region localization information package with coordinate labels, so as to provide traceable input data support for feature matching in the standard normal region template library in the next step.

[0022] Step S6: For each superpixel block in the potential interference source candidate set, extract its low-order visual features of texture complexity, edge blurring, and grayscale contrast, and perform similarity matching with reference features in the standard normal region template library to identify interference regions that conform to typical noise patterns. Specifically, this includes: S6.1: Based on each superpixel block in the candidate set of potential interference sources output by S5, the gray-level distribution in each superpixel block is modeled using the Local Binary Pattern (LBP) algorithm, and its histogram statistical moments are calculated as texture complexity feature vectors to quantify the degree of non-uniformity of the internal structure of the region and obtain texture representation parameters with discriminative ability. S6.2: Apply the Canny edge detection operator combined with Gaussian gradient magnitude decay analysis to the same superpixel block, calculate the standard deviation of edge response intensity and the maximum gradient descent slope, construct an edge ambiguity scoring function based on the above indicators to evaluate the boundary sharpness degradation in the region, and generate an edge ambiguity feature scalar. S6.3: Based on the gray value distribution at the corresponding position in the original preprocessed image, calculate the average gray value difference and variance ratio between the superpixel block and its surrounding neighborhood, use the normalized difference index to characterize the local contrast characteristics, and generate gray-level contrast feature parameters to reflect the degree of significant deviation of the region under imaging conditions. S6.4: Combine the texture complexity feature vector, edge blur feature scalar, and grayscale contrast feature parameters extracted from S6.1, S6.2, and S6.3 into a multidimensional low-order visual feature vector, which serves as the comprehensive feature representation of the current superpixel block. Input it into a pre-built standard normal region template library to perform nearest neighbor matching based on Euclidean distance. S6.5: Based on the feature matching results in S6.4, determine whether the current superpixel block falls within the clustering range of typical noise patterns stored in the template library. If the match is successful, mark it as the corresponding type of interference region (such as uneven illumination, surface reflection or microcrack interference), and output the classification result as the key input for interpretability cause tracing. Based on the matching results between the multidimensional low-order visual feature vectors output by S6.4 and the standard normal region template library, a pattern clustering determination method is adopted (parameter: Euclidean distance threshold). (and the noise mode cluster center vector set), to determine the noise mode affiliation of the current superpixel block; Furthermore, through the distance metric calculation module (parameter: ,in For candidate superpixel block feature vectors, (For the feature vector of the noise pattern cluster center), the similarity score between the candidate feature and each noise pattern center is realized, and the distance vector is obtained as the matching metric data; Furthermore, the minimum distance index retrieval method is used (parameters: Top-1 minimum distance value and index). This enables the nearest neighbor association mapping between candidate features and noisy pattern clusters, and generates corresponding pattern label indices; Furthermore, through threshold comparison operation (parameter: ), to perform relationship analysis between distance value and judgment threshold, if satisfied If the match is successful, a matching success flag will be output, and the superpixel block will be marked as an interference region of the corresponding type in the template library; Furthermore, through label assignment processing, the successfully matched interference areas are coded as categories such as uneven illumination, surface reflection, or microcrack interference, serving as key input data for interpretable cause tracing; Through pattern clustering determination and label assignment, the feature matching results of the previous step are transformed into categorized interference region identifiers, which can be used as structured inputs for subsequent semantic mapping of uncertain causes. For example, in the CT inspection scenario of die castings, assume that the template library contains three typical noise pattern clusters: uneven illumination cluster center features =[0.12,0.45,0.30], surface reflective cluster center features =[0.78,0.15,0.40], characteristics of the center of microcrack interference clusters =[0.55,0.50,0.20], threshold Set to 0.25. For a given candidate superpixel block, the feature vector is composed of its texture complexity, edge blurring, and grayscale contrast. Given the value [0.10, 0.50, 0.28], the Euclidean distance is calculated to be 0.054. Similar calculations yielded center distances of 0.73 and 0.40 for other clusters. The minimum value of 0.054 is taken as the center of the cluster with uneven illumination, satisfying the following conditions. Based on the given criteria, this superpixel block is classified as an area of ​​uneven illumination interference. In the output, this area is directly converted into the cause label "uneven illumination leading to local feature deviation" in the subsequent S7 step. Verification results show that this classification can significantly improve the accuracy of uncertainty cause localization.

[0023] Step S7: Determine whether there is a detection result that meets the high uncertainty judgment condition. If so, generate a corresponding interpretable cause label based on the identified typical noise pattern type, forming a composite output result package containing defect location, category, uncertainty score, and cause label. Specifically, this includes: S7.1: Based on the typical noise pattern recognition results output in the previous step S6 and the predicted probability distribution obtained by the main branch network through Monte Carlo sampling, calculate the uncertainty score of the current detection result; use classification entropy or prediction variance as uncertainty measure index to quantitatively evaluate each candidate defect region and generate an uncertainty score vector with numerical representation. S7.2: Compare the uncertainty score vector with the preset high uncertainty threshold and perform a binary judgment operation; if the uncertainty score of a certain defect detection result exceeds the threshold, mark the result as a 'high uncertainty instance' and trigger the subsequent interpretability cause analysis process to ensure that the source tracing mechanism is only started for identification results with insufficient confidence in order to control computational overhead; S7.3: For detection instances marked as high uncertainty, call the typical noise pattern types identified in step S6, including interference categories such as uneven illumination, surface reflection, blurred edges, or texture ambiguity, and input these patterns as causal hypotheses into the rule mapping engine; based on the pre-built noise pattern-semantic label association table, perform semantic mapping transformation from pattern to interpretable label to generate preliminary causal description text; S7.4: Combining the spatial location information of defects in the original visual image with the superpixel block-level response intensity ranking results, the initial generated cause description is subjected to context enhancement processing; specifically, the spatial adjacency relationship of the highest response superpixel block and the relative position of the defect region are analyzed topologically to determine whether it is located at the edge of the defect or the internal core region, thereby optimizing the spatial orientation of the cause label and outputting interpretable labels with spatial semantic accuracy, such as 'suspected pore edge blurring leads to feature ambiguity' or 'local oxide film coverage affects texture consistency'. S7.5: Integrate defect location coordinates, identification category labels, uncertainty score values, and optimized interpretable cause labels to construct a structured composite output result package. This result package is encapsulated in a unified data format, supports subsequent transmission to the quality decision system for anomaly handling strategy selection, and provides unlabeled supervised samples with causal annotations for the historical case database, enabling knowledge accumulation for model iteration. Based on the optimized interpretable cause label and corresponding defect area location information output in step S7.4, the structured data mapping interface is called to load the defect location coordinate data, ensuring that the location data is accurately bound to the identification category label and uncertainty score value in three-dimensional coordinate form (X, Y, Z), and realizing the data initialization of multi-field synchronous calls; A field merging algorithm (parameters: primary key is work order number, foreign key is imaging timestamp) is used to achieve unified association of defect location coordinates, identification category labels, uncertainty scores and cause labels, and generate intermediate-level joint record structure to ensure that composite fields maintain consistency and integrity in subsequent encapsulation. Furthermore, by using a data format verification algorithm (parameters: data type constraint rule set, null value detection threshold), the data type standardization and missing value detection of each field in the joint record are realized, and fields that do not meet the constraints are automatically filled or format converted to obtain a verification qualified record that meets the preset unified data format requirements. Furthermore, a multi-level nested JSON template generation algorithm (parameters: tag namespace, level depth = 4) is adopted to convert the qualified records into a composite output result package with a unified encapsulation format. The top-level fields include defect location, category, uncertainty score and cause label, and the nested secondary fields include coordinate precision, score calculation method and cause label source path, forming a structured encapsulation unit with traceability. By using an index binding algorithm (parameters: index key = work order number, index value = hash value of defect location coordinates), a one-to-one index relationship is established between the encapsulated composite output result package and the receiving interface of the quality decision system, so as to realize fast retrieval and transmission optimization in subsequent calls to the quality decision system. The algorithm chain described above transforms the causal labels and detection data from the previous step into a structured composite output package with a unified format, achieving the expected technical effect of directly supporting the selection of anomaly handling strategies and being used for the accumulation of causal annotation samples in historical case databases. For example, in an X-ray inspection of a batch of die-cast parts, the defect area coordinates output by step S7.4 are X=128.56mm, Y=64.23mm, Z=15.78mm, the identification category is "shrinkage cavity defect", and the uncertainty score is calculated based on the prediction variance. The optimized cause label is "Local oxide film coverage affects texture consistency". The data mapping interface loads these parameters and executes a field merging algorithm, associating them with work order number #20240315-07 to generate a joint record. During format validation, the uncertainty score field is converted from the original decimal format to floating-point format and retains 6 significant digits, and the defect coordinates are standardized to millimeters. The multi-layer nested JSON template generation algorithm encapsulates the above record as follows: top-level field "DefectLocation"={"X":128.56, "Y":64.23, "Z":15.78}, "DefectType"="shrinkage defect", "UncertaintyScore"=0.012500, "CauseLabel"="Local oxide film coverage affects texture consistency", secondary field "LocationPrecision"=0.01mm, "ScoreCalculation"="variance normalization method", and records the cause label source path as "LBP texture complexity + contrast difference analysis". The index binding algorithm generates the coordinate hash value e3b0c442 corresponding to the index key #20240315-07, forming a structured encapsulation unit that can be directly transmitted to the quality decision system and archived in the case database. Field verification shows that the delay of this encapsulation unit in the system retrieval and calling process is significantly reduced, meeting the performance requirements of synchronous operation of online detection and closed-loop feedback.

[0024] Step S8: The composite output result package is transmitted to the quality decision system to support the selection of anomaly handling strategies and the optimization of process parameters. Simultaneously, the cause labels and corresponding original image fragments are stored in the historical case database to provide unlabeled supervision signals for subsequent model iterations. Specifically, this includes: S8.1: Based on the defect location and category information in the composite output result package, generate a standardized structured inspection report data frame as an input unit that the quality decision system can parse; S8.2: Perform communication protocol encapsulation processing on the structured inspection report data frame, and transmit it to the quality decision system using the industrial Ethernet protocol to trigger the anomaly handling strategy matching process; S8.3: Based on the uncertainty score and interpretable cause label in the composite output result package, extract the corresponding original image fragment and its cause semantic description, and generate a quality anomaly event record entry with context annotation; S8.4: Write the recorded entries of the quality anomaly events into the historical case database, and establish an index mapping relationship from the cause label to the local area of ​​the original image to form a knowledge graph basic node that can be used for model backtracking analysis; S8.5: Based on the distribution characteristics of high-frequency causal patterns in the basic nodes of the knowledge graph, generate sample enhancement strategy suggestions for specific noise interference types, providing unlabeled supervision signal-driven optimization directions for subsequent model iterations.

[0025] The technical solution of the present invention has been described above with reference to the preferred embodiments shown in the accompanying drawings. However, it will be readily understood by those skilled in the art that the scope of protection of the present invention is obviously not limited to these specific embodiments. Without departing from the principles of the present invention, those skilled in the art can make equivalent changes or substitutions to the relevant technical features, and the technical solutions after these changes or substitutions will all fall within the scope of protection of the present invention.

[0026] The above description is merely a preferred embodiment of the present invention and is not intended to limit the invention. Various modifications and variations can be made to the present invention by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and rules of the present invention should be included within the scope of protection of the present invention.

Claims

1. A machine vision-based method for detecting and analyzing internal shrinkage cavities in die-cast parts, characterized in that, Includes the following steps: S1: Acquire the original visual image of the shrinkage cavity defect inside the die casting and record the ambient light intensity and sensor position information during image acquisition; S2: Perform grayscale normalization and nonlocal mean denoising on the original visual image to generate a preprocessed image; S3: Input the preprocessed image into a dual-branch deep learning network, wherein the main branch performs the task of classifying and locating the pinhole defects, and the auxiliary branch simultaneously extracts the gradient weighted class activation map of the multi-scale convolutional layer to form a multi-granularity feature response distribution map. S4: Based on the multi-granularity feature response distribution map, calculate the feature gradient of each key convolutional layer relative to the final predicted output, and generate a pixel-level sensitivity heatmap by combining the attention weights. S5: Perform superpixel segmentation on the original visual image to obtain a set of superpixel blocks, and map the response intensity of the pixel-level sensitivity heatmap to each superpixel block, and select the highest response region to form a potential interference source candidate set; S6: For each superpixel block in the potential interference source candidate set, extract its texture complexity, edge blurring and grayscale contrast low-order visual features, and perform similarity matching with reference features in the standard normal region template library to identify interference regions that conform to typical noise patterns. S7: When there is a detection result that meets the high uncertainty judgment condition, the corresponding interpretable cause label is generated according to the identified typical noise pattern type, forming a composite output result package.

2. The method for detecting and analyzing internal shrinkage cavities in die-cast parts based on machine vision according to claim 1, characterized in that, Following step S7, the following is also included: S8: Transmit the composite output result package to the quality decision system to support the selection of anomaly handling strategies and the optimization of process parameters. At the same time, store the cause labels and corresponding original image fragments in the historical case database to provide unlabeled supervision signals for subsequent model iterations.

3. The method for detecting and analyzing internal shrinkage cavities in die-cast parts based on machine vision according to claim 1, characterized in that, The original visual image is obtained by die casting under X-ray or industrial CT imaging equipment, stored in grayscale image form with a resolution of 1024×1024 pixels or higher and a bit depth of 16.

4. The method for detecting and analyzing internal shrinkage cavities in die-cast parts based on machine vision according to claim 1, characterized in that, The nonlocal mean denoising includes local texture consistency verification and adaptive parameter adjustment. The denoising intensity is dynamically adjusted by using a sliding window and gradient direction entropy calculation to generate an adaptively optimized denoised image.

5. The method for detecting and analyzing internal shrinkage cavities in die-cast parts based on machine vision according to claim 1, characterized in that, Step S3 specifically includes: The input tensor of a dual-branch deep learning network is constructed based on preprocessed images, and a normalized pixel matrix is ​​used as the input data of the convolutional neural network to generate a normalized input tensor. In the main branch, a residual convolution module and a region proposal network are deployed to perform multi-level spatial convolution and non-linear activation operations on the standardized input tensor to extract deep semantic features and generate candidate defect regions. The output includes preliminary detection results containing location box coordinates and category confidence. An attention gating mechanism is integrated into the auxiliary branch. Based on the feature map sequence output by each key convolutional layer in the main branch, the weight coefficients corresponding to each type of shrinkage defect are calculated to generate a multi-scale gradient weighted class activation map. The multi-scale gradient weighted activation maps are weighted and fused along the channel dimension to generate a multi-granularity feature response distribution map. The candidate defect region, the preliminary detection result, and the multi-granularity feature response distribution map are output simultaneously to form a joint decision output.

6. The method for detecting and analyzing internal shrinkage cavities in die-cast parts based on machine vision according to claim 5, characterized in that, The auxiliary branch uses gradient backpropagation to calculate the weight coefficients corresponding to each type of shrinkage defect, and uses a weighted linear combination method to perform channel dimension weighting on feature maps of different scales and bilinear interpolation to perform resolution unification processing on gradient weighted class activation maps of each scale, generating multi-scale gradient weighted class activation maps.

7. The method for detecting and analyzing internal shrinkage cavities in die-cast parts based on machine vision according to claim 1, characterized in that, Step S4 specifically includes: Based on the multi-scale convolutional layer gradient weighted class activation map output by the auxiliary branch, the feature map tensor of the corresponding layer in the backbone network and the class score of the classification task are obtained. The gradient backpropagation of the class score relative to the feature map of each key convolutional layer is performed using an automatic differentiation mechanism to calculate the gradient signal matrix of each layer. The gradient signal matrix is ​​subjected to global average pooling to obtain the gradient weight coefficients for each channel. Based on the gradient weight coefficients, a weighted linear combination operation is performed on the feature maps of the corresponding levels to generate a preliminary class-independent feature response map. The initial class-independent feature response map is multiplied element-wise with the channel and spatial joint attention weight map output by the attention gating module in the main branch to generate an enhanced feature response map. The enhanced feature response map is subjected to bilinear interpolation upsampling to restore its resolution to the original input image size, and ReLU nonlinear activation and L2 normalization are performed to generate a pixel-level sensitivity heatmap. The pixel-level sensitivity heatmap is overlaid and registered with the original visual image after channel expansion to generate an intermediate product for heatmap visualization.

8. The method for detecting and analyzing internal shrinkage cavities in die-cast parts based on machine vision according to claim 1, characterized in that, Step S5 specifically includes: Based on the original visual image, superpixel segmentation is performed to generate a set of image patches composed of superpixel blocks; Perform the same spatial grid alignment operation as the superpixel segmentation result on the pixel-level sensitivity heatmap generated in step S4 to form a spatially registered heatmap response distribution. For each superpixel block, calculate the average response intensity value of all pixels contained therein in the heatmap after spatial registration, and generate a superpixel-level sensitivity vector; Based on the superpixel-level sensitivity vector, a descending sorting strategy is used to select the top K superpixel blocks with the highest response scores, which are regarded as the key regions that have the greatest impact on the uncertainty of the current detection results, and form a potential interference source candidate set. A spatial index mapping relationship is established between each superpixel block in the potential interference source candidate set and its corresponding local region in the original image, generating a region localization information packet with coordinate labels.

9. The machine vision-based method for detecting and analyzing internal shrinkage cavities in die-cast parts according to claim 8, characterized in that, The superpixel segmentation process is performed using a simple linear iterative clustering algorithm, with the number of segments N ranging from 1000 to 3000. Each superpixel block in the image block set composed of superpixel blocks represents a group of pixel units with similar colors and spatial proximity.

10. The method for detecting and analyzing internal shrinkage cavities in die-cast parts based on machine vision according to claim 1, characterized in that, The composite output package includes defect location, category, uncertainty score, and cause label.