Method for detecting surface defects of aluminum magnesium alloy

Through layered processing of surface images of aluminum-magnesium alloy components and adaptive gradient threshold comparison, the problem of defect detection under complex surface structure of aluminum-magnesium alloy is solved, and precise identification of pits, protrusions and deformation defects is achieved.

CN120495246APending Publication Date: 2025-08-15NANJING LONGCHAO METAL MFG TECH
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202510597511.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-05-09
Publication Date
2025-08-15

AI Technical Summary

Technical Problem

The prior art is difficult to accurately detect pits, protrusions and deformation defects on the surface of aluminum-magnesium alloy members, especially when the surface structure is complex.

Method used

By collecting the surface images of aluminum-magnesium alloy components, performing pre-processing and layering processing, using edge detection and adaptive gradient threshold values ​​to compare the layered image with the standard image, calculating the normal difference, and determining whether there are defects.

Benefits of technology

Accurate detection of pits, protrusions and deformation defects on the surface of aluminum-magnesium alloy is achieved, and detection efficiency and accuracy are improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120495246A_ABST
    Figure CN120495246A_ABST
Patent Text Reader

Abstract

The invention belongs to the technical field of visual inspection, and discloses a method for detecting surface defects of an aluminum magnesium alloy. Comprising the following steps: S1, acquiring a surface image of the aluminum magnesium alloy component and preprocessing the surface image to obtain a to-be-detected image; s2, layering the to-be-detected image to obtain a plurality of layered images of the to-be-detected image; s3, comparing the plurality of layered images with a preset standard image to obtain a difference set formed by a plurality of difference results; according to the method, the to-be-detected image is layered into a plurality of layered images, and the layered images are compared with the standard image, so that gaps, pits and convex parts on the surface of the aluminum magnesium alloy component and defects caused by deformation of the pits and the convex parts can be detected according to the difference result, and defect areas corresponding to the surface defects can be obtained.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of visual inspection technology, and more specifically, to a method for detecting surface defects of aluminum-magnesium alloys. Background Art

[0002] Aluminum-magnesium alloys are widely used in a number of high-end manufacturing fields, such as aerospace skins, ship components, automobile body components, and electronic communications, due to their low density, high specific strength, good corrosion resistance, and good processing properties. However, some die-cast aluminum-magnesium alloy components are prone to form circular or elliptical pits in the thick-walled area of the casting or near the gate due to excessively fast injection speed, poor mold exhaust, and incomplete melt degassing. Edge burrs or notches may also appear on the edges of the casting surface due to improper demoulding of the aluminum-magnesium alloy casting or mismatched process parameters. In addition, some extruded aluminum-magnesium alloy components are prone to uneven surfaces on the profile surface due to mold working belt wear, uneven cooling, oxide scale or oil stains on the billet surface, etc. Therefore, it is of great significance to accurately detect defects such as pits, unevenness, notches and burrs on the surface of the aluminum-magnesium alloy.

[0003] However, when performing defect detection on the surface of existing aluminum-magnesium alloys, the surface structure of some aluminum-magnesium alloy components is often relatively complex. Therefore, when performing defect detection on their surfaces, it is difficult to detect defects such as notches, pits, protrusions, and deformation of pits and protrusions.

[0004] In view of this, the present invention proposes a method for detecting surface defects of aluminum-magnesium alloy to solve the above problems. Summary of the Invention

[0005] In order to overcome the above-mentioned defects of the prior art and to achieve the above-mentioned purpose, the present invention provides the following technical solution: a method for detecting surface defects of aluminum-magnesium alloy, comprising the following steps:

[0006] Step S1: collecting and preprocessing the surface image of the aluminum-magnesium alloy component to obtain an image to be detected;

[0007] Step S2: performing layered processing on the image to be detected to obtain a plurality of layered images of the image to be detected;

[0008] Step S3: comparing the plurality of layered images with a preset standard image to obtain a difference set consisting of a plurality of difference results;

[0009] Step S4: for each difference result in the difference set, determine whether each difference result is less than a corresponding preset difference threshold; if not, it is considered that the image to be detected has defects.

[0010] Furthermore, 2. The method for detecting surface defects of an aluminum-magnesium alloy according to claim 1 is characterized in that step S1 comprises:

[0011] Step S11: photographing the surface of the aluminum-magnesium alloy component using an industrial camera to obtain a surface image;

[0012] Step S12: denoising the surface image using bilateral filtering, performing adaptive histogram equalization on the denoised surface image, and then performing grayscale conversion on the surface image after the adaptive histogram equalization process to obtain an image to be detected.

[0013] Furthermore, the step S2 includes:

[0014] Step S21: Calculate the horizontal and vertical gradients of the image to be detected and the directional consistency of the gradients to obtain a preliminary edge map of the image to be detected, and perform non-maximum suppression on the preliminary edge map to obtain a final edge map;

[0015] Step S22: Generate a constraint matrix using the edges of the final edge map and use the constraint matrix to merge the current pixel into the region of surrounding pixels until every pixel in the image to be detected is completely assigned to the region, that is, multiple segmented regions are obtained;

[0016] Step S23: traverse all segmented regions and perform histogram matching on each extracted segmented region, thereby obtaining a plurality of layered images.

[0017] Furthermore, step S3 includes:

[0018] Step S31: collecting and preprocessing the surface image of the standard part of the aluminum-magnesium alloy component, and using the preprocessed surface image of the standard part as a preset standard image;

[0019] Step S32: construct a spatial matrix of the image to be detected using a plurality of layered images, and then compare the spatial matrix with a preset standard image. The specific contents of the comparison are as follows:

[0020] Step S33: aligning each layered image in the spatial matrix with the corresponding standard area in a preset virtual space and comparing them to obtain a first difference result.

[0021] Step S34: Calculate the position difference between the maximum value of each layered image and the corresponding standard region as a first position difference, and calculate the position difference between the minimum value of each layered image and the corresponding standard region as a second position difference. The first position difference and the second position difference constitute the position difference between each layered image and the corresponding standard region.

[0022] Step S35: Define an adaptive gradient threshold, use the adaptive gradient threshold to obtain the area range corresponding to the position difference, use the position difference and the area range corresponding to the position difference as the second difference result between each layered image and the corresponding standard area, and store the first difference result and the second difference result in a set to obtain a difference set.

[0023] Furthermore, in step S32, the step of constructing a spatial matrix of the image to be detected using a plurality of layered images includes:

[0024] Step S321: Create a three-dimensional matrix with dimensions [H, W, N_LayerS], where H and W represent the height and width of the layered image, respectively, and N_LayerS represents the number of layers corresponding to the layered image.

[0025] Step S322: Store several layered images into a three-dimensional matrix, extract key points and descriptors of each layered image, and associate the key points and descriptors with the corresponding layered images to obtain a spatial matrix of the image to be detected.

[0026] Furthermore, in step S35, the step of defining an adaptive gradient threshold and obtaining the area range corresponding to the position difference using the adaptive gradient threshold includes:

[0027] Step S351: Obtain the regional range of the maximum value and the minimum value in the corresponding standard area in the standard image, and set the calculation formula of the adaptive gradient threshold based on the regional range of the maximum value and the minimum value in the corresponding standard area. The calculation formula is expressed as follows:

[0028] Where, T cur represents the gradient threshold of the layered image, T std Indicates the gradient threshold corresponding to the extreme value of the standard area, V cur Represents the extreme value of the layered image, V std Indicates the extreme value of the standard area, which is either a maximum value or a minimum value;

[0029] Step S352: Substitute the maximum value and the minimum value of the layered image into the above calculation formula to obtain the gradient threshold of the maximum value and the minimum value of the layered image;

[0030] Step S353: The range between the maximum value and the corresponding gradient threshold, and the range between the minimum value and the corresponding gradient threshold of the layered image are respectively used as the first maximum value region range and the second minimum value region range;

[0031] Step S354: Compare the first maximum value region range and the second minimum value region range with the corresponding maximum value region range and minimum value region range in the standard region, and use the different region ranges obtained by comparison as the region range of position difference.

[0032] Furthermore, in step S351, the step of obtaining the area range of the maximum value and the minimum value in the corresponding standard area in the standard image includes:

[0033] The positions of the maximum and minimum values in the corresponding standard area in the standard image are obtained, and the ranges of the maximum and minimum values in the corresponding standard area are manually marked based on the positions of the maximum and minimum values in the corresponding standard area, that is, the regional ranges of the maximum and minimum values in the standard area in the standard image are obtained.

[0034] Furthermore, in step S33, the step of obtaining the first difference result includes:

[0035] Step S331: align each layered image in the spatial matrix with the corresponding standard area using the extracted key points and descriptors, and set a first normal and a second normal on the edge of each layered image and the corresponding standard area. The first normal and the second normal are used to vertically align each layered image with the corresponding standard area.

[0036] Step S332: Obtain non-overlapping normal line groups of the first normal and the second normal, use the area between the non-overlapping normal line groups as the misaligned area of each layered image, and use the position difference of the non-overlapping normal line groups and the misaligned area as the first difference result between this layered image and the corresponding standard area.

[0037] Furthermore, in step S332, the step of obtaining a non-overlapping normal line group of the first normal and the second normal includes:

[0038] Define the coordinates of the intersection of the first normal and the edge of the layered image as F1 = (x'i'1, y'i'1) and the coordinates of the intersection of the second normal and the corresponding standard area as F2 = (x'j'2, y'j'2). Calculate the position difference between the first and second normals in virtual space using the following expression:

[0039]

[0040] Where d(i', j') represents the position difference between the first normal and the second normal in the virtual space. When this position difference is equal to 0, the first normal and the second normal are considered to coincide. Otherwise, the first normal and the second normal are considered to not coincide and form a non-coincident normal group. i' represents the index of the first normal, and j' represents the index of the second normal.

[0041] Furthermore, the step S4 includes:

[0042] Step S41: Obtain the maximum first difference result and second difference result allowed in historical aluminum-magnesium alloy components, obtain the corresponding maximum position difference and maximum area range based on the maximum first difference result and the second difference result, associate the maximum position difference and the maximum area range to obtain a first difference threshold, and associate the maximum position difference and the maximum area range to obtain a second difference threshold;

[0043] Step S42: Compare the first difference result and the second difference result of the image to be detected with the corresponding first difference threshold and second difference threshold respectively. If they are less than, it is judged that there is no defect in the image to be detected. If they are greater than or equal to, it is judged that there is a defect in the image to be detected, and the area corresponding to the defect is marked as a defective area.

[0044] The technical effects and advantages of the method for detecting surface defects of aluminum-magnesium alloys of the present invention are as follows:

[0045] 1. By layering the image to be inspected into several layered images, the problem of uneven grayscale distribution and overlap of defect areas and background grayscale caused by curvature changes, height differences, and local reflections on the surface of aluminum-magnesium alloy components can be solved. Each layered image on the surface of the aluminum-magnesium alloy component can contain complete defects, facilitating subsequent comparison of each layered image with the corresponding standard area to detect defects and defective areas.

[0046] 2. By setting an adaptive gradient threshold, the adaptive gradient threshold can be used as the edge of the area corresponding to the maximum and minimum values in the layered image. This solves the problem of overall grayscale difference between the layered image and the corresponding standard area, and the difficulty in determining the edges of pits and protrusions on the aluminum-magnesium alloy surface after deformation. As a result, pits and protrusions on the magnesium-aluminum alloy surface and the corresponding defect area range of the pits and protrusions can be more accurately identified, resulting in better recognition of deformation of pits and protrusions on the aluminum-magnesium alloy surface.

[0047] 3. By calculating the position difference between the first normal and the second normal, the problem of accurately determining the non-overlapping edge position of the layered image and the corresponding standard area is solved, and accurate edge defect detection is achieved, thereby effectively detecting surface defects such as gaps and protrusions at the edges of the layered image. BRIEF DESCRIPTION OF THE DRAWINGS

[0048] Figure 1 The figure is a flow chart of a method for detecting surface defects of aluminum-magnesium alloy according to the present invention. DETAILED DESCRIPTION

[0049] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of the present invention.

[0050] Application scenarios:

[0051] When using machine vision algorithms for defect detection on existing aluminum-magnesium alloy surfaces, it is often only possible to detect cracks and obvious pits and protrusions on the aluminum-magnesium alloy plane. Some aluminum-magnesium alloy surfaces with curved surfaces or complex structures (such as multi-layer height differences and non-uniform height differences) are easily difficult to detect due to interference such as gradient changes between the curved surface and the plane, multi-layer height differences, etc., such as notches, pits, protrusions, and deformation of pits and protrusions on the aluminum-magnesium alloy surface. In view of this, the present invention proposes a method for detecting surface defects of aluminum-magnesium alloys to solve the above problems.

[0052] See also Figure 1 As shown, the method for detecting surface defects of aluminum-magnesium alloy described in this embodiment includes the following steps:

[0053] Step S1: collecting and preprocessing the surface image of the aluminum-magnesium alloy component to obtain an image to be detected;

[0054] Step S2: performing layered processing on the image to be detected to obtain a plurality of layered images of the image to be detected;

[0055] Step S3: comparing the plurality of layered images with a preset standard image to obtain a difference set consisting of a plurality of difference results;

[0056] Step S4: for each difference result in the difference set, determine whether each difference result is less than a corresponding preset difference threshold; if not, it is considered that the image to be inspected has defects;

[0057] In this embodiment, by layering the image to be detected into several layered images and comparing them with the standard image, the defects caused by notches, pits, protrusions and deformation of pits and protrusions on the surface of the aluminum-magnesium alloy component can be detected based on the difference results, and the defect area corresponding to the surface defect can also be obtained.

[0058] As an optional embodiment, the step of collecting and preprocessing the surface image of the aluminum-magnesium alloy component to obtain the image to be detected includes:

[0059] Step S11: arranging an industrial camera on an industrial quality inspection line for aluminum-magnesium alloy components, and using the industrial camera to photograph the surface of the aluminum-magnesium alloy components to obtain a surface image;

[0060] Step S12: denoising the surface image using bilateral filtering, performing adaptive histogram equalization on the denoised surface image, and then performing grayscale conversion on the surface image after the adaptive histogram equalization process to obtain an image to be detected;

[0061] In this embodiment, when arranging industrial cameras, it is also necessary to arrange a ring-shaped LED light source or an oblique light source on the industrial quality inspection line, so as to enhance the shooting effect of the surface structure or texture of the aluminum-magnesium alloy component and reduce the situation caused by reflection and uneven brightness; by denoising the surface image through bilateral filtering, the edge information of the surface image can be retained and the noise can be reduced. Adaptive histogram equalization helps to enhance the contrast of the surface image, especially the areas with low contrast, which can make small defects on the surface of the aluminum-magnesium alloy component more obvious. For example, if a small scratch on the surface of the aluminum-magnesium alloy component is similar to the background color, after adaptive histogram equalization, the grayscale value of the scratch will be more significantly different from the surrounding area, so as to facilitate subsequent layered processing and defect detection of the surface image; by performing grayscale conversion on the surface image after adaptive histogram equalization processing, the computational complexity of subsequent defect detection can be reduced and subsequent defect detection can be made more efficient.

[0062] As an optional embodiment, the step of performing layered processing on the image to be detected to obtain a plurality of layered images of the image to be detected includes:

[0063] Step S21: Calculate the horizontal and vertical gradients of the image to be detected using the Sobel operator, calculate the directional consistency of the gradients using OpenCV to obtain a preliminary edge map of the image to be detected, and perform non-maximum suppression on the preliminary edge map using the Canny algorithm to highlight the edges to obtain a final edge map;

[0064] Step S22, using the edge of the final edge map to generate a constraint matrix and using the constraint matrix to merge the current pixel into the area of the surrounding pixels, until each pixel in the image to be detected is completely assigned to the area, that is, multiple segmented areas are obtained. It should be noted that after using the edge of the final edge map to generate the constraint matrix, if any pixel in the constraint matrix belongs to the edge, the areas on both sides of it are marked as prohibited from merging, and each pixel of the final edge map is traversed. If the current pixel belongs to the edge, the adjacency relationship of the areas on both sides of it is recorded. If the current pixel does not belong to the edge, the grayscale value of the pixels around the edge is checked. If the grayscale difference between the current pixel and the surrounding pixels is less than a preset gradient threshold, the current pixel is merged into the area of the surrounding pixels until each pixel in the image to be detected is completely assigned to the area, that is, multiple segmented areas are obtained;

[0065] Step S23: traverse all segmented regions and perform histogram matching on each extracted segmented region, that is, obtain several layered images (layered images are vector images), among which the largest connected region in the segmented region is extracted and used as the background region, and the background region is deleted;

[0066] It should be noted that, for example, if the aluminum-magnesium alloy component is a component with a curved surface, which is composed of a first plane-curved surface-second plane from top to bottom, after layering processing using the above technical means, the area of the first plane, the area of the curved surface, and the area of the second plane can be respectively divided into a layered image. If the aluminum-magnesium alloy component is a component with a height difference, the third plane, the fourth plane, the fifth inclined surface, and the sixth plane are composed from top to bottom, after layering processing using the above technical means, the third plane, the fourth plane, the fifth inclined surface, and the sixth plane can be respectively divided into a layered image, thereby reducing the reflection interference of the image to be detected, facilitating layered parallel processing, and shortening the overall detection time.

[0067] In this embodiment, the Sobel operator is used to calculate the gradient of the image to be detected in the horizontal and vertical directions and the Canny operator is used to generate a preliminary edge map, thereby solving the noise interference caused by reflection or processing texture on the surface of the aluminum-magnesium alloy and the problem of missed detection of weak edges (such as small scratches and gaps) by traditional edge detection, thereby detecting the edge area in the image to be detected and highlighting the defective part on the surface of the aluminum-magnesium alloy component. The Canny algorithm is used to perform non-maximum suppression on the preliminary edge map, which can effectively remove the false edges caused by uneven lighting or noise on the alloy surface and reduce artifact interference, ensuring that only the real defect edges are retained, thereby providing reliable edge information for subsequent image segmentation; the edge constraint matrix is used to mark the prohibited merging areas, By traversing pixels and merging surrounding pixels based on grayscale differences, the over-segmentation problem of complex surfaces or texture areas can be solved, and the mis-merging of edge areas due to noise can be reduced, thereby preserving the integrity of the edge and improving the accuracy of image segmentation; by setting up histogram matching and extracting the largest connected area as the background and deleting it to obtain several layered images, the problem of uneven grayscale distribution and overlap of defective areas with background grayscale caused by curvature changes, height differences (there are different height differences on the surface of aluminum-magnesium alloy components) and local reflections on the surface of aluminum-magnesium alloy components can be solved, and each layered image on the surface of the aluminum-magnesium alloy component can include complete defects, which is convenient for subsequent comparison of each layered image with the corresponding standard area to detect defects and defective areas.

[0068] As an optional embodiment, the step of comparing the plurality of layered images with a preset standard image to obtain a difference set consisting of a plurality of difference results includes:

[0069] Step S31: Acquire a surface image of a standard part of an aluminum-magnesium alloy component and perform preprocessing (refer to claim 2 for the preprocessing method), and use the preprocessed surface image of the standard part as a preset standard image;

[0070] Step S32: construct a spatial matrix of the image to be detected using a plurality of layered images, and then compare the spatial matrix with a preset standard image. The specific contents of the comparison are as follows:

[0071] Step S33: Using the Sift algorithm, each layered image in the spatial matrix is vertically aligned with the corresponding standard area in a preset virtual space, and then compared to obtain a first difference result (wherein the corresponding standard area in the standard image may be manually annotated in advance);

[0072] Step S34: Calculate the positional difference between the maximum value (grayscale maximum value) of each layered image and the corresponding standard region as a first positional difference, and calculate the positional difference between the minimum value (grayscale minimum value) of each layered image and the corresponding standard region as a second positional difference. The first positional difference and the second positional difference constitute the positional difference between each layered image and the corresponding standard region.

[0073] Step S35: defining an adaptive gradient threshold, using the adaptive gradient threshold to obtain the region range corresponding to the position difference, using the position difference and the region range corresponding to the position difference as the second difference result between each layered image and the corresponding standard region, and storing the first difference result and the second difference result in a set to obtain a difference set;

[0074] It should be noted that the first position difference and the second position difference are both obtained by calculating the Euclidean distance. The number of layered images of the image to be detected is the same as the number of corresponding standard areas in the standard image. If the image to be detected is an image taken of a standard part, the number and image content of the layered images of the image to be detected are the same as the corresponding standard areas in the standard image. For example, the three layered layers of the image to be detected are d1, d2 and d3, and the three corresponding standard areas of the standard image are b1, b2 and b3. Then, b1 is the standard area corresponding to d1 on the standard image, b2 is the standard area corresponding to d2 on the standard image, and b3 is the standard area corresponding to d3 on the standard image. By aligning and comparing b1 with d1, b2 with d2, and b3 with d3, the first difference result and the second difference result of each layered image of the image to be detected and the corresponding standard area can be obtained, thereby facilitating the acquisition of defects in the image to be detected.

[0075] In this embodiment, each layered image of the image to be detected is aligned with the corresponding standard area through the Sift algorithm, so as to facilitate the subsequent acquisition of the first difference result and the second difference result. The first position difference and the second position difference obtained by the Euclidean distance calculation can reflect the position offset of the maximum and minimum values between the layered image and the corresponding standard area, so as to facilitate more accurate detection of defects. Moreover, by setting the adaptive gradient threshold, the adaptive gradient threshold can be used as the edge of the area range corresponding to the maximum and minimum values in the layered image, which solves the problem that when there is a difference in the overall grayscale value between the layered image and the corresponding standard area and the pits and protrusions on the surface of the aluminum-magnesium alloy are difficult to determine the edges of the pits and protrusions after deformation, and facilitates the use of the adaptive gradient threshold as the edge of the pits and protrusions to obtain the area range corresponding to the maximum or minimum value in the layered image, thereby facilitating more accurate identification of the pits, protrusions (or curved surfaces) on the surface of the magnesium-aluminum alloy and the defect area range corresponding to the pits and protrusions, which has a better recognition effect on the deformation (expansion or reduction) of the pits and protrusions on the surface of the aluminum-magnesium alloy.

[0076] As an optional embodiment, the step of constructing a spatial matrix of the image to be detected using a plurality of layered images includes:

[0077] Step S321: Create a three-dimensional matrix with dimensions [H, W, N_LayerS], where H and W represent the height and width of the layered image, respectively, and N_LayerS represents the number of layers corresponding to the layered image.

[0078] Step S322: storing a plurality of layered images into a three-dimensional matrix, extracting key points and descriptors of each layered image, and associating the key points and descriptors with the corresponding layered images to obtain a spatial matrix of the image to be detected;

[0079] It should be noted that the key points and descriptors of the layered image and the corresponding standard area are extracted by the Sift algorithm. The specific extraction process is as follows: the potential key points of the image at different scales are detected by Gaussian blur and difference pyramid, the low contrast points and edge responses are eliminated by fitting a three-dimensional quadratic function to obtain the key points, the main direction of the key points is calculated to give rotation invariance, and the gradient direction histogram of the surrounding area with the key point as the center is extracted as the feature vector to obtain the descriptor;

[0080] In this embodiment, the key points and descriptors of the image are extracted by the Sift algorithm, which solves the problem of aligning each layered image with the corresponding standard area in the spatial matrix using key points and descriptors. The layered images are uniformly managed through a three-dimensional matrix to retain spatial position and hierarchical information, thereby facilitating subsequent comparison of the layered images with the corresponding standard areas to obtain defects on the surface of the aluminum-magnesium alloy.

[0081] As an optional embodiment, the step of defining an adaptive gradient threshold and obtaining the region range corresponding to the position difference using the adaptive gradient threshold includes:

[0082] Step S351: Obtain the regional range of the maximum value and the minimum value in the corresponding standard area in the standard image, and set the calculation formula of the adaptive gradient threshold based on the regional range of the maximum value and the minimum value in the corresponding standard area. The calculation formula is expressed as follows:

[0083] Where, T cur represents the gradient threshold of the layered image, T std Indicates the gradient threshold corresponding to the extreme value of the standard area, V cur Represents the extreme value of the layered image, V std Indicates the extreme value of the standard area, which is either a maximum value or a minimum value. It should be noted that during calculation, the extreme value in the calculation formula can only be a maximum value or only a minimum value. When calculating the gradient threshold of the maximum value of a layered image, the input is the maximum value of the layered image and the standard area, as well as the gradient threshold corresponding to the maximum value. Conversely, when calculating the gradient threshold of the minimum value of a layered image, the input is the minimum value of the layered image and the standard area, as well as the gradient threshold corresponding to the minimum value.

[0084] Step S352: Substitute the maximum value and the minimum value of the layered image into the above calculation formula to obtain the gradient threshold of the maximum value and the minimum value of the layered image;

[0085] Step S353: The range between the maximum value and the corresponding gradient threshold, and the range between the minimum value and the corresponding gradient threshold of the layered image are respectively used as the first maximum value region range and the second minimum value region range;

[0086] Step S354: Compare the first maximum value region range and the second minimum value region range with the corresponding maximum value region range and minimum value region range in the standard region, and use the different region ranges obtained by comparison as the region range of position difference;

[0087] It should be noted that, for example, the maximum coordinates (xmax, ymax) and the corresponding grayscale value of the standard area corresponding to the layered image in the standard image are 150, the minimum coordinates (xmin, ymin) and the corresponding grayscale value are 30, the area range of the maximum value is Pmax, and the area range of the minimum value is Pmin; if the areas corresponding to the maximum value and the minimum value are both circular, the area range of Pmax (with the maximum value as the center and a radius of 20), and the grayscale value of the circumferential edge corresponding to the Pmax radius of 20 are 80, then the gradient threshold of the maximum value of the standard area is 80, and further, if the maximum value of a layered image in the image to be detected is 75 and the minimum value is 15, the ratio of the maximum value of the layered image 75 to the corresponding maximum value of the standard area 150 is obtained (75 / 150=0.5), based on this ratio, the gradient threshold of the layered image is calculated to be (80*0.5=40), and further, the area with a grayscale value of 40 corresponding to the coordinates around the maximum value of the layered image is taken as the area range of the maximum value of the layered image;

[0088] In this embodiment, by calculating the adaptive gradient threshold of the maximum or minimum value of the layered image, the adaptive gradient threshold can be used as the edge of the area range corresponding to the maximum and minimum values in the layered image, thereby solving the problem of overall grayscale difference between the layered image and the corresponding standard area, and the difficulty in determining the edges of the pits and protrusions on the surface of the aluminum-magnesium alloy after deformation. Therefore, the pits and protrusions on the surface of the magnesium-aluminum alloy and the defective area range corresponding to the pits and protrusions can be more accurately identified, making the recognition effect of the deformation of the pits and protrusions on the surface of the aluminum-magnesium alloy more excellent.

[0089] As an optional embodiment, the step of obtaining the area range of the maximum value and the minimum value in the corresponding standard area in the standard image includes:

[0090] Obtaining the positions of the maximum and minimum values in the corresponding standard area in the standard image, and manually marking the ranges of the maximum and minimum values in the corresponding standard area based on the positions of the maximum and minimum values in the corresponding standard area, thereby obtaining the regional ranges of the maximum and minimum values in the standard area in the standard image;

[0091] In this embodiment, the maximum value, minimum value and corresponding area range of the corresponding standard area in the surface image can be manually marked, so as to facilitate the subsequent comparison of these area ranges with the first maximum area range and the second minimum area range of the layered image.

[0092] As an optional embodiment: the step of obtaining the first difference result includes:

[0093] Step S331: align each layered image in the spatial matrix with the corresponding standard area using the key points and descriptors extracted by the Sift algorithm. Set a first normal and a second normal on the edge of each layered image and the corresponding standard area. The first normal and the second normal are used to vertically align each layered image with the corresponding standard area.

[0094] Step S332: Obtain non-overlapping normal line groups of the first normal and the second normal, use the area between the non-overlapping normal line groups as the misaligned area of each layered image, and use the position difference of the non-overlapping normal line groups and the misaligned area as the first difference result between this layered image and the corresponding standard area.

[0095] As an optional embodiment, the step of obtaining a non-overlapping normal line group of the first normal and the second normal includes:

[0096] Define the coordinates of the intersection of the first normal and the edge of the layered image as F1 = (x'i'1, y'i'1) and the coordinates of the intersection of the second normal and the corresponding standard area as F2 = (x'j'2, y'j'2). Calculate the position difference between the first and second normals in virtual space using the following expression:

[0097]

[0098] Where d(i', j') represents the position difference between the first normal and the second normal in the virtual space (calculated by the Euclidean distance). When this position difference is equal to 0, the first normal and the second normal are considered to coincide. Otherwise, the first normal and the second normal are considered to not coincide and form a non-coincident normal group. i' represents the index of the first normal, and j' represents the index of the second normal.

[0099] It should be noted that, for example, a first normal (2, 4) and a second normal (3, 4) are respectively set on the edge of the layered image and the corresponding standard area, and the position difference between the first normal F1 and the second normal F2 is calculated to be 1, then d(i', j') is not 0, indicating that the two normals do not overlap, indicating that there is a deviation or misalignment between the layered image and the corresponding standard area, that is, there is a misaligned area. The maximum position difference of these misaligned areas is calculated, and the position difference and the misaligned area are used as the first difference result between the layered image and the corresponding standard area;

[0100] In this embodiment, by using the Euclidean distance to calculate the position difference between the first normal and the second normal, the problem of accurately determining the non-overlapping edge position of the layered image and the corresponding standard area is solved, thereby achieving accurate edge defect detection, and effectively detecting the surface defects of gaps and protrusions at the edges of the layered image.

[0101] As an optional embodiment, the step of determining, for each difference result in the difference set, whether each difference result is less than a corresponding preset difference threshold, and if not, determining that the image to be inspected has a defect includes:

[0102] Step S41: Obtain the maximum first difference result and second difference result allowed in historical aluminum-magnesium alloy components, obtain the corresponding maximum position difference and maximum area range based on the maximum first difference result and the second difference result, associate the maximum position difference and the maximum area range to obtain a first difference threshold, and associate the maximum position difference and the maximum area range to obtain a second difference threshold;

[0103] Step S42: Compare the first difference result and the second difference result of the image to be inspected with the corresponding first difference threshold and second difference threshold, respectively. If the first difference threshold and the second difference threshold are less than each other, it is determined that the image to be inspected does not have defects. If the first difference threshold and the second difference threshold are greater than or equal to each other, it is determined that the image to be inspected does have defects, and the area corresponding to the defect is marked as a defect area.

[0104] It should be noted that, for example, the three first difference results of the image to be detected are (2, 10 pixels), (0, 0), and (4, 40 pixels), and the three second difference results of the image to be detected are (0, 0), (20, 30 pixels), and (0, 0). If the first difference threshold is (2.5, 30 pixels) and the second difference threshold is (10, 25 pixels), then it can be considered that the first difference result does not meet the preset difference threshold, and (20, 30 pixels) in the second difference result does not meet the preset difference threshold. Therefore, the area corresponding to (4, 40 pixels) in the first difference result and (20, 30 pixels) in the second difference result has defects and is marked as a defective area.

[0105] In this embodiment, by comparing the difference result with the preset difference threshold, it is possible to automatically determine whether the image to be detected has defects, which can greatly improve the detection efficiency and accuracy. By setting the difference threshold (first difference threshold and second difference threshold), it is possible to more accurately determine whether the defects of the aluminum-magnesium alloy component meet the requirements, reducing the possibility of misjudgment and missed judgment. If it does not meet the requirements, the defective area can also be marked.

[0106] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed in the present invention can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.

[0107] In the several embodiments provided by the present invention, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of the units is only one type. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0108] The above description is only a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any technician familiar with this technical field can easily think of changes or replacements within the technical scope disclosed by the present invention, which should be covered by the scope of protection of the present invention.

[0109] Finally: The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.

Claims

1. A method for detecting surface defects of aluminum-magnesium alloys, characterized in that: The following steps are involved: Step S1: collecting and preprocessing the surface image of the aluminum-magnesium alloy component to obtain an image to be detected; Step S2: performing layered processing on the image to be detected to obtain a plurality of layered images of the image to be detected; Step S3: comparing the plurality of layered images with a preset standard image to obtain a difference set consisting of a plurality of difference results; Step S4: for each difference result in the difference set, determine whether each difference result is less than a corresponding preset difference threshold; if not, it is considered that the image to be detected has defects.

2. The method for detecting surface defects of aluminum-magnesium alloy according to claim 1, characterized in that: The step S1 comprises: Step S11: photographing the surface of the aluminum-magnesium alloy component using an industrial camera to obtain a surface image; Step S12: denoising the surface image using bilateral filtering, performing adaptive histogram equalization on the denoised surface image, and then performing grayscale conversion on the surface image after the adaptive histogram equalization process to obtain an image to be detected.

3. The method for detecting surface defects of aluminum-magnesium alloy according to claim 1, characterized in that: The step S2 comprises: Step S21: Calculate the horizontal and vertical gradients of the image to be detected and the directional consistency of the gradients to obtain a preliminary edge map of the image to be detected, and perform non-maximum suppression on the preliminary edge map to obtain a final edge map; Step S22: Generate a constraint matrix using the edges of the final edge map and use the constraint matrix to merge the current pixel into the region of surrounding pixels until every pixel in the image to be detected is completely assigned to the region, that is, multiple segmented regions are obtained; Step S23: traverse all segmented regions and perform histogram matching on each extracted segmented region, thereby obtaining a plurality of layered images.

4. The method for detecting surface defects of aluminum-magnesium alloy according to claim 1, characterized in that: The step S3 comprises: Step S31: collecting and preprocessing the surface image of the standard part of the aluminum-magnesium alloy component, and using the preprocessed surface image of the standard part as a preset standard image; Step S32: construct a spatial matrix of the image to be detected using a plurality of layered images, and then compare the spatial matrix with a preset standard image. The specific contents of the comparison are as follows: Step S33: aligning each layered image in the spatial matrix with the corresponding standard area in a preset virtual space and comparing them to obtain a first difference result. Step S34: Calculate the position difference between the maximum value of each layered image and the corresponding standard region as a first position difference, and calculate the position difference between the minimum value of each layered image and the corresponding standard region as a second position difference. The first position difference and the second position difference constitute the position difference between each layered image and the corresponding standard region. Step S35: Define an adaptive gradient threshold, use the adaptive gradient threshold to obtain the area range corresponding to the position difference, use the position difference and the area range corresponding to the position difference as the second difference result between each layered image and the corresponding standard area, and store the first difference result and the second difference result in a set to obtain a difference set.

5. The method for detecting surface defects of aluminum-magnesium alloy according to claim 4, characterized in that: In step S32, the step of constructing a spatial matrix of the image to be detected using a plurality of layered images includes: Step S321: Create a three-dimensional matrix with dimensions [H, W, N_LayerS], where H and W represent the height and width of the layered image, respectively, and N_LayerS represents the number of layers corresponding to the layered image. Step S322: Store several layered images into a three-dimensional matrix, extract key points and descriptors of each layered image, and associate the key points and descriptors with the corresponding layered images to obtain a spatial matrix of the image to be detected.

6. The method for detecting surface defects of aluminum-magnesium alloy according to claim 4, characterized in that: In step S35, the steps of defining an adaptive gradient threshold and obtaining the region range corresponding to the position difference using the adaptive gradient threshold include: Step S351: Obtain the regional range of the maximum value and the minimum value in the corresponding standard area in the standard image, and set the calculation formula of the adaptive gradient threshold based on the regional range of the maximum value and the minimum value in the corresponding standard area. The calculation formula is expressed as follows: Where, T cur represents the gradient threshold of the layered image, T std Indicates the gradient threshold corresponding to the extreme value of the standard area, V cur Represents the extreme value of the layered image, V std Indicates the extreme value of the standard area, which is either a maximum value or a minimum value; Step S352: Substitute the maximum value and the minimum value of the layered image into the above calculation formula to obtain the gradient threshold of the maximum value and the minimum value of the layered image; Step S353: The range between the maximum value and the corresponding gradient threshold, and the range between the minimum value and the corresponding gradient threshold of the layered image are respectively used as the first maximum value region range and the second minimum value region range; Step S354: Compare the first maximum value region range and the second minimum value region range with the corresponding maximum value region range and minimum value region range in the standard region, and use the different region ranges obtained by comparison as the region range of position difference.

7. The method for detecting surface defects of aluminum-magnesium alloy according to claim 6, characterized in that: In step S351, the step of obtaining the area range of the maximum value and the minimum value in the corresponding standard area in the standard image includes: The positions of the maximum and minimum values of the corresponding standard area in the standard image are obtained, and the ranges of the maximum and minimum values in the corresponding standard area are manually marked based on the positions of the maximum and minimum values of the corresponding standard area, that is, the maximum and minimum values in the standard image and the corresponding area range are obtained.

8. The method for detecting surface defects of aluminum-magnesium alloy according to claim 5, characterized in that: In step S33, the step of obtaining the first difference result includes: Step S331: align each layered image in the spatial matrix with the corresponding standard area using the extracted key points and descriptors, and set a first normal and a second normal on the edge of each layered image and the corresponding standard area. The first normal and the second normal are used to vertically align each layered image with the corresponding standard area. Step S332: Obtain non-overlapping normal line groups of the first normal and the second normal, use the area between the non-overlapping normal line groups as the misaligned area of each layered image, and use the position difference of the non-overlapping normal line groups and the misaligned area as the first difference result between this layered image and the corresponding standard area.

9. The method for detecting surface defects of aluminum-magnesium alloy according to claim 8, characterized in that: In step S332, the step of obtaining a non-overlapping normal line group of the first normal and the second normal includes: Define the coordinates of the intersection of the first normal and the edge of the layered image as F1 = (x'i'1, y'i'1) and the coordinates of the intersection of the second normal and the corresponding standard area as F2 = (x'j'2, y'j'2). Calculate the position difference between the first and second normals in virtual space using the following expression: Where d(i', j') represents the position difference between the first normal and the second normal in the virtual space. When this position difference is equal to 0, the first normal and the second normal are considered to coincide. Otherwise, the first normal and the second normal are considered to not coincide and form a non-coincident normal group. i' represents the index of the first normal, and j' represents the index of the second normal.

10. The method for detecting surface defects of aluminum-magnesium alloy according to claim 4, characterized in that: The step S4 comprises: Step S41: Obtain the maximum first difference result and second difference result allowed in historical aluminum-magnesium alloy components, obtain the corresponding maximum position difference and maximum area range based on the maximum first difference result and the second difference result, associate the maximum position difference and the maximum area range to obtain a first difference threshold, and associate the maximum position difference and the maximum area range to obtain a second difference threshold; Step S42: Compare the first difference result and the second difference result of the image to be detected with the corresponding first difference threshold and second difference threshold respectively. If they are less than, it is judged that there is no defect in the image to be detected. If they are greater than or equal to, it is judged that there is a defect in the image to be detected, and the area corresponding to the defect is marked as a defective area.

Citation Information

Patent Citations

  • Edge detection method based on gray-scale image of specific class

    CN102521836A

  • Multidimensional image segmentation method

    CN106504259A

  • Aluminum electrolytic capacitor outgoing line abnormity identification method

    CN115880285A