Aluminum alloy die casting surface defect detection method based on machine vision
Patent Information
- Application Number
- CN202511610945.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-05
- Publication Date
- 2026-08-21
- Estimated Expiration
- 2045-11-05
AI Technical Summary
然而,现有基于曲率的检测算法大多采用固定尺度邻域进行分析,这种单一尺度模型存在显著局限性:当邻域过小,算法对噪声及微细纹理极为敏感,易造成误报;当邻域过大,又会平滑掉尺寸较小的真实缺陷信号,导致漏检
[0021] Further filtering removes noise points or meaningless micro-texture regions that may still remain after morphological processing, retaining only connected regions with an area greater than a preset threshold as surface defect regions, thereby effectively reducing the false alarm rate.
Smart Images

Figure CN121810557B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of image processing technology, and in particular to a method for detecting surface defects in aluminum alloy die castings based on machine vision. Background Technology
[0002] Aluminum alloy die castings are widely used in the automotive, consumer electronics, and aerospace manufacturing industries due to their high specific strength, excellent dimensional accuracy, and forming efficiency. However, the high-pressure, high-speed die casting process, along with subsequent machining, grinding, and sandblasting processes, often leads to various surface defects such as porosity, shrinkage cavities, cracks, scratches, top damage, and cold shuts. These defects not only affect the appearance quality but can also cause stress concentration, shortened fatigue life, or reduced sealing performance, posing a potential threat to the safety and reliability of components. Therefore, implementing automated inspection of surface defects in die castings is a crucial step in achieving stable quality control and intelligent production.
[0003] Traditional inspection methods rely primarily on manual visual inspection, which suffers from low efficiency, high subjectivity, and poor repeatability. Defect detection technologies based on industrial vision and visual intelligence analysis have been applied. By deploying high-resolution industrial cameras and ring light sources on the production line, multi-angle, multi-spectral image acquisition of die-cast parts can be achieved. Typical methods identify defects by analyzing the grayscale, texture, or edge features of the acquired images. For example, methods using threshold segmentation to distinguish pores from the background; methods using the Canny operator to detect crack edges; and methods using Local Binary Pattern (LBP) and Gray-Level Co-occurrence Matrix (GLCM) to extract texture differences and identify pitting. However, due to the numerous curved surfaces, grooves, rounded corners, and reinforcing ribs on the part surface, their projection in the image can produce strong differences in brightness or edge responses due to changes in the incident light angle and camera viewing angle, such as high-gloss reflections and shadow areas, which are easily misjudged as bright spots, scratches, or pits. When these general algorithms are applied to aluminum alloy die-cast parts with complex geometries, they are often interfered with by geometric pseudo-features.
[0004] To suppress the interference from the aforementioned geometric spurious features, researchers attempted to use curvature features, which can characterize three-dimensional morphology, for detection. The curvature analysis method assumes that the normal surface of a part has a continuous and smooth curvature change, while surface defect regions exhibit local curvature anomalies. Therefore, by calculating the second derivative or Hessian matrix features of the grayscale image, regions with abrupt curvature changes can be identified. However, most existing curvature-based detection algorithms use a fixed-scale neighborhood for analysis. This single-scale model has significant limitations: when the neighborhood is too small, the algorithm is extremely sensitive to noise and fine textures, easily causing false alarms; when the neighborhood is too large, it smooths out smaller, real defect signals, leading to missed detections. Summary of the Invention
[0005] To reduce the occurrence of missed or misjudged defects in the surface defect detection process of aluminum alloy die castings, this application provides a machine vision-based method for surface defect detection of aluminum alloy die castings.
[0006] Firstly, this application provides a machine vision-based method for detecting surface defects in aluminum alloy die-cast parts, employing the following technical solution: A machine vision-based method for detecting surface defects in aluminum alloy die castings includes: acquiring grayscale images of the die casting surface; constructing a Gaussian scale space for the grayscale images and acquiring scale images at multiple scales; calculating the defect saliency index corresponding to each pixel in the grayscale images based on the multi-scale images to generate a defect saliency map; performing threshold segmentation on the defect saliency map to obtain segmented images; and performing morphological processing on the segmented images to identify and determine the location of surface defect regions. The steps for calculating the defect saliency index for each pixel in a grayscale image include: calculating the gradient magnitude and absolute value of the Laplacian response for each pixel in the image at each scale; for any pixel in the grayscale image, taking the maximum absolute value of the Laplacian response at all scales as the peak curvature response; taking the coefficient of variation of the gradient magnitude at all scales as the gradient cross-scale variability; taking the maximum maximum gradient magnitude at all scales as the maximum gradient strength; calculating the defect saliency index for each pixel based on the peak curvature response, gradient cross-scale variability, and maximum gradient strength, where the peak curvature response and gradient cross-scale variability are positively correlated with the defect saliency index; and the maximum gradient strength is negatively correlated with the defect saliency index.
[0007] A grayscale image of the die-cast part surface is acquired to avoid the influence of spectral redundancy and color differences of color images on the detection results. Then, a Gaussian scale space of the grayscale image is constructed, and the structural changes of the image are analyzed at multiple smooth scales, thereby achieving an adaptive response to defects of different sizes and reducing the defect omissions caused by the fixed window in single-scale curvature analysis in related technologies.
[0008] Finally, by calculating the gradient magnitude and absolute value of the Laplacian response for each pixel in multi-scale images, the maximum value of the absolute value of the Laplacian response across all scales is taken as the peak curvature response. For surface defects in die-cast parts, regardless of their size, there exists a scale image where the response intensity is relatively large. Therefore, in this embodiment, the maximum value of the absolute value of the Laplacian response across all scales is taken as the peak curvature response. Meanwhile, normal contour edges of parts typically exhibit strong response values across multiple scale images. Therefore, this method distinguishes whether a pixel belongs to a normal workpiece region by calculating the coefficient of variation of the gradient magnitude at multiple scales. Finally, since the edges of normal workpieces are usually clearer and have a larger gradient magnitude than the contour of surface defect regions, this method also combines the magnitude of the pixel's gradient magnitude to identify surface defect regions.
[0009] Optionally, after acquiring a grayscale image of the die-cast part surface, the grayscale image is subjected to edge-preserving smoothing processing.
[0010] Edge-preserving smoothing can effectively filter out random noise in images while preserving edge information of defects and workpiece geometry to the maximum extent, thus improving the accuracy of surface defect identification in die-cast parts.
[0011] Optionally, a bilateral filter can be applied to perform edge-preserving smoothing on the grayscale image.
[0012] Bilateral filtering takes into account both the spatial proximity of pixels and the similarity of pixel values, which can effectively remove noise while better protecting high-frequency edge details in the image from being blurred.
[0013] Optionally, the standard deviations of the Gaussian kernels corresponding to each scale in the Gaussian scale space form a geometric series.
[0014] Constructing a scale space using a geometric progression is a systematic and efficient approach that ensures uniform sampling along the logarithmic scale axis, thereby providing more comprehensive and non-redundant coverage of scales ranging from fine to coarse.
[0015] Optionally, apply a scale image The absolute value of the Laplace response is obtained by performing a convolution operation on the Laplace kernel.
[0016] Optionally, the steps for calculating the defect significance index for each pixel based on the peak curvature response, gradient cross-scale variability, and maximum gradient strength include: constructing an instability coefficient negatively correlated with gradient cross-scale variability using an exponential function, and using the product of the instability coefficient, the normalized result of the peak curvature response, and the normalized result of the maximum gradient strength as the defect significance index.
[0017] Optionally, the Otsu method can be used to perform thresholding segmentation on the defect saliency map to obtain a segmented image.
[0018] The Otsu method can automatically calculate the optimal segmentation threshold based on the grayscale distribution characteristics of each image, making the segmentation process adaptive and able to cope with changes in the overall brightness of the saliency image under different workpieces and lighting conditions.
[0019] Optionally, the steps for morphological processing of the segmented image include: extracting candidate defect regions from the segmented image, performing opening and closing operations on the candidate defect regions in sequence to obtain a binary defect map, and selecting surface defect regions from the binary defect map.
[0020] Optionally, in the step of selecting surface defect regions in the binary defect map, connected component analysis is performed on the binary defect map to obtain connected regions. For any connected region, if the area of the connected region is greater than a preset threshold, the connected region is taken as a surface defect region.
[0021] Further filtering removes noise points or meaningless micro-texture regions that may still remain after morphological processing, retaining only connected regions with an area greater than a preset threshold as surface defect regions, thereby effectively reducing the false alarm rate.
[0022] Optionally, after determining the location of the surface defect region, the location and outline of the filtered defect candidate region are marked on a grayscale image of the die-cast surface using a bounding box or highlight mask.
[0023] This application has the following technical effects: constructing a scale space, using a series of Gaussian kernels of different scales to obtain images of multiple scales, extracting features from the images of multiple scales and fusing them, so as to facilitate the detection and identification of defects of different scales and reduce the occurrence of false detections and false negatives. Attached Figure Description
[0024] Figure 1 This is a flowchart of the surface defect detection method for aluminum alloy die castings based on machine vision, according to an embodiment of this application.
[0025] Figure 2 This is a flowchart of a method for calculating the defect saliency index corresponding to each pixel in a grayscale image according to an embodiment of this application. Detailed Implementation
[0026] This application discloses a machine vision-based method for detecting surface defects in aluminum alloy die castings. By extracting and fusing multi-scale features, it achieves an adaptive response to different defect sizes, thereby significantly reducing the false alarm rate while ensuring high sensitivity. This enables high-precision and robust detection of surface defects in complex aluminum alloy die castings.
[0027] Reference Figure 1 The machine vision-based method for detecting surface defects in aluminum alloy die castings includes steps S1-S4.
[0028] S1: Obtain a grayscale image of the die-cast part surface.
[0029] Digital images of the surface of aluminum alloy die-cast parts are acquired under industrial visual lighting conditions. For example, a diffuse dome light source can be used in conjunction with a coaxial light source; the former provides uniform background illumination, while the latter effectively highlights surface irregularities. High-resolution industrial cameras (such as area-array CCD or CMOS cameras) are used to capture images from an angle perpendicular to the main surface to be inspected.
[0030] To eliminate interference from irrelevant backgrounds, fixtures, or other objects in the image and reduce computational load, it is necessary to first locate and extract the effective region containing the die-casting part. This effective region can be automatically extracted using template matching or machine learning-based segmentation methods (such as pre-training a simple U-Net model to segment the foreground and background). All subsequent processing is performed only within this effective region.
[0031] The image after background removal is converted to a grayscale image, thus obtaining a grayscale image of the die-cast part surface. To enhance the visibility of defects, local contrast enhancement processing can be performed on the grayscale image, for example, by applying Limiting Contrast Adaptive Histogram Equalization (CLAHE). The CLAHE algorithm can effectively suppress excessive noise amplification while enhancing contrast.
[0032] To suppress random noise while preserving the fine geometric edges and defect contours of the parts to the greatest extent possible, a bilateral filter can be used to smooth the image enhanced by the CLAHE algorithm, resulting in a preprocessed image. Bilateral filtering and contrast-limited adaptive histogram equalization algorithms are conventional techniques in this field and will not be elaborated upon here.
[0033] S2: Construct the Gaussian scale space of the grayscale image to obtain scale images at multiple scales.
[0034] In constructing the Gaussian scale space of a grayscale image, a series of discrete Gaussian kernel standard deviations are selected to represent different analytical scales. The scale sequence is typically chosen in a geometric progression. For example In the formula, This indicates the Gaussian kernel standard deviation; It is the base scale (e.g., 1.0 or 1.5 pixels). It is a scaling factor (e.g.) Or 2), This represents the total number of scale layers (e.g., 3 to 5 layers). A series of scale images are generated by convolving the grayscale image of the die-cast surface with Gaussian filters of different Gaussian kernel standard deviations.
[0035] S3: Calculate the defect saliency index corresponding to each pixel in the grayscale image based on multi-scale image, and generate a defect saliency map.
[0036] Reference Figure 2 The steps for calculating the defect saliency index corresponding to each pixel in a grayscale image include steps S31-S35.
[0037] S31: Calculate the gradient cross-scale variability and absolute value of the Laplacian response for each pixel in the image at each scale.
[0038] For any pixel in an image of any scale, calculate its gradient magnitude.
[0039] In the formula, Represents pixels In scale The gradient magnitude below; The scale is represented as pixels in a scaled image In the image Partial derivatives in direction, The scale is represented as pixels in a scaled image In the image The partial derivatives in a direction can be calculated using a Sobel, Scharr, or Gaussian derivative filter.
[0040] Reflects scale At the smoothing level, pixels The maximum rate of change of grayscale (intensity) within the neighborhood. It typically achieves higher values in edge and textured regions.
[0041] For any pixel in an image at any scale, the absolute value of its Laplacian response is obtained using the Laplacian operator.
[0042] The Laplacian operator is the trace of the second derivative, responding strongly to corners, blobs, and curved edges in an image. A larger absolute value of the Laplacian response indicates a stronger response at different scales. Below, pixels The more curved or uneven the grayscale changes within a neighborhood, the more sensitive it is to the inflection points of the center and edges of point-like and line-like structures, and the more it can reflect local shape anomalies.
[0043] S32: For any pixel in a grayscale image, take the maximum absolute value of the Laplacian response at all scales as the peak curvature response.
[0044] Real defects (such as pores, pits, and protrusions) usually have specific physical dimensions, and their corresponding absolute values of the Laplacian response will be strongly expressed in one or more specific scale images that match their size.
[0045] Therefore, in this embodiment, for any pixel in a grayscale image, the maximum absolute value of its Laplacian response is found among its corresponding multiple scale images, and this maximum value is taken as the peak curvature response. The peak curvature response reflects the strongest local curvature or unevenness that can be exhibited at multiple scales in scale space.
[0046] Regardless of the defect size, as long as it elicits a sufficiently strong response at a certain scale, the peak curvature response can capture this peak as preliminary evidence of an anomaly at that point.
[0047] S33: The coefficient of variation of gradient magnitude at all scales is taken as the gradient cross-scale volatility.
[0048] For clear, regular geometric edges on a part (such as ridges and large rounded corners), they typically exhibit strong gradient magnitudes stably across multiple consecutive scales. The gradient magnitude varies relatively little with scale.
[0049] Therefore, in this embodiment, the coefficient of variation of gradient magnitude at all scales is taken as the gradient cross-scale volatility.
[0050] The formula for calculating gradient cross-scale volatility can be expressed as: In the formula, Represents pixels The coefficient of variation of the gradient magnitude across multiple scales, i.e., gradient cross-scale volatility; Represents pixels The standard deviation of the gradient magnitude at multiple corresponding scales; Represents pixels The median of the gradient magnitude across multiple scales; This represents a hyperparameter, primarily used to prevent situations where the denominator is 0, making calculation impossible.
[0051] If a pixel is located on a stable geometric edge, its gradient magnitude is relatively similar across different scales with small fluctuations, resulting in low gradient cross-scale variability. However, if a pixel is located in a defective region or a complex texture area, its gradient response may only be significant at certain scales or vary drastically with scale, leading to higher gradient cross-scale variability. The height of the edge can be used to distinguish between stable edges and unstable structures.
[0052] S34: The maximum gradient magnitude across all scales is taken as the maximum gradient strength.
[0053] Compared to macroscopic geometric edges, the gradient response of a defect region may only be significant at a specific scale, or even if significant, its absolute intensity may be weaker than that of the main geometric edges. Therefore, in this embodiment, for any pixel in a grayscale image, the maximum gradient magnitude across all scales corresponding to that pixel is taken as the maximum gradient intensity. The larger the maximum gradient intensity, the more likely it corresponds to a high-contrast, sharp edge in the image; these pixels are often the main geometric contours or edges of a part.
[0054] S35: The defect saliency index of each pixel is calculated based on the peak curvature response, gradient cross-scale variability, and maximum gradient strength. The peak curvature response and gradient cross-scale variability are positively correlated with the defect saliency index; the maximum gradient strength is negatively correlated with the defect saliency index.
[0055] Specifically, an instability coefficient negatively correlated with gradient cross-scale volatility is constructed using an exponential function, and the product of the instability coefficient, the normalized result of the peak curvature response, and the normalized result of the maximum gradient intensity is used as the defect significance index.
[0056] The formula for calculating the defect significance index can be expressed as: In the formula, Represents pixels The defect significance index; Represents pixels The corresponding peak curvature response; It represents the maximum value of the peak curvature response corresponding to all pixels in a grayscale image, and is mainly used to normalize the denominator. Represents pixels The corresponding gradient cross-scale volatility; The reference value representing the preset gradient cross-scale variability can be the mean or median of the gradient cross-scale variability corresponding to all pixels in the grayscale image, and is mainly used to scale the denominator. Represents pixels The corresponding maximum gradient strength; It represents the maximum value of the maximum gradient intensity corresponding to all pixels in a grayscale image, and is mainly used to normalize the denominator. This is a hyperparameter, mainly used to prevent the denominator from being zero; Indicated by An exponential function with base 0; The weights are positive and are mainly used to adjust the influence of the maximum gradient strength on the defect significance index.
[0057] This represents the normalized result of the peak curvature response. The larger this part is, the more curved or uneven the grayscale changes in the pixel neighborhood are, and the more likely the pixel is to be an anomalous pixel. This represents the normalized result of gradient cross-scale variability. The larger this part is, the greater the fluctuation of the gradient magnitude of the pixel across multiple scales, and the more likely the pixel is to be an anomalous pixel. This represents the normalized result of the maximum gradient intensity. The larger this part is, the greater the gradient of the pixel and the clearer the edge, which may belong to the normal structural edge of the part. Therefore, the larger this part is, the smaller the defect significance index is.
[0058] After the defect saliency index of each pixel is calculated, the defect saliency index of each pixel constitutes a defect saliency map.
[0059] S4: Threshold segmentation is performed on the defect saliency map to obtain a segmented image. Morphological processing is then performed on the segmented image to identify and determine the location of the surface defect region.
[0060] Normalize the defect saliency map, for example, by linear stretching to The range is set for display and processing. Then, an adaptive thresholding method is applied to segment the saliency map, resulting in an initial binary defect map. In this embodiment, the Otsu method (maximum inter-class variance method) is used to determine the segmentation threshold of the defect saliency map and to segment the image. In other embodiments, other methods can also be used to determine the segmentation threshold. For example, it can be determined by the mean and standard deviation of the defect saliency index of each pixel in the image. Specifically, the product of a preset adjustment coefficient and the standard deviation of the defect saliency index can be calculated, and then the sum of this product and the mean of the defect saliency index can be used as the segmentation threshold.
[0061] Extract candidate defect regions from the segmented image, perform opening and closing operations on the candidate defect regions in sequence to obtain a binary defect map, and select surface defect regions from the binary defect map.
[0062] In this step, the opening operation refers to using a small structuring element to perform an opening operation to effectively remove isolated bright spots or fine burrs caused by noise or minute textures. The structuring element can be... A round or square core.
[0063] Closing operations refer to using slightly larger structuring elements to fill small holes that may exist inside a defective region, connect broken defective parts (such as scratches), and make the defective region more complete and connected. The structuring element in a closing operation can be... or A round or square core.
[0064] In the step of selecting surface defect regions in a binary defect map, connected component analysis is performed on the binary defect map to obtain connected regions. For any connected region, if the area of the connected region is greater than a preset threshold, the connected region is taken as a surface defect region.
[0065] In this step, regions with a preset area threshold are removed, thereby reducing noise interference in the image. Of course, in other embodiments, regions whose aspect ratios do not conform to typical defect characteristics can also be removed; these regions may be residual edge artifacts. Specifically, the aspect ratio of each connected region can be calculated, and regions with aspect ratios greater than a preset threshold are identified as surface defect regions.
[0066] The output will contain information about the filtered surface defect regions. This information may include the location (e.g., centroid coordinates or circumscribed rectangle), dimensions (e.g., area, maximum diameter), and shape parameters of each surface defect region. To facilitate user inspection and subsequent processing, detected surface defect regions can be highlighted in the grayscale image using different colored bounding boxes, fill masks, or outlines.
[0067] This application also discloses a machine vision-based method for detecting surface defects in aluminum alloy die castings, including a processor and a memory. The memory stores computer program instructions, which are executed by the processor to implement the machine vision-based method for detecting surface defects in aluminum alloy die castings according to this application.
[0068] 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.
[0069] The above are all preferred embodiments of this application, and are not intended to limit the scope of protection of this application. Therefore, all equivalent changes made in accordance with the structure, shape and principle of this application should be covered within the scope of protection of this application.
Claims
1. A machine vision-based method for detecting surface defects in aluminum alloy die-castings, characterized in that, Acquire grayscale images of the die-cast part surface; construct a Gaussian scale space for the grayscale images and acquire scale images at multiple scales; calculate the defect saliency index corresponding to each pixel in the grayscale images based on the multi-scale images to generate a defect saliency map; perform threshold segmentation on the defect saliency map to obtain segmented images; perform morphological processing on the segmented images to identify and determine the location of surface defect regions. The steps for calculating the defect saliency index for each pixel in a grayscale image include: calculating the gradient magnitude and absolute value of the Laplacian response for each pixel at each scale; for any pixel in the grayscale image, taking the maximum absolute value of the Laplacian response across all scales as the peak curvature response; taking the coefficient of variation of the gradient magnitude across all scales as the gradient cross-scale variability; taking the maximum maximum gradient magnitude across all scales as the maximum gradient strength; and calculating the defect saliency index for each pixel based on the peak curvature response, gradient cross-scale variability, and maximum gradient strength, using the following formula: , Represents pixels The defect significance index, Represents pixels The corresponding peak curvature response; This represents the maximum value of the peak curvature response corresponding to all pixels in the grayscale image, and is used to normalize the denominator. Represents pixels The corresponding gradient cross-scale volatility; The reference value representing the preset gradient cross-scale variability is the mean or median of the gradient cross-scale variability corresponding to all pixels in the grayscale image, which is used to scale the denominator. Represents pixels The corresponding maximum gradient strength; This represents the maximum value of the maximum gradient intensity corresponding to all pixels in the grayscale image, used to normalize the denominator. This is a hyperparameter used to prevent the denominator from being zero; Indicated by An exponential function with base 0; The positive weight is used to adjust the effect of the maximum gradient strength on the defect significance index.
2. The method for detecting surface defects in aluminum alloy die-castings based on machine vision according to claim 1, characterized in that, After acquiring the grayscale image of the die-cast part surface, the grayscale image is processed to maintain smooth edges.
3. The method for detecting surface defects in aluminum alloy die-castings based on machine vision according to claim 2, characterized in that, A bilateral filter is applied to perform edge-preserving smoothing on grayscale images.
4. The method for detecting surface defects in aluminum alloy die-castings based on machine vision according to claim 1, characterized in that, The standard deviations of the Gaussian kernels at each scale in the Gaussian scale space form a geometric sequence.
5. The method for detecting surface defects in aluminum alloy die-castings based on machine vision according to claim 1, characterized in that, Apply a scale image The absolute value of the Laplace response is obtained by performing a convolution operation on the Laplace kernel.
6. The method for detecting surface defects in aluminum alloy die-castings based on machine vision according to claim 1, characterized in that, The Otsu method is used to perform thresholding segmentation on the defect saliency map to obtain a segmented image.
7. The method for detecting surface defects in aluminum alloy die-castings based on machine vision according to claim 6, characterized in that, The steps for morphological processing of a segmented image include: extracting candidate defect regions from the segmented image, performing opening and closing operations on the candidate defect regions sequentially to obtain a binary defect map, and selecting surface defect regions from the binary defect map.
8. The method for detecting surface defects in aluminum alloy die-castings based on machine vision according to claim 7, characterized in that, In the step of selecting surface defect regions in a binary defect map, connected component analysis is performed on the binary defect map to obtain connected regions. For any connected region, if the area of the connected region is greater than a preset threshold, the connected region is taken as a surface defect region.
9. The method for detecting surface defects in aluminum alloy die-castings based on machine vision according to claim 1, characterized in that, It also includes, after determining the location of the surface defect area, marking the location and outline of the filtered defect candidate area on the grayscale image of the die-cast part surface using a bounding box or highlight mask.
Citation Information
Patent Citations
A complex casting defect identification method based on gray saliency
CN109816652A
Food packaging bottle defect visual detection method and system
CN118864468A