Method and system for detecting internal defects of aluminum alloy casting

The method for detecting internal defects in aluminum alloy castings by multi-angle projection and multi-scale feature extraction solves the problem of insufficient adaptability of traditional detection methods to small and fuzzy defects, and realizes efficient and accurate detection of internal defects in aluminum alloy castings, thereby improving the accuracy and efficiency of detection.

CN121707933APending Publication Date: 2026-03-20NANJING LONGCHAO METAL MFG TECH
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-03
Publication Date
2026-03-20

AI Technical Summary

Technical Problem

Traditional methods for detecting internal defects in aluminum alloy castings rely on single image features or fixed global thresholds, resulting in insufficient adaptability to small, blurry, or morphologically variable defects. This affects the reliability and accuracy of the detection results, making it difficult to meet the high standards of industrial quality inspection.

Method used

By acquiring multi-angle projection images of aluminum alloy castings, combining structural feature recognition and multi-scale feature extraction, a defect probability map is generated. Binarization segmentation is performed based on an adaptive segmentation threshold, and the geometric and morphological parameters of the defects are calculated. A preset defect classification rule set is then used for quantitative evaluation and classification.

Benefits of technology

It significantly improves the accuracy and specificity of defect identification, reduces the risk of misjudgment, achieves objective and repeatable accurate judgment of defect size, shape and type, optimizes the contour integrity of defect areas, and improves the efficiency and scalability of industrial inspection.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121707933A_ABST
    Figure CN121707933A_ABST
Patent Text Reader

Abstract

The invention relates to an internal defect detection method and system for an aluminum alloy casting, and the method comprises the steps: collecting a projection image sequence of the aluminum alloy casting, and carrying out the structural feature recognition, thereby obtaining a structural feature image; performing feature extraction and pixel-level segmentation on the structural feature image to generate a defect probability graph; calculating a segmentation threshold value of the defect probability graph, carrying out binarization segmentation on the defect probability graph based on the segmentation threshold value, and generating a defect distribution graph when the number of connected regions in an obtained initial binary image exceeds a preset number threshold value; and performing defect matching and type identification on the geometrical characteristic parameters, the morphological parameters and a preset defect classification rule set, and outputting detection result information. According to the method, the geometric characteristic parameters and the morphological parameters of the defects can be accurately calculated, quantitative evaluation and classification are carried out based on a clear rule set, and objective, repeatable and accurate judgment on the sizes, the shapes and the types of the defects is achieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the technical field of aluminum alloy casting inspection, and particularly to a method and system for detecting internal defects in aluminum alloy castings. Background Technology

[0002] As a key structural component in modern industry, the internal quality of aluminum alloy castings directly affects the performance, reliability, and safety of the final product. Efficient and accurate detection of internal defects in castings is a crucial quality assurance step in manufacturing. Traditional image analysis methods typically rely on single image features or fixed global thresholds for defect identification, failing to fully integrate prior knowledge of the casting structure and exhibiting insufficient adaptability to minute, ambiguous, or morphologically variable defects. These limitations lead to misjudgments or inaccurate assessments of defect geometric features, thus affecting the reliability of the final inspection results and making it difficult to meet the high standards of industrial quality inspection. Summary of the Invention

[0003] The main objective of this invention is to provide a method and system for detecting internal defects in aluminum alloy castings. This method can accurately calculate the geometric and morphological parameters of defects and perform quantitative evaluation and classification based on a clear set of rules, thereby achieving an objective, repeatable, and accurate judgment of the size, shape, and type of defects.

[0004] To achieve the above objectives, the present invention provides a method for detecting internal defects in aluminum alloy castings, comprising: Structural feature images are obtained by acquiring a sequence of projected images of aluminum alloy castings and identifying their structural features. The structural feature image is subjected to feature extraction and pixel-level segmentation to generate a defect probability map; Calculate the segmentation threshold of the defect probability map, perform binarization segmentation on the defect probability map based on the segmentation threshold, and when the number of connected regions in the obtained initial binary map exceeds a preset number threshold, perform region optimization on the initial binary map to generate a defect distribution map; The defect connected regions are identified from the defect distribution map. The geometric feature parameters and morphological parameters of each defect connected region are calculated. The geometric feature parameters and morphological parameters are matched with a preset defect classification rule set for defect matching and type identification, and the detection result information is output.

[0005] Furthermore, the acquired sequence of projected images of the aluminum alloy casting is used for structural feature recognition to obtain a structural feature image, including: Acquire a sequence of projected images of the aluminum alloy casting at multiple projection angles; The process involves sequentially traversing each projected image in the projected image sequence and extracting the pixel gradient features and local texture features of the projected image. The pixel positions in the pixel gradient features are matched point by point with the preset casting contour threshold, and the pixel positions that are higher than the casting contour threshold are marked as candidate structural points. Based on the local texture features, adjacent candidate structure points are connected to form structure outline segments; The structural contour lines are combined to form the casting structural contour, and the projected image is segmented based on the casting structural contour to obtain the structural feature image.

[0006] Further, the step of performing multi-scale feature extraction and pixel-level segmentation on the structural feature image to generate a defect probability map includes: Based on a preset feature extraction template set, neighborhood feature calculation is performed on the pixels in the structural feature image to obtain feature response values; The feature response value is compared with a preset defect feature threshold range. If the feature response value falls within the defect feature threshold range, the pixel is marked as a candidate defect pixel. The distribution density of all candidate defect pixels is statistically analyzed. When the distribution density is higher than a preset density threshold, the defect probability value of the candidate defect pixel is calculated based on the feature response value. Based on the original coordinate positions of each candidate defect pixel, all the defect probability values ​​are arranged into a defect probability map with the same size as the structural feature image.

[0007] Further, the step of calculating the segmentation threshold of the defect probability map, performing binarization segmentation on the defect probability map based on the segmentation threshold, and when the number of connected regions in the obtained initial binary map exceeds a preset threshold, performing region optimization on the initial binary map to generate a defect distribution map includes: The defect probability map is divided into multiple local sub-regions, and the pixel grayscale feature values ​​of each local sub-region are extracted. The segmentation threshold corresponding to the local sub-region is calculated based on the pixel grayscale feature values. The local sub-region is binarized using the segmentation threshold, and the pixel grayscale feature values ​​in the sub-region that are greater than or equal to the segmentation threshold are set as foreground pixels to form the initial binary image. The total number of connected regions in the initial binary graph is counted. When the total number of connected regions exceeds a preset threshold, region optimization is performed on the initial binary graph to generate the defect distribution map.

[0008] Further, the step of binarizing the local sub-region using the segmentation threshold, and setting the pixel grayscale feature values ​​in the sub-region that are greater than or equal to the segmentation threshold as foreground pixels to form the initial binary image, includes: Create a binary marker map with consistent pixel size for each of the local sub-regions; Traverse each sub-pixel in each of the local sub-regions, read the pixel grayscale feature value of the sub-pixel, and compare the pixel grayscale feature value with the segmentation threshold; If the pixel grayscale feature value is greater than or equal to the segmentation threshold, it is marked as a foreground pixel value at the corresponding position in the binarized marker map; If the pixel grayscale feature value is less than the segmentation threshold, the corresponding position in the binarized marker map is marked as the background pixel value; Based on the original coordinates of each local sub-region in the defect probability map, all binarized marker maps are stitched together to form the initial binary map.

[0009] Further, the step of counting the total number of connected regions in the initial binary graph, and when the total number of connected regions exceeds a preset threshold, performing region optimization on the initial binary graph to generate the defect distribution map, includes: Traverse and count all connected regions in the initial binary graph, and compare the total number of connected regions obtained with a preset number threshold. When the total number of connected regions exceeds a preset threshold, the region similarity between adjacent connected regions is calculated, and the morphological features of each connected region are extracted. Each of the morphological features is compared with a preset benchmark morphology. If the morphological feature does not conform to the preset benchmark morphology, the connected region is marked as a background region to be optimized. The connected regions whose similarity to the region is higher than a preset merging threshold are marked as regions to be merged. The foreground pixels in the background region to be optimized are adjusted to background pixels, and the regions to be merged are merged into a single connected region to obtain the defect distribution map.

[0010] Further, the step of identifying connected defect regions from the defect distribution map and calculating the geometric feature parameters and morphological parameters of each connected defect region includes: Traverse all distribution map pixels in the defect distribution map, mark and connect the distribution map pixels with the same pixel value to form multiple candidate defect regions; Extract the boundary coordinates of each of the defect connected regions, and calculate and integrate the defect area, defect perimeter, major axis length and minor axis length of the defect connected regions based on the boundary coordinates to form the geometric feature parameters; Based on the boundary coordinates, the minimum bounding rectangle of each defective connected region is identified. The ratio of the long side to the short side of the minimum bounding rectangle is used as the aspect ratio of the rectangle. The ratio of the area of ​​the defective connected region to the area of ​​the minimum bounding rectangle is used as the region fullness. The morphological parameters are obtained by integrating the aspect ratio of the rectangle and the fullness of the region.

[0011] Further, the step of performing defect matching and type identification by comparing the geometric feature parameters and morphological parameters with a preset defect classification rule set, and outputting detection result information, includes: Each of the geometric feature parameters is compared with a first-class threshold in the defect classification rule set to generate a first group of candidate type labels; The morphological parameters are compared with the second type threshold in the defect classification rule set to generate a second set of candidate type labels; The first group of candidate type tags and the second group of candidate type tags are logically combined to obtain a tag combination, and the tag combination is matched with the type rules of the defect classification rule set; When the combination of tags completely matches a certain type rule, the defect type corresponding to that type rule is extracted; The geometric feature parameters, morphological parameters, and defect types of all the defect-connected regions are summarized to generate detection result information.

[0012] Furthermore, it also includes determining the defect type according to the priority order defined in the defect classification rule set when the tag combination partially matches multiple type rules: Calculate the matching degree between the tag combination and the type rule that matches each part, and compare all the matching degrees with a preset matching degree threshold; If there is a type rule whose matching degree is higher than the matching degree threshold, extract the defect type corresponding to the type rule; If multiple type rules have a matching degree higher than the matching degree threshold, compare the priority values ​​of these type rules in the defect classification rule set, and extract the defect type corresponding to the type rule with the highest priority value.

[0013] The present invention also provides an internal defect detection system for aluminum alloy castings, applied to the internal defect detection method for aluminum alloy castings described in any one of the above-mentioned methods, comprising: The acquisition module is used to acquire a sequence of projected images of aluminum alloy castings for structural feature recognition, thereby obtaining structural feature images; The identification module is used to extract features and segment pixels at the structural feature image to generate a defect probability map; The calculation module is used to calculate the segmentation threshold of the defect probability map, perform binarization segmentation on the defect probability map based on the segmentation threshold, and when the number of connected regions in the obtained initial binary map exceeds a preset number threshold, perform region optimization on the initial binary map to generate a defect distribution map. The processing module is used to identify defect connected regions from the defect distribution map, calculate the geometric feature parameters and morphological parameters of each defect connected region, perform defect matching and type identification with the geometric feature parameters and morphological parameters and a preset defect classification rule set, and output detection result information.

[0014] The present invention provides a method and system for detecting internal defects in aluminum alloy castings, which has the following beneficial effects: By introducing multi-angle projection and structural feature recognition, the prior structural knowledge of castings is effectively integrated, enhancing the ability to distinguish between real defect areas and complex structural backgrounds. This significantly improves the accuracy and specificity of defect identification and reduces the risk of misjudgment. Multi-scale feature extraction and adaptive local segmentation threshold calculation overcome the limitations of traditional fixed thresholds, reducing missed detections. By accurately calculating the geometric and morphological parameters of defects and performing quantitative evaluation and classification based on a clear set of rules, objective and repeatable accurate judgments of defect size, shape, and type are achieved. A region optimization step is designed to filter and merge initial detection results based on morphology and spatial relationships, effectively filtering noise interference and optimizing the contour integrity of defect areas. The entire process, through systematic image processing and logical judgment steps, transforms defect detection from subjective experience-based judgment to objective data-driven automated analysis, improving consistency and significantly enhancing the efficiency and scalability of industrial inspection. Attached Figure Description

[0015] Figure 1 This is a flowchart of an internal defect detection method for aluminum alloy castings provided by the present invention; Figure 2 This is a structural diagram of an internal defect detection system for aluminum alloy castings provided by the present invention.

[0016] The realization of the objective, functional features and advantages of the present invention will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation

[0017] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention.

[0018] The present invention will now be further described in conjunction with the accompanying drawings and specific embodiments.

[0019] Reference Figure 1 As shown, the present invention provides a method for detecting internal defects in aluminum alloy castings, comprising: Step S1: Acquire a sequence of projected images of the aluminum alloy casting for structural feature recognition to obtain structural feature images; Step S2: Perform feature extraction and pixel-level segmentation on the structural feature image to generate a defect probability map; Step S3: Calculate the segmentation threshold of the defect probability map, and perform binarization segmentation on the defect probability map based on the segmentation threshold. When the number of connected regions in the initial binary map exceeds the preset number threshold, perform region optimization on the initial binary map to generate a defect distribution map. Step S4: Identify the connected regions of defects from the defect distribution map, calculate the geometric feature parameters and morphological parameters of each connected region of defects, match the geometric feature parameters and morphological parameters with the preset defect classification rule set to identify defects and type, and output the detection result information.

[0020] Based on the steps described above, the detailed process is as follows: Step S1: The acquisition of the projected image sequence needs to cover different orientations of the casting to ensure complete structural information is obtained. After acquisition, the projected images undergo dark field correction and gain correction to eliminate the effects of sensor noise and uneven illumination. The structural feature recognition process performs pixel-level analysis on the corrected images, extracting the gradient magnitude and direction features. These gradient features are then matched with a predefined casting structural contour template to identify pixel regions belonging to the casting's main structure.

[0021] Local texture feature analysis is used to connect adjacent structural pixels to form continuous structural contour boundaries. Finally, based on the identified structural contours, the image is segmented into the casting structure region and the background region, generating a structural feature image that highlights the geometric shape of the casting.

[0022] Step S2: Using observation windows of different sizes, the algorithm traverses each pixel position in the image, calculating the gray-level statistical features and texture distribution features within the neighborhood of each pixel. The extracted feature values ​​are matched against the standard feature range in a pre-defined defect feature rule base, calculating the matching degree of each pixel as a defect feature. Pixels with matching degrees higher than a pre-set threshold are marked as candidate defect pixels, and the distribution density of candidate defect pixels across the entire image is calculated. When the distribution density meets the requirements, multiple feature matching degrees for each pixel are weighted and fused to calculate the probability value of that pixel being a defect. The probability values ​​of all pixels are arranged according to their spatial coordinates to form a defect probability map with the same size as the original image. This probability map represents the likelihood of each pixel having a defect in gray-level value form.

[0023] Step S3: The segmentation threshold is calculated using a local adaptive strategy. The defect probability map is divided into multiple sub-regions of uniform size. The statistical distribution of pixel probability values, such as the mean and standard deviation, is calculated for each sub-region, and an independent segmentation threshold is determined for each sub-region based on this distribution. Using the segmentation thresholds corresponding to each sub-region, the defect probability map is partitioned and binarized. Pixels with probability values ​​greater than or equal to the local threshold are set as foreground, and pixels with probability values ​​less than the threshold are set as background, thus generating an initial binary map.

[0024] The initial binary image is labeled with connected components, and the total number of all foreground connected components is counted. This total is compared with a preset threshold. If the threshold is not exceeded, the initial binary image is directly output as the defect distribution map; if the threshold is exceeded, a region optimization process is triggered. Region optimization includes morphological opening operations to filter out noise points with excessively small areas, and calculating the feature similarity between adjacent connected components. Regions with similarity higher than a merging threshold are merged. The output is a defect distribution map that accurately reflects the defect location and has better regional coherence.

[0025] Step S4: Connectivity component analysis is performed on the defect distribution map to identify and mark all independent defect connected regions, excluding invalid regions with too small an area to form a valid defect set. For each defect connected region in the set, its boundary pixel coordinate sequence is extracted. Based on these boundary coordinates, the basic geometric feature parameters of the defect are calculated, including the area represented by the total number of pixels in the defect region, the perimeter represented by the total length of the boundary pixels, and the lengths of the long and short sides of the minimum bounding rectangle of the defect region.

[0026] Based on geometric parameters, morphological parameters are derived. The main calculations are the aspect ratio of the minimum bounding rectangle of the defect region to describe the elongation of the shape, and the ratio of the area of ​​the defect region to the area of ​​its minimum bounding rectangle to describe the fullness of the region.

[0027] The geometric and morphological parameters of each defect are matched against a pre-defined set of defect classification rules. This rule set defines the parameter threshold ranges and logical conditions corresponding to different defect types. By comparing the defect parameters with each rule condition, the defect type is identified. For fuzzy defects that can match multiple types, a decision is made based on the preset priority in the rule set. All defect types, location coordinates, size information, and feature parameters are summarized, and a structured inspection result report is generated according to a preset format, completing the entire inspection process.

[0028] This invention provides a method for detecting internal defects in aluminum alloy castings. By introducing multi-angle projection and structural feature recognition, it effectively integrates prior structural knowledge of the casting, enhancing the ability to distinguish between real defect areas and complex structural backgrounds. This significantly improves the accuracy and specificity of defect identification and reduces the risk of misjudgment. Multi-scale feature extraction and adaptive local segmentation threshold calculation overcome the limitations of traditional fixed thresholds, reducing missed detections. By accurately calculating the geometric and morphological parameters of defects and performing quantitative evaluation and classification based on a clear set of rules, objective and repeatable accurate judgments of defect size, shape, and type are achieved. A region optimization step is designed to filter and merge initial detection results based on morphology and spatial relationships, effectively filtering noise interference and optimizing the contour integrity of defect areas. The entire process, through systematic image processing and logical judgment steps, transforms defect detection from subjective experience-based judgment to objective data-driven automated analysis, improving consistency and significantly enhancing the efficiency and scalability of industrial inspection.

[0029] 2. The method for detecting internal defects in aluminum alloy castings according to claim 1, characterized in that, in one embodiment, a sequence of projected images of the aluminum alloy casting is acquired for structural feature recognition to obtain a structural feature image, including: [1] The projected image sequence is acquired using a multi-angle X-ray imaging device. The aluminum alloy casting is precisely fixed on a rotating platform and rotated in increments along a specific axis, stopping at each preset projection angle and triggering image acquisition. The number and interval of projection angles are determined based on the complexity of the casting structure and the required inspection accuracy, covering a uniform distribution within a 180-degree range.

[0030] Each acquired projection image is a two-dimensional distribution of the attenuation intensity of X-rays after penetrating the casting using a multi-angle X-ray imaging device. This distribution contains a superposition of three-dimensional information about the casting's internal structure in a specific direction. Strict control of radiation dose and exposure time is required during acquisition to ensure sufficient signal-to-noise ratio and contrast, while avoiding saturation or underexposure. All projection images undergo standard image preprocessing operations, including dark field correction to eliminate detector dark current noise and flat field correction to compensate for X-ray beam inhomogeneity and detector pixel response differences, resulting in a sequence of projection images.

[0031] Each image in the sequence is processed sequentially. For each projected image, pixel gradient features are calculated by convolving the image using a differential operator, which significantly highlights regions in the image where grayscale values ​​change drastically; these regions often correspond to the edges or contours of objects. The gradient magnitude and direction at each pixel location are further obtained by calculating the gradient components in the horizontal and vertical directions.

[0032] The gradient magnitude characterizes the degree of change in the image at that point, while the gradient direction indicates the direction of the edge normal. Local texture feature extraction is accomplished by calculating a set of statistics within a specific neighborhood window of a pixel. These statistics describe the distribution pattern of pixel grayscale values ​​within the window, such as their uniformity, contrast, and regularity, thereby quantifying the microscopic texture structure of the region.

[0033] The extraction of pixel gradient features and local texture features is performed in parallel, and they describe the essential properties of an image from different perspectives. Pixel gradient features are mainly sensitive to macroscopic edge contour information, while local texture features focus more on the microstructure within a region, assigning a set of multidimensional feature vectors to each pixel or local region in the image.

[0034] The preset casting contour threshold is a gradient magnitude threshold determined based on prior knowledge or analysis of a large number of samples. This threshold is used to distinguish obvious structural edges from flat areas or weak gradient responses caused by noise. The matching process is carried out in a pixel-by-pixel scanning manner, where the gradient magnitude at each pixel location is extracted and compared with this fixed threshold.

[0035] When the gradient magnitude of a pixel is significantly greater than a preset threshold, the pixel is determined to be located on a prominent image edge, and the structural boundary of the casting is composed of such strong edge pixels. The coordinates of these threshold-filtered pixels are recorded and marked as candidate structural points. This operation is essentially a preliminary binarization decision based on single-point features, aiming to quickly filter out a small number of key points that may belong to the target contour from a massive amount of image pixels, significantly reducing the amount of data in subsequent processing. The output of this step is a set of points composed of two-dimensional coordinates, sparsely distributed along the edge contour of the image.

[0036] After obtaining the candidate structural point set, the local texture features of the surrounding area of ​​each candidate point are analyzed. These texture features describe the gray-level distribution pattern within a small area of ​​the image, and the texture features of continuous structural regions also exhibit a slow change characteristic. The connection operation is first performed between spatially adjacent candidate points, calculating the texture feature similarity of the local regions of each pair of adjacent points. If the similarity is higher than a preset continuity threshold, the two points are determined to belong to the same physical contour, and a connection is established between them. This process is usually combined with a contour tracking algorithm, starting from a seed point, iteratively finding and connecting the next candidate point most likely to belong to the same contour based on texture similarity and spatial proximity, thus growing a continuous path. For contour gaps caused by noise or inappropriate thresholds, interpolation or predictive connection can be performed based on the direction of texture features. Finally, multiple continuous curves of a certain length formed by the connection operation of candidate points are constructed, and each curve is a structural contour segment.

[0037] All obtained structural contour segments are globally optimized and integrated. The relative positions and directions between the endpoints of each segment are examined, and segments with collinearity and adjacent endpoints are connected and merged to form longer, smoother contour segments. Prior geometric knowledge of the casting structure (such as the closure and continuity of the contour) is used to constrain and guide the segment combinations, forming one or more complete, closed, or physically meaningful contour polygons. This set of polygons is the identified casting structure contour. The original projected image is segmented using this structural contour as the boundary. The image region inside the contour polygon is marked as the casting structure region, while the region outside the contour is marked as the background region. To highlight the casting structure, the pixel grayscale of the structural region remains unchanged, while the pixel grayscale of the background region is uniformly set to a specific value (such as 0 or 255), thereby generating an image where the background is suppressed and only the structural features of the casting geometry are highlighted.

[0038] This embodiment extracts pixel gradients and local texture features from each image sequentially, comprehensively describing the essential attributes of the image from different dimensions and accurately identifying structural contour information. By matching gradient features with preset thresholds point by point and marking candidate points, it achieves accurate localization of potential structural edges from massive pixels, significantly improving processing efficiency. Contour segments are generated by connecting adjacent candidate points based on the continuity of local texture features, effectively overcoming the contour breakage problem caused by noise or inappropriate thresholds, ensuring the continuity and integrity of the contour.

[0039] In one embodiment 3, the method for detecting internal defects in aluminum alloy castings according to claim 1 is characterized in that multi-scale feature extraction and pixel-level segmentation are performed on the structural feature image to generate a defect probability map, including: [2] The preset feature extraction template set is a collection of digital templates built upon prior knowledge. Each template is designed to capture potential defect features at a specific scale or morphology, such as the circular pattern of micropores or the banded pattern of linear cracks. The feature calculation process traverses each pixel in the structural feature image using a sliding window, extracting a neighborhood block centered on the current pixel with the same size as the template. A similarity metric is then calculated between this neighborhood block and each feature extraction template; this metric reflects the degree of matching between the local image region and the pattern defined by the template.

[0040] This process is repeated for each template, generating a set of multi-dimensional feature response values ​​for each pixel, with each dimension corresponding to a matching result for a specific template. This set of feature response values ​​constitutes a numerical description of the neighborhood features of that pixel, and the completeness and discriminative power of these features directly affect the accuracy of subsequent defect detection. This transforms the image data into a more discriminative feature space representation. The design of the template set must consider the feature diversity of different defect types to ensure comprehensive detection.

[0041] The preset defect feature threshold range is one or more pre-defined numerical intervals for each feature extraction template. These intervals are determined by analyzing the feature response distribution of known defect samples to define the difference in response values ​​between normal structural features and abnormal defect features. The comparison process is performed on each pixel and its corresponding feature response value generated by each template.

[0042] Each response value is validated against its corresponding threshold range. If the value falls within the preset defect feature threshold range, it indicates that the neighborhood features of the current pixel show sufficient similarity to the defect pattern represented by the template. This determination process can be based on a logical OR relationship; that is, if any one or more of the multiple feature response values ​​of a pixel fall within its corresponding threshold range, a marking operation is triggered. Pixels that meet the conditions are marked as candidate defect pixels, and their spatial coordinates are recorded. This operation realizes the transformation from continuous feature values ​​to binary decision (candidate or non-candidate), significantly reducing the amount of data for subsequent processing and initially focusing on regions containing defects in the image.

[0043] After obtaining the candidate defect pixel set, the distribution density of this set across the entire structural feature image is calculated. Distribution density is typically measured by the number of candidate defect pixels per unit area, or more precisely, by spatial statistical methods such as kernel density estimation. The calculated distribution density value is compared with a preset density threshold, which distinguishes between sparse pseudo-defect points caused by random noise and valid candidate point sets formed by clusters of real defect regions.

[0044] If the distribution density is lower than or equal to the threshold, it indicates that there are no significantly clustered defect features in the current image, which may originate from background noise or slight interference. In this case, no further probability calculation is required. Conversely, if the distribution density is higher than the preset threshold, it indicates that there are one or more clustered regions of candidate defect pixels in the image. These regions have a high probability of containing real defects, thus triggering the calculation of the defect probability value for each candidate defect pixel.

[0045] The probability value is calculated based on the multidimensional feature response values ​​of the pixel obtained in the previous step. This is typically achieved using weighted fusion or a probabilistic model-based transformation method, mapping multiple feature response values ​​to a scalar probability value between 0 and 1. This probability value represents the confidence level that the pixel belongs to a defect.

[0046] For each pixel marked as a candidate defect, its two-dimensional spatial coordinates and the calculated defect probability value constitute a triplet. The process of generating the defect probability map involves reconstructing a grayscale image with the exact same size and spatial reference as the original structural feature image based on these triplet data. Specifically, this involves creating a blank image with the same size as the structural feature image and all pixels initialized to 0.

[0047] The algorithm iterates through the triplet data of all candidate defect pixels, assigning the pixel value in the blank image corresponding to the original coordinates of each candidate defect pixel the calculated defect probability value. For non-candidate defect pixels, their corresponding pixel values ​​in the blank image remain 0. This results in a defect probability map where the grayscale value of each pixel intuitively reflects the probability of a defect at that location; higher values ​​indicate a greater probability.

[0048] This embodiment performs neighborhood feature calculations on pixels in a structural feature image based on a preset feature extraction template set, enabling comprehensive capture of potential defect features at different scales. This provides multi-dimensional criteria for defect identification, improving the comprehensiveness and adaptability of the detection. By comparing the feature response values ​​with a preset defect feature threshold range and marking candidate defect pixels, preliminary screening of image data is achieved, effectively focusing on suspicious areas and reducing the risk of misjudgment caused by background interference and random noise.

[0049] By statistically analyzing the distribution density of candidate defect pixels and triggering defect probability calculation based on a density threshold, a spatial clustering criterion is introduced. This avoids ineffective processing of isolated noise points and enhances the robustness and rationality of defect discrimination. By arranging the defect probability values ​​into a complete probability map based on the original coordinate positions of the candidate defect pixels, a continuous probability distribution representation is generated. This preserves rich confidence information for subsequent adaptive threshold segmentation, laying the foundation for high-precision defect localization and segmentation.

[0050] In one embodiment 4, the method for detecting internal defects in aluminum alloy castings according to claim 1 is characterized in that: a segmentation threshold of the defect probability map is calculated, the defect probability map is binarized based on the segmentation threshold, and when the number of connected regions in the obtained initial binary map exceeds a preset number threshold, the initial binary map is optimized to generate a defect distribution map, including: [3] The local sub-regions are divided using a regular grid method, uniformly dividing the defect probability map into several rectangular blocks of the same size. Each local sub-region is treated as an independent processing unit, and the defect probability values ​​of the pixels within it are considered to have relatively consistent statistical characteristics. For each sub-region, the grayscale feature values ​​of all pixels within it are extracted, i.e., its defect probability values. Statistical analysis is performed on these probability value sets to calculate statistics that characterize the overall distribution characteristics of the region, such as the mean, median, standard deviation, or specific quantile values ​​of the probability values.

[0051] Based on the calculated statistics, a pre-defined threshold calculation rule is applied to determine an independent segmentation threshold for the local sub-region. This threshold calculation rule may involve linear or non-linear combinations of the statistics, with the core objective of adapting the threshold to the gray-level distribution center and dispersion of the local region. This process generates a customized segmentation threshold for each local sub-region, which better reflects the actual situation of the local region, laying the foundation for subsequent accurate binarization.

[0052] The process is performed on a local sub-region basis. For the currently processed sub-region, each pixel within it is traversed, and its grayscale feature value, i.e., its defect probability value, is read. This probability value is compared with the segmentation threshold assigned to that sub-region. If the defect probability value of a pixel is greater than or equal to the local segmentation threshold, the pixel is considered to be more likely to belong to a defective region, and its corresponding pixel position in the output image is marked as a foreground pixel. If the defect probability value of a pixel is less than the local segmentation threshold, the pixel is considered to be more likely to belong to the background or normal structure, and it is marked as a background pixel.

[0053] Foreground and background pixels are typically represented using significantly different numerical values, such as 1 and 0 respectively. After scanning and binarizing all local sub-regions one by one, the binarized results of all sub-regions are stitched together according to their original spatial relationships to form a complete initial binary image. This initial binary image clearly distinguishes the foreground and background, initially revealing the distribution of potential defects.

[0054] Connectivity component labeling analysis is performed on the initial binary image obtained from the preceding steps to identify and count all independent connected regions formed by interconnected foreground pixels. Each connected region represents a preliminarily detected potential defect unit. The total number of connected regions is compared with a preset threshold, which is set based on prior knowledge of defect granularity and image complexity in practical applications. If the total number of connected regions does not exceed the preset threshold, it indicates that the initial segmentation result is relatively ideal and the number of regions is within an acceptable range. In this case, the initial binary image is directly output as the final defect distribution map.

[0055] If the total number of connected regions exceeds a preset threshold, it indicates that the initial segmentation result may be over-segmented. This means that a single real defect may be segmented into multiple fragmented small regions, or the image may contain spurious defects caused by a large amount of noise. In this case, region optimization should be triggered. Region optimization typically includes morphological post-processing, such as using morphological opening operations to eliminate isolated foreground regions that are too small, often caused by noise or irrelevant structural details.

[0056] Connected regions that are adjacent in location and have similar features are merged and analyzed. The distance or feature similarity between regions is calculated, and if the merging conditions are met, they are merged into a continuous defect region. After this series of optimization operations, a new binary image is generated with the number of connected regions effectively controlled and the region shapes more complete, which is the final defect distribution map. This map more accurately reflects the distribution of real defects, providing a higher-quality foundation for subsequent feature extraction and classification.

[0057] This embodiment achieves adaptive processing for uneven image grayscale distribution by dividing the defect probability map into multiple local sub-regions and calculating their respective segmentation thresholds. This effectively overcomes the limitations of a single global threshold on complex probability maps and improves segmentation accuracy. By employing local adaptive thresholding to independently binarize each sub-region, the method ensures that different regions achieve the most suitable segmentation results, enhancing its adaptability to defects with varying contrast. By statistically analyzing the total number of connected regions and comparing it with a preset threshold, a quality judgment mechanism based on the number of regions is introduced, providing an objective decision-making basis for subsequent optimization. By performing region optimization operations on the initial binary map under threshold conditions, fragmented regions caused by over-segmentation are effectively eliminated, and adjacent regions that should belong to the same defect are merged, making the final defect distribution map more accurately reflect the actual shape and distribution of defects.

[0058] In one embodiment 5, the method for detecting internal defects in aluminum alloy castings according to claim 4 is characterized in that, by performing binarization processing on local sub-regions through segmentation threshold, the pixel grayscale feature values ​​in the sub-regions that are greater than or equal to the segmentation threshold are set as foreground pixels to form an initial binary image, including: [4] After dividing the defect probability map into local sub-regions, a corresponding binarized marker map needs to be created for each independent local sub-region. The pixel size of this marker map must be completely consistent with its corresponding local sub-region to ensure that each pixel position corresponds one-to-one. The creation process essentially initializes a two-dimensional data matrix of the same size as the sub-region. The initial values ​​of all elements in this matrix are usually set to a uniform background marker value. This binarized marker map serves as a temporary buffer to temporarily store the binarization result of each pixel in the current sub-region after thresholding.

[0059] Using independent labeled maps for processing allows for parallel or sequential independent computation on each local sub-region, avoiding mutual interference between different sub-regions during processing. It also provides structured intermediate data for subsequent stitching and assembly steps. This preprocessing method clarifies the data flow, laying the foundation for subsequent pixel-by-pixel judgment operations.

[0060] The processing proceeds sequentially, region by region. For the currently processing region, every pixel location within it, known as a sub-pixel, is systematically accessed. At each sub-pixel location, a read operation is performed to obtain the pixel's grayscale feature value from the corresponding position in the defect probability map. This value represents an estimate of the probability of a defect existing at that location. This probability value is then compared with an adaptive segmentation threshold pre-calculated for that region. This comparison determines whether the pixel should be classified as foreground (potential defect) or background (normal area). The entire traversal process ensures that all pixels within the region are processed without omission, thus guaranteeing the integrity of subsequent binarization labeling.

[0061] This marking operation is performed when the result of the previous comparison operation shows that the grayscale feature value of the current sub-pixel is greater than or equal to the segmentation threshold calculated for its local sub-region. This criterion means that the pixel exhibits a sufficiently strong defect probability feature, meeting the criteria for being identified as a potential defect area. The marking action involves writing a specific value representing the foreground at the corresponding coordinate position of the binary marker map pre-created for the sub-region. This value representing the foreground pixel is usually chosen to be a value that differs significantly from the background value; for example, when the background is marked as 0, the foreground can be marked as 1. This operation essentially transforms continuous probability estimation into discrete category assignment, formally classifying pixels that meet the conditions as target objects for further analysis.

[0062] This marking operation is performed when the result of the previous comparison operation shows that the grayscale feature value of the current sub-pixel is less than the segmentation threshold calculated for its local sub-region. This criterion means that the pixel exhibits a weak defect probability feature and does not meet the standard for being identified as a potential defect area, therefore it is classified as background or normal structure area. The marking action involves writing a specific value representing the background, usually 0, at the corresponding coordinate position of the binary marker map corresponding to the sub-region. This operation excludes pixels that do not meet the threshold from the target to be detected, effectively filtering out non-target areas and noise interference in the image, thereby focusing on high-probability defect areas. This step, together with the foreground marking step, completes the binary classification of each pixel within the sub-region.

[0063] This labeling operation is performed when the result of the previous comparison operation shows that the grayscale feature value of the current sub-pixel is less than the segmentation threshold calculated for its local sub-region. This criterion means that the pixel exhibits a weak defect probability feature and does not meet the standard for being identified as a potential defect area, therefore it is classified as background or normal structure area. The labeling action involves writing a specific value representing the background, usually 0, at the corresponding coordinate position of the binary label map corresponding to the sub-region. This operation excludes pixels that do not meet the threshold from the target to be detected, effectively filtering out non-target areas and noise interference in the image, thereby focusing on high-probability defect areas. This step, together with the foreground labeling step, completes the binary classification of each pixel within the sub-region.

[0064] After the aforementioned steps complete the traversal and independent binarization of all local sub-regions, multiple binarized marker maps are generated, equal in number to the number of sub-regions. Each marker map corresponds to a specific block on the original defect probability map. The stitching and combination process requires determining the position of each local sub-region based on its global spatial coordinates in the original defect probability map. Specifically, each binarized marker map is placed at its corresponding position in a new blank image with the exact same size as the original defect probability map. This corresponding position is uniquely determined by the coordinates of the top-left vertex of the local sub-region in the original image. Once all the binarized marker maps of the local sub-regions have been placed according to their original coordinates, these local results collectively fill the entire blank image, forming a complete initial binary map with the same spatial resolution as the original probability map. This map integrates the results of all local adaptive thresholding segmentation, achieving a global transformation from a continuous probability map to a binary segmentation map.

[0065] This embodiment achieves parallel or sequential independent computation on different image blocks by creating independent binary marker maps for each local sub-region, avoiding mutual interference during processing and improving processing efficiency and modularity. By traversing each sub-pixel and performing threshold comparisons, it ensures that each image point receives independent binarization judgment, eliminating the local region missegmentation problem that may be caused by a globally uniform threshold and improving segmentation accuracy. By marking pixels that meet the threshold conditions as foreground and those that do not as background, accurate binary classification of the defect probability map is achieved, clearly separating potential defect areas from normal background areas. By stitching the marker maps into a complete initial binary map based on the original coordinates of each sub-region, the spatial consistency between the final result and the original image is guaranteed, providing a structurally accurate binary data foundation for subsequent analysis.

[0066] In one embodiment 6, the method for detecting internal defects in aluminum alloy castings according to claim 4 is characterized in that, the total number of connected regions in the initial binary graph is counted, and when the total number of connected regions exceeds a preset threshold, region optimization is performed on the initial binary graph to generate a defect distribution map, including: [5] The process of traversing and counting connected regions is accomplished using a connected component labeling algorithm. Each pixel in the initial binary image is scanned, and by examining its connectivity with neighboring pixels (typically using 4-connectivity or 8-connectivity rules), interconnected foreground pixels are grouped into a single, independent connected region, and each region is assigned a unique identifier. After completing the full image scan and labeling, the number of distinct identifiers is counted, yielding the total number of connected regions. This total number reflects the scale of independent potential defect targets in the current binary segmentation result.

[0067] The total number of connected components is compared with a preset threshold. This preset threshold is an empirical value set based on prior knowledge of the number of real defects and the number of false defects caused by noise in a normal casting image. The purpose of the comparison operation is to determine whether the current segmentation result is likely to be oversegmented, that is, whether the number of connected components is excessively high. This usually means that there may be a large number of small false defects caused by noise or texture interference in the image, or that a single real defect has been inappropriately segmented into multiple fragments.

[0068] This step is triggered when the comparison results of the previous step confirm that the total number of connected regions exceeds a preset threshold. Region similarity is calculated for spatially adjacent pairs of connected regions. First, it's necessary to identify which connected regions are adjacent to each other, determined by analyzing the minimum distance between the boundary pixels of each region or checking whether their outer envelope rectangles intersect. For each pair of adjacent regions, a similarity metric is calculated between them. This metric is based on various features, such as comparing the grayscale statistical features of the two regions (e.g., average grayscale value), texture features, or more simply, their spatial distance and relative size. Extracting the morphological features of each connected region involves analyzing each individual connected region.

[0069] The extracted morphological features aim to describe the geometric characteristics of the regions, typically including but not limited to: the region's area (total number of pixels), the region's perimeter, the aspect ratio of the region's minimum bounding rectangle, the region's roundness (measuring how closely the region's shape approximates a circle), and the region's compactness. These features quantify the shape, size, and contour complexity of each region, providing objective and quantifiable criteria for determining whether a region represents a genuine macroscopic defect or noise fragments that need to be filtered out. Region similarity and morphological features together form the information basis for subsequent optimization decisions.

[0070] The preset baseline shape is a judgment criterion established through the analysis of the morphological characteristics of a large number of known real defects and typical noise areas. It usually exists in the form of threshold ranges for key morphological parameters. For example, the baseline shape may specify the minimum area threshold, the maximum aspect ratio range, or the minimum level of roundness that a qualified defect area should possess. The comparison process is performed on each independent connected region, comparing the specific morphological feature values ​​extracted therefrom with the preset baseline shape threshold range one by one.

[0071] Situations where morphological features do not conform to the preset baseline shape mainly include: the area of ​​the region is less than the minimum area threshold, indicating that the region may be a noise point rather than a meaningful defect; the aspect ratio of the region exceeds the reasonable range, suggesting that it may be an unnatural linear artifact; or the roundness of the region is too low, indicating that the shape is too irregular and may be a non-defect structure. When one or more key morphological feature values ​​of a connected region fall outside the preset acceptable range, the morphological features of the region are determined to not conform to the preset baseline shape, and it is marked as a background region to be optimized. This marking means that the region will be considered for removal from the foreground in subsequent processing.

[0072] Region similarity is a quantitative metric calculated in previous steps for each pair of spatially adjacent connected regions, used to measure the similarity of two regions in terms of features. A preset merging threshold is a key threshold used to determine whether the similarity between two regions is high enough to support merging them as the same entity. The comparison process is performed on all pairs of adjacent connected regions, comparing the calculated similarity value of each pair with the preset merging threshold. If the similarity value of a pair of adjacent connected regions is higher than the preset merging threshold, it indicates that the two regions are highly similar in features, and they are very likely to belong to the same continuous defective entity, but were improperly separated in the previous segmentation process. This pair of regions is then marked as the regions to be merged.

[0073] For connected regions marked as "background regions to be optimized" in the previous steps, a pixel reclassification operation is performed. This involves traversing all foreground pixels within these regions and changing their pixel values ​​from those representing the foreground to those representing the background. Essentially, this operation removes these regions deemed invalid or noisy from the binary image, preventing them from being considered defect candidates. For the marked "regions to be merged," a region merging operation is performed.

[0074] The merging process typically involves fusing the bounding contours of all connected regions belonging to the same set to be merged, forming a new, larger, continuous region, and then uniformly setting all pixels within this merged region to foreground values. After completing the removal of all background regions to be optimized and the merging of regions to be merged, a new binary image is generated. This optimized image is the final defect distribution map. This image effectively eliminates most of the pseudo-defect fragments caused by noise, merges over-segmented defect parts, and makes the remaining connected regions in the image more accurately reflect the number, location, and complete shape of the real defects.

[0075] This embodiment automatically identifies potential oversegmentation or noise interference by traversing and counting the total number of connected regions in the initial binary graph and comparing it with a preset threshold. This provides an objective basis for subsequent optimization and avoids the subjectivity of manual intervention. By calculating the region similarity between adjacent connected regions and extracting the morphological features of each region, a quantitative assessment of the correlation between regions and individual shape characteristics is achieved. By comparing the morphological features with a preset benchmark morphology and marking regions that do not meet the requirements, invalid connected regions generated by noise or irrelevant structures are effectively filtered out, thereby reducing the false detection rate. By marking connected regions with a similarity higher than the merging threshold as objects to be merged, it is ensured that the same defect parts that have been discrete due to oversegmentation can be reintegrated, maintaining the integrity of the defect morphology. By adjusting the marked regions to be optimized to background pixels and merging the regions to be merged, a defect distribution map with a reasonable number of connected regions and clear defect outlines is finally generated, significantly improving the accuracy and efficiency of subsequent feature extraction and classification.

[0076] In one embodiment 7, the method for detecting internal defects in aluminum alloy castings according to claim 1, characterized in that, the method involves identifying connected defect regions from a defect distribution map and calculating the geometric feature parameters and morphological parameters of each connected defect region, including: [6] The binarized defect distribution map is transformed into a set of discrete defect units that can be analyzed independently. The traversal process uses a connected component labeling algorithm to systematically scan each pixel position in the defect distribution map. The algorithm starts scanning pixel by pixel from the top left corner of the image. When an unvisited foreground pixel is encountered, it is used as a seed point to initiate the region growing process. By checking the connection state between the current pixel and its neighboring pixels (usually using 4-connectivity or 8-connectivity rules), all pixels that are connected and have the same foreground pixel value are grouped into the same connected region, and a unique identifier is assigned to this region. This process is recursively or iteratively performed until all pixels in the connected region have been visited and labeled. After labeling a region, the scanning continues until the next unlabeled foreground pixel is found, and the above process is repeated until the entire image has been traversed. All foreground pixels are grouped into different connected regions, each representing an independent candidate defect region.

[0077] Based on the successful identification and labeling of all candidate defect regions, a precise geometric quantization description is performed for each region. Boundary coordinate extraction is achieved through a boundary tracking algorithm. This algorithm starts from a primary pixel on the region's edge and sequentially searches for and records the coordinates of consecutive pixels forming the region's outer boundary in a predetermined search direction (e.g., clockwise or counterclockwise), forming a closed boundary coordinate sequence. The geometric parameters of the region are calculated based on this boundary coordinate sequence. The defect area is obtained by counting the total number of pixels contained within this closed boundary, directly reflecting the size of the defect.

[0078] The perimeter of the defect is calculated by summing the Euclidean distances between adjacent pixels on the boundary, representing the complexity of the defect profile. The lengths of the major and minor axes are typically determined based on principal component analysis of the region or by finding the smallest bounding rectangle (or ellipse) that completely encloses the defect region. The major axis corresponds to the maximum size of the region in its main extension direction, while the minor axis corresponds to the maximum size in the direction perpendicular to it; these two parameters together describe the basic shape and orientation of the defect. Integrating these four parameters—defect area, defect perimeter, major axis length, and minor axis length—constitutes a set of feature parameters describing the basic geometric properties of the connected region of the defect.

[0079] The identification of the minimum bounding rectangle is a calculation process based on the set of boundary coordinates of the connected region of the defect. This rectangle must be determined to have the minimum area while completely enclosing all boundary points of the defect region. The calculation process typically involves a rotating caliper algorithm or similar methods, achieved by finding the rectangle with the minimum area enclosing the defect region. The orientation of this rectangle reflects the main extension direction of the defect on the image plane.

[0080] After obtaining the minimum bounding rectangle, its basic geometric properties are extracted. The aspect ratio of the rectangle is calculated by measuring the pixel length of the longer side and the pixel length of the shorter side of the rectangle and calculating the ratio between them. This parameter is always greater than or equal to 1; the larger the value, the narrower and longer the defect shape; the closer the value is to 1, the closer the shape is to a square. The region fullness is calculated by dividing the area of ​​the defect region itself (measured in total pixels) by the area of ​​the minimum bounding rectangle (measured in total pixels).

[0081] This parameter characterizes the degree to which the defect region fills its circumscribed rectangle, with a value ranging from 0 to 1. A higher value indicates that the defect shape fills its circumscribed rectangle more fully and tightly; a lower value indicates that the defect shape is sparser and more dispersed, or that there are more depressions and pores. These two parameters describe the overall shape characteristics of the defect from different perspectives.

[0082] The integration operation is not a simple numerical superposition, but rather uses the aspect ratio of the rectangle and the region fullness as a pair of complementary feature parameters to form a set of morphological parameters. The aspect ratio of the rectangle mainly describes the overall elongation and directional characteristics of the defect shape, and has a good ability to distinguish defects such as linear cracks or strip-shaped shrinkage cavities. The region fullness focuses on describing the density of the internal structure of the defect and the complexity of its contour, and can effectively distinguish defects with different internal morphologies such as dense pores and dispersed shrinkage cavities.

[0083] Integrating these two parameters into a single parameter pair allows for a more comprehensive characterization of the defect's morphological properties. This integration enables the morphological parameters to simultaneously reflect both the defect's macroscopic contour features and internal filling characteristics, providing richer shape information for subsequent defect classification. The resulting morphological parameters, together with the previously calculated geometric feature parameters, constitute a complete digital feature description of each defect's connected region.

[0084] This embodiment accurately identifies all independent candidate defects by traversing all pixels in the defect distribution map and marking connected regions, ensuring comprehensive defect identification. By extracting boundary coordinates and calculating geometric feature parameters such as defect area, perimeter, major axis, and minor axis length, a precise quantitative description of the basic size and shape characteristics of the defect is achieved. By determining the minimum bounding rectangle based on the boundary coordinates and calculating the aspect ratio and region fullness, the overall elongation and internal density of the defect can be effectively characterized, enhancing the distinguishability of the morphological description. By integrating the rectangle's aspect ratio and region fullness to form morphological parameters, a complementary morphological feature description system is constructed, comprehensively characterizing the morphological properties of the defect from both macroscopic contour and internal filling aspects.

[0085] In one embodiment 8, the method for detecting internal defects in aluminum alloy castings according to claim 1 is characterized in that geometric feature parameters and morphological parameters are matched with a preset defect classification rule set for defect matching and type identification, and the detection result information is output, including: [7] Defect types are initially screened and classified based on geometric dimensional characteristics. Geometric feature parameters include quantitative indicators characterizing the basic size and shape of defects, such as defect area, defect perimeter, major axis length, and minor axis length. The first type of thresholds predefined in the defect classification rule set are specific numerical ranges or critical values ​​set for these geometric feature parameters. These thresholds are classification criteria determined through statistical analysis of the geometric characteristics of a large number of known defect types.

[0086] The comparison process is performed independently for each connected region of the defect to be classified, comparing the actual geometric feature parameter values ​​of that region with the geometric feature threshold ranges set for each defect type in the rule set. When a specific geometric feature parameter of a defect falls within the threshold range corresponding to a certain type of defect, that type of defect is recorded as a possible classification result in the candidate type label set for that defect. This comparison process generates a preliminary set of classification suggestions based on geometric features for each defect, namely the first set of candidate type labels.

[0087] Defect types are further screened and verified based on morphological features. Morphological parameters include quantitative indicators describing the overall shape and internal structural characteristics of defects, such as the aspect ratio of a rectangle and the fullness of the region. A second set of predefined thresholds in the defect classification rule set are specific discrimination criteria set for these morphological parameters, reflecting the typical morphological characteristics of different defect categories. The comparison process is performed on the connected regions of the same defect, independently verifying the actual morphological parameter values ​​of that region against the morphological threshold conditions set for each defect type in the rule set.

[0088] When the morphological features of a defect meet the morphological threshold requirements of a certain type of defect, the possible classification of that type of defect as supported by morphological features is recorded in the candidate type label set for that defect. This comparison process generates a supplementary classification suggestion set based on morphological features for each defect, namely the second set of candidate type labels. This label set verifies the degree of matching between the defect and various standard defect types from a morphological perspective, forming a complementary judgment basis with the first set of labels.

[0089] Logical combination operations perform correlation analysis between the first and second sets of candidate type labels corresponding to the same defect. Combination methods typically employ set operations or logical AND operations, retaining only defect types that appear in both sets of candidate labels. This cross-validation mechanism ensures that the final candidate types must simultaneously meet the basic requirements of geometric and morphological features. The label combination generated after logical combination represents the most likely set of defect types based on multi-feature fusion. This label combination is then compared with predefined type rules in the defect classification rule set. The type rules specify the set of geometric and morphological feature conditions that each defect type must simultaneously satisfy. The matching process essentially checks whether the current label combination fully meets the feature label requirements of a certain defect type.

[0090] A perfect match requires that the current defect's label combination contain all the feature labels required by the target defect type rule, and that there are no conflicting label entries. When a type rule is found to be a perfect match with the current label combination, a type determination operation is triggered. This operation extracts the standard defect type identifier corresponding to the matching rule from the rule set, such as predefined classification results like "porosity," "shrinkage," or "crack." This type identifier is then formally assigned to the currently detected defect region as its final classification conclusion. The perfect match mechanism ensures that the classification results have clear technical basis, avoiding ambiguous judgments.

[0091] The process involves traversing all identified and classified defect-connected regions, and structurally integrating their spatial location information, geometric feature parameters, morphological parameters, and the final defect type. The generated results are typically organized in a table or tree structure, with each defect entry containing complete data such as its relative position coordinates within the entire casting, dimensional parameters, morphological features, and type determination. This structured dataset constitutes the final inspection report, providing comprehensive quantitative evidence for quality assessment and subsequent process improvements.

[0092] This embodiment achieves preliminary classification and screening based on defect size features by comparing geometric feature parameters with a first-type threshold of a preset rule set and generating candidate labels, providing an objective quantitative basis for type identification. By comparing morphological parameters with a second-type threshold of the rule set and generating candidate labels, supplementary verification from the perspective of defect shape characteristics is provided, enhancing the comprehensiveness and accuracy of classification judgment. By logically combining candidate labels from both geometric and morphological aspects and matching them with type rules, a multi-feature collaborative discrimination decision mechanism is established, effectively avoiding the risk of misjudgment based on a single feature. When the label combination perfectly matches a specific type rule, the corresponding defect type is directly extracted, ensuring the clarity and traceability of the classification results.

[0093] In one embodiment 9, the method for detecting internal defects in aluminum alloy castings according to claim 8 is characterized in that it further includes determining the defect type according to the priority order defined in the defect classification rule set when the mark combination partially matches multiple type rules: [8] The matching degree calculation process applies to each type rule that partially matches the current defect's tag combination. Matching degree is a quantitative indicator used to precisely characterize the degree of conformity between the actual feature tags of the current defect and the ideal feature rules for a certain type of defect. The calculation process is typically based on a predefined matching degree function, which comprehensively considers the number of type rule conditions actually satisfied in the tag combination and the degree to which each condition is satisfied. For example, for a partially matching type rule, if the current defect's tag combination satisfies most of the key feature conditions required by the rule, a higher matching degree value is calculated; if only a few non-key conditions are satisfied, the matching degree value is lower.

[0094] The matching degree function involves a statistical weighting of the number of matching rules, or a similarity measure of the degree of conformity of continuous feature parameters. After calculating the corresponding matching degree value for each partially matching type rule, these values ​​are compared with a preset matching degree threshold. This threshold is a limit value used to distinguish between "barely relevant" and "significantly relevant" matching degrees, and its setting directly affects the strictness of subsequent type adjudication. The result of the comparison operation will generate a binary judgment state for each candidate type rule, i.e., whether its matching degree exceeds the minimum acceptable level.

[0095] The comparison results of the previous step show that this classification operation is performed when only one type rule among all partially matching type rules has a matching degree calculation result higher than the preset matching degree threshold. This situation indicates that among multiple possible candidate types, only one type's matching degree reaches an acceptable confidence level, while the matching degrees of other types are all below the threshold, meaning that their feature conformity is insufficient to support classifying them as that type of defect.

[0096] The appearance of a single high-match degree indicates that the current combination of defect features exhibits the strongest correlation with the definition of that type rule, exceeding the minimum acceptable standard. In this case, the system extracts the standard defect type identifier corresponding to the type rule with a match degree higher than the threshold, such as a predefined classification label like "porosity" or "shrinkage," and formally assigns it to the currently detected defect region as its determined classification result. This adjudication mechanism ensures that when a clearly optimal matching option exists, the defect type can be directly and explicitly determined, avoiding unnecessary complex adjudication processes.

[0097] When the previous step confirms that two or more different types of rules have a matching degree higher than the preset matching degree threshold, it indicates that the feature combination of the current defect and the feature rules of multiple defect types show a significant correlation exceeding the minimum acceptance standard, resulting in classification ambiguity. At this time, the system initiates a final decision-making procedure based on predefined priorities. The defect classification rule set assigns a specific priority value to each predefined defect type. This value system is pre-established based on domain knowledge and reflects the priority level of different defect types in terms of detection importance, process relevance, or judgment.

[0098] The system retrieves the priority values ​​of all candidate type rules with a matching degree higher than a threshold from the rule set. These values ​​are then compared to identify the highest priority rule. The type rule corresponding to this highest priority rule is determined as the most appropriate classification result. Finally, the system extracts the standard defect type identifier corresponding to the type rule with the highest priority value and formally assigns it to the current defect as the final classification conclusion.

[0099] This embodiment establishes a quantitative evaluation mechanism for fuzzy matching by calculating the matching degree between the tag combination and each partial matching type rule and comparing it with a threshold. This provides an objective numerical basis for classification decisions and effectively improves the accuracy of the ruling. When the matching degree of a single rule is significantly higher than the threshold, the corresponding type is directly extracted, ensuring that a classification decision can be made quickly when there are clearly advantageous options, thus improving detection efficiency. When the matching degrees of multiple rules all exceed the threshold, a hierarchical ruling mechanism for multiple matching cases is constructed by comparing predefined priority values ​​and selecting the type corresponding to the highest priority, ensuring the consistency and interpretability of the classification results. This priority ruling system provides a clear decision path for complex situations, effectively solves the classification ambiguity problem of feature similarity defects, and significantly improves the reliability and practicality of the detection system.

[0100] Reference Figure 2 As shown, this invention provides an internal defect detection system for aluminum alloy castings, applicable to any of the methods for detecting internal defects in aluminum alloy castings, comprising: The acquisition module is used to acquire a sequence of projected images of aluminum alloy castings for structural feature recognition, thereby obtaining structural feature images. The recognition module is used to extract features and segment pixels at the structural feature image to generate a defect probability map. The calculation module is used to calculate the segmentation threshold of the defect probability map, and perform binarization segmentation on the defect probability map based on the segmentation threshold. When the number of connected regions in the initial binary map exceeds the preset number threshold, the initial binary map is optimized to generate a defect distribution map. The processing module is used to identify connected regions of defects from the defect distribution map, calculate the geometric feature parameters and morphological parameters of each connected region of defects, match the geometric feature parameters and morphological parameters with the preset defect classification rule set for defect matching and type identification, and output detection result information.

[0101] This invention provides an internal defect detection system for aluminum alloy castings. By introducing multi-angle projection and structural feature recognition, it effectively integrates prior structural knowledge of the casting, enhancing the ability to distinguish between real defect areas and complex structural backgrounds. This significantly improves the accuracy and specificity of defect identification and reduces the risk of misjudgment. Multi-scale feature extraction and adaptive local segmentation threshold calculation overcome the limitations of traditional fixed thresholds, reducing missed detections. By accurately calculating the geometric and morphological parameters of defects and performing quantitative evaluation and classification based on a clear set of rules, it achieves objective, repeatable, and accurate judgment of defect size, shape, and type. A region optimization step is designed to filter and merge initial detection results based on morphology and spatial relationships, effectively filtering noise interference and optimizing the contour integrity of defect areas. The entire process, through systematic image processing and logical judgment steps, transforms defect detection from subjective experience-based judgment to objective data-driven automated analysis, improving consistency and significantly enhancing the efficiency and scalability of industrial inspection.

[0102] It should be noted that those skilled in the art will understand that, for the sake of convenience and brevity, the specific working processes of the system and each module described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.

[0103] In this embodiment, the processor and memory can be connected via a bus or other means. The memory may include volatile memory, such as random access memory; the memory may also include non-volatile memory, such as read-only memory, flash memory, hard disk, or solid-state drive. The processor may be a general-purpose processor, such as a central processing unit, digital signal processor, application-specific integrated circuit, or one or more integrated circuits configured to implement embodiments of the present invention.

[0104] The above description is only a preferred embodiment of the present invention and does not limit the patent scope of the present invention. Any equivalent structural or procedural transformations made based on the content of the present invention specification and drawings, or direct or indirect applications in other related technical fields, are similarly included within the patent protection scope of the present invention.

Claims

1. A method for detecting internal defects in aluminum alloy castings, characterized in that, include: Structural feature images are obtained by acquiring a sequence of projected images of aluminum alloy castings and identifying their structural features. The structural feature image is subjected to feature extraction and pixel-level segmentation to generate a defect probability map; Calculate the segmentation threshold of the defect probability map, perform binarization segmentation on the defect probability map based on the segmentation threshold, and when the number of connected regions in the obtained initial binary map exceeds a preset number threshold, perform region optimization on the initial binary map to generate a defect distribution map; The defect connected regions are identified from the defect distribution map. The geometric feature parameters and morphological parameters of each defect connected region are calculated. The geometric feature parameters and morphological parameters are matched with a preset defect classification rule set for defect matching and type identification, and the detection result information is output.

2. The method for detecting internal defects in aluminum alloy castings according to claim 1, characterized in that, The acquired sequence of projected images of the aluminum alloy casting is used for structural feature recognition to obtain structural feature images, including: Acquire a sequence of projected images of the aluminum alloy casting at multiple projection angles; The process involves sequentially traversing each projected image in the projected image sequence and extracting the pixel gradient features and local texture features of the projected image. The pixel positions in the pixel gradient features are matched point by point with the preset casting contour threshold, and the pixel positions that are higher than the casting contour threshold are marked as candidate structural points. Based on the local texture features, adjacent candidate structure points are connected to form structure outline segments; The structural contour lines are combined to form the casting structural contour, and the projected image is segmented based on the casting structural contour to obtain the structural feature image.

3. The method for detecting internal defects in aluminum alloy castings according to claim 1, characterized in that, The step of performing multi-scale feature extraction and pixel-level segmentation on the structural feature image to generate a defect probability map includes: Based on a preset feature extraction template set, neighborhood feature calculation is performed on the pixels in the structural feature image to obtain feature response values; The feature response value is compared with a preset defect feature threshold range. If the feature response value falls within the defect feature threshold range, the pixel is marked as a candidate defect pixel. The distribution density of all candidate defect pixels is statistically analyzed. When the distribution density is higher than a preset density threshold, the defect probability value of the candidate defect pixel is calculated based on the feature response value. Based on the original coordinate positions of each candidate defect pixel, all the defect probability values ​​are arranged into a defect probability map with the same size as the structural feature image.

4. The method for detecting internal defects in aluminum alloy castings according to claim 1, characterized in that, The process involves calculating a segmentation threshold for the defect probability map, performing binarization segmentation on the defect probability map based on the segmentation threshold, and optimizing the initial binary map to generate a defect distribution map when the number of connected regions in the resulting initial binary map exceeds a preset threshold. The defect probability map is divided into multiple local sub-regions, and the pixel grayscale feature values ​​of each local sub-region are extracted. The segmentation threshold corresponding to the local sub-region is calculated based on the pixel grayscale feature values. The local sub-region is binarized using the segmentation threshold, and the pixel grayscale feature values ​​in the sub-region that are greater than or equal to the segmentation threshold are set as foreground pixels to form the initial binary image. The total number of connected regions in the initial binary graph is counted. When the total number of connected regions exceeds a preset threshold, region optimization is performed on the initial binary graph to generate the defect distribution map.

5. The method for detecting internal defects in aluminum alloy castings according to claim 4, characterized in that, The step of binarizing the local sub-region using the segmentation threshold, and setting the pixel grayscale feature values ​​in the sub-region that are greater than or equal to the segmentation threshold as foreground pixels to form the initial binary image, includes: Create a binary marker map with consistent pixel size for each of the local sub-regions; Traverse each sub-pixel in each of the local sub-regions, read the pixel grayscale feature value of the sub-pixel, and compare the pixel grayscale feature value with the segmentation threshold; If the pixel grayscale feature value is greater than or equal to the segmentation threshold, it is marked as a foreground pixel value at the corresponding position in the binarized marker map; If the pixel grayscale feature value is less than the segmentation threshold, the corresponding position in the binarized marker map is marked as the background pixel value; Based on the original coordinates of each local sub-region in the defect probability map, all binarized marker maps are stitched together to form the initial binary map.

6. The method for detecting internal defects in aluminum alloy castings according to claim 4, characterized in that, The process involves counting the total number of connected regions in the initial binary graph. When the total number of connected regions exceeds a preset threshold, region optimization is performed on the initial binary graph to generate the defect distribution map, including: Traverse and count all connected regions in the initial binary graph, and compare the total number of connected regions obtained with a preset number threshold. When the total number of connected regions exceeds a preset threshold, the region similarity between adjacent connected regions is calculated, and the morphological features of each connected region are extracted. Each of the morphological features is compared with a preset benchmark morphology. If the morphological feature does not conform to the preset benchmark morphology, the connected region is marked as a background region to be optimized. The connected regions whose similarity to the region is higher than a preset merging threshold are marked as regions to be merged. The foreground pixels in the background region to be optimized are adjusted to background pixels, and the regions to be merged are merged into a single connected region to obtain the defect distribution map.

7. The method for detecting internal defects in aluminum alloy castings according to claim 1, characterized in that, The step of identifying connected regions of defects from the defect distribution map and calculating the geometric feature parameters and morphological parameters of each connected region of defects includes: Traverse all distribution map pixels in the defect distribution map, mark and connect the distribution map pixels with the same pixel value to form multiple candidate defect regions; Extract the boundary coordinates of each of the defect connected regions, and calculate and integrate the defect area, defect perimeter, major axis length and minor axis length of the defect connected regions based on the boundary coordinates to form the geometric feature parameters; Based on the boundary coordinates, the minimum bounding rectangle of each defective connected region is identified. The ratio of the long side to the short side of the minimum bounding rectangle is used as the aspect ratio of the rectangle. The ratio of the area of ​​the defective connected region to the area of ​​the minimum bounding rectangle is used as the region fullness. The morphological parameters are obtained by integrating the aspect ratio of the rectangle and the fullness of the region.

8. The method for detecting internal defects in aluminum alloy castings according to claim 1, characterized in that, The step of matching and identifying defects by combining the geometric feature parameters and morphological parameters with a preset defect classification rule set, and outputting detection result information, includes: Each of the geometric feature parameters is compared with a first-class threshold in the defect classification rule set to generate a first group of candidate type labels; The morphological parameters are compared with the second type threshold in the defect classification rule set to generate a second set of candidate type labels; The first group of candidate type tags and the second group of candidate type tags are logically combined to obtain a tag combination, and the tag combination is matched with the type rules of the defect classification rule set; When the combination of tags completely matches a certain type rule, the defect type corresponding to that type rule is extracted; The geometric feature parameters, morphological parameters, and defect types of all the defect-connected regions are summarized to generate detection result information.

9. The method for detecting internal defects in aluminum alloy castings according to claim 8, characterized in that, It also includes determining the defect type according to the priority order defined in the defect classification rule set when the tag combination partially matches multiple type rules: Calculate the matching degree between the tag combination and the type rule that matches each part, and compare all the matching degrees with a preset matching degree threshold; If there is a type rule whose matching degree is higher than the matching degree threshold, extract the defect type corresponding to the type rule; If multiple type rules have a matching degree higher than the matching degree threshold, compare the priority values ​​of these type rules in the defect classification rule set, and extract the defect type corresponding to the type rule with the highest priority value.

10. An internal defect detection system for aluminum alloy castings, characterized in that, The method for detecting internal defects in aluminum alloy castings according to any one of claims 1-9 includes: The acquisition module is used to acquire a sequence of projected images of aluminum alloy castings for structural feature recognition, thereby obtaining structural feature images; The identification module is used to extract features and segment pixels at the structural feature image to generate a defect probability map; The calculation module is used to calculate the segmentation threshold of the defect probability map, perform binarization segmentation on the defect probability map based on the segmentation threshold, and when the number of connected regions in the obtained initial binary map exceeds a preset number threshold, perform region optimization on the initial binary map to generate a defect distribution map. The processing module is used to identify defect connected regions from the defect distribution map, calculate the geometric feature parameters and morphological parameters of each defect connected region, perform defect matching and type identification with the geometric feature parameters and morphological parameters and a preset defect classification rule set, and output detection result information.