A method and system for identifying surface defects in neodymium iron boron magnets

By employing frequency domain notch filtering and topology analysis techniques, the problem of distinguishing between grain boundary networks and microcracks in the surface inspection of NdFeB magnets has been solved, enabling accurate identification and efficient detection of surface defects.

CN122134683APending Publication Date: 2026-06-02JINTONG FLNORESCENT MAGNETIZED MATERIALS CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
JINTONG FLNORESCENT MAGNETIZED MATERIALS CO LTD
Filing Date
2026-02-28
Publication Date
2026-06-02

AI Technical Summary

Technical Problem

Existing visual inspection technologies struggle to effectively distinguish between grain boundary networks and micro-cracks on the surface of neodymium iron boron magnets. This leads to detection algorithms frequently misjudging normal processing marks as scratches or cracks, and they are unable to remove high-intensity periodic processing textures while preserving the intrinsic grain boundary network information of the material.

Method used

A frequency-domain notch filter is used to suppress the periodic machining mark components in the grayscale image of the magnet surface. The microstructure skeleton is extracted by second-derivative ridge response and skeleton refinement, a grain boundary network topology map is constructed, and the grain boundary network topology anomaly index is calculated to achieve accurate identification of surface defects.

Benefits of technology

While preserving grain boundary network information, it effectively filters out interference from periodic machining marks and quantifies surface integrity through topological analysis. This enables accurate identification of latent anomalies such as near-surface weakening layer fractures and oxidation coalescence, significantly improving the robustness and accuracy of detection.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122134683A_ABST
    Figure CN122134683A_ABST
Patent Text Reader

Abstract

This invention relates to the field of industrial visual inspection technology, and discloses a method and system for identifying surface defects in NdFeB magnets, including processing steps such as surface texture suppression, grain boundary network reconstruction, structural deviation analysis, and anomaly identification. The core of this invention lies in firstly, using grayscale normalization and frequency domain directional notch filtering techniques to directionally suppress the periodic machining mark components on the magnet surface, thereby obtaining a pure grain boundary enhanced image; then, extracting the microstructure skeleton based on the second derivative ridge response and constructing a grain boundary network topology map; subsequently, calculating the grain boundary network topology anomaly index, which includes the proportion of irregular nodes and the network density deviation term, to quantitatively assess the degree of topological deviation of the current grain boundary network relative to the baseline state; finally, comparing this index with a quality control threshold to determine surface anomalies. This invention can effectively overcome the complex background interference introduced by the grain boundary diffusion process, achieving accurate identification of latent damage on the magnet surface.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of industrial visual inspection technology, and more specifically, to a method and system for identifying surface defects in neodymium iron boron magnets. Background Technology

[0002] Sintered neodymium iron boron (Nd-Fe-B) magnets are widely used in new energy vehicles, wind power generation, and consumer electronics due to their excellent magnetic properties. To further enhance the high-temperature coercivity of magnets, grain boundary diffusion technology has become the mainstream production process in the industry. This process involves attaching heavy rare earth elements to the magnet surface and then subjecting it to high-temperature heat treatment, allowing the rare earth elements to diffuse into the magnet along the grain boundaries, thereby optimizing the grain boundary phase structure. In the actual production chain, after grain boundary diffusion treatment, magnets typically require machining processes such as grinding, polishing, or cleaning to remove surface residues and ensure dimensional accuracy before proceeding to electroplating or coating. At this stage, quality monitoring of the magnet surface is crucial to prevent defective products from flowing into subsequent processes. However, existing surface visual inspection technologies face significant challenges for Nd-Fe-B magnets that have undergone grain boundary diffusion and subsequent machining. First, the grain boundary diffusion process introduces changes in the near-surface layer of the magnet. The diffusion process may lead to the formation of a weakened layer with low mechanical strength in the near-surface region, and the fracture mechanism of the magnet may change, such as transgranular fracture or relay fracture, resulting in discontinuous and concealed crack paths. Secondly, grinding inevitably leaves periodic machining textures (such as saw marks or grinding lines) on the magnet surface. Furthermore, NdFeB materials themselves have a complex microscopic grain boundary network structure, and the grain boundary phase is highly susceptible to selective oxidation or slight corrosion during the air exposure window, causing the grain boundary lines to exhibit grayscale contrasts similar to cracks in the image. Current industrial visual inspection solutions typically rely on pixel-based grayscale thresholding methods or deep learning methods based on texture appearance. These existing technologies have significant limitations when handling the aforementioned complex scenarios: Interference factors are difficult to eliminate: Existing image processing methods are difficult to effectively remove high-intensity periodic processing textures while preserving the grain boundary network information of the material itself, which often leads to detection algorithms misjudging normal processing marks as scratches or cracks.

[0003] Defect and structural confusion: Because microcracks, oxide grain boundaries, and the intrinsic grain boundary network of the material are visually highly similar, detection methods that rely solely on appearance similarity cannot distinguish between normal grain boundary networks and abnormal networks caused by damage. Existing technologies lack means to quantify and analyze material integrity at the topological level through complex surface textures, leading to missed detections of latent defects or false positives for normal products. Summary of the Invention

[0004] This invention provides a method and system for identifying surface defects in neodymium iron boron magnets, which solves the technical problems mentioned in the background art.

[0005] In a first aspect, a surface defect identification system for neodymium iron boron magnets includes: The surface texture suppression module is used to normalize the grayscale image of the acquired magnet surface, analyze the main peak direction of the spectrum of the grayscale image of the magnet surface, suppress the periodic processing tool mark component in the grayscale image of the magnet surface using a frequency domain notch filter, and output a grain boundary enhancement image. The grain boundary network reconstruction module is used to calculate the second derivative ridge response of the grain boundary enhancement image, extract the microstructure skeleton through binarization and skeleton refinement, and construct a grain boundary network topology map containing the set of grain boundary nodes and the set of grain boundary edges based on the microstructure skeleton. The structural deviation analysis module is used to calculate the grain boundary network topology anomaly index based on the grain boundary network topology diagram. The grain boundary network topology anomaly index is obtained by summing the irregular node proportion term and the network density deviation term: the irregular node proportion term represents the proportion of non-triangular grain boundary nodes in the set of grain boundary nodes, and the network density deviation term represents the weighted absolute difference between the current grain boundary network density and the reference grain boundary network density; wherein, the current grain boundary network density is the ratio of the number of triangular grain boundary nodes in the set of grain boundary nodes to the square of the total side length of the set of grain boundary edges. An anomaly identification module is used to compare the grain boundary network topology anomaly index with a preset quality control threshold. If the index exceeds the quality control threshold, a surface defect judgment signal is output.

[0006] Secondly, a method for identifying surface defects in neodymium iron boron magnets, applied to any one of the surface defect identification systems for neodymium iron boron magnets, includes: The grayscale image of the acquired magnet surface is normalized, and the main peak direction of the spectrum of the grayscale image of the magnet surface is analyzed. The periodic processing tool mark component in the grayscale image of the magnet surface is suppressed by the frequency domain notch filter, and the grain boundary enhancement image is output. The second derivative ridge response of the grain boundary enhancement image is calculated, the microstructure skeleton is extracted by binarization and skeleton refinement, and a grain boundary network topology graph containing the set of grain boundary nodes and the set of grain boundary edges is constructed based on the microstructure skeleton. The grain boundary network topology anomaly index is calculated based on the aforementioned grain boundary network topology graph. This index is obtained by summing an irregular node proportion term and a network density deviation term. The irregular node proportion term represents the percentage of non-triangular grain boundary nodes in the set of grain boundary nodes, while the network density deviation term represents the weighted absolute difference between the current grain boundary network density and the baseline grain boundary network density. The current grain boundary network density is the ratio of the number of triangular grain boundary nodes in the set of grain boundary nodes to the square of the total edge length of the set of grain boundary edges. The grain boundary network topology anomaly index is compared with a preset quality control threshold. If it exceeds the quality control threshold, a surface defect judgment signal is output.

[0007] The beneficial effects of this invention include: By constructing a specific frequency domain filtering and topology analysis link, this invention effectively solves the technical challenge of the extremely complex surface state of NdFeB magnets after grain boundary diffusion and machining, making it difficult for conventional visual inspection to distinguish between grain boundary networks and micro-cracks. This invention utilizes frequency domain directional notch filtering technology to accurately filter out periodic machining mark interference while preserving the two-dimensional micro-network structure. Furthermore, by calculating the grain boundary network topology anomaly index, it quantifies surface integrity from two dimensions: network connectivity and structural density. This achieves accurate identification of latent anomalies such as near-surface weakened layer fractures and oxidation fusion without relying on appearance texture samples for training, significantly improving the robustness and accuracy of detection. Attached Figure Description

[0008] Figure 1 This is a flowchart of a surface defect identification system for neodymium iron boron magnets according to the present invention; Figure 2 This is a schematic diagram of the NdFeB magnet surface defect identification system of the present invention. Detailed Implementation

[0009] The subject matter described herein will now be discussed with reference to exemplary embodiments. It should be understood that these embodiments are discussed only to enable those skilled in the art to better understand and implement the subject matter described herein, and changes may be made to the function and arrangement of the elements discussed without departing from the scope of this specification. Various processes or components may be omitted, substituted, or added as needed in the examples. Furthermore, features described in some examples may be combined in other examples.

[0010] Example 1: As Figure 1 As shown, a surface defect identification system for neodymium iron boron magnets includes: The surface texture suppression module is used to normalize the grayscale image of the acquired magnet surface, analyze the main peak direction of the spectrum of the grayscale image of the magnet surface, suppress the periodic processing tool mark component in the grayscale image of the magnet surface using a frequency domain notch filter, and output a grain boundary enhancement image. The grain boundary network reconstruction module is used to calculate the second derivative ridge response of the grain boundary enhancement image, extract the microstructure skeleton through binarization and skeleton refinement, and construct a grain boundary network topology map containing the set of grain boundary nodes and the set of grain boundary edges based on the microstructure skeleton. The structural deviation analysis module is used to calculate the grain boundary network topology anomaly index based on the grain boundary network topology diagram. The grain boundary network topology anomaly index is obtained by summing the irregular node proportion term and the network density deviation term: the irregular node proportion term represents the proportion of non-triangular grain boundary nodes in the set of grain boundary nodes, and the network density deviation term represents the weighted absolute difference between the current grain boundary network density and the reference grain boundary network density; wherein, the current grain boundary network density is the ratio of the number of triangular grain boundary nodes in the set of grain boundary nodes to the square of the total side length of the set of grain boundary edges. An anomaly identification module is used to compare the grain boundary network topology anomaly index with a preset quality control threshold. If the index exceeds the quality control threshold, a surface defect judgment signal is output.

[0011] Preferably, the acquired grayscale image of the magnet surface is normalized, and the main peak direction of the grayscale image spectrum is analyzed, including: Step A1: Linear mapping processing; converting the grayscale image of the magnet surface... The pixel grayscale values ​​are mapped to The interval is used to obtain the basic normalized image. The calculation formula is: in, and Images The minimum and maximum gray values, It is a very small constant; Step A2: Local contrast enhancement processing; perform local mean-variance normalization on the base normalized image to obtain a normalized background-purified image. The calculation formula is: in, and In pixels The side length of the center is The mean and standard deviation of local gray levels within a square window; Step B1: Spectrum transformation and centering; for Perform a two-dimensional discrete Fourier transform and spectral centering operation to obtain a complex matrix in the frequency domain. And calculate its amplitude spectrum. ; Step B2: Main peak search and location; in the amplitude spectrum Excluding the frequency domain center With center and radius as After identifying the DC component region, search for the coordinates corresponding to the maximum amplitude. : in To exclude the amplitude spectrum after the DC region; if there are parallel maximum values, then select the distances from the center Manhattan value in sequence. Minimum, horizontal coordinate Minimum, vertical coordinates The smallest point; Step B3: Directional analysis; calculate the geometric azimuth angle of the main peak relative to the frequency domain center. The calculation formula is: in For the arctangent function, this That is, the direction of the main peak of the spectrum.

[0012] The fixed window side length w is the side length of the square window centered on each pixel in the local contrast enhancement process. It is preferably 31, which can balance local information capture and calculation efficiency, cover a sufficient range of local grayscale features, and avoid distortion of mean and standard deviation calculation due to excessively large windows, thus adapting to the scale features of grain boundaries and processing textures on the surface of NdFeB magnets.

[0013] The tiny division-to-zero constant ε is a very small value set to avoid the denominator being zero during the calculation process. It is preferably 10 to the power of -12. This value is small enough that it will not have a substantial impact on the calculation results such as grayscale normalization and local contrast enhancement, while effectively avoiding division-to-zero errors.

[0014] The neighborhood radius r0 of the central DC component is the radius of the region in the spectrum where the central DC component needs to be excluded. A radius of 5 is preferred because the DC component is mainly concentrated in a very small area at the center of the spectrum. This radius can accurately exclude DC component interference without affecting the surrounding useful frequency domain information, thus adapting to the spectral distribution characteristics of common images.

[0015] The specific calculation for local contrast enhancement includes: first, determining a square window centered on each pixel with a side length of 31; calculating the average grayscale value of all pixels within the window, i.e., the local grayscale mean; then calculating the average of the squares of the differences between the grayscale values ​​of all pixels within the window and the local grayscale mean, taking the square root to obtain the local grayscale standard deviation; finally, subtracting the local grayscale mean from the pixel's grayscale value, and then dividing by the sum of the local grayscale standard deviation and 10 to the power of -12, to obtain the enhanced grayscale value of the pixel. For example, if a pixel has a grayscale value of 150, a local grayscale mean of 120 within the window, and a local grayscale standard deviation of 20, then the enhanced grayscale value is (150 minus 120) divided by (20 plus 10 to the power of -12) approximately equal to 1.5.

[0016] The preprocessing for spectral peak localization includes: first, performing a two-dimensional discrete Fourier transform on the background-purified image to convert the image from the spatial domain to the frequency domain, obtaining a frequency domain complex matrix; then, performing spectrum centering processing to move the center of the frequency domain matrix to the center of the image, so that the low-frequency components are concentrated in the center of the image and the high-frequency components are distributed around it; then, setting a circular region with a radius of 5, excluding the DC component in this region, and obtaining the amplitude spectrum after removing the DC component.

[0017] The priority determination of points with the largest amplitude in parallel includes: when there are multiple frequency domain points with the same amplitude and the largest amplitude in the amplitude spectrum, first calculate the Manhattan distance from each point to the center of the frequency domain, which is the sum of the horizontal and vertical distances, and select the point with the smallest Manhattan distance; if multiple points have the same Manhattan distance, select the point with the smallest horizontal coordinate value; if multiple points still meet the condition, select the point with the smallest vertical coordinate value as the main peak coordinate. For example, if the coordinates of three points with the largest amplitude in parallel are 100, 200, 90, 210, and 90, 205, and the frequency domain center is 100, 200, the Manhattan distance of the first point is 0, the second is 20, and the third is 15, then the first point is selected as the main peak coordinate.

[0018] The direction of the main peak is determined by: taking the center of the frequency domain as the origin, the horizontal direction to the right as the starting direction of the angle, and the counterclockwise direction as the rotation direction, calculating the geometric azimuth angle of the line connecting the main peak coordinates and the center of the frequency domain. This angle is the direction of the main peak in the spectrum. For example, if the main peak coordinates are located to the upper right of the center of the frequency domain, and the angle between the line connecting the two points and the horizontal direction to the right is 30 degrees, then the direction of the main peak is 30 degrees.

[0019] The fixed window side length is 31, which is an odd number. This ensures that the window center is precisely aligned with the pixel. It also adapts to the scale of the microstructure on the surface of the neodymium iron boron magnet. This allows it to capture the local features of the grain boundary network without incorporating too much irrelevant information due to an excessively large window, thus ensuring the accuracy of the calculation of the local mean and standard deviation.

[0020] The radius of the neighborhood of the central DC component is 5. This radius is determined based on the distribution characteristics of the DC component in the spectrum of common images. The DC component mainly corresponds to the average gray level of the image and is concentrated in the minimum region at the center of the spectrum. A radius of 5 can completely cover the DC component region, effectively eliminating its interference with the location of the main peak and ensuring accurate identification of the main peak direction.

[0021] The coordinate system rules for calculating geometric azimuth include: the coordinate system has the frequency domain center as the origin, the horizontal rightward direction as the positive X-axis (i.e., the starting direction of the angle), and counterclockwise rotation as the direction of angle increase. The angle range is from 0 degrees to 360 degrees. For example, when the main peak's coordinates are directly to the right of the origin, the azimuth is 0 degrees; when it is directly above the origin, the azimuth is 90 degrees; when it is directly to the left of the origin, the azimuth is 180 degrees; and when it is directly below the origin, the azimuth is 270 degrees.

[0022] Preferably, the periodic machining mark component in the grayscale image of the magnet surface is suppressed using a frequency domain notch filter to output a grain boundary enhanced image, including: Step C1: Notch filter geometry parameter calculation; define the frequency domain center as... For any coordinate point in the frequency domain First, calculate its translation coordinates relative to the center of the frequency domain. Subsequently, based on the main peak direction of the spectrum Calculate the rotated vertical projection coordinates The calculation formula is: Next, define the perpendicular frequency distance from this coordinate point to the principal direction axis. for: Step C2: Constructing the frequency domain directional notch function; constructing the frequency domain directional notch function using the vertical frequency distance. The calculation formula is: in, The preset fixed notch bandwidth constant, It is a natural exponential function; Step C3: Frequency domain filtering and inverse transform; convert the background purified image into a frequency domain complex matrix. With the frequency domain directional notch function Multiply and perform inverse transform to obtain the grain boundary enhanced image. The calculation formula is: in, This represents the two-dimensional discrete Fourier inverse transform. This indicates taking the real part of a complex number.

[0023] The fixed notch bandwidth constant is a key constant used to control the width of the notch range when constructing the frequency domain directional notch function. A value of 3 is preferred, as this value accurately covers the frequency domain energy distribution range corresponding to the periodic machining marks. This effectively suppresses the frequency domain components of the machining marks without excessively attenuating the useful frequency domain information corresponding to the grain boundary network, thus adapting to the periodic characteristics of the machining marks on the NdFeB magnet surface and the difference in frequency domain distribution between the grain boundaries.

[0024] Vertical frequency distance includes: in a frequency domain coordinate system with the center of the spectrum as the origin, the horizontal axis is positive to the right, and the vertical axis is positive downwards. The straight line determined by the main peak direction is a straight line passing through the center of the frequency domain and parallel to the main peak direction. The vertical frequency distance is the perpendicular distance from the frequency domain coordinate point to this straight line. This distance directly reflects the degree of correlation between the frequency domain point and the frequency domain components of the periodic machining marks; the smaller the distance, the stronger the correlation. For example, if the main peak direction is 30 degrees, and the perpendicular distance from a certain frequency domain point to this straight line is 0, then this point is where the core frequency domain component of the machining marks is located.

[0025] The frequency domain directional notch function includes: The notch function attenuates the energy of specific frequency components using a Gaussian function. The ratio of the square of the vertical frequency distance to the square of twice the fixed notch bandwidth constant in the exponent term quantifies the deviation of the frequency point from the frequency component of the machining mark. A negative value ensures greater attenuation for frequency points with smaller distances. Subtracting the Gaussian exponent term from 1 makes the notch function value close to 0 in the frequency region corresponding to the machining mark, achieving energy suppression, while it takes a value close to 1 in other regions, retaining useful information. For example, when the vertical frequency distance is 0, the exponent term is 0, the notch function value is 0, and the energy at that frequency point is completely suppressed; as the vertical frequency distance increases, the notch function value gradually approaches 1, increasing the energy retention ratio.

[0026] The frequency domain filtering process includes: first, obtaining the frequency domain complex matrix of the background purification image after a two-dimensional discrete Fourier transform, which contains all the frequency domain information of the image; then, performing point-by-point multiplication operations between the frequency domain complex matrix and the frequency domain directional notch function to attenuate the energy of the frequency domain components corresponding to the machining marks and retain the energy of the frequency domain components corresponding to the grain boundaries; next, performing a two-dimensional discrete Fourier inverse transform on the filtered frequency domain matrix to convert the frequency domain information back to the spatial domain; finally, taking the real part of the inverse transform result, because the imaginary part generated by the inverse transform is the numerical calculation error, and the real part is the grain boundary enhancement image after removing the interference of machining marks.

[0027] The method for constructing the straight axis determined by the direction of the main peak includes: taking the center coordinates in the frequency domain as a point on the straight line, and determining the slope of the straight line according to the direction of the main peak. Let the center coordinates in the frequency domain be (u... c v cLet the angle of the main peak direction be θ*, then the slope of the line is k = tanθ* (the slope is 0 when θ is 0 degrees, and the slope does not exist when θ is 90 degrees, i.e., the line is perpendicular). The equation of the line is: when θ ≠ 90 degrees, y - v c = k(x - u c When θ* = 90 degrees, x = u c For example, if the frequency domain center is (512, 512), the main peak direction is 45 degrees, the slope k=1, and the equation of the straight line is y - 512 = x - 512, that is, y=x.

[0028] The calculation of the vertical frequency distance includes: First, translating the frequency domain coordinate point (u, v) to a position relative to the frequency domain center (u). c v c The new coordinates (u', v') of the origin are calculated as u' = u - u c v' = v - v c The second step is to rotate the translated coordinates according to the main peak direction θ. The rotation formula is v'' = -u' × sinθ + v' × cosθ*, where v'' is the projected coordinate of the rotated coordinate point on the straight axis perpendicular to the main peak direction. The third step is to take the absolute value of v'', which is the vertical frequency distance of the frequency domain coordinate point relative to the straight axis.

[0029] Preferably, the second derivative ridge response of the grain boundary enhancement image is calculated, and the microstructure skeleton is extracted through binarization and skeleton refinement, including: Step D1: Hessian matrix construction and eigenvalue calculation; setting the Gaussian scaling constant. Pixels, kernel size Using Gaussian second-order partial derivative kernels Enhanced image of the grain boundary Convolution is performed to obtain the second derivative components. And construct the Hessian matrix : calculate Two eigenvalues and satisfy ; Step D2: Extraction of second-order derivative ridge response; define initial ridge response. for: The second derivative ridge response was obtained by normalizing it. : in It is a minimal constant that can be divided by zero; Step D3: Adaptive binarization; calculation The mean of the whole graph and standard deviation Set a fixed multiple constant Calculate the binarization threshold : according to Generate a binary structure diagram and remove those with areas smaller than Connected components of a pixel; Step D4: Refine the microstructure framework; for Applying the Zhang-Suen refinement algorithm, define For pixels The total number of non-zero pixels in the eight neighboring regions, In the eight-neighbor sequence The number of transitions; In the first sub-iteration, delete pixels that satisfy all of the following conditions. : (a) ; (b) ; (c) ; (d) ; In the second sub-iteration, delete pixels that satisfy conditions (a), (b), and the following conditions. : (e) ; (f) ; in for The clockwise eight neighboring pixel values ​​are used; the process is repeated until no pixels can be deleted, and the microstructure skeleton is output.

[0030] The fixed scale σ of the Gaussian second derivative kernel is a key parameter controlling the smoothness of the Gaussian function, used to adjust the accuracy of capturing detailed structures in the grain boundary enhancement image. A value of 1.6 pixels is preferred, as this value accurately matches the scale characteristics of grain boundaries and microcracks on the surface of NdFeB magnets, ensuring stability in the second derivative calculation without losing detail due to over-smoothing or retaining excessive noise due to insufficient smoothing.

[0031] The fixed kernel size K of the Gaussian second derivative kernel is the size specification of the Gaussian second derivative kernel, which determines the coverage of the convolution operation. It is preferably 11×11. This size is derived from the 3xσ rule, which can completely contain the effective energy region of the Gaussian function, while balancing computational efficiency and detail capture ability, and avoiding computational distortion caused by an excessively small kernel size.

[0032] The preset multiplier k for the binarization threshold calculation is a coefficient used to adjust the sensitivity of the binarization threshold, affecting the extraction range of the ridge response. A value of 1.2 is preferred, as this value can suppress weak noise responses while preserving the true grain boundary and crack responses, making the binarization results more closely resemble the actual microstructure.

[0033] The preset area threshold Amin for connected component filtering is the critical area standard for determining whether a connected region is noise. It is preferably 20 pixels because the noise region on the NdFeB surface is typically smaller than this area, while the connected regions corresponding to grain boundaries and cracks are larger, effectively separating noise from useful structures.

[0034] Extraction of the second derivative ridge response involves the following: The Hessian matrix has two real eigenvalues. The eigenvalue with the smaller absolute value reflects the lateral variation characteristics of the structure and is highly correlated with linear structures such as grain boundaries and cracks. If the eigenvalue is negative, it indicates the presence of a concave linear structure in the corresponding region; taking its opposite can enhance the response of this structure. If it is positive, it indicates a convex structure or the absence of a clear linear structure; setting it to zero can weaken irrelevant signals. For example, if the eigenvalues ​​of a pixel's Hessian matrix are 5 and -3, and the eigenvalue with the smaller absolute value is -3, the initial response value is set to 3; if the eigenvalues ​​are 4 and 2, the initial response value is set to zero.

[0035] The calculation of the adaptive binarization threshold includes: first, calculating the average grayscale value of all pixels in the second derivative ridge response map, i.e., the global mean; then, calculating the average of the sum of squares of the differences between the grayscale values ​​of all pixels and the global mean, and taking the square root to obtain the global standard deviation; finally, adding the global mean to 1.2 times the global standard deviation, and using the result as the binarization threshold. For example, if the global mean is 0.3 and the global standard deviation is 0.1, the binarization threshold is 0.3 plus 1.2 multiplied by 0.1, which equals 0.42. Pixels with a response value greater than or equal to 0.42 are retained as foreground, and the rest are background.

[0036] The Zhang-Suen thinning algorithm employs two sub-iteration deletions: the total number of non-zero pixels in the neighborhood is between 2 and 6, ensuring that edge pixels are deleted rather than core structures; and the number of neighborhood transitions is 1, ensuring that structural connectivity is not disrupted after deletion. In the first sub-iteration, the product of p2, p4, and p6 is zero, and the product of p4, p6, and p8 is also zero. In the second sub-iteration, the product of p2, p4, and p8 is also zero. Through these two differential conditional deletions, over-thinning that could lead to structural breakage is avoided. For example, if an edge pixel satisfies the following conditions: the total number of non-zero pixels in the neighborhood is 3, the number of transitions is 1, and there are zeros in p2, p4, and p6, and zeros in p4, p6, and p8, then it will be deleted in the first sub-iteration.

[0037] Connected component filtering includes: labeling connected components in the binarized image, calculating the number of pixels contained in each connected component (i.e., the area of ​​the connected component); classifying connected components with an area less than 20 pixels as noise and setting them as background; and retaining connected components with an area greater than or equal to 20 pixels as valid structures for subsequent thinning processing. For example, a connected component containing only 8 pixels is judged as noise and removed; a connected component containing 30 pixels is retained as valid structure.

[0038] Numerical calculation of the eigenvalues ​​of a Hessian matrix includes: calculating the eigenvalues ​​of a 2×2 Hessian matrix analytically. The specific steps are as follows: Let the Hessian matrix be [[a, b], [b, c]]. First, calculate the trace t = a + c, the determinant d = a × c - b × b, and then calculate the discriminant Δ = t × t - 4 × d. The eigenvalues ​​are (t + √Δ) divided by 2 and (t - √Δ) divided by 2, respectively. The results are sorted by absolute value to obtain the eigenvalues ​​with larger and smaller absolute values. For example, for a Hessian matrix [[2, 1], [1, 3]], with trace t = 5, determinant d = 5, and discriminant Δ = 15, the eigenvalues ​​are approximately 4.33 and 0.67, respectively. The eigenvalue with the smaller absolute value is 0.67.

[0039] The numbering order of neighboring pixels p2-p9 in the Zhang-Suen thinning algorithm is as follows: taking the center pixel p1 as the reference, the pixels are numbered clockwise, starting from the pixel directly above p1, in the following order: p2 (directly above), p3 (directly to the upper right), p4 (directly to the right), p5 (directly to the lower right), p6 (directly to the lower right), p7 (directly to the lower left), p8 (directly to the left), and p9 (directly to the upper left). For example, if the coordinates of p1 are (x, y), then p2 is (x, y-1), p3 is (x+1, y-1), p4 is (x+1, y), and so on.

[0040] The generation of the Gaussian second derivative kernel includes: the kernel size is determined by K = 11 × 11, the kernel elements are calculated based on the second partial derivatives of the two-dimensional Gaussian function, and the kernel elements in the x-direction are (x... 2 Decrease σ 2Divide by (σ to the power of 4) and multiply by the Gaussian function value; the kernel element of the second partial derivative in the y-direction is (y 2 Decrease σ 2 The kernel element is calculated by dividing (σ to the power of 4) by the Gaussian function value. The cross-second partial derivative kernel element is (x multiplied by y) divided by (σ to the power of 4) by the Gaussian function value. The kernel element quantization precision is retained to six decimal places, and normalization is used to make the sum of the kernel elements zero. Edge elements with absolute values ​​less than 10 to the power of negative 6 are set to zero to ensure the effectiveness and computational efficiency of the kernel. For example, when σ = 1.6, elements near the kernel center are calculated according to the formula, while edge elements are set to zero because their values ​​are too small.

[0041] Preferably, constructing a grain boundary network topology diagram based on the microstructure framework, including a set of grain boundary nodes and a set of grain boundary edges, includes: Step E1: Grain boundary node identification; calculation of the microstructure framework. Each foreground pixel Eight-neighbor connectivity degree The calculation formula is: in Represents pixels The set of eight neighboring pixels; constructing the set of grain boundary nodes. The set is defined as: in Represents pixels For skeleton pixels, This represents the logical AND operation; Step E2: Grain boundary edge tracing and construction; defining directed half-edge access markers. ,in For pixel coordinates, Eight-neighbor direction index; traversal Each grain boundary node in and direction index If neighboring pixels For skeleton pixels and If not visited, initialize a new grain boundary edge. and along the degree of connection Skeleton path tracing until the termination node is reached. During the tracing process, all traversed directed half-edges and their reverse half-edges are marked as visited, and the generated grain boundary edges are recorded. Add the set of grain boundaries ; Step E3: Calculate grain boundary length; calculate the length of each grain boundary. Grain boundary edge length values During tracking, if the displacement from the current pixel to the next pixel is an orthogonal neighborhood, then the length is accumulated. If it is a diagonal neighborhood, then accumulate the length. ; Calculate the total edge length of the set of grain boundary edges. The calculation formula is: in This represents the summation of all elements in the set.

[0042] The connectivity degree includes: the eight-neighborhood of a skeleton pixel refers to the set of pixels surrounding that pixel in eight directions (up, top right, right, bottom right, bottom, bottom left, left, top left). The connectivity degree is the number of non-zero skeleton pixels in this set. For example, if a skeleton pixel has three non-zero skeleton pixels in its eight-neighborhood, then the connectivity degree of that pixel is 3.

[0043] The determination of grain boundary nodes includes: pixels with a connection degree of 2 in the skeleton only serve a connecting function and are considered intermediate pixels in the chain, not constituting a network branch; while pixels with a connection degree of 1 (endpoint), 3 (branch point), 4 and above (intersection point) are key nodes in the network branch and are therefore determined to be grain boundary nodes. For example, a pixel with a connection degree of 1 is the endpoint of a crack, and a pixel with a connection degree of 3 is the intersection point of three grain boundaries, both of which are included in the set of grain boundary nodes.

[0044] The directed access marking matrix includes a matrix used to record the access status of each skeleton pixel in eight neighborhood directions, avoiding repeated tracking of the same grain boundary edge. For example, when accessing pixel B from pixel A along the upper right direction, the upper right direction of A and the lower left direction of B are marked as visited simultaneously, and this path will not be processed again in subsequent traversals.

[0045] The differential accumulation of grain boundary lengths includes: the distance between adjacent pixels in the horizontal or vertical direction is one unit length, and the distance between adjacent pixels in the diagonal direction is 1.414 times the unit length (i.e., an approximation of the square root of two). This rule conforms to the geometric distance calculation logic in the pixel coordinate system. For example, moving horizontally from pixel (10,10) to (11,10), the length accumulates by 1; moving diagonally from (10,10) to (11,11), the length accumulates by 1.414.

[0046] The tracing of grain boundary edges terminates as follows: starting from the initial grain boundary node, only the skeleton pixel chain with a connection degree of 2 is traced. These pixels have no branches and can form a continuous path. When another grain boundary node with a connection degree other than 2 is encountered, the path terminates, and the pixel chain between the two points constitutes a complete grain boundary edge. For example, starting from the endpoint (connection degree 1), tracing a series of pixels with a connection degree of 2 until a triangular point (connection degree 3) is encountered, this path is a grain boundary edge.

[0047] The data structure of the directed access marker matrix includes: the matrix dimension is the image height multiplied by the image width multiplied by 8, which corresponds to the eight neighborhood directions of each pixel; the initial state is unvisited (represented by 0); the update mechanism is: when pixel p is visited along the m-th direction to pixel q, the state of (p,m) and (q,m') in the matrix is ​​set to visited (represented by 1), where m' is the reverse direction of m (e.g., the reverse direction of the top is down, and the reverse direction of the upper right is the lower left).

[0048] The arrangement of fixed neighborhood order includes: clockwise arrangement, with the central skeleton pixel as the reference, and the eight neighborhood directions in sequence as top, top right, right, bottom right, bottom, bottom left, left, top left. This order is strictly followed during traversal and judgment to ensure consistency of operation.

[0049] The determination of adjacent skeleton pixels during skeleton pixel chain tracing includes: allowing diagonal adjacency; as long as the pixels within the eight-neighborhood of a pixel are non-zero skeleton pixels, they are considered adjacent. For example, if the diagonal pixels to the upper right and lower right of the center skeleton pixel are skeleton pixels, they are considered adjacent pixels and can be included in the tracing path.

[0050] Preferably, the grain boundary network topology anomaly index is calculated based on the grain boundary network topology graph; the grain boundary network topology anomaly index is obtained by summing an irregular node proportion term and a network density deviation term: the irregular node proportion term represents the proportion of non-triangular grain boundary nodes in the set of grain boundary nodes, and the network density deviation term represents the weighted absolute difference between the current grain boundary network density and the reference grain boundary network density; wherein, the current grain boundary network density is the ratio of the number of triangular grain boundary nodes in the set of grain boundary nodes to the square of the total edge length of the set of grain boundary edges, including: Step F1: Calculate topological statistics; statistically analyze the set of grain boundary nodes. The total number of elements is taken as the total number of grain boundary nodes. ; Statistical analysis of the connectivity degree The number of nodes equal to three is used as the number of three-way grain boundary nodes. : Calculate the set of grain boundary edges The grain boundary length values ​​of all grain boundary edges. The sum is used as the total side length value. : Step F2: Density normalization solution calculation; calculate the current grain boundary network density. The calculation formula is: in It is a tiny, zero constant. Step F3: Anomaly index synthesis; calculate the grain boundary network topological anomaly index. The calculation formula is: in, This refers to the percentage of irregularly shaped nodes. This refers to the network density deviation term; The preset reference grain boundary network density constant, This is the preset deviation weighting coefficient.

[0051] The reference grain boundary network density is a benchmark constant characterizing the topological density of the grain boundary network on the surface of a standard qualified NdFeB magnet, reflecting the inherent proportional relationship between the three-way grain boundary nodes and the total edge length under normal conditions. Preferably, it is the median value of the current grain boundary network density from 200 standard qualified sample images, because the median has the characteristic of resisting interference from abnormal samples, can stably represent the density level of the normal grain boundary network, and avoids the influence of individual abnormal qualified samples on the accuracy of the benchmark.

[0052] The deviation weighting coefficient is a coefficient that adjusts the contribution of the network density deviation term, used to balance the weights of the irregular node proportion term and the network density deviation term in the anomaly index. Preferably, it is 1 divided by (density dispersion plus a small, zero-prevention constant), where the density dispersion is the median of the absolute deviations of the current grain boundary network density relative to κ0 for all standard qualified samples multiplied by 1.4826. This value automatically adapts the weights according to the density distribution of normal samples, making the quantification of network density deviation more consistent with reality.

[0053] The current grain boundary network density is calculated as the ratio of the number of three-way grain boundary nodes to the square of (total edge length plus a small constant divided by zero). The total edge length is the sum of the lengths of all grain boundary edges. The square is used as the denominator because the total edge length increases linearly with the image scale, and the squared value is dimensionless with the area, achieving scale independence of the density and making image densities at different scales comparable. For example, if the number of three-way grain boundary nodes is 360, the total edge length is 8200, and ε is 10 to the power of -12, then the current grain boundary network density is 360 divided by the square of (8200 plus 10 to the power of -12), which is approximately equal to 5.35 multiplied by 10 to the power of -6.

[0054] The calculation of the irregular node ratio involves: first, counting the total number of grain boundary nodes and the number of three-way grain boundary nodes; then, dividing the number of three-way grain boundary nodes by the total number of grain boundary nodes to obtain the three-way node ratio; finally, subtracting this ratio from 1 to obtain the irregular node ratio. A larger ratio indicates more non-three-way nodes (endpoints, intersections, etc.) and a more significant deviation of the grain boundary network topology from the normal state. For example, if the total number of grain boundary nodes is 520 and the number of three-way grain boundary nodes is 360, then the irregular node ratio is 1 minus 360 divided by 520, which is approximately 0.3077.

[0055] The calculation of the network density deviation term includes: first, calculating the difference between the current grain boundary network density and the reference grain boundary network density κ0, taking the absolute value, and then multiplying it by the deviation weighting coefficient α. The larger this value, the more significant the deviation between the current grain boundary network density and the normal reference. For example, if the current grain boundary network density is 5.35 x 10⁻⁶, κ0 is 4.90 x 10⁻⁶, and α is 2.5 x 10⁻⁶, then the network density deviation term is 2.5 x 10⁻⁶ x 0.45 x 10⁻⁶, which equals 1.125.

[0056] The synthesis of the grain boundary network topology anomaly index involves directly adding the irregular node proportion term and the network density deviation term to obtain a single scalar anomaly index. This index integrates topological characteristics from two dimensions: node type distribution and network density, and can comprehensively quantify the degree of anomaly in the grain boundary network. For example, if the irregular node proportion term is 0.3077 and the network density deviation term is 1.125, then the anomaly index is 1.4327.

[0057] The connectivity degree of a three-way grain boundary node must be equal to 3, with no slight deviation allowed. The connectivity degree is the total number of non-zero pixels in the eight-neighborhood of a skeleton pixel. Only when this value is exactly 3 can it be identified as a three-way grain boundary node, ensuring the accuracy of node type determination and avoiding topological statistical distortion due to deviation.

[0058] When summing the total edge length values, six decimal places are retained, and the decimal part is processed using rounding rules. For example, if the length of a grain boundary edge is 1.41421356, it becomes 1.414214 after retaining six decimal places. This ensures that the accuracy of the edge length summation meets the requirements of density calculation, while avoiding calculation redundancy due to excessive precision.

[0059] The value of ε is 10 to the power of -12. This value is an extremely small positive number, which can effectively avoid the division error when the total side length is zero, and will not have a substantial impact on the calculation result of the square of the total side length, thus ensuring the stability and accuracy of the density calculation.

[0060] Preferably, the grain boundary network topology anomaly index is compared with a preset quality control threshold. If it exceeds the quality control threshold, a surface defect determination signal is output, including: Step G1: Exception logic determination; execute the determination logic. : in The grain boundary network topology anomaly index is given. The quality control threshold is... Let be an indicator function; if Then the surface defect determination signal is output; Step G2: Control parameters for offline curing; the reference grain boundary network density The deviation weighting coefficient and the quality control threshold Through the A standard qualified sample image Obtained through offline calculation: First, calculate the current grain boundary network density for each sample image. Take the median to determine : Secondly, calculate the density dispersion. And determine : Finally, the anomaly index for each sample image is calculated. Calculate the median value and dispersion and determine : in, Let be the consistency constant of the normal distribution. For preset multiples, The number of samples is a constant.

[0061] The number of standard qualified sample images is the total number of standard qualified NdFeB magnet surface images used for offline statistical benchmark parameters and quality control thresholds. Preferably, it is 200. This number satisfies the statistical significance requirement, ensuring that the benchmark parameters reflect the general characteristics of normal products while also resisting interference from individual abnormal qualified samples through median statistics, thus ensuring parameter stability.

[0062] The normality consistency constant of 1.4826 is a fixed coefficient used to convert the absolute deviation of the median into an approximate standard deviation. 1.4826 is preferred, as this value is a statistically accepted constant suitable for non-normally distributed sample data. It makes the dispersion calculation more closely resemble the actual distribution, improving the reliability of the baseline parameters and thresholds.

[0063] The preset multiple of 4 for calculating the quality control threshold is a coefficient used to adjust the threshold coverage range. A value of 4 is preferred, as this value covers the vast majority of fluctuations in normal samples, avoiding both missed detections due to an excessively wide threshold and misjudgments of normal products due to an excessively strict threshold, thus adapting to the fluctuation characteristics of the normal grain boundary network on the surface of NdFeB magnets.

[0064] The baseline grain boundary network density is determined by selecting 200 standard qualified sample images, calculating the current grain boundary network density for each image, arranging these density values ​​in ascending order, and taking the middle value as κ0. For example, after sorting the density values ​​of the 200 samples, if the average of the 100th and 101st values ​​is 5.0 × 10⁻⁶, then κ0 is 5.0 × 10⁻⁶. This method effectively eliminates the influence of extreme qualified samples.

[0065] The deviation weighting coefficient includes: first, calculating the absolute difference between the current grain boundary network density and κ0 for each standard qualified sample, obtaining a set of absolute deviations; arranging these absolute deviations in ascending order, taking the value at the middle position as the median of the absolute deviations; multiplying this median of absolute deviations by 1.4826, adding 10 to the power of -12, and finally taking the reciprocal, which is α. For example, if the median of absolute deviations is 0.4 × 10⁻⁶, multiplying it by 1.4826 yields approximately 0.593 × 10⁻⁶, adding 10 to the power of -12 gives approximately 0.593 × 10⁻⁶, and α is 1 divided by this value, which is approximately equal to 1.686 × 10⁶.

[0066] The quality control threshold includes: First, calculating the grain boundary network topological anomaly index for each standard qualified sample, arranging these indices in ascending order, and taking the median value as the sample median; then calculating the absolute difference between each sample index and the sample median value, and taking the median value as the sample absolute deviation median; adding four times the sample absolute deviation median to the sample median value, and then multiplying by 1.4826, gives T. For example, if the sample median is 0.8, the sample absolute deviation median is 0.1, and four times the sample absolute deviation median is 0.4, the sum is 1.2, multiplying by 1.4826 gives approximately 1.779, i.e., T is 1.779.

[0067] The single-threshold anomaly determination includes: comparing the grain boundary network topology anomaly index of the magnet under test with a quality control threshold T. If the index is greater than T, a defect is determined to exist on the magnet surface, and a surface defect determination signal is output; if the index is less than or equal to T, the magnet surface is determined to be normal, and a normal determination signal is output. For example, if the anomaly index of the magnet under test is 1.8 and T is 1.779, 1.8 is greater than 1.779, so a defect signal is output; if the anomaly index is 1.7, which is less than 1.779, a normal signal is output.

[0068] The selection criteria for standard qualified sample images include: the sample must be of the same model and production batch as the magnet to be tested, and must have undergone grain boundary diffusion and subsequent grinding and cleaning processes, and be in the same pre-surface treatment exposure window; the sample surface must be confirmed by manual inspection to be free of defects such as cracks, dark scratches, and corrosion, and the appearance must be free of obvious stains and scratches; the size and processing parameters of the sample must be consistent with the product to be tested to ensure uniformity of the process window coverage and good consistency of the samples.

[0069] The calculation of the median absolute deviation of the samples includes: First, calculating the target parameter (current grain boundary network density or grain boundary network topology anomaly index) for each standard qualified sample; Second, calculating the median value of the target parameter for all samples; Third, calculating the absolute difference between the target parameter of each sample and the median value, forming an absolute deviation set; Fourth, arranging the absolute deviation sets in ascending order; Fifth, if the number of samples is even, taking the average of the two middle values; if it is odd, taking the value in the middle position, which is the median absolute deviation of the samples; Extreme outliers are not excluded during the calculation process, because the median itself has the characteristic of resisting interference from extreme values.

[0070] The minimum value of M is 200, which meets the statistical significance requirement and ensures that the calculation results of the benchmark parameters and thresholds are representative. If M is less than 200, the insufficient sample size will lead to an increase in the randomness of the statistical results, which will not be able to reflect the general characteristics of normal products and affect the accuracy of defect identification.

[0071] When the dispersion of the grain boundary network topology anomaly index of all samples is too large, the following steps are taken: First, check whether the samples meet the selection criteria and remove samples that do not meet the process window or have hidden defects; if the number of samples still meets 200 after removal, recalculate the dispersion; if the dispersion is still too large, increase the sample size to 300 to increase the representativeness of the samples; if it still cannot be improved, it is necessary to check whether there are unstable factors in the production process, and re-collect samples after the process is stable to ensure that the benchmark parameters and thresholds can truly reflect the characteristics of normal products.

[0072] like Figure 2 As shown, Figure 2 This is a schematic diagram of a neodymium iron boron magnet surface defect identification system. Its workflow is as follows: a conveyor belt transports neodymium iron boron magnets, and a positioning fixture fixes the magnets to ensure stable detection position; a light shield isolates external stray light interference, and a line light source provides uniform illumination; after the industrial camera acquires images of the magnet surface, the images are transmitted to an industrial control computer, which runs the corresponding defect identification algorithm to complete the anomaly judgment of the magnet surface and realize the automated detection of magnet surface defects.

[0073] Example 2: A method for identifying surface defects in NdFeB magnets, applied to any of the surface defect identification systems for NdFeB magnets described above, comprising: The grayscale image of the acquired magnet surface is normalized, and the main peak direction of the spectrum of the grayscale image of the magnet surface is analyzed. The periodic processing tool mark component in the grayscale image of the magnet surface is suppressed by the frequency domain notch filter, and the grain boundary enhancement image is output. The second derivative ridge response of the grain boundary enhancement image is calculated, the microstructure skeleton is extracted by binarization and skeleton refinement, and a grain boundary network topology graph containing the set of grain boundary nodes and the set of grain boundary edges is constructed based on the microstructure skeleton. The grain boundary network topology anomaly index is calculated based on the aforementioned grain boundary network topology graph. This index is obtained by summing an irregular node proportion term and a network density deviation term. The irregular node proportion term represents the percentage of non-triangular grain boundary nodes in the set of grain boundary nodes, while the network density deviation term represents the weighted absolute difference between the current grain boundary network density and the baseline grain boundary network density. The current grain boundary network density is the ratio of the number of triangular grain boundary nodes in the set of grain boundary nodes to the square of the total edge length of the set of grain boundary edges. The grain boundary network topology anomaly index is compared with a preset quality control threshold. If it exceeds the quality control threshold, a surface defect judgment signal is output.

[0074] The embodiments of this example have been described above. However, this example is not limited to the specific implementation methods described above. The specific implementation methods described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms based on the guidance of this example, and all of them are within the protection scope of this example.

Claims

1. A surface defect identification system for neodymium iron boron magnets, characterized in that, include: The surface texture suppression module is used to normalize the grayscale image of the acquired magnet surface, analyze the main peak direction of the spectrum of the grayscale image of the magnet surface, suppress the periodic processing tool mark component in the grayscale image of the magnet surface using a frequency domain notch filter, and output a grain boundary enhancement image. The grain boundary network reconstruction module is used to calculate the second derivative ridge response of the grain boundary enhancement image, extract the microstructure skeleton through binarization and skeleton refinement, and construct a grain boundary network topology map containing the set of grain boundary nodes and the set of grain boundary edges based on the microstructure skeleton. The structural deviation analysis module is used to calculate the grain boundary network topology anomaly index based on the grain boundary network topology diagram. The grain boundary network topology anomaly index is obtained by summing the irregular node proportion term and the network density deviation term: the irregular node proportion term represents the proportion of non-triangular grain boundary nodes in the set of grain boundary nodes, and the network density deviation term represents the weighted absolute difference between the current grain boundary network density and the reference grain boundary network density; wherein, the current grain boundary network density is the ratio of the number of triangular grain boundary nodes in the set of grain boundary nodes to the square of the total side length of the set of grain boundary edges. An anomaly identification module is used to compare the grain boundary network topology anomaly index with a preset quality control threshold. If the index exceeds the quality control threshold, a surface defect judgment signal is output.

2. The surface defect identification system for neodymium iron boron magnets according to claim 1, characterized in that, The acquired grayscale image of the magnet surface is normalized, and the main peak direction of the grayscale image spectrum is analyzed, including: A linear mapping process is performed to map the pixel grayscale values ​​of the magnet surface grayscale image to a unit value range, resulting in a basic normalized image. Subsequently, a local contrast enhancement process is performed on the basic normalized image. For each pixel in the basic normalized image, the local grayscale mean and local grayscale standard deviation within a fixed window centered on that pixel are calculated. The grayscale value of the pixel is then subtracted from the local grayscale mean and divided by the sum of the local grayscale standard deviation and a small zero constant to obtain the normalized background purification image. A two-dimensional discrete Fourier transform is performed on the background purification image and the spectrum is centered to calculate the amplitude spectrum. After excluding the neighborhood of the central DC component in the amplitude spectrum, the frequency domain energy extremum point with the largest amplitude value is searched. If there are multiple maximum amplitude points, the main peak coordinates are determined according to the priority order of the smallest Manhattan distance from the frequency domain center, the smallest horizontal coordinate value, and the smallest vertical coordinate value. Calculate the geometric azimuth angle of the main peak coordinates relative to the frequency domain center, and take this geometric azimuth angle as the direction of the main peak of the spectrum.

3. The surface defect identification system for neodymium iron boron magnets according to claim 2, characterized in that, The periodic machining mark component in the grayscale image of the magnet surface is suppressed using a frequency domain notch filter, and a grain boundary enhanced image is output, including: Based on the spectral center coordinates of the background purified image, a frequency domain coordinate system is established; for each frequency domain coordinate point in the frequency domain coordinate system, the vertical frequency distance of the frequency domain coordinate point relative to the straight line axis determined by the main peak direction of the spectrum is calculated; A frequency domain directional notch function is constructed based on the vertical frequency distance and a preset fixed notch bandwidth constant; the value of the frequency domain directional notch function is obtained by subtracting the exponent of a Gaussian function, wherein the independent variable of the exponent is the negative value of the ratio of the square of the vertical frequency distance to twice the square of the fixed notch bandwidth constant. The frequency domain complex matrix of the background purification image is multiplied point-by-point with the frequency domain directional notch function to obtain the filtered frequency domain matrix; a two-dimensional discrete Fourier inverse transform is performed on the filtered frequency domain matrix, and the real part of the inverse transform result is taken as the grain boundary enhancement image.

4. A surface defect identification system for neodymium iron boron magnets according to claim 3, characterized in that, Calculate the second derivative ridge response of the grain boundary enhancement image, and extract the microstructure skeleton through binarization and skeleton refinement, including: The grain boundary enhancement image is convolved using a Gaussian second derivative kernel with a fixed scale and a fixed kernel size to construct a Hessian matrix corresponding to each pixel; the real eigenvalues ​​of the Hessian matrix are then calculated. Select a real number eigenvalue with a small absolute value. If the real number eigenvalue is negative, take its opposite as the initial response value; otherwise, set the initial response value to zero. Normalize the initial response value to the unit value range to obtain the second derivative ridge response. The global mean and global standard deviation of the second derivative ridge response are statistically analyzed, and the sum of the global mean and the global standard deviation by a preset multiple is determined as the binarization threshold. The second derivative ridge response is binarized and segmented using the binarization threshold, and connected regions with an area smaller than a preset area threshold are filtered out to obtain a binarized structure map. The Zhang-Suen thinning algorithm is applied to the binarized structure map. Boundary pixels that satisfy the preset conditions of the total number of non-zero pixels in the neighborhood, the preset number of neighborhood transitions, and the preset condition of the neighborhood product being zero are deleted through two sub-iteration loops until the binarized structure map converges, thus obtaining the microstructure skeleton with a single pixel width.

5. A surface defect identification system for neodymium iron boron magnets according to claim 4, characterized in that, Based on the aforementioned microstructural framework, a grain boundary network topology diagram is constructed, comprising a set of grain boundary nodes and a set of grain boundary edges, including: For each skeleton pixel in the microstructure skeleton, the total number of non-zero pixels in its eight neighborhoods is calculated as the connectivity degree; if the connectivity degree of the skeleton pixel is not equal to two, then the skeleton pixel is determined as a grain boundary node and included in the set of grain boundary nodes. A directed access marker matrix is ​​established to record the access status of skeleton pixels and their eight neighboring directions. Each grain boundary node in the set of grain boundary nodes is traversed, and a neighboring direction connected to a skeleton pixel is checked in a fixed neighborhood order. If such a direction exists, the adjacent skeleton pixel chain with a connection degree of two is traced along the neighboring direction from the grain boundary node until another grain boundary node is encountered, thereby constructing a grain boundary edge and adding it to the set of grain boundary edges. During the tracing process, the traversed path direction and its reverse path direction are marked as visited in the directed access marker matrix. During the construction of the grain boundary edge, the path length is accumulated; if the tracking step is a horizontal or vertical movement, the path length is increased by a unit length value; if the tracking step is a diagonal movement, the path length is increased by the square root of two units of length value; the accumulated path length is used as the grain boundary edge length value of the grain boundary edge.

6. A surface defect identification system for neodymium iron boron magnets according to claim 5, characterized in that, The grain boundary network topology anomaly index is calculated based on the aforementioned grain boundary network topology diagram, including: The total number of grain boundary nodes in the set of grain boundary nodes is counted, and the three-way grain boundary nodes with a connection degree of three are selected and their number is counted to obtain the number of three-way grain boundary nodes; the grain boundary edge length values ​​of all grain boundary edges in the set of grain boundary edges are summed to obtain the total edge length value. The current grain boundary network density is calculated, and its value is equal to the number of three-way grain boundary nodes divided by the square of the sum of the total edge length and the infinitesimal constant. The value of the irregular node ratio term is equal to one minus the ratio of the number of three-way grain boundary nodes to the total number of grain boundary nodes; the value of the network density deviation term is equal to the absolute value of the current grain boundary network density minus the preset benchmark grain boundary network density multiplied by the preset deviation weight coefficient. The ratio of irregular nodes is added to the network density deviation term to obtain the grain boundary network topology anomaly index.

7. A surface defect identification system for neodymium iron boron magnets according to claim 6, characterized in that, The grain boundary network topology anomaly index is compared with a preset quality control threshold. If it exceeds the quality control threshold, a surface defect determination signal is output, including: Determine whether the value of the grain boundary network topology anomaly index is greater than the value of the quality control threshold; if yes, generate and output the surface defect judgment signal to indicate that there is an anomaly on the surface of the NdFeB magnet; if no, output the normal judgment signal. The baseline grain boundary network density, the deviation weighting coefficient, and the quality control threshold are obtained offline statistically based on multiple standard qualified sample images, as detailed below: For each standard qualified sample image, calculate its current grain boundary network density, and take the median value of all current grain boundary network densities as the reference grain boundary network density; Calculate the median of the absolute deviations of all current grain boundary network densities relative to the reference grain boundary network density, multiply the median of the absolute deviations by the normal distribution uniformity constant, add it to the small zero constant, and take the reciprocal as the deviation weighting coefficient. The grain boundary network topology anomaly index of each standard qualified sample image is calculated based on the benchmark grain boundary network density and the deviation weighting coefficient. The median value and the median absolute deviation of the sample are statistically analyzed. The quality control threshold is obtained by multiplying the sum of the median value and the median absolute deviation of the sample by a preset multiple by the normal distribution consistency constant.

8. A method for identifying surface defects in neodymium iron boron magnets, applied to the surface defect identification system for neodymium iron boron magnets as described in any one of claims 1-7, characterized in that, include: The grayscale image of the acquired magnet surface is normalized, and the main peak direction of the spectrum of the grayscale image of the magnet surface is analyzed. The periodic processing tool mark component in the grayscale image of the magnet surface is suppressed by the frequency domain notch filter, and the grain boundary enhancement image is output. The second derivative ridge response of the grain boundary enhancement image is calculated, the microstructure skeleton is extracted by binarization and skeleton refinement, and a grain boundary network topology graph containing the set of grain boundary nodes and the set of grain boundary edges is constructed based on the microstructure skeleton. The grain boundary network topology anomaly index is calculated based on the aforementioned grain boundary network topology graph. This index is obtained by summing an irregular node proportion term and a network density deviation term. The irregular node proportion term represents the percentage of non-triangular grain boundary nodes in the set of grain boundary nodes, while the network density deviation term represents the weighted absolute difference between the current grain boundary network density and the baseline grain boundary network density. The current grain boundary network density is the ratio of the number of triangular grain boundary nodes in the set of grain boundary nodes to the square of the total edge length of the set of grain boundary edges. The grain boundary network topology anomaly index is compared with a preset quality control threshold. If it exceeds the quality control threshold, a surface defect judgment signal is output.