A surface defect real-time detection method and system for castings production
By combining superpixel segmentation and an improved Gaussian filtering algorithm with edge detection, the problem of excessive smoothing in traditional Gaussian filtering leading to loss of detail and decreased recognition rate in casting surface inspection is solved, achieving efficient and accurate detection of casting surface defects.
Patent Information
- Application Number
- CN202511383780.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-26
- Publication Date
- 2026-02-10
- Estimated Expiration
- 2045-09-26
AI Technical Summary
Traditional Gaussian filtering suffers from problems such as loss of detail and reduced defect recognition rate due to excessive smoothing in the detection of surface defects in castings, especially under factors such as uneven lighting and local contamination.
By combining superpixel segmentation, an improved Gaussian filtering algorithm, and edge detection, and by dynamically adjusting the Gaussian weights and noise impact, fine denoising and defect highlighting of the surface image of the casting is achieved.
It improves the accuracy and stability of defect identification, adapts to the detection needs under different surface conditions, and enhances the practicality and application value of the detection system.
Smart Images

Figure CN120876475B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of image data processing. More particularly, the present application relates to a surface defect real-time detection method and system for castings production. BACKGROUND
[0002] As key basic parts in the fields of mechanical manufacturing, automobile industry, aerospace and energy equipment, the surface quality of castings directly affects the mechanical properties, service life and safety reliability of products. Therefore, how to realize fast and accurate detection of surface defects of castings in the casting production process has always been the focus of the industry. At present, surface defect detection mainly relies on manual visual inspection, traditional image processing methods and automatic detection methods based on machine vision. The manual detection method depends on the experience and subjective judgment of the operator, which is not only low in efficiency, but also prone to missed detection or false detection under long-time continuous detection. The automatic detection method based on image processing overcomes the instability of manual detection to a certain extent, can obtain the surface image of the casting through an industrial camera, and realize defect recognition by using algorithms such as filtering, edge detection and feature extraction, so it has gradually become an important direction of quality control in the casting industry.
[0003] In the existing image processing method, Gaussian filtering is widely used in image denoising preprocessing link because of its simple calculation and stable effect. Gaussian filtering effectively reduces the interference of random noise on subsequent edge detection and defect recognition by weighted smoothing of the image.
[0004] However, in the actual scene of casting surface defect detection, the traditional Gaussian filtering has obvious shortcomings: there are usually uneven illumination, surface reflection and local pollution and other factors in the casting production site. The noise distribution introduced by these factors has obvious regional difference, and the traditional Gaussian filtering algorithm only convolves based on fixed spatial weight and gray similarity, cannot adaptively adjust according to the noise intensity of different regions, resulting in the phenomenon of over-smoothing or insufficient denoising in some areas of the denoising result, and further causing the problems of detail loss and defect recognition rate reduction in the real-time detection of casting surface defects due to over-smoothing. SUMMARY
[0005] To solve the problem of detail loss and defect recognition rate reduction in the real-time detection of casting surface defects due to over-smoothing in the background art, the present application provides solutions in the following aspects.
[0006] In a first aspect, the present invention provides a real-time detection method for surface defects in casting production, comprising: acquiring a surface image of a casting to be inspected, and performing superpixel segmentation on the surface image of the casting to be inspected to obtain multiple superpixel regions, acquiring the noise level of each superpixel region, and determining superpixel regions with noise levels greater than a first set threshold as noise regions; performing denoising processing on the multiple superpixel regions using an improved Gaussian filtering algorithm to obtain a denoised surface image of the casting to be inspected; performing edge detection on the denoised surface image of the casting to be inspected to obtain multiple edge contours, and determining that the surface image of the casting to be inspected has defects if the number of detected edge contours is greater than a set contour threshold; wherein the improved Gaussian filtering algorithm includes Gaussian weights, the Gaussian weights being positively correlated with the initial weights of the target pixel and negatively correlated with the noise influence degree of the superpixel region where the target pixel is located, the noise influence degree characterizing the degree of influence of each superpixel region on the noise region, and the target pixel being any pixel in the surface image of the casting to be inspected.
[0007] The above technical solution combines superpixel segmentation, noise assessment and improved Gaussian filtering to achieve fine denoising and defect highlighting of casting surface images, and solves the problem that existing algorithms lose details and reduce defect recognition rate due to excessive smoothing when performing real-time detection of casting surface defects.
[0008] Furthermore, the noise level of each superpixel region for, , For the first The first superpixel region Gradient magnitude of each pixel For the first The first superpixel region The grayscale value of each pixel For the first The average gray level of all pixels in a superpixel region For the first The maximum value of the gradient magnitude of each pixel in a superpixel region To preset hyperparameters, For the first The total number of pixels in a superpixel region.
[0009] The aforementioned technical solution achieves a more refined characterization of regional noise levels by comprehensively considering pixel grayscale deviations and local gradient changes within the superpixel region. By simultaneously introducing differences in gradient magnitude and grayscale mean, it effectively distinguishes between genuine surface defect edges and random noise disturbances, thus avoiding misjudgments caused by a single feature indicator. Furthermore, the combination of normalization processing and parameter adjustment ensures that the calculation results exhibit strong stability and comparability under different regional complexities and noise levels.
[0010] Furthermore, noise impact for, , For the first Noise level of each superpixel region In order to be with the first The superpixel region is adjacent to the first The noise level of each noise area For the first The superpixel region and the first The Euclidean distance between the centers of the noise regions In order to be with the first The total number of all noise regions adjacent to a superpixel region. These are the weighting coefficients.
[0011] The aforementioned technical solution achieves a comprehensive assessment of noise distribution in local space by simultaneously considering the noise level of the superpixel region itself and the influence of its neighboring noise regions during noise impact calculation. When multiple noise regions exist around a certain area and are relatively close, even if the noise level of that area itself is low, the overall degree of noise interference will still be reasonably amplified, thus reflecting the spatial diffusion characteristics of noise. Conversely, smooth areas far from noise regions will not be misjudged as interfered areas. In this way, it can improve the stability of overall judgment while maintaining local sensitivity, effectively enhance the targeting of denoising processing, and provide a more reliable basis for subsequent edge protection and defect detection.
[0012] Furthermore, the term "proximity" specifically means that if two superpixel regions have at least one adjacent pixel boundary in the superpixel segmentation result, they are determined to be proximity.
[0013] Furthermore, Gaussian weights for, , For the natural constant An exponential function with base 0. For pixels The noise impact of the superpixel region For pixels The initial weights.
[0014] The technical scheme combines the initial weight of the pixel point with the noise influence degree of the region where the pixel point is located, dynamically adjusts the Gaussian weight by using an exponential decay method, so that the contribution of a region with high noise degree is significantly reduced in the filtering process, and a region with low noise degree and clear texture can retain more initial weight. This mechanism effectively prevents the interference of noise pixels on the filtering result, protects the real edges and detail features, avoids the over-smoothing phenomenon in traditional uniform filtering, and thus maintains the integrity of the image structure and the recognizability of the defect features while denoising.
[0015] Further, the edge detection is Canny edge detection.
[0016] Further, a CCD camera or a CMOS camera is used to acquire the surface image of the casting to be detected.
[0017] Further, the surface image of the casting to be detected is subjected to grayscale processing.
[0018] Further, a SLIC segmentation algorithm is used to perform superpixel segmentation on the surface image of the casting to be detected.
[0019] The technical scheme introduces a SLIC segmentation algorithm to perform superpixel segmentation on the surface image of the casting, aggregates the original pixel points into region units with stronger homogeneity, thereby significantly reducing the calculation amount while maintaining the local edge structure of the image. Compared with the pixel-by-pixel processing method, the superpixel segmentation can better fit the real texture and defect boundary of the surface of the casting, so that the region division is more natural and compact, which is conducive to the accuracy of subsequent noise evaluation and defect positioning.
[0020] In a second aspect, the application provides a surface defect real-time detection system for casting production, comprising a memory and a processor, and the memory stores computer program instructions, which realize the casting production surface defect real-time detection method of any one of the above when executed by the processor.
[0021] The application has the following advantages:
[0022] The present application organically combines various technologies such as image segmentation, noise evaluation, improved Gaussian filtering and edge detection, and constructs an efficient real-time detection method for surface defects of castings. The method can effectively denoise the image while fully retaining the surface structure and edge features, so that the surface defects can be more accurately identified and determined. By comprehensively considering the noise influence and regional characteristics, the detection result is more stable and reliable, which not only improves the accuracy and efficiency of defect identification, but also can adapt to the detection requirements under different surface conditions, provides a solid technical support for quality control and management in the production process of castings, and significantly enhances the practicability and application value of the detection system. BRIEF DESCRIPTION OF DRAWINGS
[0023] Figure 1 is a flow chart schematically showing a surface defect real-time detection method for casting production according to an embodiment of the present application;
[0024] Figure 2 is a structural block diagram schematically showing a surface defect real-time detection system for casting production according to an embodiment of the present application. DETAILED DESCRIPTION
[0025] A surface defect real-time detection method for casting production embodiment.
[0026] As Figure 1 shown, the flow chart of a surface defect real-time detection method for casting production according to an embodiment of the present application includes the following steps:
[0027] S1: obtaining a surface image of a casting to be detected, and performing superpixel segmentation on the surface image of the casting to be detected to obtain a plurality of superpixel regions.
[0028] In a preferred embodiment, an industrial imaging device is first used to collect images of the surface of the casting to be detected. Specifically, the imaging device can be a CCD camera or a CMOS camera, both of which can provide high-resolution image acquisition capability in complex industrial environments. Among them, the CCD camera has high imaging sensitivity and low noise characteristics in weak light conditions, and is suitable for detecting castings with uneven surface illumination or minor defects; while the CMOS camera has the advantages of low power consumption and high frame rate, and can meet the demand for high-speed image acquisition in the process of real-time detection of the surface of the casting. Therefore, in this embodiment, the appropriate camera type can be selected according to the specific requirements of the casting surface detection scene to ensure the clarity and stability of the image acquisition link.
[0029] The surface image of the casting to be detected is subjected to grayscale processing, and then the surface image of the casting is subjected to superpixel segmentation processing. Specifically, the SLIC segmentation algorithm is used to segment the image. The SLIC algorithm can effectively reduce the computational complexity while ensuring the consistency of the local region of the image. In this embodiment, the SLIC algorithm constrains the clustering process in the pixel space and the color space at the same time, so that the generated superpixel region boundary is highly consistent with the actual texture boundary and structural edge of the surface of the casting. The technical effect lies in that, on the one hand, a large number of pixels can be divided into a plurality of relatively homogeneous superpixel regions, thereby effectively reducing the computational complexity of subsequent processing; on the other hand, by maintaining the texture consistency within the region, the accuracy of noise detection and defect extraction can be significantly improved.
[0030] S2: The improved Gaussian filtering algorithm is used to respectively perform denoising processing on a plurality of superpixel regions, so as to obtain a denoising processed surface image of the casting to be detected.
[0031] In a preferred embodiment, the improved Gaussian filtering algorithm includes a Gaussian weight, a pixel point Gaussian weight is , is an exponential function with a natural constant as the base, is a noise influence degree of a superpixel region where the pixel point is located, is an initial weight of the pixel point .
[0032] In the Gaussian filtering process, the weight correction related to the noise influence degree is introduced, so that the contribution of the pixel point in the filtering is no longer determined by the fixed spatial position or the gray difference, but is dynamically adjusted by the noise level of the region where the pixel point is located. When the noise influence degree of a region is high, the weight of the pixel point in the region is significantly reduced in an exponential decay manner, thereby avoiding excessive interference of the noise pixels on the result in the filtering process; when the noise influence degree of a region is low, the initial weight of the pixel point can be fully reserved, so that the structure and detail information of the region are better preserved in the filtering. In this way, the filtering result can effectively suppress the noise while avoiding excessive smoothing, thereby improving the clarity of the edge and the texture and the detectability of the overall image, and providing a more accurate and reliable image basis for subsequent defect identification.
[0033] Noise influence degree is , is a noise degree of an i-th superpixel region, is a noise degree of an i-th superpixel region adjacent to the j-th superpixel region, is a noise degree of an i-th superpixel region adjacent to the j-th superpixel region, is a noise degree of an i-th superpixel region adjacent to the j-th superpixel region, The noise level of each noise area For the first The superpixel region and the first The Euclidean distance between the centers of the noise regions In order to be with the first The total number of all noise regions adjacent to a superpixel region. , where is the weighting coefficient. The term "proximity" specifically refers to the following: if two superpixel regions have at least one adjacent pixel boundary in the superpixel segmentation result, they are considered proximity.
[0034] By simultaneously incorporating the noise level of a region itself and the influence of neighboring noise areas into the calculation of noise impact, the true extent of noise interference in the current region can be more comprehensively reflected. The core principle is that if a region itself has a high noise level, its probability of being identified as disturbed naturally increases; conversely, even if a region itself is relatively smooth, if multiple noise areas exist nearby, it will still be classified as a high-risk area for noise pollution. By constraining proximity relationships, the diffusion trend of noise in local space can be identified, avoiding missed detections caused by isolated judgments; while the introduction of distance between regions ensures that normal regions far from noise areas are not misclassified, thus maintaining the stability of overall judgment while considering local sensitivity. Ultimately, this method achieves more accurate modeling of the noise impact range, helping to improve the targeting of subsequent filtering processes and the fidelity of edge details.
[0035] Noise level of each superpixel region for, , For the first The first superpixel region Gradient magnitude of each pixel For the first The first superpixel region The grayscale value of each pixel For the first The average gray level of all pixels in a superpixel region For the first The maximum value of the gradient magnitude of each pixel in a superpixel region To preset hyperparameters, For the first The total number of pixels in each superpixel region is used to determine the superpixel region with a noise level greater than a first set threshold, which can be set based on the actual situation.
[0036] When evaluating the noise level of superpixel regions, the method does not rely solely on grayscale differences. Instead, it combines local grayscale deviations with the gradient intensity at the corresponding locations. This ensures that pixels located at texture edges or real structure boundaries, even with large grayscale differences, are not simply misclassified as noise. This is because such pixels often have high gradient magnitudes, effectively suppressing their contribution to noise levels after normalization. Conversely, pixels in flat regions with large grayscale values deviating from the region's average are more easily identified because the gradient intensity is relatively weak in these areas, making grayscale anomalies the primary criterion for judgment. Through this design, the method can distinguish between real edges and noise points.
[0037] S3: Perform edge detection on the surface image of the denoised casting to be tested, and determine whether there are defects in the casting to be tested based on the edge detection results.
[0038] In a preferred embodiment, the edge detection can be Canny edge detection, specifically: edge detection is performed on the denoised image of the casting surface to be inspected to obtain multiple edge contours. If the number of detected edge contours is greater than a set contour threshold, it is determined that the surface image of the casting to be inspected has defects. Specifically: since the number of edge contours on a normal casting surface is relatively limited and regularly distributed during imaging, while defects such as cracks, pores, inclusions, or shrinkage cavities on the surface will generate additional irregular boundaries, the comparison between the number of contours and the set contour threshold can effectively distinguish between defects and normal surfaces.
[0039] This invention organically combines multiple techniques, including image superpixel segmentation, noise assessment, improved Gaussian filtering, and edge detection, to construct a highly efficient real-time detection method for surface defects in castings. This method effectively suppresses image noise interference while preserving surface structure and edge features, thereby improving the accuracy and stability of defect identification and enhancing the reliability of detection results. Through this comprehensive processing approach, this invention not only adapts to the detection needs of different surface textures and complex environments but also provides a fast, feasible, and efficient technical means for quality control in the casting production process, significantly improving the automation level and overall efficiency of production inspection.
[0040] An embodiment of a real-time surface defect detection system for casting production:
[0041] like Figure 2 As shown in the figure, a structural block diagram of a real-time surface defect detection system for casting production according to an embodiment of the present invention includes a processor and a memory.
[0042] This invention also provides a real-time surface defect detection system for casting production. For example... Figure 2As shown, the system includes a processor and a memory. The memory stores computer program instructions, which, when executed by the processor, implement a real-time surface defect detection method for casting production according to the present invention.
[0043] The aforementioned real-time surface defect detection system for casting production also includes other components well-known to those skilled in the art, such as communication interfaces. Their settings and functions are known in the art and will not be described in detail here.
[0044] In this invention, the aforementioned memory can be any tangible medium containing or storing a program that can be used or combined with an instruction execution system, apparatus, or device. For example, a computer-readable storage medium can be any suitable magnetic or magneto-optical storage medium, such as Resistive Random Access Memory (RRAM), Dynamic Random Access Memory (DRAM), Static Random Access Memory (SRAM), Enhanced Dynamic Random Access Memory (EDRAM), High-Bandwidth Memory (HBM), Hybrid Memory Cube (HMC), etc., or any other medium that can be used to store desired information and can be accessed by an application, module, or both. Any such computer storage medium can be part of a device or accessible to or connected to a device. Any application or module described in this invention can be implemented by computer-readable / executable instructions stored or otherwise maintained on such a computer-readable medium.
[0045] In the description of this specification, "multiple" or "several" means at least two, such as two, three or more, unless otherwise explicitly specified.
[0046] While this specification has shown and described numerous embodiments of the invention, it will be apparent to those skilled in the art that such embodiments are provided by way of example only. Many modifications, alterations, and alternatives will occur to those skilled in the art without departing from the spirit and essence of the invention. It should be understood that various alternatives to the embodiments of the invention described herein may be employed in the practice of this invention.
Claims
1. A method for real-time detection of surface defects in casting production, characterized in that, include: A surface image of the casting to be inspected is acquired, and the surface image of the casting to be inspected is segmented into multiple superpixel regions. The noise level of each superpixel region is acquired, and the superpixel region with a noise level greater than a first set threshold is determined as a noise region. An improved Gaussian filtering algorithm is used to denoise multiple superpixel regions to obtain a denoised surface image of the casting to be inspected. Edge detection is performed on the denoised surface image of the casting to be inspected to obtain multiple edge contours. If the number of detected edge contours is greater than a set contour threshold, it is determined that there is a defect in the surface image of the casting to be inspected. The improved Gaussian filtering algorithm includes Gaussian weights, which are positively correlated with the initial weights of the target pixel and negatively correlated with the noise influence of the superpixel region where the target pixel is located. The noise influence characterizes the degree of influence of each superpixel region on the noise region. The target pixel is any pixel in the surface image of the casting to be detected. Gaussian weights for, , For the natural constant An exponential function with base 0. For pixels The noise impact of the superpixel region For pixels The initial weights; Noise impact for, , For the first Noise level of each superpixel region In order to be with the first The superpixel region is adjacent to the first The noise level of each noise area For the first The superpixel region and the first The Euclidean distance between the centers of the noise regions In order to be with the first The total number of all noise regions adjacent to a superpixel region. These are the weighting coefficients; When multiple noise areas exist around a certain area and are close to each other, even if the noise level of the area itself is low, the overall degree of noise interference will still be reasonably amplified, thus reflecting the spatial diffusion characteristics of noise; conversely, smooth areas far away from noise areas will not be misjudged as disturbed areas.
2. The method for real-time detection of surface defects in casting production according to claim 1, characterized in that, Noise level of each superpixel region for, , For the first The first superpixel region Gradient magnitude of each pixel For the first The first superpixel region The grayscale value of each pixel For the first The average gray level of all pixels in a superpixel region For the first The maximum value of the gradient magnitude of each pixel in a superpixel region To preset hyperparameters, For the first The total number of pixels in a superpixel region.
3. The method for real-time detection of surface defects in casting production according to claim 1, characterized in that, The term "neighborhood" specifically refers to the following: if two superpixel regions have at least one adjacent pixel boundary in the superpixel segmentation result, they are determined to be neighbors.
4. The method for real-time detection of surface defects in casting production according to claim 1, characterized in that, The edge detection method is Canny edge detection.
5. The method for real-time detection of surface defects in casting production according to claim 1, characterized in that, Use a CCD or CMOS camera to acquire images of the surface of the casting to be inspected.
6. The method for real-time detection of surface defects in casting production according to claim 1, characterized in that, The surface image of the casting to be inspected is converted to grayscale.
7. The method for real-time detection of surface defects in casting production according to claim 1, characterized in that, The SLIC segmentation algorithm is used to perform superpixel segmentation on the surface image of the casting to be inspected.
8. A real-time surface defect detection system for casting production, characterized in that, The method includes a memory and a processor. The memory stores computer program instructions, which, when executed by the processor, implement the real-time surface defect detection method for casting production as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Machining defect identification method for air-cooled radiator
CN118823024A
Shell flaw detection method and system based on machine vision
CN120411116A