Diamond quality detection method and system based on image recognition
By constructing a structural tensor and multi-scale shear wave transform for diamond images, and combining adaptive filtering and differential operations, the problem of inaccurate detection in diamond inspection is solved, and high-precision defect extraction and quality inspection are achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- SHANGQIU LIREN SUPERHARD MATERIAL PROD CO LTD
- Filing Date
- 2026-05-08
- Publication Date
- 2026-07-14
AI Technical Summary
Existing technologies suffer from inaccurate detection in diamond quality inspection, especially in high-reflectivity, polycrystalline, and complex texture scenarios where it is difficult to accurately extract minute defects, leading to false defect reports and missed detection of real defects, thus failing to meet the requirements of high-precision non-destructive testing.
An initial structural guide map is constructed by calculating the structural tensor of the diamond image, and a composite guide map is generated by combining multi-scale shear wave transform. Defect information is extracted by using spatial adaptive regularized iterative filtering, combined with difference operations and threshold segmentation.
It significantly improves the completeness and accuracy of diamond defect detection, avoids edge blurring, and fully extracts defects such as micro-cracks and scratches, thereby improving the precision and quality of detection.
Smart Images

Figure CN122391180A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of image recognition technology, specifically relating to a diamond quality inspection method and system based on image recognition. Background Technology
[0002] Diamond, as an important superhard material and precious gemstone, has irreplaceable applications in precision machining, semiconductor device manufacturing, and jewelry. During the synthesis and cutting of diamond, defects such as micro-cracks, scratches, or inclusions are inevitably generated internally and on the surface. These defects directly determine the overall grade and actual lifespan of the diamond. Manual observation under a microscope is not only inefficient but also easily affected by human fatigue and subjective experience. In recent years, automated image inspection technology based on machine vision has become increasingly widespread. However, diamond itself has an extremely high refractive index and polyhedral crystal faces. Images acquired under illumination often exhibit strong reflections and flickering, as well as complex interwoven textures. This makes it easy for subtle defect features to be confused and overlapped with the high-frequency, strong light background or inherent crystal edges, greatly increasing the difficulty of high-precision automated separation and identification of true defect areas.
[0003] Chinese patent application CN118111993A discloses a visual inspection method, system, equipment and medium for surface defects of diamond tools. The method achieves defect detection through image acquisition, texture extraction, projection correction and polyline analysis. However, it does not enhance edge and structural features, nor does it preserve edges and reduce noise. In scenes with high reflectivity, polycrystalline planes and complex textures, it is easy to blur edges, miss small defects and generate false defect reports, making it difficult to meet the requirements of high-precision non-destructive testing.
[0004] Rolling guided filtering can iteratively smooth out small-scale texture details and interference noise while preserving the main large-scale structure of the image. Theoretically, by performing a difference operation between the original image and the filtered, detail-removed structural image, a residual image representing defect information can be extracted, thus enabling automatic extraction of diamond quality defects. However, when processing complex diamond images, the rolling guided filtering method struggles to provide accurate structural indications due to factors such as illumination, easily leading to blurred crystal edges or misinterpreting large defects as part of the main structure. Furthermore, images exhibit anisotropic characteristics and spatial differences in local uncertainties between different regions, such as flat areas and significant edge regions. It cannot suppress strong light noise in flat areas and accurately preserve true boundaries in edge regions, resulting in numerous false defect false alarms or missed detections of genuine minute defects in the final extracted residual image, failing to meet the accuracy requirements of high-quality diamond nondestructive testing. Summary of the Invention
[0005] This invention provides a diamond quality inspection method and system based on image recognition to solve the technical problem of inaccurate diamond quality inspection in the prior art.
[0006] In a first aspect, the present invention provides a diamond quality inspection method based on image recognition, comprising the following steps: The process involves acquiring a diamond image to be detected, calculating the structure tensor in the local neighborhood of each pixel in the diamond image, constructing an initial structure guidance map based on the eigenvalue distribution, and recording the difference between the maximum and minimum eigenvalues of the structure tensor as the anisotropy map. A multi-scale shear wave transform is then performed on the diamond image to extract the high-frequency subband coefficients at each scale and calculate the local energy. The local energies at each scale are then fused to obtain a multi-scale edge saliency map. Finally, the initial structure guidance map and the multi-scale edge saliency map are fused to generate a composite guidance map. Using a composite guiding map as the initial guide, an iterative rolling guided filter is performed on the diamond image. In each iteration, the local variance of the previous output image is calculated as an uncertainty measure. A spatial adaptive regularization parameter map is constructed by combining the anisotropy map and the uncertainty measure. The regularization parameter value of the edge salient region is smaller than that of the regularization parameter value of the flat region. When performing guided filtering to calculate the local linear coefficient, the spatial adaptive regularization parameter map is used for constraint, and the output image is updated until the set iteration termination condition is met. The original diamond image is compared with the final output image after the set iteration termination condition to obtain the residual image; the residual image is then subjected to threshold segmentation and connected component analysis to extract defect information and complete the quality inspection.
[0007] Its effects are as follows: By generating composite guide maps through structural tensors and multi-scale shear wave transforms, it can accurately characterize diamond texture and edge features; the use of spatial adaptive regularized iterative filtering can denoise flat areas and preserve edges in edge areas, avoiding edge blurring common in traditional filtering; and through difference, threshold segmentation, and connected component analysis, defects can be completely extracted, significantly improving the completeness of diamond defect detection and the accuracy of quality inspection. Furthermore, the structure tensor within the local neighborhood of each pixel in the diamond image is calculated, and an initial structure guidance map is constructed based on the eigenvalue distribution, including: A local window is set on the diamond image, and the image gradient of each pixel in the local window in the horizontal and vertical directions is calculated. The structure tensor matrix is calculated using image gradients, and eigenvalue decomposition is performed to obtain the maximum and minimum eigenvalues. The minimum eigenvalue is used as the corner feature measure, and the ratio of the maximum eigenvalue to the minimum eigenvalue is used as the edge feature measure. An initial structure guide graph representing texture consistency is constructed by combining corner feature measures and edge feature measures.
[0008] Its effects are as follows: Based on local gradient calculation of the structure tensor and eigenvalue decomposition, the minimum eigenvalue represents corner points and the eigenvalue ratio represents edges. By jointly constructing an initial structure guidance map, it can accurately distinguish corner points, edges, and flat regions, clearly reflecting texture consistency and providing stable and reliable structure guidance for subsequent guided filtering. Furthermore, multi-scale shear wave transform is performed on the diamond image to extract high-frequency subband coefficients at each scale, calculate local energy, and fuse the local energies at each scale to obtain a multi-scale edge saliency map, including: A non-subsampled shear wave filter was used to decompose the diamond image in multiple scales and directions to obtain the low-frequency subband coefficients and the high-frequency subband coefficients in each scale and direction. Calculate the sum of the absolute squares of the high-frequency subband coefficients in the local neighborhood at each scale, and use it as the local energy at the corresponding scale. Calculate the normalized weights of the local energy at each scale, and then use the normalized weights to perform a linear weighted summation of the local energy at all scales to obtain a multi-scale edge saliency map.
[0009] Its effects are as follows: by using non-subsampled shear wave multi-scale and multi-directional decomposition, the details of high-frequency defects in diamond are completely preserved; by using local energy weighted fusion at each scale to obtain an edge saliency map, noise interference can be suppressed, the true edges and weak defects can be highlighted, and the recognition accuracy of defects such as micro-cracks and scratches can be improved.
[0010] Furthermore, a spatially adaptive regularized parameter graph is constructed by combining the anisotropy degree graph and the uncertainty measure, including: The anisotropy map and the uncertainty measure are normalized and mapped to the same numerical range. The normalized anisotropy map and the normalized uncertainty measure are multiplied by corresponding pixels to obtain the fused uncertainty matrix; By using an exponential function to perform a nonlinear mapping on the fusion uncertainty matrix, a spatial adaptive regularization parameter map is obtained, which makes the regularization parameter values of regions with complex textures or significant edge structures decrease exponentially.
[0011] Its effect is as follows: it normalizes the anisotropy degree and uncertainty by dot product, amplifies the difference between the edge and the flat area, and achieves an exponential decrease in the regularization parameter of the edge area and an increase in the parameter of the flat area through exponential mapping, so that the filtering intensity is adaptively adjusted, taking into account both the denoising effect and the edge fidelity, and improving the ability to preserve defect edges.
[0012] Furthermore, when performing guided filtering to calculate local linear coefficients, a spatial adaptive regularization parameter map is used for constraint, and the output image is updated until the set iteration termination condition is met, including: In the cost function of the iterative rolling guided filter, a spatial adaptive regularization parameter graph is introduced, and the mean of the regularization parameters within the current local window is extracted as the scalar weight of the regularization term. The local linear coefficients within each local window are solved by minimizing the cost function with constraints. The pixels within the current local window are reconstructed using linear transformation based on the solved local linear coefficients, and the average of the reconstruction results of all overlapping windows is used as the output image after this iteration.
[0013] Its effects are as follows: an adaptive regularization parameter is introduced into the iterative filtering cost function, the linear coefficients are solved by local window mean constraints, the image is reconstructed by overlapping window mean, the smoothing and edge preservation effects are dynamically balanced, the image transition is natural and there is no block effect, the iterative convergence is stable and the high-quality edge-preserving smoothing result is output.
[0014] Furthermore, the Sobel operator is used to calculate the image gradient vectors of the diamond image in the horizontal and vertical directions, respectively.
[0015] Furthermore, the Adama product algorithm is used to multiply and fuse the initial structural guide map with the multi-scale edge saliency map pixel by pixel to generate a composite guide map that takes into account both image structure texture and edge saliency information.
[0016] Secondly, the present invention provides a diamond quality inspection system based on image recognition, comprising: The guide map generation module is used to acquire the diamond image to be detected, calculate the structure tensor in the local neighborhood of each pixel in the diamond image, construct an initial structure guide map based on the eigenvalue distribution, and record the difference between the maximum and minimum eigenvalues of the structure tensor as the anisotropy map; perform multi-scale shear wave transform on the diamond image, extract the high-frequency subband coefficients at each scale to calculate the local energy, and fuse the local energies at each scale to obtain a multi-scale edge saliency map; and fuse the initial structure guide map and the multi-scale edge saliency map to generate a composite guide map. The iterative module is used to perform iterative rolling guided filtering on the diamond image using a composite guided map as the initial guide. In each iteration, the local variance of the previous output image is calculated as an uncertainty measure. A spatial adaptive regularization parameter map is constructed by combining the anisotropy map and the uncertainty measure. The regularization parameter value of the edge salient region is smaller than that of the regularization parameter value of the flat region. When performing guided filtering to calculate the local linear coefficient, the spatial adaptive regularization parameter map is used for constraint, and the output image is updated until the set iteration termination condition is met. The detection module is used to perform a difference operation between the original diamond image and the final output image after satisfying the set iteration termination condition to obtain a residual image; the residual image is then subjected to threshold segmentation and connected component analysis to extract defect information and complete the quality inspection.
[0017] Furthermore, the structure tensor within the local neighborhood of each pixel in the diamond image is calculated, and an initial structure guidance map is constructed based on the eigenvalue distribution, including: A local window is set on the diamond image, and the image gradient of each pixel in the local window in the horizontal and vertical directions is calculated. The structure tensor matrix is calculated using image gradients, and eigenvalue decomposition is performed to obtain the maximum and minimum eigenvalues. The minimum eigenvalue is used as the corner feature measure, and the ratio of the maximum eigenvalue to the minimum eigenvalue is used as the edge feature measure. An initial structure guide graph representing texture consistency is constructed by combining corner feature measures and edge feature measures.
[0018] Furthermore, multi-scale shear wave transform is performed on the diamond image to extract high-frequency subband coefficients at each scale, calculate local energy, and fuse the local energies at each scale to obtain a multi-scale edge saliency map, including: A non-subsampled shear wave filter was used to decompose the diamond image in multiple scales and directions to obtain the low-frequency subband coefficients and the high-frequency subband coefficients in each scale and direction. Calculate the sum of the absolute squares of the high-frequency subband coefficients in the local neighborhood at each scale, and use it as the local energy at the corresponding scale. Calculate the normalized weights of the local energy at each scale, and then use the normalized weights to perform a linear weighted summation of the local energy at all scales to obtain a multi-scale edge saliency map.
[0019] The beneficial effects are as follows: This invention constructs an initial structural guide map by calculating the structural tensor of a diamond image, and obtains a multi-scale edge saliency map by extracting high-frequency local energy using multi-scale shear wave transform. The two are then fused to generate a composite guide map, which can extract the edge and texture features of the diamond. A spatial regularization parameter map is constructed by combining the anisotropy map and the local variance uncertainty measure. This provides precise spatial constraints on the solution of local linear coefficients, increasing the regularization parameter value in flat areas to fully smooth the background and interference noise, while decreasing the regularization parameter value in salient edge areas to maximize the preservation of defect edge details. Defect information is extracted through difference operations and connected component analysis between the original image and the final filtered output, avoiding the edge blurring phenomenon easily caused by traditional filtering, and improving the completeness of diamond surface defect extraction and the accuracy of overall quality detection. Attached Figure Description
[0020] Figure 1 This is a flowchart of a diamond quality inspection method based on image recognition.
[0021] Figure 2 This is a comparison image of the original image and the anisotropy map.
[0022] Figure 3 This is a schematic diagram of the differential residual plot and the detection results.
[0023] Figure 4 This is a comparison chart of the experiments. Detailed Implementation
[0024] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0025] An embodiment of the diamond quality inspection method based on image recognition provided by this invention: like Figure 1 As shown, the diamond quality inspection method based on image recognition includes the following steps: S1 generates a composite guide map that blends the structure with the edges.
[0026] The process involves acquiring a diamond image to be detected, calculating the structure tensor in the local neighborhood of each pixel in the diamond image, constructing an initial structure guidance map based on the eigenvalue distribution, and recording the difference between the maximum and minimum eigenvalues of the structure tensor as the anisotropy map. A multi-scale shear wave transform is then performed on the diamond image to extract the high-frequency subband coefficients at each scale and calculate the local energy. The local energies at each scale are then fused to obtain a multi-scale edge saliency map. Finally, the initial structure guidance map and the multi-scale edge saliency map are fused to generate a composite guidance map.
[0027] The process involves acquiring the diamond limescale image to be detected, reading the image pixel data, and converting the image data type to double-precision floating-point. When calculating the structure tensor, the Sobel operator is used to calculate the image gradient vectors in the horizontal and vertical directions of the diamond image. The structure tensor is constructed based on the autocorrelation matrix of the image gradient vectors. A mean filter is used to perform local window smoothing on the autocorrelation matrix to obtain the structure tensor of each pixel's neighborhood. The maximum and minimum eigenvalues of the structure tensor are then solved. The initial structure guidance map is constructed based on the eigenvalue distribution by using the sum of the maximum and minimum eigenvalues as the initial structure guidance map value for each pixel position, while simultaneously calculating the difference between the maximum and minimum eigenvalues to obtain the anisotropy map. Figure 2As shown, the anisotropy map is normalized to the interval of 0 to 1 using the minimum-maximum normalization algorithm.
[0028] A multi-scale shear wave transform is performed, specifically using the discrete shear wave transform algorithm to decompose the diamond image into three layers, obtaining low-frequency subbands and high-frequency subband coefficients at each scale and in each direction. For each high-frequency subband at each scale, the sum of squares of the high-frequency coefficients within the neighborhood window of the corresponding pixel is calculated as the local energy. Then, the local energy matrices at all scales are fused by finding the maximum value pixel by pixel. Finally, the fused matrix is normalized using the minimum-maximum normalization method to obtain a multi-scale edge saliency map. The Hadamard product algorithm is used to multiply and fuse the initial structural guide map with the multi-scale edge saliency map pixel by pixel to generate a composite guide map that takes into account both image structure texture and edge saliency information.
[0029] In an optional embodiment, the structure tensor within the local neighborhood of each pixel in the diamond image is calculated, and an initial structure guidance map is constructed based on the feature value distribution, including: A local window is set on the diamond image, and the image gradient of each pixel in the local window in the horizontal and vertical directions is calculated. The structure tensor matrix is calculated using image gradients, and eigenvalue decomposition is performed to obtain the maximum and minimum eigenvalues. The minimum eigenvalue is used as the corner feature measure, and the ratio of the maximum eigenvalue to the minimum eigenvalue is used as the edge feature measure. An initial structure guide graph representing texture consistency is constructed by combining corner feature measures and edge feature measures.
[0030] After acquiring a grayscale diamond image with a resolution of, for example, 1024×1024 or 2048×2048 pixels, a local sliding window of size W×W is set, preferably 3×3, 5×5, or 7×7. Within each local window, the Sobel or Scharr operator is used to convolve the pixel I(x,y) to calculate the horizontal image gradient. Image gradient in the vertical direction .
[0031] Calculate the structure tensor matrix according to the formula. The tensor matrix is smoothed using a Gaussian kernel to suppress random imaging noise on the diamond surface. Eigenvalue decomposition is then performed on the smoothed structural tensor matrix S, and the characteristic equation is solved to obtain the maximum eigenvalue. and minimum eigenvalue The smallest eigenvalue As a corner feature measure, it reflects the gradient changes of the pixel neighborhood in multiple directions; to avoid the denominator being zero, a minimal constant is introduced. The edge feature measure is defined as When this ratio is much greater than 1, it is judged as a significant diamond linear scratch or edge structure. An initial structure guide map is constructed through nonlinear combination, using the following formula: Among them, control parameters and The preferred ranges are [0.1, 0.5] and [0.01, 0.1], respectively, with example values as follows: and The pixel value range of the generated initial structure guide map is normalized to the [0,1] interval. The closer the region is to 1, the stronger the edge defect features, indicating the texture consistency of the diamond surface.
[0032] In an optional embodiment, a multi-scale shear wave transform is performed on the diamond image to extract high-frequency subband coefficients at each scale, calculate local energy, and fuse the local energies at each scale to obtain a multi-scale edge saliency map, including: A non-subsampled shear wave filter was used to decompose the diamond image in multiple scales and directions to obtain the low-frequency subband coefficients and the high-frequency subband coefficients in each scale and direction. Calculate the sum of the absolute squares of the high-frequency subband coefficients in the local neighborhood at each scale, and use it as the local energy at the corresponding scale. Calculate the normalized weights of the local energy at each scale, and then use the normalized weights to perform a linear weighted summation of the local energy at all scales to obtain a multi-scale edge saliency map.
[0033] A non-subsampled shear wave transform is applied to the input diamond image. This transform process includes multi-scale decomposition using a non-subsampled pyramid filter and multi-directional decomposition using an improved directional filter bank based on a pseudo-polarization grid. The number of decomposition layers is [not specified]. The preferred range is 2 ≤ J ≤ 4, and the example uses J = 3 layers; the directional decomposition number set for each layer is set sequentially as follows: , , After decomposition, the diamond image was resolved into one smooth low-frequency subband coefficient and 28 high-frequency subband coefficients. Where j represents the scale index and k represents the orientation index. High-frequency subband coefficients help preserve high-frequency edge details such as cracks and bubbles at different depths and orientations on the diamond surface. For the extracted high-frequency subband coefficients, within a set local neighborhood window... Calculate its local energy, corresponding to the scale. Local energy The calculation method is to sum the squares of the absolute values of all directional subband coefficients within the window at that scale.
[0034] Calculate the spatial consistency of local energy at each scale as a normalization weight. The calculation method involves dividing the energy at the target scale by the sum of the energies at all scales, and introducing a small constant. To prevent the denominator from being zero, this normalized weight is used. Local energy at the corresponding scale An adaptive linear weighted summation is performed to obtain a multi-scale edge saliency map. This saliency map integrates macroscopic contour and microscopic defect features, which can suppress the interference of isolated artifacts.
[0035] S2, adaptive regular iterative filtering, outputs a smooth image with edge preservation.
[0036] Using a composite guiding map as the initial guide, an iterative rolling guided filter is performed on the diamond image. In each iteration, the local variance of the previous output image is calculated as an uncertainty measure. A spatial adaptive regularization parameter map is constructed by combining the anisotropy map and the uncertainty measure. The regularization parameter value of the edge salient region is smaller than that of the regularization parameter value of the flat region. When performing guided filtering to calculate the local linear coefficient, the spatial adaptive regularization parameter map is used for constraint, and the output image is updated until the set iteration termination condition is met.
[0037] In the initialization phase of the iterative rolling guided filter, the original diamond image is used as the input image for each iteration, and the composite guided image is used as the initial guided image for the first iteration. After entering the iteration loop, the local mean and local mean square value of the output image of the previous round are calculated. The local variance matrix of each pixel under a given window size is obtained by subtracting the square of the local mean from the local mean square value. This local variance matrix is used as the uncertainty metric map.
[0038] The process of constructing a spatial adaptive regularization parameter map by combining the anisotropy map and the uncertainty measure is as follows: the weighted sum of the corresponding pixel values of the anisotropy map and the uncertainty measure map is subtracted from the preset global basic regularization parameter. This results in a smaller regularization parameter value calculated in significant edge regions such as diamond edges and high variance regions, and a larger regularization parameter value calculated in flat regions such as background or smooth texture. The clip function is used to truncate the parameter map to ensure that it is strictly greater than the set non-zero minimum value to prevent division by zero errors.
[0039] The guided filtering process calculates local linear coefficients. When solving for the optimal ridge regression solution of the local linear coefficients, the values of the corresponding pixels in the spatial adaptive regularization parameter map are added to the local variance of the guided image as a denominator for constraint. This process yields the local linear coefficients and generates a smooth and edge-preserving output image for the current iteration. The output image of the current iteration is used as the guided image for the next iteration. The linalg.norm function of the NumPy library is used to calculate the L2 norm of the difference between the pixel values of the output images of two adjacent iterations. When the L2 norm is less than the set minimum threshold or the number of iterations reaches the set maximum number of iterations, the set iteration termination condition is met, the loop is exited, and the final output image is obtained.
[0040] In an optional embodiment, a spatially adaptive regularized parameter graph is constructed by jointly using the anisotropy degree graph and the uncertainty measure, including: The anisotropy map and the uncertainty measure are normalized and mapped to the same numerical range. The normalized anisotropy map and the normalized uncertainty measure are multiplied by corresponding pixels to obtain the fused uncertainty matrix; By using an exponential function to perform a nonlinear mapping on the fusion uncertainty matrix, a spatial adaptive regularization parameter map is obtained, which makes the regularization parameter values of regions with complex textures or significant edge structures decrease exponentially.
[0041] Let the anisotropy map extracted from the preceding sequence be... The local variance array obtained from the previous round of rolling guided filtering output image is used as the uncertainty measure U(x,y). The minimax normalization method is used to uniformly map both A(x,y) and U(x,y) to the numerical range of [0,1]. This not only eliminates the dimensional differences between the structural tensor features and the image variance features, but also limits the offset effect of extreme outliers on subsequent calculations.
[0042] The two normalized matrices are multiplied pixel-wise using Hadamard multiplication to obtain the fused uncertainty matrix F(x,y). When impurities or sharp boundaries exist on the diamond surface, both metrics exhibit high responses, and the multiplication operation further amplifies the numerical differences between these high-frequency salient regions and smooth background regions. Based on this, an inversely proportional nonlinear mapping function is introduced to construct a spatially adaptive regularization parameter map. The mapping function is an exponential decay model with baseline constraints: .in, The global basic regularization constant, preferably in the range [1e-3, 1e-1], is 0.01 in the example; the decay control factor. The steepness of the parameter descent is adjusted, preferably within the range of [5, 15], for example, 10. When the pixel is located at a defect or complex texture, F(x, y) approaches 1, and the regularization parameter will change by an order of magnitude of approximately The exponential decay of the filter causes edge-preserving degradation at that point; however, when the pixel is located in the flat region of the pure diamond substrate, F(x,y) approaches 0, and the parameter bounces back to the basic value of 0.01, thereby achieving spatial anisotropic filtering constraint with adaptive intensity adjustment.
[0043] In an optional embodiment, when performing guided filtering to calculate local linear coefficients, a spatially adaptive regularized parameter map is used for constraint, and the output image is updated until a set iteration termination condition is met, including: In the cost function of the iterative rolling guided filter, a spatial adaptive regularization parameter graph is introduced, and the mean of the regularization parameters within the current local window is extracted as the scalar weight of the regularization term. The local linear coefficients within each local window are solved by minimizing the cost function with constraints. The pixels within the current local window are reconstructed using linear transformation based on the solved local linear coefficients, and the average of the reconstruction results of all overlapping windows is used as the output image after this iteration.
[0044] In the t-th iteration of the guided filtering algorithm framework, a local bounding window centered at pixel k with radius r is defined. Within, the output image q and the guiding image I satisfy a linear model. For each window, construct a ridge regression cost function that includes spatial dynamic constraints: ,in For the current input image, scalar weights The system is derived from the pre-computed spatial adaptive regularization parameter graph. Extracting windows The arithmetic mean of all pixel values for all parameters is used. The linear coefficients are obtained by solving the cost function with its partial derivatives set to zero using the least squares method. and Where Cov(I,p) is the covariance, Mean() is the pixel mean, and Var() is the variance operation, ensuring that the model does not exhibit division-by-zero oscillations when handling low-contrast defects, and relying on The floating property achieves strong smoothing of flat areas and high fidelity at defect edges. It calculates the entire image... and After the matrix is applied, since the same pixel i will be contained within multiple overlapping sliding windows, a mean stacking mechanism is used for linear transformation reconstruction. The output of all local windows containing pixel i is calculated. and arithmetic mean and And calculate the updated output value for that point. The result of this full graph reconstruction is used as the input for the (t+1)th iteration. This iterative process will continue until the set iteration termination condition is triggered: reaching the maximum iteration limit. Or, the mean square error (MSE) of two consecutive output images is less than the set tolerance threshold. This outputs the best denoised reference image where the diamond background is highly smoothed and defects are preserved without loss.
[0045] S3, the residual is obtained by difference of the original image, and the defect is extracted by segmentation analysis.
[0046] The original diamond image is compared with the final output image after the set iteration termination condition to obtain the residual image; the residual image is then subjected to threshold segmentation and connected component analysis to extract defect information and complete the quality inspection.
[0047] The original diamond image matrix is subtracted from the filtered output image matrix, and the absolute value is taken to obtain a residual image containing significant defect features, such as... Figure 3 As shown. In order to further remove noise interference and segment the defect region, Otsu's algorithm, i.e., the maximum inter-class variance method, is used to determine the adaptive threshold for the residual image, and global threshold segmentation is performed based on the adaptive threshold. The residual image is then binarized to generate a defect mask image.
[0048] Connectivity analysis is performed on the defect mask image. By scanning the connectivity of pixels in the binary image, each independent connected component is marked. The area, perimeter, and centroid coordinates of each connected component are calculated. Minimal connected components with an area smaller than a preset noise area threshold are removed. The remaining connected components are the extracted defects such as cracks, pits, or scratches on the diamond surface. Based on the bounding box information of the remaining connected components, the rectangle function is used to perform rectangular box visualization annotation on the original diamond image. The total number of defects and the total area are counted to complete the quality inspection of the diamond.
[0049] The experiments were conducted on a workstation equipped with an RTX 3090 graphics card and 64GB of RAM, using a standard dataset of two thousand real grayscale images of diamond industrial inspection at a resolution of 1024×1024 pixels. Four models were designed for comparison. The baseline model used only traditional fixed-parameter iterative rolling guided filtering. Variant Model 1 added a multi-scale shear wave edge saliency map extraction module to the baseline. Variant Model 2 added an initial structure guided map construction module based on the structure tensor to Variant Model 1. The complete model integrated all the above modules and used a spatially adaptive regularized parameter map to constrain the filtering process. Peak signal-to-noise ratio, structural similarity, and edge preservation index were uniformly used as quantitative evaluation metrics in the experiments.
[0050] like Figure 4 As shown, specific experimental data on the same diamond test set demonstrate that each improvement brings significant performance gains. The baseline model achieved a peak signal-to-noise ratio (PSNR) of 32.15 dB, a structural similarity of 0.8342, and an edge preservation index of 0.753. Variant Model 1 improved the PSNR to 34.62 dB, achieved a structural similarity of 0.8875, and increased the edge preservation index to 0.826. Variant Model 2 further improved the PSNR to 37.28 dB, achieved a structural similarity of 0.9413, and increased the edge preservation index to 0.898. Using the final complete implementation, the test results show that the PSNR reached a maximum of 40.55 dB, the structural similarity jumped to 0.9824, and the edge preservation index achieved an optimal value of 0.967. Multi-scale shear wave transformation helps to obtain multi-scale high-frequency micro-crack details on the diamond surface, significantly improving the edge preservation capability during the initial feature extraction of the model. Building upon this foundation, an initial guiding map is constructed using structural tensor features. This enhances the identification of texture-consistent regions such as corners and edges, preventing detail loss due to feature mixing and resulting in a significant leap in structural similarity metrics. By utilizing a spatially adaptive regularized parameter map that incorporates uncertainty to dynamically constrain iterative guiding filtering, the filtering intensity can be intelligently adjusted based on local texture complexity. This allows for the removal of background noise in flat areas while preserving defect contour edges, achieving optimal reconstruction quality for diamond denoised images.
[0051] An embodiment of the diamond quality inspection system based on image recognition provided by the present invention includes the following modules: The guide map generation module is used to acquire the diamond image to be detected, calculate the structure tensor in the local neighborhood of each pixel in the diamond image, construct an initial structure guide map based on the eigenvalue distribution, and record the difference between the maximum and minimum eigenvalues of the structure tensor as the anisotropy map; perform multi-scale shear wave transform on the diamond image, extract the high-frequency subband coefficients at each scale to calculate the local energy, and fuse the local energies at each scale to obtain a multi-scale edge saliency map; and fuse the initial structure guide map and the multi-scale edge saliency map to generate a composite guide map. The iterative module is used to perform iterative rolling guided filtering on the diamond image using a composite guided map as the initial guide. In each iteration, the local variance of the previous output image is calculated as an uncertainty measure. A spatial adaptive regularization parameter map is constructed by combining the anisotropy map and the uncertainty measure. The regularization parameter value of the edge salient region is smaller than that of the regularization parameter value of the flat region. When performing guided filtering to calculate the local linear coefficient, the spatial adaptive regularization parameter map is used for constraint, and the output image is updated until the set iteration termination condition is met. The detection module is used to perform a difference operation between the original diamond image and the final output image after satisfying the set iteration termination condition to obtain a residual image; the residual image is then subjected to threshold segmentation and connected component analysis to extract defect information and complete the quality inspection.
[0052] The above are all preferred embodiments of the present invention and are not intended to limit the scope of protection of the present invention. Therefore, all equivalent changes made in accordance with the structure, shape and principle of the present invention should be covered within the scope of protection of the present invention.
Claims
1. A diamond quality inspection method based on image recognition, characterized in that, Includes the following steps: The process involves acquiring a diamond image to be detected, calculating the structure tensor in the local neighborhood of each pixel in the diamond image, constructing an initial structure guidance map based on the eigenvalue distribution, and recording the difference between the maximum and minimum eigenvalues of the structure tensor as the anisotropy map. A multi-scale shear wave transform is then performed on the diamond image to extract the high-frequency subband coefficients at each scale and calculate the local energy. The local energies at each scale are then fused to obtain a multi-scale edge saliency map. Finally, the initial structure guidance map and the multi-scale edge saliency map are fused to generate a composite guidance map. Using a composite guide image as the initial guide, an iterative rolling guide filter is performed on the diamond image. In each iteration, the local variance of the previous output image is calculated as an uncertainty measure. A spatial adaptive regularization parameter map is constructed by combining the anisotropy degree map and the uncertainty measure. The regularization parameter value of the edge salient region is smaller than that of the regularization parameter value of the flat region. When performing guided filtering to calculate local linear coefficients, a spatial adaptive regularization parameter map is used for constraint, and the output image is updated until the set iteration termination condition is met; The residual image is obtained by performing a difference operation between the original diamond image and the final output image after satisfying the set iteration termination condition. Thresholding segmentation and connected component analysis are performed on the residual image to extract defect information and complete the quality inspection.
2. The diamond quality inspection method based on image recognition according to claim 1, characterized in that, Calculate the structure tensor in the local neighborhood of each pixel in the diamond image, and construct an initial structure guidance map based on the eigenvalue distribution, including: A local window is set on the diamond image, and the image gradient of each pixel in the local window in the horizontal and vertical directions is calculated. The structure tensor matrix is calculated using image gradients, and eigenvalue decomposition is performed to obtain the maximum and minimum eigenvalues. The minimum eigenvalue is used as the corner feature measure, and the ratio of the maximum eigenvalue to the minimum eigenvalue is used as the edge feature measure. An initial structure guide graph representing texture consistency is constructed by combining corner feature measures and edge feature measures.
3. The diamond quality inspection method based on image recognition according to claim 1, characterized in that, Multi-scale shear wave transform is performed on diamond images to extract high-frequency subband coefficients at each scale, calculate local energy, and fuse the local energies at each scale to obtain a multi-scale edge saliency map, including: A non-subsampled shear wave filter was used to decompose the diamond image in multiple scales and directions to obtain the low-frequency subband coefficients and the high-frequency subband coefficients in each scale and direction. Calculate the sum of the absolute squares of the high-frequency subband coefficients in the local neighborhood at each scale, and use it as the local energy at the corresponding scale. Calculate the normalized weights of the local energy at each scale, and then use the normalized weights to perform a linear weighted summation of the local energy at all scales to obtain a multi-scale edge saliency map.
4. The diamond quality inspection method based on image recognition according to claim 1, characterized in that, A spatially adaptive regularized parameter graph is constructed by combining the anisotropy degree graph and the uncertainty measure, including: The anisotropy map and the uncertainty measure are normalized and mapped to the same numerical range. The normalized anisotropy map and the normalized uncertainty measure are multiplied by corresponding pixels to obtain the fused uncertainty matrix; By using an exponential function to perform a nonlinear mapping on the fusion uncertainty matrix, a spatial adaptive regularization parameter map is obtained, which makes the regularization parameter values of regions with complex textures or significant edge structures decrease exponentially.
5. The diamond quality inspection method based on image recognition according to claim 1, characterized in that, When performing guided filtering to calculate local linear coefficients, a spatial adaptive regularization parameter map is used for constraint, and the output image is updated until the set iteration termination condition is met, including: In the cost function of the iterative rolling guided filter, a spatial adaptive regularization parameter graph is introduced, and the mean of the regularization parameters within the current local window is extracted as the scalar weight of the regularization term. The local linear coefficients within each local window are solved by minimizing the cost function with constraints. The pixels within the current local window are reconstructed using linear transformation based on the solved local linear coefficients, and the average of the reconstruction results of all overlapping windows is used as the output image after this iteration.
6. The diamond quality inspection method based on image recognition according to claim 2, characterized in that, The Sobel operator is used to calculate the image gradient vectors of the diamond image in the horizontal and vertical directions, respectively.
7. The diamond quality inspection method based on image recognition according to claim 1, characterized in that, The Adama product algorithm is used to multiply and fuse the initial structural guide map with the multi-scale edge saliency map pixel by pixel to generate a composite guide map that takes into account both image structure texture and edge saliency information.
8. A diamond quality inspection system based on image recognition, characterized in that, include: The guide map generation module is used to acquire the diamond image to be detected, calculate the structure tensor in the local neighborhood of each pixel in the diamond image, construct an initial structure guide map based on the eigenvalue distribution, and record the difference between the maximum and minimum eigenvalues of the structure tensor as the anisotropy map; perform multi-scale shear wave transform on the diamond image, extract the high-frequency subband coefficients at each scale to calculate the local energy, and fuse the local energies at each scale to obtain a multi-scale edge saliency map; and fuse the initial structure guide map and the multi-scale edge saliency map to generate a composite guide map. The iterative module is used to perform iterative rolling guided filtering on the diamond image using the composite guide map as the initial guide. In each iteration, the local variance of the previous output image is calculated as an uncertainty measure. The spatial adaptive regularization parameter map is constructed by combining the anisotropy map and the uncertainty measure. The regularization parameter value of the edge salient region is smaller than the regularization parameter value of the flat region. When performing guided filtering to calculate local linear coefficients, a spatial adaptive regularization parameter map is used for constraint, and the output image is updated until the set iteration termination condition is met; The detection module is used to perform a difference operation between the original diamond image and the final output image after satisfying the set iteration termination condition to obtain the residual image; Thresholding segmentation and connected component analysis are performed on the residual image to extract defect information and complete the quality inspection.
9. The system according to claim 8, characterized in that, Calculate the structure tensor in the local neighborhood of each pixel in the diamond image, and construct an initial structure guidance map based on the eigenvalue distribution, including: A local window is set on the diamond image, and the image gradient of each pixel in the local window in the horizontal and vertical directions is calculated. The structure tensor matrix is calculated using image gradients, and eigenvalue decomposition is performed to obtain the maximum and minimum eigenvalues. The minimum eigenvalue is used as the corner feature measure, and the ratio of the maximum eigenvalue to the minimum eigenvalue is used as the edge feature measure. An initial structure guide graph representing texture consistency is constructed by combining corner feature measures and edge feature measures.
10. The system according to claim 8, characterized in that, Multi-scale shear wave transform is performed on diamond images to extract high-frequency subband coefficients at each scale, calculate local energy, and fuse the local energies at each scale to obtain a multi-scale edge saliency map, including: A non-subsampled shear wave filter was used to decompose the diamond image in multiple scales and directions to obtain the low-frequency subband coefficients and the high-frequency subband coefficients in each scale and direction. Calculate the sum of the absolute squares of the high-frequency subband coefficients in the local neighborhood at each scale, and use it as the local energy at the corresponding scale. Calculate the normalized weights of the local energy at each scale, and then use the normalized weights to perform a linear weighted summation of the local energy at all scales to obtain a multi-scale edge saliency map.
Citation Information
Patent Citations
CN118111993A