A method and system for detecting surface defects of magnetic tiles based on machine vision
The local bright area difference calculation and PM diffusion method combined with the Canny algorithm for surface defect detection of magnetic tile is solved, and the problems of low image contrast and high noise in the prior art are achieved, and efficient defect recognition and detection effects are achieved.
Patent Information
- Application Number
- CN202310368203.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-04-08
- Publication Date
- 2025-07-22
- Estimated Expiration
- 2043-04-08
AI Technical Summary
The prior art has problems such as low image contrast, local uneven light, high Gaussian noise, and bright bar interference in the detection of surface defects of magnetic tile, resulting in low accuracy of defect recognition, and the existing methods have large calculation volume and poor real-time performance, making it difficult to adapt to industrial on-site inspection.
Image enhancement is performed by local bright area difference calculation, local bright area feature descriptor normalization, diffusion coefficient function calculation and PM diffusion method, defect edge detection and segmentation are performed by combining Canny algorithm, and finally template matching algorithm is used for identification and detection.
It achieves a high accuracy and recall rate of defect detection, reduces the difficulty of identification algorithms, improves detection speed, and has important industrial application value.
Smart Images

Figure CN116363112B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of quality inspection of magnetic tiles for motors in new energy vehicles, and more specifically, to a method and system for detecting surface defects of magnetic tiles based on machine vision. Background Art
[0002] With the rapid development of new energy vehicle technology, the quality requirements for magnetic tiles in permanent magnet motors are getting higher and higher. Due to manufacturing technology and transportation conditions, various surface defects are inevitably generated during the production of magnetic tiles, among which cracks and pores account for the largest proportion.
[0003] The cutting texture left during the processing of magnetic tiles. In machine vision inspection, using parallel light imaging is likely to cause CCD exposure saturation and submerge defect features. Using uniform scattered light imaging, although it has the advantages of large illumination area and non-directional light path, the image will have problems such as low contrast, uneven local illumination, high Gaussian noise, and bright stripe interference. Image enhancement of low-contrast scattered light imaging is the key step to improve the success rate of defect detection and is also a difficult point in current magnetic tile defect detection.
[0004] Existing detection methods using spectra will amplify noise while enhancing edges, and inevitably damage edge information while filtering noise, resulting in low defect recognition accuracy. Detection methods using artificial intelligence require a large number of accurately labeled samples for training, have a huge amount of calculation, poor real-time performance, and are difficult to adapt to industrial on-site inspection.
[0005] The nonlinear anisotropic diffusion method based on partial differential equations (PDE) is another good solution. Especially, the two-dimensional nonlinear diffusion PM model proposed by Perona and Malik can perform different diffusion operations in the edge region and non-edge region, thus synchronously filtering the background and protecting details. However, this method has poor effect on bright stripe interference in magnetic tile images and low defect recognition accuracy.
[0006] In view of this, it is necessary to provide an efficient method for detecting surface defects of magnetic tiles based on machine vision to overcome or alleviate the above defects in the prior art. Summary of the Invention
[0007] The purpose of the present invention is to provide a method and system for detecting surface defects of magnetic tiles based on machine vision to overcome the defects existing in the prior art.
[0008] To achieve the above purpose, the technical solution adopted by the present invention is as follows:
[0009] A method for detecting surface defects of magnetic tiles based on machine vision includes the following steps:
[0010] S1. Calculate the local bright area difference P of the image s ;
[0011] S2. Calculate the local bright area feature descriptor F of the image according to the local bright area difference P of the image s ; s ;
[0012] S3. Perform a normalization operation on the local bright area feature descriptor F to obtain the F value; s ;
[0013] S4. Calculate the diffusion coefficient function g(x) based on the F value;
[0014] S5. Perform image enhancement using the PM diffusion method based on the diffusion coefficient function g(x);
[0015] S6. Perform defect edge detection and segmentation on the result after image enhancement;
[0016] S7. Use the template matching algorithm for defect recognition and detection.
[0017] Furthermore, the formula for the local bright area difference P of the image in step S1 is: s ;
[0018]
[0019] where H s is the sum of the neighborhood pixels with a size of 2S + 1 of the pixel point I, and P s is the difference between the neighborhood mean and the center point I*.
[0020] Furthermore, the formula for the local bright area feature descriptor F of the image in step S2 is: s ;
[0021]
[0022] Furthermore, the formula for the normalization operation in step S3 is:
[0023]
[0024] Furthermore, the formula for the diffusion coefficient function g(x) in step S4 is:
[0025]
[0026] where is the average gradient of the pixel point at coordinates (x, y) in the up, down, left, and right four directions in the image.
[0027] Furthermore, the formula for image enhancement using the PM diffusion method in step S5 is:
[0028]
[0029] In the formula, the function v(x) is a sharpening weight function, and its expression is α is a sharpening weight factor.
[0030] Further, in the step S6, the Canny algorithm is used for defect edge detection.
[0031] The present invention also provides a system according to the above-mentioned machine vision-based magnetic tile surface defect detection method, including:
[0032] A first calculation module for calculating the local bright area difference P of the image s ;
[0033] A second calculation module for calculating the local bright area feature descriptor F of the image according to the local bright area difference P of the image s ; s A normalization module for performing a normalization operation on the local bright area feature descriptor F to obtain an F value;
[0034] A third calculation module for calculating a diffusion coefficient function g(x) based on the F value; s ;
[0035] An image enhancement module for performing image enhancement using the PM diffusion method based on the diffusion coefficient function g(x);
[0036] An edge detection and segmentation module for performing defect edge detection and segmentation on the result of the image enhancement;
[0037] An identification and detection module for performing defect identification and detection using a template matching algorithm.
[0038] The first calculation module, the second calculation module, the normalization module, the third calculation module, the image enhancement module, the edge detection and segmentation module, and the identification and detection module are connected in sequence.
[0039] Compared with the prior art, the advantages of the present invention are as follows: After image enhancement, the present invention can achieve high accuracy and recall rates only by using a conventional comparison algorithm, with a large performance improvement compared to similar enhancement algorithms, which is of great significance for reducing the difficulty of the recognition algorithm and improving the detection speed.
[0040] Description of the Drawings
[0041] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the accompanying drawings required for the description of the embodiments or the prior art. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other accompanying drawings can be obtained based on these drawings.
[0042] Figure 1 It is a flowchart of the method for detecting surface defects of magnetic tiles based on machine vision of the present invention.
[0043] Figure 2 It is the local neighborhood of size 2 in the present invention.
[0044] Figure 3 It is a comparison diagram of the diffusion effects of each model in the present invention.
[0045] Figure 4 It is a comparison diagram of the segmentation effects of each model in the present invention.
[0046] Figure 5 It is a schematic diagram of the system for detecting surface defects of magnetic tiles based on machine vision of the present invention. Specific Embodiments
[0047] The following will elaborate on the preferred embodiments of the present invention in conjunction with the accompanying drawings, so that the advantages and features of the present invention can be more easily understood by those skilled in the art, thereby making the protection scope of the present invention more clearly defined.
[0048] Refer to Figure 1 As shown, this embodiment discloses a method for detecting surface defects of magnetic tiles based on machine vision, including the following steps:
[0049] Step S1: Calculate the local bright area difference P of the image s .
[0050] Specifically, to accurately describe the brightness characteristics in the local spatial domain of the image, this embodiment defines a new parameter P s , and its calculation is as shown in formula (1):
[0051]
[0052] In the formula, N s is the sum of the neighborhood pixels of size 2S + 1 of the pixel point I, and P s is the difference between the neighborhood mean and the central point I*. Figure 2 Shows the neighborhood structure diagram of size 2.
[0053] To more accurately describe the relationship between a pixel and the mean value of its neighborhood, the neighborhood sampling range can be appropriately expanded, and then its mean value can be calculated. Generally, four times are enough. For example, if the mean length of the bright bar shape is 23 pixels, the sampling range S can be taken as {2, 8, 16, 24}.
[0054] Step S2: According to the local bright area difference P of the image s Calculate the local bright area feature descriptor F of the image s .
[0055] Specifically, the local bright area difference P s Describes the mean brightness difference between the current pixel and its neighborhood. If the current pixel is darker, the value is negative; otherwise, the value is positive, and the larger the value, the greater the difference. In this embodiment, more attention is paid to suppressing the bright area, so F is defined s Only takes positive values and filters out negative values. Its calculation is as shown in formula (2):
[0056]
[0057] Step S3: Perform a normalization operation on the local bright area feature descriptor F s To obtain the F value.
[0058] Specifically, sum and normalize the four different local bright area features F s To obtain the F value. Its calculation is as shown in formula (3):
[0059]
[0060] Step S4: Calculate the diffusion coefficient function g(x) based on the F value.
[0061] Specifically, the diffusion coefficient function q(x) is the key guiding filtering function of the PM model. In existing PM model-based or improved models, the diffusion coefficient function g(x) is calculated only based on the gradient information of the current pixel point or the estimated noise level, and cannot overcome the interference in the bright stripe area. The improved diffusion coefficient function in this embodiment adds the bright area feature description F calculated in the aforementioned step S2 s . Its calculation method is as shown in formula (4).
[0062]
[0063] In the formula,[[]] Is the mean gradient of the pixel point at coordinates (x, y) in the up, down, left, and right directions in the image.
[0064] In the formula, when the value of the local bright area feature F is larger, the value of the diffusion coefficient function g(x) is larger, the diffusion degree of this area increases, and the filtering effect is obvious. In the defect area, the value of F is smaller, the value of g(x) also becomes smaller, the diffusion weakens, and the defect area is retained. Thus, the function of suppressing the bright area is achieved. On the contrary, if the suppression of the dark area and the enhancement of the bright area are to be realized, then (1 - F) can be changed to F.
[0065] Step S5: Perform image enhancement using the PM diffusion method based on the diffusion coefficient function g(x).
[0066] In the magnetic tile detection scenario of this embodiment, the contrast between the defect and the background is relatively low, which will bring difficulties to the subsequent recognition link and the detection effect is not good. This embodiment improves the defect edge enhancement diffusion mode with the function of suppressing the bright area, and its calculation is shown in formula (5).
[0067]
[0068] In the formula, the v(x) function is the sharpening weight function, and its expression is α is the sharpening weight factor, which controls the edge sharpening intensity. The monotonicity of v(x) is opposite to that of g(x). When the value of g(x) is relatively large, it corresponds to the background or bright bar area. At this time, the value of v(x) is close to zero and will not affect the diffusion. When the value of g(x) is relatively small, it corresponds to the defect edge area. At this time, the value of v(x) is relatively large, the diffusion coefficient is negative, and the diffusion direction is inverse diffusion, and the defect edge will be sharpened. Figure 3 The figure shows the effect comparison of the method of the present invention and similar methods in background smoothing and defect enhancement. Figure 3 In the figure, the first column a is the original magnetic tile image, the second column b is the result of the Perona-Malik method (PM), the third column c is the SSAD method, the fourth column d is the LVAD method, and the last column e is the diffusion result of the algorithm of the present invention. It can be seen from the figure that the bright bar interference and noise in the background area of the last column e are effectively smoothed, and the image contrast is enhanced; at the same time, the shape features of the defects are well protected, and the effect of image enhancement is relatively ideal.
[0069] Step S6: Perform defect edge detection and segmentation on the result after image enhancement.
[0070] Specifically, edge detection and image segmentation are key processing steps for defect detection. Based on the above diffusion result, the present invention uses the Canny algorithm for edge detection. Figure 4 The figure shows the defect edge detection results of different diffusion models.
[0071] Column a shows the original magnetic tile image. From the effects in columns b and c, it can be seen that the PM and SSAD methods are severely interfered by noise and bright strip regions, generating many false edges and noise points. Especially when the area of the defect region is small, the PM model even smooths the defects, resulting in missed detections. Due to the addition of a noise discrimination mechanism in column d, the detection effect is better, but when enhancing crack defects, it misjudges cracks as noise and smooths them, and it cannot suppress the interference of bright strip regions. By using the edge detection algorithm of the present invention (column e), due to the bright area discrimination and suppression mechanism, the dual goals of diffusing the background and strengthening the edges are better achieved, and the defect contour remains clear. This further verifies the effect of the enhancement algorithm of the present invention.
[0072] Step S7: Use a template matching algorithm for defect identification and detection.
[0073] Specifically, on the basis of the above steps, the present invention uses a template matching algorithm for defect identification and detection. The comparison results of the accuracy rate and recall rate are shown in Tables 1 and 2.
[0074] Table 1 Comparison of defect detection accuracy rates
[0075]
[0076] Table 2 Comparison of defect detection recall rates
[0077]
[0078] As can be seen from the above table, after being enhanced by the bright area suppression diffusion model proposed by the present invention, a high accuracy rate and recall rate can be achieved only by using a conventional comparison algorithm. There is a significant performance improvement compared with similar enhancement algorithms. It is of great significance for reducing the difficulty of the recognition algorithm and improving the detection speed.
[0079] Combined with Figure 5 As shown, the present invention also provides a system according to the above-mentioned magnetic tile surface defect detection method based on machine vision, including: a first calculation module 1 for calculating the local bright area difference P of the image s ; a second calculation module 2 for calculating the local bright area feature descriptor F of the image according to the local bright area difference P of the image s ; a normalization module 3 for normalizing the local bright area feature descriptor F s ; sThe normalization operation is performed to obtain the F value; the third calculation module 4 is used to calculate the diffusion coefficient function g(x) based on the F value; the image enhancement module 5 is used to perform image enhancement using the PM diffusion method based on the diffusion coefficient function g(x); the edge detection and segmentation module 6 is used to perform defect edge detection and segmentation on the result after image enhancement; the recognition and detection module 7 is used to perform defect recognition and detection using the template matching algorithm, and the first calculation module 1, the second calculation module 2, the normalization module 3, the third calculation module 4, the image enhancement module 5, the edge detection and segmentation module 6, and the recognition and detection module 7 are connected in sequence.
[0080] Although the embodiments of the present invention have been described in conjunction with the accompanying drawings, the patent owner can make various deformations or modifications within the scope of the appended claims. As long as it does not exceed the protection scope described by the claims of the present invention, it should be within the protection scope of the present invention.
Claims
1. A method for detecting surface defects of magnetic tiles based on machine vision, characterized in that, It includes the following steps: S1. Calculate the local bright area difference P of the image s ; S2. Calculate the local bright region feature descriptor F of the image based on the local bright region difference P of the image s s ; S3. Normalize the local bright area feature descriptor F s to obtain the F value; S4. Calculate the diffusion coefficient function g(x) based on the F value; S5. Perform image enhancement using the PM diffusion method based on the diffusion coefficient function g(x); S6. Detect and segment the defect edges of the result after image enhancement; S7. Use the template matching algorithm for defect recognition and detection; The calculation formula of the diffusion coefficient function g(x) in the step S4 is: In the formula, is the average gradient in the four directions of up, down, left, and right of the pixel point with coordinates (x, y) in the image; The formula for image enhancement using the PM diffusion method in the step S5 is: In the formula, the function v(x) is a sharpening weight function, and its expression is α is a sharpening weight factor.
2. The method for detecting surface defects of magnetic tiles based on machine vision according to claim 1, wherein The local bright area difference P of the image in the step S1 s is calculated by the following formula: Where N s is the sum of neighborhood pixels with a size of 2S + 1 of pixel point I, and P s is the difference between the neighborhood mean and the central point I * .
3. The method for detecting magnetic tile surface defects based on machine vision according to claim 1, wherein The local bright area feature descriptor F of the image in the step S2 s is calculated by the following formula:
4. The method for detecting surface defects of magnetic tiles based on machine vision according to claim 1, characterized in that, The calculation formula of the normalization operation in the step S3 is:
5. The method for detecting magnetic tile surface defects based on machine vision according to claim 1, wherein In the step S6, the Canny algorithm is used for defect edge detection.
6. A system for the method of detecting surface defects of magnetic tiles based on machine vision according to any one of claims 1-5, characterized in that, It includes: A first calculation module for calculating the local bright area difference P of an image s ; A second calculation module, configured to calculate a local bright region feature descriptor F of an image according to a local bright region difference P of the image s s ; A normalization module for normalizing the local bright region feature descriptor F s to obtain the F value through a normalization operation; A third calculation module for calculating the diffusion coefficient function g(x) based on the F value; An image enhancement module for performing image enhancement using the PM diffusion method based on the diffusion coefficient function g(x); An edge detection and segmentation module for detecting and segmenting the defect edges of the result after image enhancement; A recognition and detection module for using the template matching algorithm for defect recognition and detection; The first calculation module, the second calculation module, the normalization module, the third calculation module, the image enhancement module, the edge detection and segmentation module, and the recognition and detection module are connected in sequence.