A method and system for detecting surface defects of NdFeB magnets
The method and system use an imaging platform with data preprocessing and a deep learning model to efficiently and accurately detect defects on neodymium iron boron magnets, addressing inefficiencies and mechanical damage issues in traditional methods.
Patent Information
- Application Number
- CN202411761944.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-03
- Publication Date
- 2025-07-15
- Estimated Expiration
- 2044-12-03
AI Technical Summary
The surface defect detection of traditional neodymium iron boron magnets relies on manual visual inspection to be inefficient and subjective, making it difficult to identify small hidden defects and easily cause secondary damage.
The closed concealed image acquisition platform is used in combination with industrial cameras, and the image is preprocessed and features are extracted through the grayscale symbiosis matrix to construct an improved convolutional neural network model for defect detection and output defect categories and locations.
It realizes efficient and accurate non-destructive testing, reduces manual operation, reduces product scrap rate and mechanical damage.
Smart Images

Figure CN119762430B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of magnetic material detection, and particularly relates to a method and system for detecting surface defects of neodymium iron boron magnets. Background Art
[0002] As a high-performance permanent magnetic material, neodymium iron boron magnets are widely used in many fields such as electronics, automobiles, aerospace, etc. However, during its production and processing, due to the characteristics of raw materials and the influence of manufacturing processes (such as sintering, cutting, grinding, electroplating, etc.), defects such as cracks, scratches, pockmarks, holes, and coating peeling are likely to appear on the surface. These defects not only affect the appearance quality of the magnets, but may also damage their magnetic properties, mechanical strength, and service life. In severe cases, it may lead to failures in the usage scenarios, such as affecting the electromagnetic induction stability in electronic devices.
[0003] Traditional detection of neodymium iron boron magnet surface defects mostly relies on manual visual inspection, which has low detection efficiency, strong subjectivity, is prone to fatigue and missed detection, and it is difficult to accurately identify tiny and hidden defects; some use mechanical contact detection methods, although they have a certain degree of accuracy, they are likely to cause secondary damage to the magnet surface. With the development of industrial automation and intelligence, using non-contact detection technologies such as machine learning to achieve efficient, accurate, and non-destructive detection of neodymium iron boron magnet surface defects has become an urgent need in the industry. Summary of the Invention
[0004] The present invention aims at the above-mentioned existing technical deficiencies and provides a method and system for detecting surface defects of neodymium iron boron magnets.
[0005] The present invention is achieved through the following technical solutions:
[0006] A method for detecting surface defects of neodymium iron boron magnets is provided, and the method includes the following steps:
[0007] Step S10: Build a closed dark box type image acquisition platform and set a ring-shaped uniform light source, an industrial camera, and a stage in it. After placing the neodymium iron boron magnet on the stage, control the stage to move along a set path, and trigger the industrial camera to take images of the magnet surface at each acquisition point to obtain neodymium iron boron magnet surface image data;
[0008] Step S20: Perform data preprocessing on the obtained neodymium iron boron magnet surface image data;
[0009] Step S30: After the data preprocessing is completed, extract the neodymium iron boron magnet surface image features based on the gray level co-occurrence matrix;
[0010] Step S40: After the feature extraction is completed, build a deep learning-based neodymium iron boron magnet surface defect detection model and train it. After the training is completed, perform neodymium iron boron magnet surface defect detection and output the detection result;
[0011] Among them, before the industrial camera captures the image of the magnet surface in step S10, the focal length and aperture of the camera will be automatically adjusted according to the clarity of the presented image, and the moving path of the stage and the acquisition points of the industrial camera will be set according to the size specifications of the neodymium iron boron magnet; in addition, the image of the neodymium iron boron magnet surface captured by the industrial camera is a lossless image with a resolution of 2k, and multiple frames of images are captured for different areas on the surface of the neodymium iron boron magnet, including the top surface, bottom surface and side surface of the neodymium iron boron magnet.
[0012] Among them, in step S40, an improved convolutional neural network model is used to construct a surface defect detection model for neodymium iron boron magnets. By adding residual links to the network model structure, the convergence speed of model training is improved; after training is completed, surface defect detection of neodymium iron boron magnets is carried out, and the output detection results are defective and non-defective; when the output result is defective, the detected defect category is output at the same time, and the position where the defect appears is accurately marked in the image where the defect is detected.
[0013] Preferably, the steps of data preprocessing the obtained neodymium iron boron magnet surface image data in step S20 include:
[0014] Grayscale processing: The obtained neodymium iron boron magnet surface image data is subjected to grayscale processing to reduce the data volume and computational complexity. The channel weights of the red, green, and blue channels are respectively set as W R 、W G and W B . For each pixel point P(x, y) in the neodymium iron boron magnet surface image data, the calculation formula for its grayscale value Gray(x, y) is shown in Equation (1):
[0015] (1)
[0016] where R(x, y), G(x, y), and B(x, y) are the pixel values of the pixel point P(x, y) in the red, green, and blue channels respectively. After traversing each pixel point in the neodymium iron boron magnet surface image data, the grayscale image corresponding to the neodymium iron boron magnet surface image is obtained;
[0017] Denoising processing: Median filtering is used to remove image noise and retain edge details. The size of the filtering window is determined according to the noise level and detail richness of the image; for each pixel point P(x, y) in the neodymium iron boron magnet surface image data, a corresponding filtering window is determined with it as the center. When the filtering window exceeds the boundary, the exceeded part is processed by padding zeros or mirroring; all pixel points within the window are extracted to form a set S = {P1, P2,..., P n}, where n is the total number of pixel points within the window; sort the pixel values in set S from smallest to largest, and take the median value after sorting as the new pixel value of pixel point P(x,y). When n is odd, the median value is unique; when n is even, take the average of the two middle numbers;
[0018] Histogram equalization processing: Scan the surface image of the neodymium iron boron magnet after grayscale conversion and noise removal, count the frequency of each gray level, and construct a histogram H(k), where k is the gray level and H(k) is the number of pixels with a gray value of k; calculate the cumulative distribution function according to the histogram, and the formula is shown in Equation (2):
[0019] (2)
[0020] where CDF(k) is the cumulative distribution function, representing the cumulative proportion of pixel points with gray values less than or equal to k. Its value range gradually increases from 0 to 1. i is an index variable used to traverse all gray levels from 0 to k, and H(i) is the number of pixel points with a gray level of i; after calculating CDF(k), perform gray value mapping again to obtain a new gray value T(k), and the calculation formula is shown in Equation (3):
[0021] (3)
[0022] where L is the total number of gray levels and round is the rounding function; after traversing each pixel point in the surface image of the neodymium iron boron magnet, replace the original gray value Gray(x,y) with the new gray value T(k) to obtain the surface image of the neodymium iron boron magnet after histogram equalization.
[0023] Preferably, the steps of extracting the surface image features of the neodymium iron boron magnet based on the gray-level co-occurrence matrix in step S30 include:
[0024] Construct a gray-level co-occurrence matrix: According to the grayscale image of the surface image of the neodymium iron boron magnet obtained in step S20, determine the parameters of the number of gray levels L, the distance d, and the direction θ, and initialize a two-dimensional array of size L×L as the gray-level co-occurrence matrix A. All elements in the matrix are initialized to 0; traverse each pixel point in the image to obtain the gray value a of the current pixel point, find the corresponding adjacent pixel point according to the distance d and the direction θ, and obtain its gray value b; increment the element in the gray-level co-occurrence matrix A by 1, indicating the number of times the pixel pair with gray values a and b appears at the given distance and direction; after traversing the entire image, divide each element in the gray-level co-occurrence matrix A by the total number of pixel pairs to obtain a normalized gray-level co-occurrence matrix. In this way, A(a,b) represents the probability of the pixel pair with gray values a and b appearing.
[0025] Calculate texture feature parameters: Calculate the energy feature and contrast feature of the surface image of the neodymium iron boron magnet according to the obtained A(a,b).
[0026] Among them, in the step of calculating the texture feature parameters, the energy feature and the contrast feature of the NdFeB magnet surface image are calculated according to the obtained A(a, b), specifically including:
[0027] Calculation of energy feature: Calculate the energy feature according to the energy calculation formula, as shown in Equation (4):
[0028] (4)
[0029] For the normalized gray-level co-occurrence matrix A, use two nested loops to traverse each element A(a, b) in the matrix; calculate the square of each element A(a, b) 2 , and accumulate it into a variable Energy. Finally, the value of the variable Energy is the energy feature of the NdFeB magnet surface image;
[0030] Calculation of contrast feature: Calculate the contrast feature according to the contrast calculation formula, as shown in Equation (5):
[0031] (5)
[0032] Similarly, use nested loops to traverse the gray-level co-occurrence matrix A. For each element A(a, b), calculate (a - b) 2 A(a, b), and accumulate it into a variable Contrast to obtain the contrast feature of the NdFeB magnet surface image.
[0033] Preferably, in step S40, a deep learning-based NdFeB magnet surface defect detection model is constructed and trained. The model construction and training steps include:
[0034] Dataset preparation: Obtain the existing NdFeB magnet surface defect image data of different types from the Internet or other historical datasets of NdFeB magnet surface defect images, and divide them into a training set, a validation set, and a test set according to the ratio of 70%:15%:15%. And label the corresponding defect types in the training set image data for the model to learn the surface defect characteristics of different types of NdFeB magnets;
[0035] Determine the loss function and optimizer: Use binary cross-entropy as the loss function, and the Adam optimization algorithm as the optimizer to adaptively adjust the learning rate and dynamically update the model parameters. The initial learning rate is set to 0.001 and decays according to the number of training epochs;
[0036] Model construction: The entire network model includes an input layer, a convolutional layer, a pooling layer, a residual connection layer, a fully connected layer, and an output layer; the input of the input layer is the image data after data preprocessing and feature value extraction; ReLU is used as the activation function in the convolutional layer; the pooling layer is set after each convolutional layer and uses the max pooling method; the residual connection layer is set after the last two convolutional layers and before the pooling layer, in the middle of the convolutional layer and the pooling layer; the fully connected layer is set after the pooling layer, flattens the feature map output by the pooling layer into a one-dimensional vector form, and selects ReLU as the activation function; the output layer is set at the last layer of the entire network model, and according to the number of surface defect categories of the corresponding neodymium iron boron magnet, outputs the probability distribution of each defect category after Softmax processing, and each value corresponds to the confidence of the defect category. The confidence threshold is set to 0.5. When the confidence is less than 0.5, the output is no defect. When the confidence is greater than or equal to 0.5, the output is defective and the defect category is also output; the confidence threshold is dynamically adjusted according to the output result;
[0037] Model training and validation: After the model is constructed, set the model parameters, use the divided training set as the input to train the model, and use the divided validation set to validate the trained model after each round of training ends;
[0038] Model evaluation: When overfitting occurs, stop the model training and validation operations, and use the divided test set for model evaluation;
[0039] Model optimization: Adjust the model parameters according to the model evaluation results and retrain until the optimal model parameter combination is obtained, and determine the corresponding model version.
[0040] Among them, the categories of defects output in the model construction step include cracks, scratches, pockmarks, and holes. The texture features extracted based on the gray-level co-occurrence matrix corresponding to different defect types are different. The model determines the defect types existing in the input image by learning the features of different NdFeB magnet surface defect types. For example, for cracks, it can be judged according to the contrast feature, which usually forms an obvious gray-level difference boundary on the surface. Along the crack direction, the gray-level value on one side is quite different from that on the other side; for pockmark defects, it can be judged through the energy feature. The existence of pockmarks makes the texture uneven and complex, resulting in a lower energy; for scratches, it can be judged by the contrast feature. The contrast will increase significantly in the scratch direction. Due to the obvious gray-level difference on both sides of the scratch, this large gray-level change between adjacent pixels will lead to an increase in contrast, forming a sharp contrast with the surrounding normal area; for holes, it can also be judged according to the energy feature. The energy of the hole area is relatively low, especially inside the hole because the gray-level distribution is relatively uniform (usually a darker gray-level value), while at the edge of the hole, there will be local changes in energy, but overall, due to the existence of the hole, the energy of this area is lower than that of the normal surface.
[0041] Cracks are linear gaps presented on the magnet surface, which may be fine hair-like cracks or wider and deeper fissures. The directions and lengths of the cracks vary. Some may be single straight cracks, and some may be complex branched cracks. They are usually caused by factors such as stress concentration inside the material, mechanical damage during the processing (such as improper cutting, grinding, etc.) or external force impacts during use.
[0042] Scratches are manifested as linear marks on the surface, generally shallower than cracks. The width of the scratches is relatively narrow, and the edges are relatively clear. They may appear singly or multiple scratches may cross each other. They are mainly caused by friction during the production process, collisions during handling, or scraping when contacting other hard objects.
[0043] Pockmarks are distributed in a dot-like manner on the magnet surface, with different sizes and approximately circular shapes. There may be slight depressions on the surface of the pockmark area, forming a contrast with the surrounding normal surface. They may be caused by impurities in the raw materials, residual bubbles during the sintering process, or local problems during the electroplating process.
[0044] Holes are obvious hollow areas formed on the magnet surface, and their sizes and depths vary depending on the specific situation. The edges of the holes may be relatively regular or irregular in shape. During the manufacturing process, such as in the powder metallurgy forming process, they may be formed due to uneven powder filling or voids left by the volatilization of substances during the sintering process.
[0045] In addition, to achieve the above object, the present invention also proposes a surface defect detection system for NdFeB magnets, and the surface defect detection system for NdFeB magnets includes:
[0046] Platform construction and data acquisition module: used to construct a closed dark box type image acquisition platform and set a ring-shaped uniform light source, an industrial camera, and a stage therein. Place the neodymium iron boron magnet on the stage and then control the stage to move along a set path. Trigger the industrial camera to take images of the magnet surface at each acquisition point to obtain the surface image data of the neodymium iron boron magnet;
[0047] Preprocessing module for surface image data of neodymium iron boron magnet: used to perform data preprocessing on the obtained surface image data of the neodymium iron boron magnet;
[0048] Feature extraction module for surface image data of neodymium iron boron magnet: used to extract the surface image features of the neodymium iron boron magnet based on the gray-level co-occurrence matrix after data preprocessing;
[0049] Training and application module for surface defect detection model of neodymium iron boron magnet: used to construct and train a surface defect detection model of neodymium iron boron magnet based on deep learning after feature extraction. After training, perform surface defect detection on the neodymium iron boron magnet and output the detection results;
[0050] Before the industrial camera in the platform construction and data acquisition module takes images of the magnet surface, the focal length and aperture of the camera will be automatically adjusted according to the clarity of the presented image, and the moving path of the stage and the acquisition points of the industrial camera will be set according to the size specifications of the neodymium iron boron magnet. In addition, the surface image of the neodymium iron boron magnet taken by the industrial camera is a lossless image with a resolution of 2k. Multiple frames of images are taken of different regions on the surface of the neodymium iron boron magnet, including the top surface, bottom surface, and side surface of the neodymium iron boron magnet;
[0051] In the training and application module for surface defect detection model of neodymium iron boron magnet, an improved convolutional neural network model is used to construct the surface defect detection model of neodymium iron boron magnet based on deep learning. By adding residual connections to the network model structure, the convergence speed of model training is improved. After training, perform surface defect detection on the neodymium iron boron magnet. The output detection results are defective and non-defective. When the output result is defective, the detected defect category is output simultaneously and the position where the defect appears is accurately marked in the image where the defect is detected.
[0052] In addition, to achieve the above object, the present invention also proposes a surface defect detection device for neodymium iron boron magnet. The device includes: a memory, a processor, and programs such as a surface defect detection algorithm for neodymium iron boron magnet based on deep learning stored on the memory and executable on the processor. The programs such as the surface defect detection algorithm for neodymium iron boron magnet based on deep learning are used to implement the steps of a surface defect detection method for neodymium iron boron magnet as described above.
[0053] In addition, to achieve the above object, the present invention also provides a computer program product, which includes programs such as a neodymium iron boron magnet surface defect detection algorithm based on deep learning. When the programs such as the neodymium iron boron magnet surface defect detection algorithm based on deep learning are executed by a processor, a neodymium iron boron magnet surface defect detection method as described above is implemented.
[0054] The advantages and effects of the present invention are as follows:
[0055] A neodymium iron boron magnet surface defect detection method and system proposed by the present invention accurately detect minute and hidden defects on the surface of neodymium iron boron magnets by using a method combining image detection and machine learning. Through automated image acquisition and fast algorithm processing, the detection time of surface defects of neodymium iron boron magnets is greatly shortened; at the same time, through non-contact optical acquisition and processing, mechanical damage to neodymium iron boron magnets is avoided, the integrity of the product is guaranteed, the rejection rate of the product is reduced, automated, high-efficiency and accurate detection of surface defects of neodymium iron boron magnets is realized, manual operation links are reduced, and labor costs are reduced. BRIEF DESCRIPTION OF THE DRAWINGS
[0056] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, the drawings in the following description are only some embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0057] Figure 1 It is a flowchart of a neodymium iron boron magnet surface defect detection method of the present invention.
[0058] Figure 2 It is a schematic structural diagram of a neodymium iron boron magnet surface defect detection system of the present invention.
[0059] Figure 3 It is a schematic block diagram of the structure of an electronic device for detecting surface defects of neodymium iron boron magnets of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0060] The following will clearly and completely describe the technical solutions in the embodiments of the present invention with reference to the drawings in the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, rather than all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts belong to the scope of protection of the present invention.
[0061] The present invention provides a neodymium iron boron magnet surface defect detection method, as Figure 1 shown, including the following steps:
[0062] Step S10: Build a closed dark box type image acquisition platform and set a ring-shaped uniform light source, an industrial camera, and a stage therein. The central axis of the ring light source coincides with the optical axis of the camera and is perpendicular to the plane of the stage. Place the neodymium iron boron magnet on the stage and then control the stage to move along a set path. Trigger the industrial camera at each acquisition point to capture the surface image of the magnet to obtain the surface image data of the neodymium iron boron magnet.
[0063] Among them, before the industrial camera captures the surface image of the magnet, the focal length and aperture of the camera will be automatically adjusted according to the clarity of the presented image, and the moving path of the stage and the acquisition points of the industrial camera will be set according to the size specifications of the neodymium iron boron magnet. In addition, the surface image of the neodymium iron boron magnet captured by the industrial camera is a lossless image with a resolution of 2k. For example, image formats such as RAW are used to capture multiple frames of images of different regions on the surface of the neodymium iron boron magnet, including the top surface, bottom surface, and side surface of the neodymium iron boron magnet, to ensure that the surface details are completely recorded.
[0064] Step S20: Perform data preprocessing on the obtained surface image data of the neodymium iron boron magnet.
[0065] Specifically, the steps of performing data preprocessing on the obtained surface image data of the neodymium iron boron magnet in step S20 include:
[0066] Grayscale processing: Perform grayscale processing on the obtained surface image data of the neodymium iron boron magnet to reduce the data volume and computational complexity. Set the channel weights of the red, green, and blue channels to W R 、W G and W B , for example, set W R =0.299, W G =0.587, W B =0.114. For each pixel point P(x, y) in the surface image data of the neodymium iron boron magnet, the calculation formula for its grayscale value Gray(x, y) is shown in formula (1):
[0067] (1)
[0068] where R(x, y), G(x, y), and B(x, y) are the pixel values of the pixel point P(x, y) in the red, green, and blue channels respectively. After traversing each pixel point in the surface image data of the neodymium iron boron magnet, a grayscale image corresponding to the surface image of the neodymium iron boron magnet is obtained;
[0069] Denoising process: Median filtering is used to remove image noise and retain edge details. The size of the filtering window is determined according to the noise level and detail richness of the image. For example, the size of the filtering window is set to 3×3. For each pixel point P(x, y) in the surface image data of the neodymium iron boron magnet, a corresponding filtering window is determined with it as the center. When the filtering window exceeds the boundary, the exceeded part is processed by padding with zeros or mirroring. Extract all the pixel points within the window to form a set S = {P1, P2,..., P n}, where n is the total number of pixel points within the window. For example, when the size of the filtering window is set to 3×3, the value of n is 9. Sort the pixel values in set S from smallest to largest, and take the median value after sorting as the new pixel value of pixel point P(x, y) after filtering. When n is odd, the median value is unique. When n is even, take the average of the middle two numbers;
[0070] Histogram equalization process: Scan the grayscale and denoised surface image of the neodymium iron boron magnet, count the frequency of each gray level, the gray value range is from 0 to 255, and construct a histogram H(k), where k is the gray level and H(k) is the number of pixels with gray value k. Calculate the cumulative distribution function according to the histogram, and the formula is shown in Equation (2):
[0071] (2)
[0072] where CDF(k) is the cumulative distribution function, representing the cumulative proportion of pixel points with gray values less than or equal to k. Its value range gradually increases from 0 to 1. i is an index variable used to traverse all gray levels from 0 to k, and H(i) is the number of pixel points with gray level i. After calculating CDF(k), perform gray value mapping again to obtain a new gray value T(k), and the calculation formula is shown in Equation (3):
[0073] (3)
[0074] where L is the total number of gray levels and round is the rounding function. After traversing each pixel point in the surface image of the neodymium iron boron magnet, replace the original gray value Gray(x, y) with the new gray value T(k) to obtain the surface image of the neodymium iron boron magnet after histogram equalization.
[0075] Step S30: After the data preprocessing is completed, extract the surface image features of the neodymium iron boron magnet based on the gray-level co-occurrence matrix.
[0076] Specifically, the steps of extracting the surface image features of the neodymium iron boron magnet based on the gray-level co-occurrence matrix in step S30 include:
[0077] Constructing the gray-level co-occurrence matrix: Based on the grayscale image of the NdFeB magnet surface obtained in step S20, determine the parameters of the gray-level series L, distance d, and direction θ, and initialize a two-dimensional array of size L×L as the gray-level co-occurrence matrix A, with all elements in the matrix initialized to 0. Traverse each pixel point in the image to obtain the gray value a of the current pixel point, find the corresponding adjacent pixel point according to the distance d and direction θ, and obtain its gray value b. Increment the element in the gray-level co-occurrence matrix A by 1, indicating the number of times the pixel pair with gray values a and b appears at the given distance and direction. After traversing the entire image, divide each element in the gray-level co-occurrence matrix A by the total number of pixel pairs to obtain the normalized gray-level co-occurrence matrix. Thus, A(a, b) represents the probability of the pixel pair with gray values a and b appearing.
[0078] Calculating texture feature parameters: Calculate the energy feature and contrast feature of the NdFeB magnet surface image based on the obtained A(a, b).
[0079] Among them, calculating the energy feature and contrast feature of the NdFeB magnet surface image based on the obtained A(a, b) in the step of calculating texture feature parameters specifically includes:
[0080] Calculating the energy feature: Calculate the energy feature according to the energy calculation formula, as shown in Equation (4):
[0081] (4)
[0082] For the normalized gray-level co-occurrence matrix A, use two nested loops to traverse each element A(a, b) in the matrix; calculate the square of each element A(a, b) 2 , and accumulate it into a variable Energy. Finally, the value of the variable Energy is the energy feature of the NdFeB magnet surface image.
[0083] Calculating the contrast feature: Calculate the contrast feature according to the contrast calculation formula, as shown in Equation (5):
[0084] (5)
[0085] Similarly, use nested loops to traverse the gray-level co-occurrence matrix A. For each element A(a, b), calculate (a - b) 2 A(a, b), and accumulate it into a variable Contrast to obtain the contrast feature of the NdFeB magnet surface image.
[0086] Step S40: After feature extraction, construct a deep learning-based NdFeB magnet surface defect detection model and train it. After training, perform NdFeB magnet surface defect detection and output the detection results.
[0087] In step S40, an improved convolutional neural network model is used to construct a surface defect detection model for NdFeB magnets. By adding residual connections to the network model structure, the convergence speed of model training is improved. After training, the surface defects of NdFeB magnets are detected, and the output detection results are defective and non-defective. When the output result is defective, the detected defect category is output, and the position where the defect appears is accurately marked in the image where the defect is detected.
[0088] Specifically, in step S40, a surface defect detection model for NdFeB magnets based on deep learning is constructed and trained. The steps for constructing and training the model include:
[0089] Dataset preparation: Obtain the existing surface defect image data of different types of NdFeB magnets from the Internet or other historical datasets of NdFeB magnet surface defect images, and divide them into a training set, a validation set, and a test set according to the ratio of 70%:15%:15%. The corresponding defect types are marked in the training set image data for the model to learn the surface defect characteristics of different types of NdFeB magnets.
[0090] Determine the loss function and optimizer: Binary cross-entropy is used as the loss function, and the Adam optimization algorithm is used as the optimizer to adaptively adjust the learning rate and dynamically update the model parameters. The initial learning rate is set to 0.001 and adjusted according to the number of training epochs.
[0091] Model construction: The entire network model includes an input layer, convolutional layers, pooling layers, residual connection layers, fully connected layers, and an output layer. The input of the input layer is the image data after data preprocessing and feature value extraction. ReLU is used as the activation function in the convolutional layers. The pooling layer is set after each convolutional layer and uses the max pooling method. The residual connection layer is set after the last two convolutional layers and before the pooling layer, in the middle of the convolutional layer and the pooling layer. The fully connected layer is set after the pooling layer, flattens the feature map output by the pooling layer into a one-dimensional vector form, and ReLU is selected as the activation function. The output layer is set at the last layer of the entire network model. According to the number of corresponding NdFeB magnet surface defect categories, the probability distribution of each defect category is output after Softmax processing. Each value corresponds to the confidence of the defect category. The confidence threshold is set to 0.5. When the confidence is less than 0.5, the output is non-defective. When the confidence is greater than or equal to 0.5, the output is defective and the defect category is output at the same time. The confidence threshold is dynamically adjusted according to the output results.
[0092] Model training and validation: After the model is constructed, set the model parameters, use the divided training set as the input to train the model, and use the divided validation set to validate the trained model after each round of training ends.
[0093] Model evaluation: When overfitting occurs, stop the model training and validation operations, and use the divided test set for model evaluation;
[0094] Model optimization: Adjust the model parameters according to the model evaluation results and retrain until the optimal combination of model parameters is obtained, and determine the corresponding model version.
[0095] Among them, the categories of output defects in the model construction step include cracks, scratches, pitting, and holes. The texture features extracted based on the gray-level co-occurrence matrix are different for different defect types. The model determines the defect types existing in the input image by learning the features of different NdFeB magnet surface defect types. For example, for cracks, it can be judged according to the contrast feature, which usually forms an obvious gray-level difference boundary on the surface. Along the crack direction, the gray-level value on one side is quite different from that on the other side; for pitting defects, it can be judged by the energy feature. The existence of pitting makes the texture uneven and complex, resulting in lower energy; for scratches, it can be judged by the contrast feature. The contrast will increase significantly in the scratch direction. Due to the obvious gray-level difference on both sides of the scratch, this large gray-level change between adjacent pixels will lead to an increase in contrast, forming a sharp contrast with the surrounding normal area; for holes, it can also be judged according to the energy feature. The energy of the hole area is relatively low, especially inside the hole because the gray-level distribution is relatively uniform (usually a darker gray-level value), while at the edge of the hole, there will be local changes in energy, but overall, due to the existence of the cavity, the energy of this area is lower than that of the normal surface.
[0096] Cracks are linear gaps presented on the magnet surface. They may be fine hair-like cracks or wider and deeper fissures. The directions and lengths of the cracks vary. Some may be single straight cracks, and some may be complex branched cracks. They are usually caused by factors such as stress concentration inside the material, mechanical damage during the processing (such as improper cutting, grinding, etc.) or external force impacts during use;
[0097] Scratches are manifested as linear marks on the surface, generally shallower than cracks. The width of the scratches is relatively narrow, and the edges are relatively clear. They may appear singly or multiple scratches may cross each other. They are mainly caused by friction during the production process, collisions during handling, or scraping when contacting other hard objects;
[0098] Pitting is distributed in a dot-like manner on the magnet surface, with different sizes and approximately circular shapes. There may be slight depressions on the surface of the pitting area, forming a contrast with the surrounding normal surface. It may be caused by impurities in the raw materials, residual bubbles during the sintering process, or local problems during the electroplating process;
[0099] The holes are obvious hollow areas formed on the surface of the magnet. The size and depth vary according to specific circumstances. The edges of the holes may be relatively regular or irregular. During the manufacturing process, such as in the powder metallurgy forming process, they may be formed due to uneven powder filling or the remaining voids caused by the volatilization of substances during the sintering process.
[0100] In addition, more training data can be collected, especially data for those categories where the model performs poorly. Data augmentation techniques (such as rotation, scaling, flipping, etc.) can also be used to increase the diversity of the training data, further train the model, and improve the model's detection ability.
[0101] In addition, the present invention also proposes a surface defect detection system for neodymium iron boron magnets. Please refer to Figure 2 , and the surface defect detection system for neodymium iron boron magnets includes:
[0102] Platform construction and data acquisition module: used to construct a closed dark box type image acquisition platform and set a ring-shaped uniform light source, an industrial camera, and a stage therein. After placing the neodymium iron boron magnet on the stage, control the stage to move along the set path, and trigger the industrial camera to take images of the magnet surface at each acquisition point to obtain the surface image data of the neodymium iron boron magnet;
[0103] Preprocessing module for surface image data of neodymium iron boron magnets: used to perform data preprocessing on the obtained surface image data of neodymium iron boron magnets;
[0104] Feature extraction module for surface image data of neodymium iron boron magnets: used to extract the surface image features of neodymium iron boron magnets based on the gray-level co-occurrence matrix after the data preprocessing is completed;
[0105] Training and application module for surface defect detection model of neodymium iron boron magnets: used to construct and train a surface defect detection model for neodymium iron boron magnets based on deep learning after the feature extraction is completed. After the training is completed, perform surface defect detection on the neodymium iron boron magnets and output the detection results;
[0106] Among them, before the industrial camera in the platform construction and data acquisition module takes images of the magnet surface, the focal length and aperture of the camera will be automatically adjusted according to the clarity of the presented image, and the moving path of the stage and the acquisition points of the industrial camera will be set according to the size specifications of the neodymium iron boron magnet. In addition, the surface image of the neodymium iron boron magnet taken by the industrial camera is a lossless image with a resolution of 2k, and multiple frames of images are taken of different regions on the surface of the neodymium iron boron magnet, including the top surface, bottom surface, and side surface of the neodymium iron boron magnet;
[0107] Among them, in the module for training and applying the surface defect detection model of neodymium iron boron magnets, an improved convolutional neural network model is used to construct the surface defect detection model of neodymium iron boron magnets. By adding residual connections to the network model structure, the convergence speed of model training is improved. After training, the surface defects of neodymium iron boron magnets are detected, and the output detection results are defective and non-defective. When the output result is defective, the detected defect category is output simultaneously, and the position where the defect appears is accurately marked in the image where the defect is detected.
[0108] A surface defect detection system for neodymium iron boron magnets provided by this application adopts the surface defect detection method of neodymium iron boron magnets in the above-mentioned embodiment, which can solve the technical problems of low efficiency and low accuracy of the traditional surface defect detection method of neodymium iron boron magnets. Compared with the prior art, the beneficial effects of the surface defect detection system for neodymium iron boron magnets provided by this application are the same as those of the surface defect detection method of neodymium iron boron magnets provided by the above-mentioned embodiment, and other technical features in the surface defect detection system for neodymium iron boron magnets are the same as those disclosed in the method of the above-mentioned embodiment, which will not be elaborated here.
[0109] This application provides a surface defect detection device for neodymium iron boron magnets. The surface defect detection device for neodymium iron boron magnets includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein, the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute the surface defect detection method of neodymium iron boron magnets in the first embodiment above.
[0110] Next, refer to Figure 3 , which shows a schematic structural diagram of a surface defect detection device for neodymium iron boron magnets suitable for implementing the embodiments of this application. The surface defect detection device for neodymium iron boron magnets in the embodiments of this application may include, but is not limited to, mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions: tablet computers), PMPs (Portable Media Players), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 3 The surface defect detection device for neodymium iron boron magnets shown is only an example and should not impose any limitations on the functions and usage scope of the embodiments of this application.
[0111] Figure 3A surface defect detection device for a neodymium iron boron magnet as shown may include a processing system 1001 (such as a central processing unit, a graphics processing unit, etc.), which may perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Memory) 1002 or a program loaded from a storage system 1003 into a random access memory (RAM: Random Access Memory) 1004. In the RAM 1004, various programs and data required for the operation of a surface defect detection device for a neodymium iron boron magnet are also stored. The processing system 1001, the ROM 1002, and the RAM 1004 are connected to each other through a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Generally, the following systems may be connected to the I / O interface 1006: an input system 1007 including, for example, a touch screen, a touchpad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output system 1008 including, for example, a liquid crystal display (LCD: Liquid Crystal Display), a speaker, a vibrator, etc.; a storage system 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication system 1009. The communication system 1009 may allow a surface defect detection device for a neodymium iron boron magnet to communicate with other devices wirelessly or wiredly to exchange data. Although a surface defect detection device for a neodymium iron boron magnet with various systems is shown in the figure, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems may be implemented or had alternatively.
[0112] Specifically, according to the embodiments disclosed in the present application, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program contains program codes for executing the methods shown in the flowcharts. In such an embodiment, the computer program may be downloaded and installed from a network through the communication system, or installed from the storage system 1003, or installed from the ROM 1002. When the computer program is executed by the processing system 1001, the above functions defined in the methods of the embodiments disclosed in the present application are executed.
[0113] A surface defect detection device for NdFeB magnets provided by this application, which adopts a surface defect detection method for NdFeB magnets in the above-mentioned embodiment, can solve the technical problems of low efficiency and low accuracy of traditional surface defect detection methods for NdFeB magnets. Compared with the prior art, the beneficial effects of the surface defect detection device for NdFeB magnets provided by this application are the same as those of the surface defect detection method for NdFeB magnets provided by the above-mentioned embodiment, and other technical features in the surface defect detection device for NdFeB magnets are the same as those disclosed in the method of the previous embodiment, which will not be elaborated here.
[0114] Each part disclosed in this application can be implemented by hardware, software, firmware, or a combination thereof. In the description of the above embodiments, specific features, structures, materials, or characteristics can be combined in a suitable manner in any one or more embodiments or examples.
[0115] This application also provides a computer program product, including a computer program, and the steps of a surface defect detection method for NdFeB magnets as described above are implemented when the computer program is executed by a processor.
[0116] The computer program product provided by this application can solve the technical problems of low efficiency and low accuracy of traditional surface defect detection methods for NdFeB magnets. Compared with the prior art, the beneficial effects of the computer program product provided by this application are the same as those of the surface defect detection method for NdFeB magnets provided by the above-mentioned embodiment, which will not be elaborated here.
[0117] Obviously, those skilled in the art can make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalent technologies, the present invention also intends to include these changes and modifications.
Claims
1. A method for detecting surface defects of neodymium iron boron magnets, characterized in that, The method includes the following steps: Step S10: Build a closed dark box type image acquisition platform and set an annular uniform light source, an industrial camera, and a stage therein. Place the neodymium iron boron magnet on the stage and then control the stage to move along a set path. Trigger the industrial camera to capture the surface image of the magnet at each acquisition point to obtain the surface image data of the neodymium iron boron magnet. Step S20: Perform data preprocessing on the obtained surface image data of the neodymium iron boron magnet. Step S30: After the data preprocessing is completed, extract the surface image features of the neodymium iron boron magnet based on the gray level co-occurrence matrix. Step S40: After the feature extraction is completed, build a surface defect detection model for the neodymium iron boron magnet based on deep learning and train it. After the training is completed, perform surface defect detection on the neodymium iron boron magnet and output the detection result. Before the industrial camera captures the surface image of the magnet in Step S10, the focal length and aperture of the camera will be automatically adjusted according to the clarity of the presented image, and the moving path of the stage and the acquisition points of the industrial camera will be set according to the size specifications of the neodymium iron boron magnet. In addition, the surface image of the neodymium iron boron magnet captured by the industrial camera is a lossless image with a resolution of 2k. Multiple frames of images are captured for different regions on the surface of the neodymium iron boron magnet, including the top surface, bottom surface, and side surface of the neodymium iron boron magnet. The steps of extracting the surface image features of the neodymium iron boron magnet in Step S30 include constructing a gray level co-occurrence matrix and calculating texture feature parameters. Among them, calculating the texture feature parameters includes: Calculation of energy feature: Calculate the energy feature according to the calculation formula of energy, as shown in Equation (1): (1) For the gray-level co-occurrence matrix A, use two nested loops to traverse each element A(a, b) in the matrix; calculate the square of each element A(a, b) 2 , and accumulate it into a variable Energy. Finally, the value of the variable Energy is the energy feature of the image on the surface of the NdFeB magnet; Calculation of contrast feature: Calculate the contrast feature according to the calculation formula of contrast, as shown in Equation (2): (2) Similarly, use nested loops to traverse the gray-level co-occurrence matrix A. For each element A(a, b), calculate (a - b) 2 A(a, b), and accumulate it into a variable Contrast to obtain the contrast feature of the NdFeB magnet surface image; In Step S40, the surface defect detection model for the neodymium iron boron magnet based on deep learning is built using an improved convolutional neural network model. By adding residual connections in the network model structure, the convergence speed of model training is improved. After the training is completed, perform surface defect detection on the neodymium iron boron magnet. The output detection result is defective or non-defective. When the output result is defective, the detected defect category is output at the same time, and the position where the defect appears is accurately marked in the image where the defect is detected.
2. The method for detecting surface defects of a neodymium iron boron magnet according to claim 1, characterized in that, The steps of performing data preprocessing on the obtained surface image data of the neodymium iron boron magnet in Step S20 include: Grayscale processing: The surface image data of the NdFeB magnet obtained is subjected to grayscale processing to reduce the data volume and computational complexity. The channel weights of the red, green, and blue channels are respectively set to W R , W G , and W B . For each pixel point P(x, y) in the surface image data of the NdFeB magnet, the calculation formula for its grayscale value Gray(x, y) is shown in Equation (3): (3) Where R(x, y), G(x, y), and B(x, y) are the pixel values of the pixel point P(x, y) in the red, green, and blue channels respectively. After traversing each pixel point in the surface image data of the neodymium iron boron magnet, a grayscale image corresponding to the surface image of the neodymium iron boron magnet is obtained. Denoising processing: Median filtering is used to remove image noise and retain edge details. The size of the filtering window is determined according to the noise level and detail richness of the image. For each pixel point P(x, y) in the surface image data of the neodymium iron boron magnet, a corresponding filtering window is determined with it as the center. When the filtering window exceeds the boundary, the exceeded part is processed by padding with zeros or mirroring. All pixel points within the window are extracted to form a set S = {P1, P2,..., P n}, where n is the total number of pixel points within the window. The pixel values in set S are sorted from smallest to largest, and the median value after sorting is taken as the new pixel value of pixel point P(x, y) after filtering. When n is odd, the median value is unique. When n is even, the average of the two middle numbers is taken; Histogram equalization processing: Scan the grayscale and noise-removed surface image of the neodymium iron boron magnet, count the frequency of each gray level, and construct a histogram H(k), where k is the gray level and H(k) is the number of pixels with a gray value of k. Calculate the cumulative distribution function according to the histogram, and the formula is as shown in Equation (4): (4) Among them, CDF(k) is the cumulative distribution function, which represents the cumulative proportion of pixel points with gray values less than or equal to k. Its value range gradually increases from 0 to 1. i is an index variable used to traverse all gray levels from 0 to k, and H(i) is the number of pixel points with gray level i. After calculating CDF(k), the gray value is mapped again to obtain the new gray value T(k), and the calculation formula is shown in Equation (5): (5) Among them, L is the total number of gray levels, and round is the rounding function. After traversing each pixel point in the neodymium iron boron magnet surface image, the original gray value Gray(x, y) is replaced with the new gray value T(k) to obtain the histogram-equalized neodymium iron boron magnet surface image.
3. A method for detecting surface defects of a neodymium iron boron magnet according to claim 1, characterized in that, The steps of extracting the neodymium iron boron magnet surface image features based on the gray-level co-occurrence matrix in the step S30 include: Constructing the gray-level co-occurrence matrix: According to the gray-scale image of the neodymium iron boron magnet surface image obtained in step S20, determine the parameters of the gray-level number L, the distance d, and the direction θ, and initialize a two-dimensional array of size L×L as the gray-level co-occurrence matrix A. All elements in the matrix are initialized to 0. Traverse each pixel point in the image to obtain the gray value a of the current pixel point, find the corresponding adjacent pixel point according to the distance d and the direction θ, and obtain its gray value b. Add 1 to the element in the gray-level co-occurrence matrix A, indicating the number of times the pixel pair with gray values a and b appears at the given distance and direction. After traversing the entire image, divide each element in the gray-level co-occurrence matrix A by the total number of pixel pairs to obtain the normalized gray-level co-occurrence matrix. In this way, A(a, b) represents the probability of the pixel pair with gray values a and b appearing. Calculating the texture feature parameters: Calculate the energy feature and contrast feature of the neodymium iron boron magnet surface image according to the obtained A(a, b).
4. A method for detecting surface defects of a neodymium iron boron magnet according to claim 1, characterized in that In the step S40, constructing and training a neodymium iron boron magnet surface defect detection model based on deep learning, the steps of model construction and training include: Dataset preparation: Obtain the existing neodymium iron boron magnet surface defect image data of different types, and divide them into a training set, a validation set, and a test set according to the ratio of 70%:15%:15%. And label the corresponding defect types in the training set image data for the model to learn the surface defect characteristics of different types of neodymium iron boron magnets. Determining the loss function and optimizer: Use binary cross-entropy as the loss function, and the optimizer uses the Adam optimization algorithm to adaptively adjust the learning rate and dynamically update the model parameters. The initial learning rate is set to 0.001 and is attenuated and adjusted according to the number of training epochs. Model construction: The entire network model includes an input layer, convolutional layers, pooling layers, residual connection layers, fully connected layers, and an output layer. The input of the input layer is a training set with corresponding defect types annotated in the image data. ReLU is used as the activation function in the convolutional layers. Pooling layers are set after each convolutional layer, and the max-pooling method is adopted. Residual connection layers are set after the last two convolutional layers and before the pooling layer, in the middle of the convolutional layer and the pooling layer. Fully connected layers are set after the pooling layer. The feature maps output by the pooling layer are flattened into a one-dimensional vector form, and ReLU is selected as the activation function. The output layer is set at the last layer of the entire network model. According to the number of NdFeB magnet surface defect categories, the probability distribution of each defect category is output after Softmax processing. Each value corresponds to the confidence of the defect category. The confidence threshold is set to 0.
5. When the confidence is less than 0.5, the output is no defect. When the confidence is greater than or equal to 0.5, the output is defective and the defect category is also output. The defect category is the defect category with the highest probability value in the probability distribution of each defect category output. The confidence threshold is dynamically adjusted according to the output results. Model training and validation: After the model construction is completed, set the model parameters. Use the divided training set as the input to train the model, and use the divided validation set to validate the trained model after each round of training ends. Model evaluation: When overfitting occurs, stop the model training and validation operations, and use the divided test set for model evaluation. Model optimization: Adjust the model parameters according to the model evaluation results and retrain until the optimal combination of model parameters is obtained, and determine the corresponding model version.
5. A method for detecting surface defects of a neodymium iron boron magnet according to claim 4, characterized in that, The categories of output defects in the model construction steps include cracks, scratches, pitting, and holes. The texture features extracted based on the gray-level co-occurrence matrix are different for different defect types. The model determines the defect types existing in the input image by learning the features of different NdFeB magnet surface defect types.
6. A surface defect detection system for neodymium iron boron magnets, characterized in that, The NdFeB magnet surface defect detection system described above includes: Platform construction and data acquisition module: Used to construct a closed dark box type image acquisition platform and set a circular uniform light source, an industrial camera, and a stage in it. After placing the NdFeB magnet on the stage, control the stage to move along the set path, and trigger the industrial camera at each acquisition point to capture the magnet surface image to obtain the NdFeB magnet surface image data. NdFeB magnet surface image data preprocessing module: Used to perform data preprocessing on the obtained NdFeB magnet surface image data. NdFeB magnet surface image data feature extraction module: Used to extract the NdFeB magnet surface image features based on the gray-level co-occurrence matrix after the data preprocessing is completed. NdFeB magnet surface defect detection model training and application module: Used to construct a deep learning-based NdFeB magnet surface defect detection model and train it after the feature extraction is completed. After the training is completed, perform NdFeB magnet surface defect detection and output the detection results. Before the industrial camera in the platform building and data acquisition module captures the image of the magnet surface, the focal length and aperture of the camera will be automatically adjusted according to the clarity of the presented image, and the movement path of the stage and the acquisition points of the industrial camera will be set according to the size specifications of the neodymium iron boron magnet; in addition, the image of the neodymium iron boron magnet surface captured by the industrial camera is a lossless image with a resolution of 2k, and multiple frames of images are captured for different areas on the surface of the neodymium iron boron magnet, including the top surface, bottom surface and side surface of the neodymium iron boron magnet. The steps of extracting the image features of the neodymium iron boron magnet surface in the neodymium iron boron magnet surface defect detection model training and application module include constructing a gray-level co-occurrence matrix and calculating texture feature parameters, where calculating texture feature parameters includes: Energy feature calculation: Calculate the energy feature according to the energy calculation formula, as shown in Equation (1): (1) For the gray-level co-occurrence matrix A, use two nested loops to traverse each element A(a, b) in the matrix; calculate the square of each element A(a, b) 2 , and accumulate it into a variable Energy. Finally, the value of the variable Energy is the energy feature of the surface image of the NdFeB magnet; Contrast feature calculation: Calculate the contrast feature according to the contrast calculation formula, as shown in Equation (2): (2) Similarly, use nested loops to traverse the gray-level co-occurrence matrix A. For each element A(a, b), calculate (a - b) 2 A(a, b), and accumulate it into a variable Contrast to obtain the contrast feature of the NdFeB magnet surface image; In the neodymium iron boron magnet surface defect detection model training and application module, an improved convolutional neural network model is used to construct a neodymium iron boron magnet surface defect detection model based on deep learning. By adding residual links to the network model structure, the convergence speed of model training is improved; after training is completed, the surface defects of the neodymium iron boron magnet are detected, and the output detection results are defective and non-defective; when the output result is defective, the detected defect category is output at the same time, and the position where the defect appears is accurately marked in the image where the defect is detected.
7. A surface defect detection device for neodymium iron boron magnets, characterized in that, The described neodymium iron boron magnet surface defect detection device includes: A memory, a processor, and a neodymium iron boron magnet surface defect detection program stored on the memory and executable on the processor. When the neodymium iron boron magnet surface defect detection program is executed by the processor, it implements the neodymium iron boron magnet surface defect detection method according to any one of claims 1 to 5.
8. A computer program product, characterized in that, The computer program product includes a neodymium iron boron magnet surface defect detection program. When the neodymium iron boron magnet surface defect detection program is executed by a processor, it implements the neodymium iron boron magnet surface defect detection method according to any one of claims 1 to 5.
Citation Information
Patent Citations
Surface defect identification method for strong magnetic neodymium-iron-boron magnet
CN117078688A
Neodymium-iron-boron magnet surface treatment data management system
CN117274408A