Casting surface defect detection method and system
By constructing a multi-scale contrast feature cube and calculating the defect saliency score, the problem that a single window size is difficult to take into account different defect features in the detection of surface defects of castings is solved, and more accurate defect identification and higher detection system reliability are achieved.
Patent Information
- Application Number
- CN202511484635.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-17
- Publication Date
- 2025-11-18
- Estimated Expiration
- 2045-10-17
AI Technical Summary
In existing technologies, the size of surface defects in castings varies greatly, and a single fixed window size is insufficient to take into account different defect characteristics. This makes it difficult to balance missed detections and false alarms, affecting the practicality and reliability of the detection system.
By constructing a multi-scale contrast feature cube, using a predefined set of analysis window scales, multi-scale feature spectral lines of pixels are extracted, peak saliency and scale locality are calculated, and these indicators are combined to calculate the defect saliency score, construct a defect saliency map and perform binarization to mark the defect region.
It improves adaptability to defects of different sizes, effectively balances the situation of missed detection and false alarm, and improves the identification capability of the detection system.
Smart Images

Figure CN120976216A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of image processing. More particularly, the present application relates to a casting surface defect detection method and system. BACKGROUND
[0002] Casting process is a very basic and key link in manufacturing industry. In many manufacturing processes, casting process is at the beginning or important support position, providing basic components or semi-finished products for subsequent product manufacturing. The quality of casting products will directly affect the safety and reliability of the final product, and there may be some small defects on the surface of the casting, such as cracks, pores, etc. These defects are very subtle and difficult to find by naked eye.
[0003] In the automatic detection technology based on machine vision, gray level co-occurrence matrix is a commonly used texture analysis tool. By calculating the gray space distribution of pixel pairs in the local area of the image, feature parameters such as contrast, energy, and homogeneity are extracted, and whether the surface of the detected object has defects is judged according to these parameters.
[0004] However, the size of the casting surface defects varies greatly, and a single fixed window size cannot simultaneously consider the characteristics of defects of different sizes, which makes it difficult to achieve an ideal balance between missed detection and false positives, thereby affecting the practicality and reliability of the detection system. SUMMARY
[0005] To solve the above technical problems that the size of the casting surface defects varies greatly, a single fixed window size cannot simultaneously consider the characteristics of defects of different sizes, missed detection and false positives are difficult to balance, and the practicality and reliability of the detection system are affected, the present application provides solutions in the following aspects.
[0006] In a first aspect, a casting surface defect detection method comprises: obtaining a gray scale image of a casting surface to be detected, and constructing a multi-scale contrast feature cube on the gray scale image based on a pre-defined analysis window scale set; based on each pixel point in the cube, extracting a contrast feature sequence of the pixel point along the scale dimension to form a multi-scale feature spectrum line of the pixel point, and calculating a peak saliency and scale locality of the multi-scale feature spectrum line; combining the peak saliency and the scale locality to calculate a defect saliency score of each pixel point, combining the defect saliency scores of all pixel points to construct a defect saliency map, performing binaryzation processing on the defect saliency map, determining pixel points with a defect saliency score higher than a pre-set threshold as defect points, and constructing a defect region, and marking the position of the defect on the gray scale image according to the defect region.
[0007] Preferably, the set is defined as a set containing multiple odd-numbered side lengths as the scale of the analysis window.
[0008] Preferably, the construction process of the cube includes: For each scale in the set, an analysis window is constructed with each pixel in the grayscale image as the center, the grayscale co-occurrence matrix within the analysis window is obtained, the contrast feature value of the analysis window is calculated based on the grayscale co-occurrence matrix, and all pixels in the grayscale image are traversed to generate a complete contrast feature map under the analysis window. Stack the complete contrast feature maps under all analysis windows along the scale dimension, record the contrast feature values of each spatial location under all analysis windows, and form a multi-scale contrast feature cube.
[0009] Preferably, the process of obtaining the peak significance includes: Calculate the average Pearson correlation coefficient between the multi-scale feature spectral lines of a pixel and the multi-scale feature spectral lines of its eight neighbors, and use this as the spatial consistency of the pixel; obtain the local maximum points of the multi-scale feature spectral lines according to preset recognition conditions; and statistically analyze the maximum value and median of the multi-scale feature spectral lines. The peak significance of the multi-scale feature line at a pixel is calculated as the product of the ratio of the maximum value to the median of the eigenvalues on the multi-scale feature line, the spatial consistency, and the number of local maxima on the multi-scale feature line.
[0010] Preferably, the process of obtaining the scale locality includes: Based on the distribution of contrast eigenvalues on multi-scale feature spectral lines, the product of the calculated half-peak width and the high-value non-uniform distribution coefficient is used as the scale locality of the multi-scale feature spectral lines of the pixel.
[0011] Preferably, the process of obtaining the scale locality includes: The distribution of contrast feature energy at each scale is calculated, and then the scale entropy is calculated. The reciprocal of the scale entropy is used as the scale locality of the multi-scale feature spectral lines of the pixel.
[0012] Preferably, the process for obtaining the defect salience score is as follows: The product of the peak significance and the scale locality is used as the defect significance score.
[0013] Preferably, the process for obtaining the defect salience score is as follows: The peak significance and the scale locality are assigned corresponding weights respectively, and the peak significance and the scale locality are weighted and summed to obtain the defect significance score.
[0014] In a second aspect, a casting surface defect detection system includes a processor and a memory, wherein the memory stores computer program instructions that, when executed by the processor, implement any of the casting surface defect detection methods described above.
[0015] The present invention has the following beneficial effects: 1. This invention constructs a multi-scale contrast feature cube and utilizes a predefined set of analysis window scales to cover multiple different scales (especially including multiple odd-numbered side lengths as analysis window scales), avoiding the problem that a single fixed window size cannot adequately capture surface defect features of different sizes. Analysis windows of different scales can capture defect information from multiple dimensions, improving adaptability to defects of various sizes.
[0016] 2. Contrast feature sequences of pixels are extracted along the scale dimension to form multi-scale feature spectra, and peak saliency and scale locality are calculated. Peak saliency comprehensively considers the spatial consistency between multi-scale feature spectra and neighboring spectra, the number of local maxima, and the ratio of the maximum eigenvalue to the median, highlighting the significant features of true defect regions at multiple scales. Scale locality measures the concentration of features along the scale dimension using different methods (such as the product of half-peak width and high-value non-uniform distribution coefficient, the inverse of scale entropy, etc.). Peak saliency and scale locality are combined (product or weighted summation) to calculate the defect saliency score, constructing a defect saliency map and performing binarization. This comprehensive calculation method, integrating multi-scale features and multiple indicators, can more accurately determine whether a pixel is a defect point, effectively balancing false negatives and false negatives, and improving the detection system's ability to identify different defect features. Attached Figure Description
[0017] Figure 1 This is a flowchart of steps S1-S3 in a casting surface defect detection method according to an embodiment of the present invention.
[0018] Figure 2 This is a structural block diagram of a casting surface defect detection system according to an embodiment of the present invention. Detailed Implementation
[0019] The technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are some embodiments of the present invention, but not all embodiments.
[0020] Reference Figure 1 A method for detecting defects on casting surfaces includes steps S1-S7, as detailed below: S1: Obtain the grayscale image of the casting surface to be inspected, and construct a multi-scale contrast feature cube on the grayscale image based on a predefined set of analysis window scales.
[0021] In one embodiment, a high-resolution industrial camera is used to vertically image the surface of a casting fixed at the inspection station under uniform and controllable ring-shaped LED lighting conditions. The resolution of the image acquisition system is set according to the casting size and the minimum detectable defect requirement, ensuring that the smallest defect in the image occupies at least a 3×3 pixel area so that minute defects can be accurately detected subsequently.
[0022] The acquired images are denoised and homogenized to create grayscale images suitable for subsequent analysis. The image's 256 grayscale levels (0-255) are then mapped to 16 levels (0-15) to reduce computation while retaining sufficient grayscale information for analysis.
[0023] It should be noted that surface defects in castings often have unique local characteristics, such as abrupt changes in grayscale at the edge of cracks or localized reductions in grayscale in pores. Window analysis can quantify these local characteristics by setting a fixed-size window, sliding it across the image, and statistically analyzing the pixels within the window.
[0024] However, defects on the surface of castings vary in size, ranging from microcracks at the micrometer level to porous areas at the millimeter level. Defects of different scales require windows of different sizes for accurate detection. A single-scale analysis window cannot simultaneously accommodate defects of different scales, while multi-scale analysis can calculate the contrast characteristics at each scale by setting windows of different sizes, thereby comprehensively capturing information about defects at different scales.
[0025] In one embodiment, a set of analysis window scales is defined, which is a set of multiple odd-numbered side lengths used as analysis window scales. This set should cover a range characterizing from the smallest defects to larger background textures. For example, this set includes side lengths of 3, 5, 7, 9, 11, 13, and 15. The selection of the scale set is optimized based on the typical defect size distribution and surface texture characteristics of the casting to be inspected, with the minimum scale slightly smaller than the size of the target smallest defect, and the maximum scale covering the period of typical background textures.
[0026] Furthermore, for each scale in the above set, an analysis window corresponding to each pixel in the grayscale image is constructed at each scale. For any pixel within an analysis window, grayscale co-occurrence matrices in four directions (0 degrees, 45 degrees, 90 degrees, and 135 degrees) are calculated. These grayscale co-occurrence matrices describe the spatial dependencies of grayscale levels in the grayscale image and reflect the texture information of the image.
[0027] Furthermore, the gray-level co-occurrence matrices in the four directions are averaged to obtain a rotation-invariant gray-level co-occurrence matrix. This is because defects on the casting surface can appear in any direction. If only the gray-level co-occurrence matrix in a single direction is calculated, the detection results will heavily depend on the relative angle between the defect and the analysis direction, leading to directional missed detections. By averaging the gray-level co-occurrence matrices in the four main directions, the influence of image orientation on texture feature extraction is eliminated, making the feature description rotationally invariant and improving the reliability and applicability of the detection. At the same time, this processing method maintains feature robustness while avoiding the excessive computational complexity caused by calculating all possible directions, achieving an optimal balance between detection performance and computational efficiency.
[0028] Based on the averaged gray-level co-occurrence matrix, the contrast feature value of the corresponding analysis window is calculated. The contrast feature value is used to quantify the intensity of gray-level changes in local areas of the image. A larger contrast value indicates that the gray-level changes in the local area are drastic, with obvious edge or texture abrupt changes, usually corresponding to surface defect areas such as crack edges or pore boundaries; a smaller contrast value indicates that the gray-level changes in the local area are gradual, with uniform texture, usually corresponding to normal casting surface areas.
[0029] By traversing all pixels in the grayscale image, a complete contrast feature map is generated for each analysis window.
[0030] Finally, all complete contrast feature maps are stacked along the scale dimension to obtain a multi-scale contrast feature cube, which fully records the contrast feature values of each spatial location in the grayscale image under all analysis windows.
[0031] In summary, the above operations ultimately yield a grayscale image of the casting surface to be inspected, and a multi-scale contrast feature cube is constructed on the grayscale image.
[0032] S2: Based on each pixel in the cube, extract the contrast feature sequence of the pixel along the scale dimension to form the multi-scale feature spectrum of the pixel, and calculate the peak significance and scale locality of the multi-scale feature spectrum.
[0033] After obtaining the multi-scale contrast feature cube, multi-scale feature analysis is performed on each pixel, that is, the feature change pattern of each pixel under different observation ranges (scales) is observed to identify possible surface defects. By recording the feature changes of each point under multiple observation ranges from fine to broad, the difference in feature changes between real defects and normal surface areas is utilized to improve the accuracy and reliability of defect identification.
[0034] In one embodiment, a specific pixel is selected and its spatial position is kept unchanged. The contrast feature value of the pixel at each scale is obtained in the order of each scale in the analysis window scale set. The feature values corresponding to all scales are arranged in ascending order of scale to form a one-dimensional vector, i.e., multi-scale feature spectral lines.
[0035] Furthermore, the average Pearson correlation coefficient between the multi-scale feature spectral lines of the pixel and the multi-scale feature spectral lines of its eight neighboring pixels is calculated as the spatial consistency of the pixel. Real defects typically exhibit spatial continuity, with their feature spectral lines showing high similarity within their neighborhood; random noise, on the other hand, lacks this spatial consistency. This metric can eliminate the interference of random noise and improve the accuracy of defect identification.
[0036] Furthermore, in order to assess whether the feature changes of each pixel form a significant single-peak abrupt change, the difference between the feature intensity of that point at the optimal observation scale and the overall average level is compared, and the consistency of the surrounding area is used for verification to determine whether there is a significant abrupt change.
[0037] In one embodiment, for a certain scale (excluding the first and last points) on a multi-scale feature spectrum, the following two identification conditions must be met simultaneously to be determined as a local extremum point: 1. Left saliency condition: The feature value of the current scale must be significantly greater than the feature value of the left neighboring scale, and the difference between the feature value of the current scale and the feature value of the left neighboring scale must be at least 20% of the maximum feature value of the left and right neighbors (default ratio).
[0038] 2. Right-side saliency condition: The eigenvalue at the current scale must be significantly greater than the eigenvalue at the right-side adjacent scale, and the difference between the eigenvalue at the current scale and the eigenvalue at the right-side adjacent scale must be at least 20% of the maximum eigenvalue in the left and right neighborhoods (default ratio). Since the characteristic spectral lines of the defect region exhibit obvious narrow-band spike characteristics at specific scales, and high values only appear at a few scales that match the defect size, the possible defect scale can be preliminarily located by identifying local extreme points.
[0039] Additionally, obtain the maximum and median values of the eigenvalues on the multi-scale characteristic spectrum.
[0040] Furthermore, the product of the ratio of the maximum value to the median of the eigenvalues on the multi-scale feature spectrum, the spatial consistency, and the number of local maximum points of the multi-scale feature spectrum is taken as the peak significance of the multi-scale feature spectrum of the pixel.
[0041] The ratio of the maximum to the median eigenvalue on a multi-scale feature spectral line measures whether the contrast peak of the pixel is significantly higher than the background baseline at multiple scales. The contrast of a defective region will suddenly increase at a specific scale, with this ratio being much greater than 1, while the background will fluctuate smoothly, with this ratio close to 1. The number of local maxima on the multi-scale feature spectral line is used to determine whether the spectral line is single-peaked or double-peaked. By calculating the peak significance, a comprehensive judgment can be made as to whether a pixel in the grayscale image belongs to a minor defect or background texture. The larger the peak significance, the more likely the point is to be a defect; conversely, the smaller the significance, the more likely the point corresponds to background or noise.
[0042] In one embodiment, half of the maximum eigenvalue on the multi-scale characteristic spectral line is first selected as the first reference. This is because this value represents half the height of the peak of the multi-scale characteristic spectral line, objectively reflecting the main distribution range of the characteristic energy, effectively distinguishing narrow peaks from broad peaks, and is unaffected by overall contrast. Then, the number of scales with eigenvalues greater than or equal to the first reference is counted, and the concentration of characteristic energy at different scales is measured based on the statistical results, satisfying the following relationship: In the formula, For pixels The half-width of the multi-scale characteristic spectral lines. For pixels The eigenvalues on the multi-scale characteristic spectral lines are greater than or equal to the number of scales of the first reference set above. It is a constant to prevent the denominator from being 0.
[0043] True defect spectral lines exhibit sharp pulses at specific scales, appearing as narrow peaks. The value is large; the background spectral lines are distributed gently across multiple scales, exhibiting broad peaks. The value is small.
[0044] Furthermore, a second reference is set, namely 0.7 of the maximum eigenvalue on the multi-scale characteristic spectral line. This setting corresponds to the truly significant part of the multi-scale characteristic spectral line, which can more rigorously identify the key scale without being disturbed by minor fluctuations. It is high enough to exclude background noise, but not too high to miss minor defects, thus forming an ideal balance point.
[0045] Furthermore, based on the aforementioned second reference, the distribution density of high-value features across scales satisfies the following relationship: In the formula, For pixels High non-uniform distribution coefficients on multi-scale characteristic spectral lines For pixels The eigenvalues on the multi-scale characteristic spectral lines are greater than the number of scales of the second reference. This represents the total number of scales on the multi-scale characteristic spectral lines.
[0046] High values of defect spectral lines only appear at a few key scales. The value is small, such as when only the first scale is significant. The values are large; the high values of the background spectral lines are evenly distributed across multiple scales.
[0047] Furthermore, the product of the calculated half-peak width and the high-value non-uniform distribution coefficient is used as the scale locality of the multi-scale feature spectral lines of the pixel.
[0048] When scale locality approaches 1, it indicates that the energy of the feature spectral lines of the pixel is highly concentrated in a few key scales, which is very likely a defect; when scale locality approaches 0, it indicates that the energy is dispersed or not significantly concentrated, which is mostly background or noise.
[0049] In another embodiment, the distribution of contrast feature energy at each scale is calculated, and then the scale entropy is calculated. The reciprocal of the scale entropy is used as the scale locality of the multi-scale feature spectral lines of the pixel. The energy proportion at small scales is significantly higher than that at neighboring scales, the entropy value drops sharply, and the reciprocal increases dramatically, highlighting the defect.
[0050] Finally, based on the above operations, the peak significance and scale locality of the multi-scale feature spectral lines of all pixels are obtained.
[0051] S3: Combine the peak saliency and the scale locality to calculate the defect saliency score of each pixel, combine the defect saliency scores of all pixels to construct a defect saliency map, perform binarization processing on the defect saliency map, determine the pixels with defect saliency scores higher than a preset threshold as defect points, construct defect regions, and mark the position of the defect on the grayscale image according to the defect regions.
[0052] In one embodiment, the product of the peak saliency of the multi-scale feature spectral lines of a pixel and the scale locality is used as the defect saliency score of that pixel.
[0053] In another embodiment, corresponding weights are assigned to peak significance and scale locality, such as assigning a weight value of 0.6 to peak significance and a weight value of 0.4 to scale locality. These two weights are the initial weights and can be adjusted to the optimal values through cross-validation.
[0054] Alternatively, a defect saliency map can be constructed by combining the defect saliency scores of all pixels.
[0055] Then, the mean and standard deviation of the defect saliency scores of all pixels are calculated. A threshold based on the normal distribution assumption is set according to the mean and standard deviation. The defect saliency map is then binarized according to the threshold, and pixels with defect saliency scores higher than the threshold are identified as defect points.
[0056] The binarized image is further labeled with connected components to extract independent defect regions. For each defect region, its minimum bounding rectangle is calculated and drawn on the grayscale image to mark the location of the defect.
[0057] This completes the defect detection of the casting surface. Subsequent analysis and maintenance operations can be formulated based on the location of the defects.
[0058] Reference Figure 2 The system includes a processor and a memory, the memory storing computer program instructions, which, when executed by the processor, implement the casting surface defect detection method according to the first aspect of the present invention.
[0059] The system also includes other components well known to those skilled in the art, such as communication buses and communication interfaces, the settings and functions of which are known in the art and will not be described in detail here.
[0060] It should be noted that those skilled in the art can make various modifications and improvements without departing from the inventive concept, and these all fall within the scope of protection of this invention. Therefore, the scope of protection of this patent should be determined by the appended claims.
Claims
1. A method for detecting defects on casting surfaces, characterized in that, include: Obtain a grayscale image of the casting surface to be inspected, and construct a multi-scale contrast feature cube on the grayscale image based on a predefined set of analysis window scales; Based on each pixel in the cube, the contrast feature sequence of the pixel is extracted along the scale dimension to form the multi-scale feature spectral line of the pixel, and the peak significance and scale locality of the multi-scale feature spectral line are calculated. The peak saliency and the scale locality are combined to calculate the defect saliency score of each pixel. The defect saliency scores of all pixels are combined to construct a defect saliency map. The defect saliency map is binarized. Pixels with defect saliency scores higher than a preset threshold are identified as defect points and defect regions are constructed. The location of the defect is marked on the grayscale image according to the defect regions.
2. The method for detecting casting surface defects according to claim 1, characterized in that, The set is defined as a set containing multiple odd-numbered side lengths as the scale of the analysis window.
3. The method for detecting casting surface defects according to claim 2, characterized in that, The construction process of the cube includes: For each scale in the set, an analysis window is constructed with each pixel in the grayscale image as the center, the grayscale co-occurrence matrix within the analysis window is obtained, the contrast feature value of the analysis window is calculated based on the grayscale co-occurrence matrix, and all pixels in the grayscale image are traversed to generate a complete contrast feature map under the analysis window. The complete contrast feature maps under all analysis windows are stacked along the scale dimension, and the contrast feature values of each spatial location under all analysis windows are recorded, thus forming a multi-scale contrast feature cube.
4. The method for detecting casting surface defects according to claim 3, characterized in that, The process of obtaining the peak significance includes: Calculate the average Pearson correlation coefficient between the multi-scale feature spectral lines of a pixel and the multi-scale feature spectral lines of its eight neighbors, and use this as the spatial consistency of the pixel; obtain the local maximum points of the multi-scale feature spectral lines according to preset recognition conditions; and statistically analyze the maximum value and median of the multi-scale feature spectral lines. The peak significance of the multi-scale feature line at a pixel is calculated as the product of the ratio of the maximum value to the median of the eigenvalues on the multi-scale feature line, the spatial consistency, and the number of local maxima on the multi-scale feature line.
5. The method for detecting casting surface defects according to claim 4, characterized in that, The process of obtaining the scale locality includes: Based on the distribution of contrast eigenvalues on multi-scale feature spectral lines, the product of the calculated half-peak width and the high-value non-uniform distribution coefficient is used as the scale locality of the multi-scale feature spectral lines of the pixel.
6. The method for detecting casting surface defects according to claim 4, characterized in that, The process of obtaining the scale locality includes: The distribution of contrast feature energy at each scale is calculated, and then the scale entropy is calculated. The reciprocal of the scale entropy is used as the scale locality of the multi-scale feature spectral lines of the pixel.
7. The method for detecting casting surface defects according to claim 1, characterized in that, The process for obtaining the defect salience score is as follows: The product of the peak significance and the scale locality is used as the defect significance score.
8. The method for detecting casting surface defects according to claim 1, characterized in that, The process for obtaining the defect salience score is as follows: The peak significance and the scale locality are assigned corresponding weights respectively, and the peak significance and the scale locality are weighted and summed to obtain the defect significance score.
9. A casting surface defect detection system, characterized in that, include: A processor and a memory, the memory storing computer program instructions that, when executed by the processor, implement the casting surface defect detection method according to any one of claims 1-8.
Citation Information
Patent Citations
Fault diagnosis method of energy internet power converter
CN108919120A
Defect detection method for high-strength stamping part
CN117830139A
Textile quality detection method fusing multi-scale features
CN119444670A
Mura defect detection method and device of TFT-LCD display screen and electronic equipment
CN119540245A
Visual detection method and system for parts for powder metallurgy processing
CN120672747A