Inorganic mineral casting defect visual detection method and system

By combining multi-scale adaptive windows and Hough transform, the problem of insufficient single gray-scale feature analysis in the defect detection of inorganic mineral castings is solved, and the accurate identification of minute defects and the anti-interference ability are improved.

CN121998899APending Publication Date: 2026-05-08SHANDONG CLAREMONT NEW MATERIAL TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
SHANDONG CLAREMONT NEW MATERIAL TECH CO LTD
Filing Date
2025-12-10
Publication Date
2026-05-08

AI Technical Summary

Technical Problem

In the detection of defects in inorganic mineral castings, existing technologies have insufficient single-channel grayscale feature analysis capabilities, making it difficult to capture minute defects. Traditional morphological analysis is prone to misjudging textures as defects, edge detection operators are easily affected by noise, and pattern recognition algorithms have low classification accuracy and difficulty in distinguishing between similar defects such as pores and sand holes.

Method used

A multi-scale adaptive window scanning method is used to scan dual-channel grayscale images. The directional offset angle is calculated by Hough transform. Combined with connected component analysis and gradient spectrum matching, a multi-dimensional feature fusion model is constructed to identify surface defects of castings.

Benefits of technology

It improves the ability to capture micro-texture changes, reduces false defect misjudgment, and achieves accurate differentiation between slender cracks and discrete noise, thereby improving detection accuracy and anti-interference ability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121998899A_ABST
    Figure CN121998899A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of image analysis, in particular to an inorganic mineral casting defect visual detection method and system.The method comprises the following steps that extreme point coordinates are generated through two-channel gray level image non-overlapping scanning, direction angles of adjacent points are calculated through Hough transform to form an offset sequence, and a disturbance unit is marked through two-channel direction angle offset operation; connected domain analysis is combined with path length and disturbance quantity to determine a defect area, and principal axis equidistant sampling is carried out to construct a gradient spectrogram matching frequency fluctuation output defect type and coordinate. According to the method, the microscopic texture capturing capability is enhanced through two-channel gray level image non-overlapping scanning, structure distortion is quantized through a Hough transform direction offset sequence, illumination interference misjudgment is reduced through two-channel direction angle synchronous operation, and noise interference is restrained through connected domain two-index constraint judgment. The principal axis equidistant sampling is combined with gradient spectrogram frequency matching to realize accurate defect classification, and the detection precision and the anti-interference performance are improved by spatial arrangement feature quantization and multi-dimensional feature fusion.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of image analysis technology, and in particular to a visual inspection method and system for defects in inorganic mineral castings. Background Technology

[0002] Image analysis technology encompasses methods and applications for recognizing, detecting, analyzing, and processing image content based on visual information. Its core content includes the automatic identification and quantitative analysis of targets or features in images using computer vision algorithms, covering multiple stages such as image preprocessing, feature extraction, target detection, image segmentation, and pattern recognition. Image analysis is widely used in industrial inspection, medical diagnosis, security monitoring, and agricultural inspection, with typical applications in industrial inspection including automated detection of surface defects, structural anomalies, and material consistency. This field continues to evolve towards higher precision, multi-scenario adaptability, and efficient processing capabilities, aiming to replace manual inspection and improve inspection efficiency and consistency.

[0003] The visual inspection method for defects in inorganic mineral castings refers to a technical approach for detecting surface or internal defects in castings made from inorganic mineral materials through visual image acquisition and processing. The technical aspects covered in this topic include using industrial cameras to acquire image information of inorganic mineral castings under specific lighting conditions, then extracting image features of defect areas through image enhancement and denoising, and finally determining the type and location of defects using algorithms based on grayscale features and edge information to identify typical defects such as cracks, sand holes, and porosity. This method utilizes fixed-angle multi-source illumination, image filtering, edge detection operators, and morphological analysis to achieve the separation and analysis of defect image features.

[0004] Existing technologies rely on single-channel grayscale feature analysis, which has limited ability to capture grayscale differences in minute surface defects. In low-contrast scenes, sub-pixel-level cracks are easily missed. Traditional morphological analysis, based on corrosion and expansion operations using fixed structural elements, struggles to adapt to the complex texture backgrounds of inorganic mineral castings, easily misclassifying natural textures as structural defects. Edge detection operators are highly sensitive to noise, easily generating false edge interference in uneven lighting or reflective areas, leading to defect location coordinate shifts. Threshold-based defect identification methods lack directional distortion analysis, failing to effectively distinguish between genuine defects and the inherent texture direction of the material. Pattern recognition algorithms mostly employ static feature template matching, lacking a dynamic gradient spectrum analysis mechanism, resulting in insufficient accuracy in classifying similar defects such as pores and sand holes. For example, pore defects, common in industrial inspection, are easily misclassified as internal air bubbles due to the lack of frequency fluctuation feature analysis, affecting the reliability of detection results. Existing methods only consider the single indicator of region area when processing connected components, failing to introduce a joint judgment mechanism of path length and distribution density, making it difficult to effectively distinguish between elongated cracks and discrete noise points. Summary of the Invention

[0005] To address the limitations of existing technologies that rely on single-channel grayscale feature analysis, which has limited ability to capture grayscale differences in minute surface defects and is prone to missing sub-pixel-level cracks in low-contrast scenes, traditional morphological analysis, based on corrosion and expansion operations using fixed structural elements, struggles to adapt to the complex texture backgrounds of inorganic mineral castings, easily misclassifying natural textures as structural defects. Edge detection operators are highly sensitive to noise and prone to generating false edge interference in uneven lighting or reflective areas, leading to defect location coordinate shifts. Threshold-based defect identification methods lack directional distortion analysis, failing to effectively distinguish between genuine defects and the inherent texture direction of the material. Pattern recognition algorithms often employ static feature template matching without establishing a dynamic gradient spectrum analysis mechanism, resulting in insufficient accuracy in classifying similar defects such as pores and sand holes. For example, pore defects, common in industrial inspection, are easily misclassified as internal air bubbles due to the lack of frequency fluctuation feature analysis, affecting the reliability of inspection results. Existing methods only consider the region area as a single indicator when processing connected components, without introducing a joint determination mechanism based on path length and distribution density. This leads to the technical problem that it is difficult to effectively distinguish between elongated cracks and discrete noise points. This invention provides a visual inspection method and system for defects in inorganic mineral castings. The technical solution is as follows:

[0006] On the one hand, a visual inspection method for defects in inorganic mineral castings is provided, which includes:

[0007] S1: A multi-scale adaptive window is used to perform non-overlapping scanning of the dual-channel grayscale image of the casting surface. The window size is dynamically adjusted according to the local grayscale gradient. The dual-channel extreme points are extracted and fused to generate a set of extreme point coordinates on the casting surface.

[0008] S2: Based on the set of extreme point coordinates on the surface of the casting, the coordinates of the extreme points in the continuous window are arranged in space, and the direction angle of the line connecting adjacent points is calculated by Hough transform to generate a sequence of direction offset angles on the surface of the casting.

[0009] S3: Call the casting surface direction offset angle sequence, perform offset calculation on the dual-channel same coordinate direction angle, if the offset exceeds the angle difference threshold, mark it as a disturbance unit, and obtain the casting surface disturbance unit set;

[0010] S4: Based on the set of surface disturbance units of the casting, the connected component analysis algorithm is used to connect adjacent units into eight neighborhoods, and the length of the connected path and the number of disturbances per unit area are calculated. If both are greater than the set value, it is determined to be a defect area on the surface of the casting.

[0011] S5: Based on the surface defect area of ​​the casting, extract dual-channel grayscale sampling points at equal intervals along the main axis, analyze the grayscale sequence and perform gradient offset calculation, construct a gradient spectrum, match the frequency fluctuation area, and output the surface defect type and coordinates of the casting.

[0012] As a further aspect of the present invention, the setting of the spatial arrangement rules affects the configuration strategy of the Hough transform parameters, and the two work together to determine the accuracy and stability of the orientation angle detection.

[0013] The angular accuracy of the Hough transform is matched with the measurement accuracy;

[0014] The angle difference threshold is set based on the equipment noise level and measurement accuracy, and is in degrees. It is limited by Min-Max normalization.

[0015] The settings for the length of the connected path and the number of perturbations per unit area are set based on training data statistics.

[0016] The connected component analysis algorithm clusters the surface disturbance units of the casting to identify the connected regions that constitute a complete defect.

[0017] The set of extreme point coordinates on the casting surface specifically refers to the distribution coordinates of extreme points. The casting surface directional offset angle sequence includes directional change frequency, angular offset amplitude, and directional continuity index. The casting surface disturbance unit set specifically includes disturbance unit spatial density, disturbance unit morphological characteristics, and disturbance unit local gradient value. The high-confidence defect region on the casting surface includes region connectivity length, number of disturbances per unit area, and region confidence level. The casting surface defect type and coordinates include defect type label, defect location coordinates, and frequency fluctuation mode.

[0018] As a further aspect of the present invention, the specific steps of S1 include:

[0019] S101: A multi-scale adaptive window is used to scan the dual-channel grayscale image of the casting surface in a non-overlapping manner, extract all pixel grayscale values ​​of the two grayscale channels in each window, calculate the range of grayscale gradient change in the channel, compare it with the gradient distribution threshold, dynamically adjust the size of the current window, and generate a multi-scale grayscale gradient window set.

[0020] The initial size of the multi-scale adaptive window is set empirically based on the image resolution and defect scale, and the sensitivity of window adjustment is determined based on the overall gradient distribution characteristics of the image.

[0021] The gradient distribution threshold is dynamically adjusted based on the local statistical values ​​of the current scanned area.

[0022] S102: Call the window coordinates and corresponding gray values ​​in the multi-scale gray gradient window set, determine whether the pixel gray value reaches the upper and lower limits of the channel interval in the two channels, select the coordinate points that meet the conditions at the same time, and after removing the image boundary and duplicate items, obtain the boundary gray extreme value coordinate point set.

[0023] S103: Based on the pixel coordinates in the set of boundary gray-scale extreme coordinate points, coordinates are integrated in the order of their corresponding window regions, and the extreme point position information within the differentiated window regions is summarized to obtain the set of extreme point coordinates on the casting surface.

[0024] As a further aspect of the present invention, the specific steps of S2 include:

[0025] S201: Based on the coordinates of each continuous window in the set of extreme point coordinates on the surface of the casting, extract adjacent extreme point pairs, record the coordinate difference of the point pairs in the row and column directions, decompose the vector into horizontal and vertical vector components, calculate the component ratio and analyze the direction angle, and generate an extreme value connection direction angle sequence.

[0026] S202: Call the angle values ​​in the extreme value connection direction angle sequence, calculate the numerical difference between adjacent angles, compare the angle change value with the direction offset reference value according to the sequence order, filter the angle segment with the angle change value greater than the offset reference value, and obtain the direction angle offset segment data.

[0027] The directional offset benchmark value is set by adding a multiple of the standard deviation to the mean of the fluctuation distribution to determine the offset benchmark.

[0028] S203: Based on the offset value sequence in the directional angle offset segment data, statistically analyze the range of directional angle value changes and the degree of difference fluctuation between consecutive segments, calculate the range of directional angle changes and the range of change slopes for multiple segments, and obtain the directional offset angle sequence of the casting surface.

[0029] As a further aspect of the present invention, the specific steps of S3 include:

[0030] S301: Call the dual-channel orientation angle data of each coordinate point in the orientation offset angle sequence of the casting surface, match the orientation angle values ​​corresponding to the two channels according to the coordinate index, calculate the absolute difference between the two orientation angles under the same coordinate, and generate a coordinate angle difference sequence.

[0031] S302: Based on the coordinate angle difference sequence, extract the angle difference item by item and compare it with the angle difference threshold to determine whether the difference of each coordinate point exceeds the threshold. Record the coordinate point index that exceeds the threshold in spatial order to obtain the disturbed coordinate index set.

[0032] S303: Call the marked coordinate points in the disturbance coordinate index set, combine the original coordinate data with the corresponding direction angle difference, add a direction offset attribute label to each marked point, and generate a set of disturbance units on the casting surface.

[0033] As a further aspect of the present invention, the specific steps of S4 include:

[0034] S401: Based on the set of perturbation units on the surface of the casting, scan the unit coordinates and detect the connectivity of the eight neighborhoods, record the number of units and the geometric center, calculate the diagonal vertices of the circumscribed rectangle, and generate a dataset of connected region morphological features.

[0035] S402: Call the connected region morphological feature dataset, calculate the path length of the Euclidean distance of the circumscribed rectangle as the path length value, and the ratio of the number of statistical units to the area of ​​the circumscribed rectangle as the perturbation density value per unit area. Combine the path length value and the perturbation density value as a two-parameter index to generate a connected region perturbation intensity index set.

[0036] S403: Based on the set of disturbance intensity indices for connected regions, extract the path length and disturbance density per unit area item by item, and filter the connected regions that simultaneously satisfy the condition that the path length is greater than the length threshold and the disturbance density is greater than the density threshold to generate the surface defect region of the casting.

[0037] The length threshold and density threshold are set based on training data statistics.

[0038] As a further aspect of the present invention, the path length value is calculated using the following formula:

[0039] ;

[0040] Represents the path length value. Represents the range of the x-axis coordinate. Represents the range of the y-axis coordinate. Represents the total number of connected components. Represents the area of ​​the circumscribed rectangle. The area correction factor represents the ratio of the actual average density to the reference density, mitigating deviations in values ​​caused by regional density anomalies. This represents the scale adjustment length, avoiding weight imbalances in index calculations due to scale regions. .

[0041] As a further aspect of the present invention, the specific steps of S5 include:

[0042] S501: Based on the main axis direction of the defect area on the surface of the casting, the coordinates of the sampling points are set at fixed intervals, and the gray values ​​of each coordinate point are extracted and sorted along the dual-channel grayscale image to generate a dual-channel grayscale sampling point sequence.

[0043] S502: Call the dual-channel grayscale sampling point sequence, calculate the grayscale value change of adjacent sampling points as the gradient value, and synchronously superimpose the dual-channel gradient changes according to the sampling position to construct a two-dimensional distribution map with the sampling position on the horizontal axis and the gradient change on the vertical axis, and generate a gradient spectrum dataset.

[0044] S503: Based on the gradient spectrum dataset, calculate the cosine similarity between the local frequency and the reference spectrum, filter low similarity regions and match them with the defect type library, and output the surface defect type and coordinates of the casting.

[0045] As a further aspect of the present invention, the gradient change is calculated using the following formula:

[0046] ;

[0047] in, This represents the fusion gradient change at the k-th sampling point. The gradient change is used to guide spectral enhancement and defect feature extraction, distinguishing between different types of defects without introducing a neural network structure. The dynamic difference coefficient represents channel c. The mean offset coefficient representing channel c. This represents the grayscale measurement value of the k-th sampling point in channel c. This represents the local grayscale average value of channel c. The spatial attenuation factor represents channel c. This represents the sampling interval of channel c. This represents the minimum spacing compensation amount for channel c. The signal-to-noise suppression adjustment coefficient represents channel c. Let be the local grayscale standard deviation of channel c.

[0048] On the other hand, a visual inspection system for defects in inorganic mineral castings is provided. This system is used to perform the aforementioned visual inspection method for defects in inorganic mineral castings. The system includes:

[0049] The image acquisition module is used to perform non-overlapping scanning of the dual-channel grayscale image of the casting surface using a multi-scale adaptive window size, acquire the pixel coordinates corresponding to the grayscale value of each window, generate a set of extreme point coordinates, and transmit them to the extreme value extraction module.

[0050] The extreme value extraction module is used to extract continuous extreme value points from the extreme value point coordinate set and construct a path, call the path sorting function to sort the path coordinates, use the Hough transform algorithm to calculate the direction angle between two points in the path, output the direction offset angle sequence, and pass it to the direction analysis module.

[0051] The direction analysis module is used to perform inter-channel direction fluctuation judgment based on the direction offset angle sequence, calculate the corresponding coordinate direction angle offset using the angle difference operation function, determine whether it exceeds the threshold and count the number of abnormal points. If the number of abnormal points exceeds the limit, the corresponding window is marked as a disturbance area, and a set of disturbance units is output and transmitted to the disturbance identification module.

[0052] The disturbance identification module is used to perform spatial clustering detection on the set of disturbance units. It uses a connected subgraph algorithm to cluster eight neighboring regions, calls a region filtering function to evaluate whether the length of the connected region and the disturbance density meet the identification conditions, generates a high-confidence defect region, and passes it to the defect judgment module.

[0053] The defect determination module is used to extract frequency features from the high-confidence defect area, collect grayscale sequences along the main axis and calculate the gradient, perform spectrum conversion to identify frequency fluctuations, determine the defect type, and output the surface defect type and coordinates of the casting.

[0054] The beneficial effects of the technical solutions provided by the embodiments of the present invention include at least the following:

[0055] A dual-channel grayscale image non-overlapping scanning mechanism is used to obtain the coordinate set of surface extreme points, enhancing the ability to capture micro-texture changes. Dual-channel data overlay improves the sensitivity of grayscale feature contrast. A direction offset angle sequence generation method based on Hough transform converts discrete coordinate points into continuous spatial arrangement features, effectively quantifying the directional distortion of surface structures and solving the problem of misidentification of irregular crack directions in traditional edge detection. An offset threshold determination mechanism, combined with synchronous dual-channel direction angle calculation, establishes a dynamic marking system for perturbation units, reducing the probability of false defects caused by uneven illumination. A connected component analysis algorithm integrates path length and the number of perturbations per unit area as dual-indicator constraints, using geometric features and distribution density for joint determination, avoiding interference from isolated noise points in defect area identification. Principal axis equidistant sampling combined with a gradient spectrum frequency fluctuation matching mechanism constructs a multi-dimensional feature fusion defect classification model, achieving accurate differentiation between similar defects such as pores and sand holes. Gradient offset calculation enhances the feature separation of grayscale abrupt change regions. The overall processing logic, through spatial arrangement feature quantification, dynamic marking system construction, dual-indicator constraint determination, and multi-dimensional feature fusion, achieves a synergistic improvement in defect detection accuracy and anti-interference capability. Attached Figure Description

[0056] Figure 1 This is a schematic diagram of the workflow of the present invention;

[0057] Figure 2 This is a system flowchart of the present invention. Detailed Implementation

[0058] The technical solution of the present invention will now be described with reference to the accompanying drawings.

[0059] In embodiments of the present invention, words such as "exemplarily," "for example," etc., are used to indicate that something is an example, illustration, or description. Any embodiment or design described as "exemplary" in the present invention should not be construed as being more preferred or advantageous than other embodiments or designs. Specifically, the use of the word "exemplary" is intended to present the concept in a concrete manner. Furthermore, in embodiments of the present invention, the meaning expressed by "and / or" can be both, or either one.

[0060] In the embodiments of this invention, the terms "image" and "picture" may sometimes be used interchangeably. It should be noted that, without emphasizing the distinction between them, they convey the same meaning. Similarly, the terms "of," "corresponding (relevant)," and "corresponding" may sometimes be used interchangeably. It should be noted that, without emphasizing the distinction between them, they convey the same meaning.

[0061] In this embodiment of the invention, sometimes a subscript such as W1 may be written in a non-subscript form such as W1. When the difference is not emphasized, the meaning they express is the same.

[0062] To make the technical problems, technical solutions and advantages of the present invention clearer, a detailed description will be given below in conjunction with the accompanying drawings and specific embodiments.

[0063] Please see Figure 1 This invention provides a visual inspection method for defects in inorganic mineral castings. The processing flow of this method may include the following steps:

[0064] S1: A multi-scale adaptive window is used to perform non-overlapping scanning of the dual-channel grayscale image of the casting surface. The window size is dynamically adjusted according to the local grayscale gradient. The dual-channel extreme points are extracted and fused to generate a set of extreme point coordinates on the casting surface.

[0065] S2: Based on the set of extreme point coordinates on the casting surface, the coordinates of the extreme points in the continuous window are spatially arranged, and the direction angle of the line connecting adjacent points is calculated by Hough transform to generate a sequence of direction offset angles on the casting surface.

[0066] S3: Call the casting surface direction offset angle sequence, perform offset calculation on the dual-channel same coordinate direction angle, if the offset exceeds the angle difference threshold, mark it as a disturbance element, and obtain the casting surface disturbance element set;

[0067] S4: Based on the set of perturbation elements on the surface of the casting, the connected component analysis algorithm is used to connect adjacent elements in eight-neighborhood, calculate the length of the connected path and the number of perturbations per unit area. If both are greater than the set value, it is determined to be a defect area on the surface of the casting.

[0068] S5: Based on the surface defect area of ​​the casting, extract dual-channel grayscale sampling points at equal intervals along the main axis, analyze the grayscale sequence and perform gradient shift calculation, construct gradient spectrum, match frequency fluctuation areas, and output the surface defect type and coordinates of the casting.

[0069] The set of extreme point coordinates on the casting surface specifically includes the distribution coordinates of extreme points. The casting surface directional offset angle sequence includes the frequency of directional changes, the amplitude of directional offset, and the directional continuity index. The casting surface disturbance unit set specifically includes the spatial density of disturbance units, the morphological characteristics of disturbance units, and the local gradient value of disturbance units. The high-confidence defect region on the casting surface includes the region connectivity length, the number of disturbances per unit area, and the region confidence level. The casting surface defect type and coordinates include the defect type label, the defect location coordinates, and the frequency fluctuation pattern.

[0070] Specifically, the steps in S1 are as follows:

[0071] S101: A multi-scale adaptive window is used to scan the dual-channel grayscale image of the casting surface in a non-overlapping manner, extract all pixel grayscale values ​​of the two grayscale channels in each window, calculate the range of grayscale gradient change in the channel, compare it with the gradient distribution threshold, dynamically adjust the size of the current window, and generate a multi-scale grayscale gradient window set.

[0072] The initial size of the multi-scale adaptive window is set empirically based on the image resolution and defect scale, and the sensitivity of window adjustment is determined based on the overall gradient distribution characteristics of the image.

[0073] The gradient distribution threshold is dynamically adjusted based on local statistical values ​​in the current scanned area.

[0074] First, for scanning the dual-channel grayscale image of the casting surface, a multi-scale adaptive window technique is employed to achieve non-overlapping scanning. This process begins by selecting an initial window size based on empirical settings of image resolution and defect scale. For example, if the surface defect scale of the casting is 0.5mm and the image resolution is 3000dpi, a window size of 5mm×5mm is chosen, covering the defect range present on the casting surface. Next, the pixel grayscale values ​​of the two grayscale channels (e.g., red and green channels) within the window are extracted, and their grayscale gradient variation range is calculated and compared with a preset grayscale gradient threshold. If the gradient variation exceeds the set threshold (e.g., 0.2 to 0.4), the window is considered to contain defect information, and the window size is dynamically adjusted according to the actual grayscale gradient distribution characteristics.

[0075] For example, if the grayscale gradient variation range within a certain scanning area is 0.25, this value matches the set threshold range of 0.2-0.4. Therefore, a smaller window will be generated in that area for more precise scanning. This sensitivity setting is determined by the overall gradient distribution characteristics of the image and can be adjusted using local image statistics (such as local standard deviation and mean). Assuming the local mean of the image is 128 and the standard deviation is 15, the gradient variation range can be adjusted between 0.15 and 0.3 based on the statistical information, thus better adapting to the scanning needs of different areas.

[0076] Furthermore, during the dynamic adjustment of the gradient distribution threshold, adjustments are made based on the local statistical information of the current scanning area. For example, if the local gradient standard deviation of a certain area is 10, the gradient distribution threshold for that area will be increased to 0.5 to enhance the sensitivity to small-scale defects, thereby ensuring effective detection of defects of different sizes.

[0077] This process dynamically forms a multi-scale grayscale gradient window set by continuously adjusting the window size and gradient threshold, ensuring efficient capture of casting surface defect features at different scales. This multi-scale, adaptive scanning method enables precise localization of casting surface defects, thus providing accurate data support for subsequent defect identification and analysis.

[0078] S102: Call the window coordinates and corresponding gray values ​​in the multi-scale gray gradient window set, determine whether the pixel gray value reaches the upper and lower limits of the channel interval in the two channels, select the coordinate points that meet the conditions at the same time, and after removing the image boundary and duplicate items, obtain the set of boundary gray extreme value coordinate points.

[0079] After generating the multi-scale grayscale gradient window set, the next step is to determine whether the pixel grayscale has reached the preset upper and lower limits of the channel range based on the coordinates and corresponding grayscale values ​​within the window. Specifically, the grayscale range of the red and green channels is first determined by analyzing the grayscale values ​​extracted within each window. For example, in a certain window, suppose the grayscale value of the red channel is 100 to 150, and the grayscale value of the green channel is 120 to 170. Using the preset upper and lower limits of grayscale (such as 90-160 for the red channel and 110-180 for the green channel), it is determined whether the grayscale value within the window falls within the range.

[0080] If the grayscale values ​​of the red channel (100-150) coincide with the set range of 90-160, and the grayscale values ​​of the green channel (120-170) are also within the set range, then the grayscale values ​​within the window are considered to meet the criteria, and further filtering of the coordinate points that meet the criteria is required. This method effectively removes pixels that do not conform to the grayscale range, avoiding interference.

[0081] Next, pixel values ​​in image boundary regions will be excluded. This step is to avoid abnormal grayscale values ​​caused by transition effects at the boundaries interfering with defect identification results. Simultaneously, duplicate coordinate points will be removed. This is done by recording each coordinate point and checking if it has already appeared in previous scan results. If it already exists, it is removed, ensuring that each coordinate point is recorded only once.

[0082] For example, if multiple adjacent windows generate similar coordinate points within a region (such as (20, 30), (21, 30), (19, 31)), the Euclidean distance between these points will be calculated. If the distance is less than a set threshold (such as 2 pixels), the points will be merged to ensure that the final result is an independent defect coordinate. After this series of operations, a set of boundary grayscale extreme value coordinate points is obtained, and these coordinate points represent the defect areas existing on the surface of the casting.

[0083] S103: Based on the pixel coordinates of the boundary gray-scale extreme value coordinate points, coordinate integration is performed according to the order of their corresponding window regions, and the extreme value point position information within the differentiated window regions is summarized to obtain the set of extreme value point coordinates on the casting surface.

[0084] After acquiring the boundary grayscale extreme value coordinate point set, the multi-scale window regions on the casting surface are sequentially classified. First, based on the spatial distribution order of the windows, the coordinate points from different windows are sorted from left to right and from top to bottom according to the coordinate values ​​of their center points. This sorting order provides the basis for subsequent classification. Based on this sorting, coordinate points within the same or adjacent window regions are classified. Specifically, the center coordinates of the window to which each coordinate point belongs are determined. If the difference between the horizontal and vertical coordinates of the center of the windows of two coordinate points is less than 10% of the window size, then they are determined to belong to the same region. At this time, the point sets of this type are grouped into the same coordinate region group. For example, in a casting region, there are three extreme value points with coordinates (110, 135), (112, 133), and (108, 136), whose window center is (110, 135), and the window size is 5mm. The pixel size is 60 pixels, with an allowable range of ±6 pixels. Therefore, three points are grouped into one class. Based on this, the specific locations of extreme points in multiple classes are extracted, and a set of coordinates of extreme points in each window is established. Contour analysis is performed on the coordinate set within each class to extract its boundary features. By analyzing the distance between the extreme point and the center of the window point point by point, and combining the variance of the distance between the boundary point and the center, clustering judgment is performed. If the variance is less than a set threshold (e.g., 5 square pixels), it is marked as a single defect area; otherwise, it is marked as a composite defect area. The subset coordinates within the composite area are then re-clustered and split, and contour analysis is performed again to ensure accurate classification of extreme points. Finally, the coordinates of all classified extreme points are summarized to form a complete set of coordinates of extreme points on the casting surface. The final output is a data list including information on extreme points within the defect area. This data can be used for training set sample annotation in subsequent recognition tasks or for comparison and verification with known defect models.

[0085] Table 1: Set of Coordinates of Extreme Points in Multiple Regions

[0086]

[0087] As shown in Table 1, the defect areas corresponding to different numbers contain several extreme points. Each group of coordinate points is grouped according to the center position of its corresponding window, and classified and analyzed in combination with the distribution characteristics of the points, so as to obtain a structured extreme value coordinate dataset that can be used for further modeling.

[0088] Specifically, the steps of S2 are as follows:

[0089] S201: Based on the coordinates of each continuous window in the set of extreme point coordinates on the surface of the casting, extract adjacent extreme point pairs, record the coordinate difference of the point pairs in the row and column directions, decompose the vector into horizontal and vertical vector components, calculate the component ratio and analyze the direction angle, and generate an extreme value connection direction angle sequence.

[0090] Based on the coordinates of each continuous window in the set of extreme point coordinates on the casting surface, the window is first defined in the two-dimensional coordinate matrix of the image. For example, each window is set to include 5×5 pixels. A sliding window is used to move from top to bottom and from left to right, recording the pixel grayscale value matrix within each window. Then, the pixel with the largest grayscale value and its coordinates are extracted from the window and set as the extreme point of the window. If there are multiple maximum points within the window, the first detected point is used as the representative. All extreme points within the windows are sequentially arranged into an extreme point coordinate set. Then, two consecutive adjacent extreme points in the set are paired. Let the coordinates of the i-th extreme point be... , No. The coordinates of the extreme points are Calculate the difference between the horizontal and vertical directions to obtain the horizontal difference. Longitudinal difference After decomposing the vector into horizontal and vertical components, the ratio of the two components is calculated. And calculate the direction angle of the vectors using the arctangent function. All angles Arranged into a sequence of directions and angles For example, in the surface imaging of a casting, if the extreme points are (12, 8), (16, 10), and (20, 14) in sequence, then we have , ,have to , The angle is recorded in the sequence. All extreme point pairs are processed in this way, and their orientation angles are calculated for each pair to construct a complete angle sequence. This orientation angle sequence is used to further analyze the trend changes of surface features.

[0091] S202: Call the extreme value connection direction angle sequence to calculate the numerical difference between adjacent angles, compare the angle change value with the direction offset reference value according to the sequence order, filter the angle segment with the angle change value greater than the offset reference value, and obtain the direction angle offset segment data.

[0092] The directional offset benchmark value is set by adding a multiple of the standard deviation to the mean of the fluctuation distribution;

[0093] The extreme value concatenation function calls the angle values ​​in the direction angle sequence, and calculates the numerical difference between adjacent angle values ​​in turn. For example, for any two adjacent angles in the sequence... and Calculate the change in angle. All changing values A difference sequence is constructed, and then each change value is compared with the direction offset reference value item by item according to the sequence order. This point is the offset point. The reference value T for directional offset is calculated by adding a multiple of the standard deviation of the mean of the overall fluctuation distribution of the angle change values. Let the sequence... The mean is The standard deviation is Then there is Where k is the adjustment factor, set to 1.5. In an actual processing, if , Then the offset reference value is obtained. If a point has an angle change of 17°, which is obviously greater than the baseline value, it is determined to be an offset point. Then, all points that are greater than the offset baseline value are continuously combined into angle offset segments. For example, in the following difference sequence: [3.5, 7.2, 15.1, 16.3, 5.8, 4.1, 20.5, 22.7], items 3, 4, 7, and 8 are offset segments. The filtered angle offset segment data records are: segment 1: 15.1, 16.3, segment 2: 20.5, 22.7, and their original index positions in the angle sequence are marked. This process is completed by comparing the angle difference with the baseline value one by one to see if it meets the judgment condition of being greater than.

[0094] S203: Based on the offset value sequence in the direction angle offset segment data, statistically analyze the range of change and the degree of difference in the direction angle values ​​between consecutive segments, calculate the range of change and slope of multiple direction angles, and obtain the direction offset angle sequence of the casting surface.

[0095] Based on the offset value sequence in the direction angle offset segment data, the range of numerical changes in the continuous offset angle of each segment is statistically analyzed. That is, the difference between the maximum and minimum angles within each segment is calculated as the angle change amplitude. Let a certain offset angle sequence be... The range of change is Simultaneously calculate the standard deviation of the difference between two adjacent angles. This is used to assess the degree of fluctuation in the angle of that segment. Then, the slope range of the angle change is obtained by fitting a straight line or calculating the slope at the endpoints. Let the first and last angles be... The corresponding serial number is The slope of the change is For example, if the angle values ​​of a certain sequence are [13.2, 16.7, 18.9, 21.3], its variation range is... The slope is The amplitude and slope of the segment are recorded in the change sequence table. Finally, based on the combination of amplitude and slope statistics from multiple segments, a casting surface orientation offset angle sequence is constructed, and its position in the original image coordinates is marked for subsequent image structure reconstruction or regional feature recognition analysis.

[0096] Table 2: Example Table for Calculating Angle Offset of Casting Surface

[0097]

[0098] As shown in Table 2, the pairing results of multiple extreme points in the actual casting image show that the orientation angle fluctuates significantly. Combined with the benchmark value judgment method, it is found that some angle pairs belong to the offset segment, reflecting the significant change trend of the surface contour direction of the casting.

[0099] Specifically, the steps of S3 are as follows:

[0100] S301: Call the dual-channel orientation angle data of each coordinate point in the orientation offset angle sequence of the casting surface, match the orientation angle values ​​corresponding to the two channels according to the coordinate index, calculate the absolute difference between the two orientation angles under the same coordinate, and generate a coordinate angle difference sequence.

[0101] To retrieve the dual-channel orientation angle data for each coordinate point in the orientation offset angle sequence on the casting surface, it is necessary to first obtain the orientation angle data of channel 1 and channel 2 for each coordinate point on the casting surface from a scanning device or industrial control system, and then set the total number of channels on the casting surface. There are coordinate points, respectively to For each coordinate point, two orientation angle data are retrieved, i.e., the orientation angle sequence is... ,in Indicates the first The direction angle of channel 1 at each coordinate point. This indicates the direction angle of channel 2. During execution, it needs to be determined according to the coordinate point number. The process involves item-by-item matching. The order of data calls can be either directly read from the scanned data files or mapped and called in coordinate matrix form. The unit for the direction angle data is uniformly in degrees. For example, suppose some data obtained from scanning a casting is shown in Table 3. After matching the direction angle values ​​of two channels based on the coordinate index, the absolute difference is calculated for each pair of direction angles. Operations, for example, targeting ,like , Then there is Similarly, perform the difference calculation for each coordinate point to obtain a sequence of coordinate angle differences. Special attention should be paid to the fact that when the angle is greater than 180° or negative, the angle needs to be standardized to the range of [0, 180]. For example, if the calculated result of a certain angle is -5°, it should be converted to 5°. This process requires calling the direction angle data one by one and calculating the angle difference item by item. Finally, the corresponding angle difference sequence is formed for the next stage to determine whether there is a disturbance.

[0102] Table 3: Casting Orientation Angle and Angle Difference Table

[0103]

[0104] As shown in Table 3, the channel direction angles from coordinate points P1 to P6 and their corresponding angle differences have been matched and calculated, resulting in an angle difference sequence of {3.5, 2.5, 3.1, 4.1, 2.2, 0.6}. In this step, the "calculation" operation involves mapping the two channel data one-to-one and then taking their absolute difference, i.e., by taking... and The difference is then followed by the absolute value function; the precise action of this operation is to traverse the coordinate indices. ,extract , , then apply Completed; the "call" action specifically involves reading the orientation angle field of each point in the scanned data file or database, and the order must be consistent to ensure matching calculation results. This calculation result will serve as an important basis for subsequent determination of disturbances.

[0105] S302: Based on the coordinate angle difference sequence, extract the angle difference item by item and compare it with the angle difference threshold to determine whether the difference of each coordinate point exceeds the threshold. Record the coordinate point index that exceeds the threshold in spatial order to obtain the disturbed coordinate index set.

[0106] Based on the angle difference sequence obtained above Each angle difference needs to be extracted and compared with the set angle difference threshold. The angle difference threshold is set based on the surface machining accuracy requirements of the casting and the detection error range, and is set to... This value is derived from 1.5 times the upper limit of the machining consistency tolerance. It is obtained by sampling multiple groups of normal castings, statistically analyzing the upper limit of the angle difference, and multiplying it by an adjustment factor of 1.5. This factor is derived from empirical engineering adjustment to ensure that the identified disturbances have the necessary sensitivity. For example, if 90% of the angle differences in the normal samples fall within 2.0°, then the threshold is set to [value missing]. When performing a comparison, each item is evaluated one by one. Does it meet the requirements? In the current sequence, , , The remaining terms do not satisfy this condition, therefore only If the angle difference between three coordinate points exceeds a threshold, the corresponding coordinate point numbers must be recorded and combined to form a disturbance coordinate index set. The "judgment" operation in this process involves performing a "whether greater than" logical operation on each difference value and the threshold, returning a Boolean value, and filtering the coordinate point numbers. It then sequentially reads each element in the angle difference sequence, determining whether the value meets the condition of "greater than 3.0 degrees." If it does, the corresponding coordinate point index is added to the perturbation index set, arranged in the order of the original coordinate data, i.e., the order is... , , To ensure consistency with the spatial scanning order, the spatial position order can be compared with the spatial coordinates (such as 3D coordinates XYZ) of the original coordinate points. In applications, if the surface of a casting is the inner wall of a pipe, the coordinate points are distributed along the axial direction, and the corresponding index number is regarded as the order recorded from the inlet to the outlet. The final result of this step is the set of disturbed coordinate indices. .

[0107] S303: Call the marked coordinate points in the disturbance coordinate index set, combine the original coordinate data with the corresponding direction angle difference, add a direction offset attribute label to each marked point, and generate a set of disturbance elements on the casting surface.

[0108] Call the above set of perturbation coordinate indices The coordinates of the marked points are combined with the original angle data to add a direction offset attribute label to each marked point. During execution, each coordinate point in the set needs to be numbered and identified again, located to its original direction angle data, and its direction angles in channel 1 and channel 2 are read respectively. For example, correspond , The calculated directional offset is If so, the value is appended as a direction offset label to the point's attributes. This "append" operation is specifically implemented by constructing a structure or record object for each perturbation point that contains the original coordinate data, the original direction angle value, and the direction offset. For example, the structure's fields include the coordinate number and the original coordinate values ​​(such as X, Y, Z). , , This structure can be considered as a component element of the surface disturbance unit of the casting. Repeating the above steps, for... , Calculate separately , And construct the corresponding structure to form the final perturbation unit set {U1, U3, U4}, where each perturbation unit U i It contains the following fields: coordinate number, direction angle 1, direction angle 2, and offset, for example, U1={ , 35.2, 38.7, 3.5}, the “combination” action in this process is the joint processing of calling the original orientation angle data and calculating the angle difference, that is, locating the original orientation angle data of each point in the set, and then calling and calculating it again, executing the series of actions of “calling + matching + difference + addition”, and finally forming a complete set of casting surface disturbance units from the set of structures with disturbance information, which is used for subsequent processing or identification tasks. The final output result is the set of disturbance points with coordinate numbers and offset labels.

[0109] Specifically, the steps of S4 are as follows:

[0110] S401: Based on the set of perturbation elements on the surface of the casting, scan the element coordinates and detect the connectivity of the eight neighborhoods, record the number of elements and the geometric center, calculate the diagonal vertices of the circumscribed rectangle, and generate a dataset of connected region morphological features.

[0111] Based on the set of surface disturbance units on the casting, during execution, regions with abnormal grayscale values ​​are first identified in the surface image acquired by an industrial camera. These regions are then divided into disturbance units in the form of a two-dimensional pixel matrix. Each disturbance unit represents a group of pixel blocks with similar grayscale abrupt changes. For example, in an actual casting image, if the image size is 1000×1000 pixels, and there is a pore area with a diameter of approximately 15 pixels, its center grayscale value is 80, while the surrounding background grayscale value is 160, then the area with this difference exceeding 40 can be identified as a disturbance unit. Next, the two-dimensional coordinates of all disturbance units are traversed one by one in a scanning manner, and the eight-neighbor connection method is used to determine its relationship with pixels in the eight surrounding directions (up, down, left, right, and four diagonal directions). To determine whether two perturbation units belong to the same perturbation unit, a threshold for adjacency determination is set at the pixel level based on the grayscale difference. For example, if the grayscale difference threshold is set to 30, the perturbation unit is considered connected when the grayscale difference between any two adjacent pixels is less than 30. The perturbation unit is then merged with its neighboring region to form a connected region. After traversing all perturbation units, several sets of non-overlapping connected regions are obtained. Subsequently, the coordinates of all perturbation units within each connected region are recorded, and the geometric center position is calculated. The geometric center position is calculated by taking the arithmetic mean of the horizontal and vertical coordinates of all units. For example, if a connected region contains 5 perturbation units with pixel coordinates (102, 98), (103, 97), (104, 98), (104, 98), (105, 98), (106, 99), (107, 99), (108, 99), (109 ... Given (3, 99) and (102, 100), the x-coordinate of the geometric center is (102+103+104+103+102) / 5=102.8, and the y-coordinate is (98+97+98+99+100) / 5=98.4. The coordinates of the geometric center are (102.8, 98.4). Simultaneously, to extract the geometric features of this connected region, it is also necessary to calculate the coordinates of the diagonal vertices of its circumscribed rectangle, i.e., to count the minimum and maximum x and y coordinates of the connected region. For example, the minimum x-coordinate is 102 and the maximum is 104, and the minimum y-coordinate is 97 and the maximum is 100. Therefore, the coordinates of the diagonal vertices of the circumscribed rectangle are (102, 97) and (104, 100). These two points are defined as the top left and right corners. The lower corner vertex; In the process of generating the connected region morphological feature dataset, the number of units, geometric center coordinates, coordinates of the diagonal points of the circumscribed rectangle, and connectivity category number of each connected region need to be combined to form a data entry. For example, a data entry can be: [Region number 01, number of units 5, geometric center (102.8, 98.4), circumscribed rectangle vertices (102, 97)-(104, 100)]; In actual scenarios, if there are multiple casting images to be batch detected, the above feature data need to be stored in batches in the form of a two-dimensional array, and a structured input format for the data analysis module needs to be generated to facilitate subsequent index calculation and judgment processing. The feature data of the connected regions are finally summarized to form a complete morphological feature dataset.

[0112] Table 4: Data on the Morphological Characteristics of Connected Regions

[0113]

[0114] As shown in Table 4, the basic morphological characteristics of the two connected regions are recorded, which are used for subsequent calculation of disturbance intensity and defect screening.

[0115] S402: Call the connected region morphological feature dataset, calculate the path length of the Euclidean distance of the circumscribed rectangle as the path length value, count the ratio of the number of units to the area of ​​the circumscribed rectangle as the perturbation density value per unit area, combine the path length value and the perturbation density value as a two-parameter index, and generate a connected region perturbation intensity index set;

[0116] When reading the connected component morphological feature dataset, first extract the coordinates of the top-left and bottom-right vertices of each connected component, and then extract the range of the horizontal and vertical coordinates, denoted as . , Based on this, the square root of the sum of squares of the coordinate ranges is calculated, which is the basic Euclidean distance. For example, in region 01, , The Euclidean distance part is The path length is calculated using the following formula:

[0117] ;

[0118] in, This represents the path length value, in pixels (px). This represents the range of the x-axis coordinates, in pixels (px). This represents the y-axis range, in pixels (px). Represents the total number of connected components, dimensionless. Represents the area of ​​the circumscribed rectangle, in pixels (px). 2 , This represents the area correction factor, which is dimensionless and indicates the ratio of the actual average density to the reference density. It helps to mitigate deviations in values ​​caused by regional density anomalies. This represents the length of the scale adjustment, avoiding weight imbalances in index calculations due to scale regions. The unit is pixels (px). The reference area is represented by s, where s is the area of ​​the unit size. Represents the length standard.

[0119] Next, the number of units in this region and the area of ​​its circumscribed rectangle To obtain, among which ,Right now At this point, an area correction factor needs to be set. The setting method is the ratio of the average density of the region to the density of the ideal compact region, assuming the reference density is 1px. -2 (i.e., one perturbation unit per unit area), when the average perturbation density of the batch region is 0.25px -2 At that time, ,Will The absolute value of its deviation from the original number of units is Set the unit area px 2 (That is, each unit corresponds to one pixel area), length benchmark px, reference area px 2 As a log-normalized parameter, the perturbation density ρ is in units of pixels (px). -2 Unit labels are omitted in subsequent calculations.

[0120]

[0121] ,

[0122]

[0123] px, then:

[0124] ,

[0125] ,

[0126] :

[0127] px.

[0128] ,

[0129] The final dual indicators for region 01 are: ;

[0130] For region 02, , The Euclidean distance part is The area is Number of units ,set up Then the second item is:

[0131] ;

[0132] The third item is:

[0133] ;

[0134] The path length value is:

[0135] ;

[0136] The disturbance density value is The corresponding indicator for this region is ;

[0137] After performing the above steps sequentially on all connected regions, all dual-index values ​​need to be collected and stored in a structured manner. Each region corresponds to one index pair, forming a complete set of disturbance intensity indices. When the number of regions is large, it needs to be encapsulated in the form of a two-dimensional array, for example: ;

[0138] It is worth noting the path length value During execution, the actual results according to the formula are mostly distributed in the range of 1.0 to 50.0, with a perturbation density. Distributed between 0.01 and 1.0, the third term, which is adjusted by logarithmic scale, ensures that the weights of small-scale high-density regions are not unbalanced, while large-scale low-density regions are effectively distinguished due to the significant difference in the second term. This achieves a reasonable quantification of the perturbation intensity in different regions and provides a reliable indicator input for subsequent defect screening.

[0139] S403: Based on the set of disturbance intensity indices for connected regions, extract the path length and disturbance density per unit area item by item, and filter the connected regions that simultaneously satisfy the condition that the path length is greater than the length threshold and the disturbance density is greater than the density threshold to generate the surface defect region of the casting.

[0140] The length threshold and density threshold are set based on statistical analysis of the training data.

[0141] When performing a filtering operation on the set of disturbance intensity indicators, the path length value of each group of indicators is read first. With disturbance density value It performs a dual-condition judgment, with the screening criterion being that the path length value must be greater than a length threshold. The perturbation density value must be greater than the density threshold. During the threshold setting process, the threshold is set based on the statistical results of historical defect training samples. For example, 100 defect area samples are extracted from the training set, and their average path length is [value missing]. The standard deviation is Then the length threshold can be set to average perturbation density Standard deviation Then the density threshold is The set threshold is ;

[0142] Then, each indicator is evaluated item by item based on regional indicators. For example, the indicator for region 01 is... The path length does not meet the requirements. It was excluded; the indicator for region 02 was... The path length satisfies However, the density does not meet the requirements. Similarly, it is excluded; if region 03 exists, the indicator is... ,satisfy and If the condition is met, the region is retained; in practice, all regions are compared item by item according to this standard. and If both are true, the region number will be added to the defect region set, ultimately forming a number set such as {03, 07, 11}.

[0143] The key to this process lies in performing two judgment operations for each pair of indicators, which requires explicitly using a logical "AND" connection, i.e. If a region is identified as a defect, it is discarded; otherwise, it is discarded. Finally, a complete set of defect region numbers is obtained, which can be used by the structured module for report output or by the defect image positioning module for selecting defect region graphics.

[0144] Specifically, the steps in S5 are as follows:

[0145] S501: Based on the main axis direction of the defect area on the surface of the casting, the coordinates of the sampling points are set at fixed intervals. The gray values ​​of each coordinate point are extracted and sorted along the dual-channel grayscale image to generate a dual-channel grayscale sampling point sequence.

[0146] To determine the principal axis direction of the defect area on the casting surface, the outer boundary of the defect area must first be obtained through image segmentation. This process involves using grayscale thresholding to obtain a binary image, then using an edge tracking algorithm to extract a set of closed boundary points. The minimum bounding rectangle of this set is then calculated, and the direction of the long side of this rectangle is the principal axis direction of the area. After defining this direction, the sampling point positions need to be set. The starting point is determined by the edge point at one end of the principal axis direction, and 17 sampling points are sequentially set along the principal axis direction at 5mm intervals. Taking an 80mm crack region as an example, the starting point is set as the origin (0mm), and the ending point is 80mm. The coordinates are (0,0), (5,0), (10,0)...(80,0) in sequence. The sampling points are first mapped to the image coordinates and then calibrated using a calibration matrix. And the camera intrinsic parameters are back-projected, and the calculation formula is as follows: ,in For image coordinates, Let be spatial coordinates, and let be the two-dimensional coordinates of each point in the image. It needs to be converted into three-dimensional space through spatial mapping. Assuming a camera resolution of 0.1mm / pixel, the image coordinate transformation involves setting one point every 5mm, equivalent to setting one point every 50 pixels. Each sampling point is set to take one pixel to the left and right of the center, constructing a 3×1 pixel grayscale window, and reading the grayscale values ​​of three adjacent pixels, which are denoted as follows: The grayscale values ​​come from two channels: channel 1 for the thermal image and channel 2 for the visible light image. Sampling and sorting are performed independently within each channel. The sorting operation arranges the three grayscale values ​​in ascending order. If the grayscale value of a thermal imaging sampling point is [145, 138, 142], after sorting it will be [138, 142, 145], denoted as... Similarly, the visible light image is [110, 117, 113], sorted as [110, 113, 117]. The sorted grayscale set of each point... Store in sequence ,Right now , It is important to note that the original range of grayscale values ​​needs to be standardized. Normalization processing should be performed on images from different sources, using a linear mapping method. Let the normalization interval for grayscale values ​​be [0, 255]. If the original heatmap has a value range of [120, 180], then a certain grayscale value... The normalization result is:

[0147] ;

[0148] Rounding to 77, similar to processing the grayscale values ​​of all sampled points in each channel, we obtain normalized sequences for both channels. To ensure spatial consistency of sampled points in both channels, we need to verify the pixel position information after mapping. We select a 3×1 window containing the sampled points and calculate the mean values ​​of the grayscale windows for channel 1 and channel 2 respectively. Let the mean value of window 1 be... The mean of window 2 is ,like If there is an offset between channels, the sampling point positions need to be adjusted until the difference is less than or equal to 5. Then, the samples are resampled and the grayscale is extracted. Finally, the sampling data that matches the thermal imaging sequence and the visible light sequence is obtained. The sorting operation reflects the grayscale distribution structure of the micro-region of each sampling point. The sorted data sequence contains both positional order and single-point local texture features, which can be used as the basis for constructing gradient changes. Finally, the sorted grayscale value set corresponding to 17 sampling points is obtained and stored in the grayscale sampling point sequences of the two channels respectively. The sampling point sequences of the two channels need to ensure that the sampling point numbers in the main axis direction are consistent to ensure the consistency and accuracy of the data structure in subsequent analysis.

[0149] Table 5: Example of grayscale value extraction from sampling points (Channel 1: Thermal imaging, Channel 2: Visible light)

[0150]

[0151] As shown in Table 5, the gray values ​​of three adjacent pixels were extracted from the thermal imaging channel and the visible light channel under the same sampling point number and arranged in ascending order. The results were used to form a channel sampling point sequence for subsequent gradient analysis and spectrum construction. This dataset provides a consistent basis for the subsequent detection stage.

[0152] S502: Call the dual-channel grayscale sampling point sequence, calculate the grayscale value change of adjacent sampling points as the gradient value, and synchronously superimpose the gradient changes of the dual channels according to the sampling position to construct a two-dimensional distribution map with the sampling position on the horizontal axis and the gradient change on the vertical axis, and generate a gradient spectrum dataset.

[0153] After extracting and sorting the gray values ​​of the sampling points along the principal axis, it is necessary to construct a gradient spectrum based on the sampling point sequence. First, define the adjacent gradient changes of each sampling point along the principal axis. The gradient is defined as the difference sequence between the sorted gray values ​​of two adjacent sampling points, i.e., let the th... After sorting the sampling points, the gray value is , No. Each sampling point is Then, three-dimensional gradient components between adjacent sampling points can be constructed:

[0154] ,

[0155] For example, if the sorted gray values ​​of the first and second sampling points in channel 1 are respectively: - - ;

[0156] Then its gradient components are:

[0157] ;

[0158] This difference sequence forms the basic elements of the gradient spectrum. This operation is performed between every two adjacent sampling points within a channel, ultimately yielding 16 sets of gradient components, which are then stored in the gradient spectrum sequence. This gradient spectrum describes the texture variation trend of the defect region along the principal axis. An increasing gradient indicates drastic texture changes, while a gradient close to zero indicates that the texture of the region tends to be stable. This type of information is of high reference value for boundary identification and morphological analysis of casting defects such as cracks and sand holes.

[0159] The constructed gradient spectrum not only includes grayscale variation trends but also indirectly reflects the continuity and abrupt changes in the microstructure of the material surface. Further analysis can be conducted by combining gradient variation statistical characteristics (such as mean, variance, and maximum gradient amplitude) to quantify the complexity and boundary clarity of the defect region. After constructing independent gradient spectra for channels 1 and 2, cross-channel comparative analysis can be performed to determine the consistency of the response of the same physical region under thermal imaging and visible light. If one channel exhibits abrupt changes while another channel does not show similar gradient behavior, it indicates that there is an abnormality in thermal conduction or inconsistent surface structure in that region.

[0160] To further enhance the representational ability of gradient spectra in defect identification, a fusion gradient change calculation model can be introduced, extending the traditional sorted gray-level difference into a composite index that includes image statistical features and spatial weights. This fusion model enhances the response to different types of defects through a multi-dimensional parameter adjustment mechanism. The specific calculation formula is as follows:

[0161] ;

[0162] in, This represents the fusion gradient change at the k-th sampling point, measured in gray / px. The gradient change guides spectral enhancement and defect feature extraction, enabling the differentiation of different defect types without introducing a neural network structure. The dynamic difference coefficient represents channel c. The mean offset coefficient representing channel c. This represents the grayscale measurement value of the k-th sampling point in channel c, in units of gray. This represents the local grayscale average value of channel c, expressed in gray. This represents the spatial attenuation factor of channel c, expressed in pixels (px). This represents the sampling interval of channel c. This represents the minimum spacing compensation for channel c, expressed in pixels (px). The signal-to-noise suppression adjustment coefficient represents channel c. represents the local grayscale standard deviation of channel c, in gray.

[0163] Example calculation (thermal imaging channel) ):

[0164] Assumption: , , -Parameter settings: , , , , , .

[0165] Substitute into the formula:

[0166] ;

[0167] Therefore, the fusion gradient value is 8.5gray / px, which will be used for subsequent fusion gradient spectrum construction.

[0168] This calculation method combines three core types of information: grayscale difference (reflecting the changing trend of adjacent points), grayscale offset (reflecting the difference between the current point and the local background), and local noise intensity (measuring the texture complexity of the sampling area). It also uses a spatial weighting factor for scale normalization to balance global stability and local sensitivity. This fused gradient demonstrates stronger defect demarcation capabilities in practical applications, and is particularly suitable for identifying regions with blurred boundaries or indistinct texture continuity.

[0169] After the fusion gradient calculation is completed, a fusion gradient spectrum sequence can also be constructed. This sequence not only reflects the grayscale change pattern along the main axis, but also integrates multi-scale statistical features, which is the basis for constructing the spectral feature map and subsequent multi-channel fusion recognition model.

[0170] S503: Based on the gradient spectrum dataset, calculate the cosine similarity between the local frequency and the reference spectrum, filter low similarity regions and match them with the defect type library, and output the surface defect type and coordinates of the casting.

[0171] After constructing the fused gradient spectrum of the two channels, it is necessary to further extract the statistical and frequency domain features of the fused gradient spectrum and construct a similarity model to achieve defect region discrimination and type identification. (Fused gradient spectrum sequence) While reflecting the grayscale variation along the main axis, the sequence also includes frequency variation signals. To extract the periodic structure and noise characteristics, a Fast Fourier Transform (FFT) is first performed on the sequence to obtain its spectrum vector. .

[0172] Next, to achieve automatic defect type identification, a benchmark spectrum template library needs to be introduced. Each template The typical spectral morphology corresponding to a common defect (such as linear cracks, sand holes, hot spots, surface oxidation, etc.).

[0173] Local spectrum for each sampling region This can be achieved by calculating its cosine similarity to the reference spectrum:

[0174] ;

[0175] For all templates Perform a traversal, taking the defect type corresponding to the highest similarity as the candidate category. If the highest similarity is lower than a set threshold, the candidate category is removed. If the region is identified as a "suspected novel or hybrid defect", it will be included in the training dataset for manual review or adaptive update of the model.

[0176] For example, if the spectrum of a certain fusion spectrum is:

[0177] ;

[0178] With spectral template of trachoma The result after calculating the cosine similarity is: If so, the current area can be determined to be a trachoma-type defect.

[0179] In image space, regions with low similarity (e.g.) By marking the corresponding sampling locations and combining them with the coordinate mapping of the original image, the set of coordinates of the suspected defect area can be located.

[0180] ;

[0181] Finally, by integrating statistical features (such as average gradient, variance, and range), spectral features (such as dominant frequency and energy concentration) and similarity scores, a joint feature vector for each sampling region is formed, and matched with the labels in the defect type library to output the defect type and its spatial coordinates.

[0182] like Figure 2 As shown, an inorganic mineral casting defect visual inspection system includes:

[0183] The image acquisition module is used to perform non-overlapping scanning of the dual-channel grayscale image of the casting surface using a multi-scale adaptive window size, acquire the pixel coordinates corresponding to the grayscale value of each window, generate a set of extreme point coordinates, and transmit them to the extreme value extraction module.

[0184] The extreme value extraction module is used to extract continuous extreme points from the extreme point coordinate set and construct a path. It calls the path sorting function to sort the path coordinates, uses the Hough transform algorithm to calculate the direction angle between two points in the path, outputs the direction offset angle sequence, and passes it to the direction resolution module.

[0185] The direction analysis module is used to perform inter-channel direction fluctuation judgment based on the direction offset angle sequence. It uses the angle difference operation function to calculate the corresponding coordinate direction angle offset, determines whether it exceeds the threshold and counts the number of abnormal points. If the number of abnormal points exceeds the limit, it marks the corresponding window as a disturbance area, outputs a set of disturbance units, and passes it to the disturbance identification module.

[0186] The disturbance identification module is used to perform spatial clustering detection on the set of disturbance units. It uses a connected subgraph algorithm to cluster eight neighboring regions, calls a region filtering function to evaluate whether the length of the connected region and the disturbance density meet the identification conditions, generates a high-confidence defect region, and passes it to the defect judgment module.

[0187] The defect determination module is used to extract frequency features from high-confidence defect areas, collect grayscale sequences along the main axis and calculate gradients, perform spectrum conversion to identify frequency fluctuations, determine the defect type, and output the surface defect type and coordinates of the casting.

[0188] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in the present invention should be included within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.

Claims

1. A visual inspection method for defects in inorganic mineral castings, characterized in that, Includes the following steps: S1: A multi-scale adaptive window is used to perform non-overlapping scanning of the dual-channel grayscale image of the casting surface. The window size is dynamically adjusted according to the local grayscale gradient. The dual-channel extreme points are extracted and fused to generate a set of extreme point coordinates on the casting surface. S2: Based on the set of extreme point coordinates on the surface of the casting, the coordinates of the extreme points in the continuous window are arranged in space, and the direction angle of the line connecting adjacent points is calculated by Hough transform to generate a sequence of direction offset angles on the surface of the casting. S3: Call the casting surface direction offset angle sequence, perform offset calculation on the dual-channel same coordinate direction angle, if the offset exceeds the angle difference threshold, mark it as a disturbance unit, and obtain the casting surface disturbance unit set; S4: Based on the set of surface disturbance units of the casting, the connected component analysis algorithm is used to connect adjacent units into eight neighborhoods, and the length of the connected path and the number of disturbances per unit area are calculated. If both are greater than the set value, it is determined to be a defect area on the surface of the casting. S5: Based on the surface defect area of ​​the casting, extract dual-channel grayscale sampling points at equal intervals along the main axis, analyze the grayscale sequence and perform gradient offset calculation, construct a gradient spectrum, match the frequency fluctuation area, and output the surface defect type and coordinates of the casting.

2. The method for visual inspection of defects in inorganic mineral castings according to claim 1, characterized in that, The rules for spatial arrangement affect the configuration strategy of Hough transform parameters, and the two work together to determine the accuracy and stability of orientation angle detection. The angular accuracy of the Hough transform is matched with the measurement accuracy; The angle difference threshold is set based on the equipment noise level and measurement accuracy, and is in degrees. It is limited by Min-Max normalization. The settings for the length of the connected path and the number of perturbations per unit area are set based on training data statistics. The connected component analysis algorithm clusters the surface disturbance units of the casting and identifies the connected regions that constitute a complete defect. The set of extreme point coordinates on the casting surface specifically refers to the distribution coordinates of extreme points. The casting surface directional offset angle sequence includes directional change frequency, angular offset amplitude, and directional continuity index. The casting surface disturbance unit set specifically includes disturbance unit spatial density, disturbance unit morphological characteristics, and disturbance unit local gradient value. The high-confidence defect region on the casting surface includes region connectivity length, number of disturbances per unit area, and region confidence level. The casting surface defect type and coordinates include defect type label, defect location coordinates, and frequency fluctuation mode.

3. The visual inspection method for defects in inorganic mineral castings according to claim 1, characterized in that, The specific steps of S1 include: S101: A multi-scale adaptive window is used to scan the dual-channel grayscale image of the casting surface in a non-overlapping manner, extract all pixel grayscale values ​​of the two grayscale channels in each window, calculate the range of grayscale gradient change in the channel, compare it with the gradient distribution threshold, dynamically adjust the size of the current window, and generate a multi-scale grayscale gradient window set. The initial size of the multi-scale adaptive window is set empirically based on the image resolution and defect scale, and the sensitivity of window adjustment is determined based on the overall gradient distribution characteristics of the image. The gradient distribution threshold is dynamically adjusted based on the local statistical values ​​of the current scanned area. S102: Call the window coordinates and corresponding gray values ​​in the multi-scale gray gradient window set, determine whether the pixel gray value reaches the upper and lower limits of the channel interval in the two channels, select the coordinate points that meet the conditions at the same time, and after removing the image boundary and duplicate items, obtain the boundary gray extreme value coordinate point set. S103: Based on the pixel coordinates in the set of boundary gray-scale extreme coordinate points, coordinates are integrated in the order of their corresponding window regions, and the extreme point position information within the differentiated window regions is summarized to obtain the set of extreme point coordinates on the casting surface.

4. The method for visual inspection of defects in inorganic mineral castings according to claim 3, characterized in that, The specific steps of S2 include: S201: Based on the coordinates of each continuous window in the set of extreme point coordinates on the surface of the casting, extract adjacent extreme point pairs, record the coordinate difference of the point pairs in the row and column directions, decompose the vector into horizontal and vertical vector components, calculate the component ratio and analyze the direction angle, and generate an extreme value connection direction angle sequence. S202: Call the angle values ​​in the extreme value connection direction angle sequence, calculate the numerical difference between adjacent angles, compare the angle change value with the direction offset reference value according to the sequence order, filter the angle segment with the angle change value greater than the offset reference value, and obtain the direction angle offset segment data. The directional offset benchmark value is set by adding a multiple of the standard deviation to the mean of the fluctuation distribution to determine the offset benchmark. S203: Based on the offset value sequence in the directional angle offset segment data, statistically analyze the range of directional angle value changes and the degree of difference fluctuation between consecutive segments, calculate the range of directional angle changes and the range of change slopes for multiple segments, and obtain the directional offset angle sequence of the casting surface.

5. The method for visual inspection of defects in inorganic mineral castings according to claim 4, characterized in that, The specific steps of S3 include: S301: Call the dual-channel orientation angle data of each coordinate point in the orientation offset angle sequence of the casting surface, match the orientation angle values ​​corresponding to the two channels according to the coordinate index, calculate the absolute difference between the two orientation angles under the same coordinate, and generate a coordinate angle difference sequence. S302: Based on the coordinate angle difference sequence, extract the angle difference item by item and compare it with the angle difference threshold to determine whether the difference of each coordinate point exceeds the threshold. Record the coordinate point index that exceeds the threshold in spatial order to obtain the disturbed coordinate index set. S303: Call the marked coordinate points in the disturbance coordinate index set, combine the original coordinate data with the corresponding direction angle difference, add a direction offset attribute label to each marked point, and generate a set of disturbance units on the casting surface.

6. The method for visual inspection of defects in inorganic mineral castings according to claim 5, characterized in that, The specific steps of S4 include: S401: Based on the set of perturbation units on the surface of the casting, scan the unit coordinates and detect the connectivity of the eight neighborhoods, record the number of units and the geometric center, calculate the diagonal vertices of the circumscribed rectangle, and generate a dataset of connected region morphological features. S402: Call the connected region morphological feature dataset, calculate the path length of the Euclidean distance of the circumscribed rectangle as the path length value, and the ratio of the number of statistical units to the area of ​​the circumscribed rectangle as the perturbation density value per unit area. Combine the path length value and the perturbation density value as a two-parameter index to generate a connected region perturbation intensity index set. S403: Based on the set of disturbance intensity indices for connected regions, extract the path length and disturbance density per unit area item by item, and filter the connected regions that simultaneously satisfy the condition that the path length is greater than the length threshold and the disturbance density is greater than the density threshold to generate the surface defect region of the casting. The length threshold and density threshold are set based on training data statistics.

7. The method for visual inspection of defects in inorganic mineral castings according to claim 6, characterized in that, The path length is calculated using the following formula: ; in, Represents the path length value. Represents the range of the x-axis coordinate. Represents the range of the y-axis coordinate. Represents the total number of connected components. Represents the area of ​​the circumscribed rectangle. The area correction factor represents the ratio of the actual average density to the reference density, mitigating deviations in values ​​caused by regional density anomalies. This represents the scale adjustment length, avoiding weight imbalances in index calculations due to scale regions. The reference area is represented by s, where s is the area of ​​the unit size. Represents the length standard.

8. The method for visual inspection of defects in inorganic mineral castings according to claim 6, characterized in that, The specific steps of S5 include: S501: Based on the main axis direction of the defect area on the surface of the casting, the coordinates of the sampling points are set at fixed intervals, and the gray values ​​of each coordinate point are extracted and sorted along the dual-channel grayscale image to generate a dual-channel grayscale sampling point sequence. S502: Call the dual-channel grayscale sampling point sequence, calculate the grayscale value change of adjacent sampling points as the gradient value, and synchronously superimpose the dual-channel gradient changes according to the sampling position to construct a two-dimensional distribution map with the sampling position on the horizontal axis and the gradient change on the vertical axis, and generate a gradient spectrum dataset. S503: Based on the gradient spectrum dataset, calculate the cosine similarity between the local frequency and the reference spectrum, filter low similarity regions and match them with the defect type library, and output the surface defect type and coordinates of the casting.

9. The method for visual inspection of defects in inorganic mineral castings according to claim 8, characterized in that, The gradient change is calculated using the following formula: ; in, This represents the fusion gradient change at the k-th sampling point. The gradient change is used to guide spectral enhancement and defect feature extraction, distinguishing between different types of defects without introducing a neural network structure. The dynamic difference coefficient represents channel c. The mean offset coefficient representing channel c. This represents the grayscale measurement value of the k-th sampling point in channel c. This represents the local grayscale average value of channel c. The spatial attenuation factor represents channel c. This represents the sampling interval of channel c. This represents the minimum spacing compensation amount for channel c. The signal-to-noise suppression adjustment coefficient represents channel c. Let be the local grayscale standard deviation of channel c.

10. A visual inspection system for defects in inorganic mineral castings, characterized in that, The system is used to implement the visual inspection method for defects in inorganic mineral castings according to any one of claims 1-9, the system comprising: The image acquisition module is used to perform non-overlapping scanning of the dual-channel grayscale image of the casting surface using a multi-scale adaptive window size, acquire the pixel coordinates corresponding to the grayscale value of each window, generate a set of extreme point coordinates, and transmit them to the extreme value extraction module. The extreme value extraction module is used to extract continuous extreme value points from the extreme value point coordinate set and construct a path, call the path sorting function to sort the path coordinates, use the Hough transform algorithm to calculate the direction angle between two points in the path, output the direction offset angle sequence, and pass it to the direction analysis module. The direction analysis module is used to perform inter-channel direction fluctuation judgment based on the direction offset angle sequence, calculate the corresponding coordinate direction angle offset using the angle difference operation function, determine whether it exceeds the threshold and count the number of abnormal points. If the number of abnormal points exceeds the limit, the corresponding window is marked as a disturbance area, and a set of disturbance units is output and transmitted to the disturbance identification module. The disturbance identification module is used to perform spatial clustering detection on the set of disturbance units. It uses a connected subgraph algorithm to cluster eight neighboring regions, calls a region filtering function to evaluate whether the length of the connected region and the disturbance density meet the identification conditions, generates a high-confidence defect region, and passes it to the defect judgment module. The defect determination module is used to extract frequency features from the high-confidence defect area, collect grayscale sequences along the main axis and calculate the gradient, perform spectrum conversion to identify frequency fluctuations, determine the defect type, and output the surface defect type and coordinates of the casting.