Artificial intelligence-based detection method, system and medium for pesticide residues in traditional Chinese medicine

The local gradient characteristics and multi-scale fusion of the surface of Chinese medicinal materials were extracted through artificial intelligence, combined with spectral analysis, and the accuracy problem of pesticide residue detection under complex textures on the surface of Chinese medicinal materials was solved, achieving efficient and accurate pesticide residue recognition.

CN120182729BActive Publication Date: 2025-08-26GUIZHOU GUOXIN BIOTECHNOLOGY CO LTD +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510658057.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-05-21
Publication Date
2025-08-26
Estimated Expiration
2045-05-21

AI Technical Summary

Technical Problem

The existing image analysis methods are difficult to effectively distinguish normal surface features from abnormal areas caused by pesticide residues under the complex texture background of Chinese medicinal materials, resulting in reduced recognition accuracy, frequent misjudgment or missed detection.

Method used

Using the artificial intelligence-based pesticide residue detection method of traditional Chinese medicinal materials, we use the local gradient direction distribution characteristics of high-resolution images to perform gradient amplitude clustering and multi-scale fusion, combining covariance analysis of high-order color moments and spatial symbiosis matrix direction entropy, and use the Mahayana distance classifier to divide the region, and perform spectral analysis and geometric morphological characteristics fusion, and finally nonlinear decisions are made through the support vector machine.

Benefits of technology

It significantly improves the accuracy and automation of pesticide residue detection on the surface of traditional Chinese medicinal materials, can effectively distinguish between normal texture and abnormal area, and enhances the robustness and generalization ability of detection.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120182729B_ABST
    Figure CN120182729B_ABST
Patent Text Reader

Abstract

The present invention discloses a method, system and medium for detecting pesticide residues in traditional Chinese medicine based on artificial intelligence, which specifically relates to the field of image processing and intelligent detection technology. The method is used to solve the problem of insufficient ability to distinguish between complex surface textures of traditional Chinese medicines and pesticide residue areas. The method extracts local gradient directional distribution features of high-resolution images and combines them with gradient amplitude clustering processing to generate a gradient feature map of texture edge contours. The gradient features are multi-scale fused with color channel data to construct a multi-channel feature map representing texture, color and spatial distribution. The covariance analysis based on high-order color moments and directional entropy quantifies feature correlation, and the Mahalanobis distance classifier is used to divide normal texture and abnormal residue areas. The spectral band matching degree of the abnormal area is evaluated, and the geometric morphological features and spectral scores are integrated into a pre-trained classification model. The pesticide residue detection results are generated using nonlinear association decision-making to achieve accurate distinction between natural texture and pesticide residues on the surface of traditional Chinese medicines.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of image processing and intelligent detection technology, and more specifically, to an artificial intelligence-based method, system and medium for detecting pesticide residues in traditional Chinese medicine. Background Art

[0002] In the production and circulation of traditional Chinese medicines, pesticide residue detection is an important step to ensure the quality and safety of medicinal materials. Currently, detection technology based on image analysis has been applied to the rapid screening of pesticide residues. It locates and classifies residues by collecting images of the medicinal material surface and identifying abnormal areas. However, during the natural growth and processing of traditional Chinese medicines, complex texture structures and color changes often form on their surfaces. These characteristics are determined by the physiological morphology and processing technology of the medicinal materials and are normal physical properties of the medicinal materials. When dealing with such complex textures, existing image analysis methods have difficulty in effectively distinguishing normal surface features from abnormal areas caused by pesticide residues, and the detection results are easily interfered with.

[0003] Due to the high similarity in visual features between the natural texture on the surface of Chinese medicinal materials and the pesticide residue areas, the existing image detection methods have significantly reduced the recognition accuracy of pesticide residues under complex texture backgrounds, resulting in misjudgments or missed detections. Traditional methods lack the ability to effectively distinguish between the inherent characteristics of the medicinal material surface and the characteristics of pesticide residues, and are difficult to adapt to the complex and changeable surface morphology of Chinese medicinal materials. Summary of the Invention

[0004] In order to overcome the above-mentioned defects of the prior art, the embodiments of the present invention provide a method, system and medium for detecting pesticide residues in traditional Chinese medicine based on artificial intelligence to solve the problems raised in the above-mentioned background technology.

[0005] To achieve the above object, the present invention provides the following technical solutions:

[0006] The artificial intelligence-based method for detecting pesticide residues in traditional Chinese medicines includes the following steps:

[0007] S1. Obtain a high-resolution image of the surface area of ​​the Chinese medicinal material and extract the local gradient direction distribution characteristics of the pixel points in the high-resolution image;

[0008] S2, performing gradient amplitude clustering processing on adjacent pixel points in the texture-dense area of ​​the high-resolution image based on the local gradient direction distribution characteristics to generate a gradient feature map containing the texture edge contour;

[0009] S3, performing multi-scale fusion processing on the gradient feature map and the color channel data in the high-resolution image to obtain a multi-channel feature map;

[0010] S4. Based on the covariance analysis of the high-order color moment of each pixel in the multi-channel feature map and the directional entropy of the spatial co-occurrence matrix, the surface area of ​​the Chinese medicinal materials is divided into normal texture areas and abnormal residue areas using the Mahalanobis distance classifier;

[0011] S5. Spectral analysis is performed on the abnormal residue area, and a spectral correlation score reflecting the possibility of pesticide residue is generated by evaluating the matching degree of preset bands;

[0012] S6. The geometric morphological features and spectral correlation scores of the abnormal residue area are input into the pre-trained classification model, and the pesticide residue detection results are generated based on nonlinear correlation decision-making.

[0013] In a preferred embodiment, obtaining a high-resolution image of the surface area of ​​the Chinese medicinal material and extracting the local gradient direction distribution characteristics of the pixel points in the high-resolution image include:

[0014] Obtain high-resolution images of the surface area of ​​Chinese medicinal materials and perform HSV color space conversion to extract the grayscale image of the saturation channel;

[0015] Based on the grayscale image, the horizontal gradient amplitude and vertical gradient amplitude of the pixel point are calculated respectively by Sobel operator;

[0016] According to the ratio of the transverse gradient amplitude to the longitudinal gradient amplitude, the local gradient direction distribution characteristics of each pixel point in the surface area of ​​the Chinese medicinal materials are generated, and the local gradient direction distribution characteristics are represented by the gradient direction distribution histogram.

[0017] In a preferred embodiment, gradient amplitude clustering is performed on adjacent pixels in a texture-dense area of ​​a high-resolution image based on local gradient direction distribution characteristics to generate a gradient feature map containing texture edge contours, including:

[0018] Based on the gradient direction distribution histogram in the local gradient direction distribution feature, K-means clustering is performed on adjacent pixels in the texture-dense area to divide the areas with high gradient amplitude and low gradient amplitude.

[0019] According to the distribution density of the direction angle interval in the gradient direction distribution histogram, the cluster center threshold is dynamically adjusted to retain the pixels corresponding to the high gradient amplitude area;

[0020] The retained pixels are processed by morphological closing operation to generate continuous closed texture edge contours and form a gradient feature map.

[0021] In a preferred embodiment, the gradient feature map is subjected to multi-scale fusion processing with the color channel data in the high-resolution image to obtain a multi-channel feature map, including:

[0022] Construct the Laplacian pyramid of gradient feature map and color channel data, perform three-layer decomposition respectively, and obtain multi-scale gradient feature map and multi-scale color feature map;

[0023] Perform weighted fusion on the gradient feature map and color feature map of the same scale;

[0024] The features at each level of the weighted fused Laplacian pyramid are inversely transformed and reconstructed to generate a fused multi-channel feature map.

[0025] In a preferred embodiment, the weight in the weighted fusion of the gradient feature map and the color feature map of the same scale is dynamically adjusted according to the difference between the edge intensity of the gradient feature map and the saturation of the color feature map.

[0026] In a preferred embodiment, based on the covariance analysis of the high-order color moment of each pixel point and the directional entropy of the spatial co-occurrence matrix in the multi-channel feature map, the normal texture area and the abnormal residual area of ​​the surface area of ​​the Chinese medicinal material are divided by the Mahalanobis distance classifier, including:

[0027] Extract the high-order color moment of each pixel in the saturation channel of the HSV color space from the multi-channel feature map and generate a high-order color moment feature vector;

[0028] Construct the gray-level co-occurrence matrix of the multi-channel feature map, calculate the entropy values ​​in multiple directions and extract the mean of the directional entropy to generate the directional entropy feature vector of the spatial co-occurrence matrix;

[0029] Perform covariance matrix analysis on the high-order color moment eigenvectors and the spatial co-occurrence matrix directional entropy eigenvectors to calculate the joint distribution covariance of the two types of eigenvectors;

[0030] The decision boundary of the Mahalanobis distance classifier is dynamically adjusted based on the eigenvalue distribution of the covariance matrix, and the normal texture area and the abnormal residual area are divided according to the adjusted decision boundary.

[0031] In a preferred embodiment, spectral analysis is performed on the abnormal residue area, and a spectral correlation score reflecting the possibility of pesticide residue is generated by evaluating the matching degree of preset bands, including:

[0032] Extract the spectral reflectance curve of the abnormal residual area in the visible to near-infrared band;

[0033] Selecting preset pesticide characteristic bands, including a first absorption band corresponding to a first type of pesticide and a second absorption band corresponding to a second type of pesticide;

[0034] Calculate the correlation coefficient between the spectral reflectance curve and each pesticide characteristic band to generate a band matching score;

[0035] The spectral correlation score is generated based on the dynamic weighted sum of the correlation coefficient and the reflectance peak amplitude, and the weighting coefficient is preset according to the pesticide type.

[0036] In a preferred embodiment, the geometric features of the abnormal residue area and the spectral correlation score are input into a pre-trained classification model, and the pesticide residue detection result is generated based on nonlinear correlation decision making, including:

[0037] The geometric features of the abnormal residual area and the spectral correlation score are combined into a multidimensional feature vector. The geometric features include the area ratio of discrete spots and the aspect ratio of continuous stripes.

[0038] The multi-dimensional feature vector is input into the pre-trained support vector machine classification model and mapped to the high-dimensional space through the kernel function for nonlinear decision making;

[0039] Based on the comparison of the output confidence of the support vector machine classification model with the preset threshold, the presence of pesticide residues is determined and the detection results are generated.

[0040] In another aspect, the present invention provides an artificial intelligence-based pesticide residue detection system for traditional Chinese medicines, comprising the following modules:

[0041] Gradient feature module: used to obtain high-resolution images of the surface area of ​​Chinese medicinal materials and extract the local gradient direction distribution characteristics of pixel points in the high-resolution image;

[0042] Feature clustering module: used to perform gradient amplitude clustering processing on adjacent pixel points in texture-dense areas in high-resolution images based on local gradient direction distribution characteristics, and generate a gradient feature map containing texture edge contours;

[0043] Feature fusion module: used to perform multi-scale fusion processing on the gradient feature map and the color channel data in the high-resolution image to obtain a multi-channel feature map;

[0044] Covariance classification module: It is used to analyze the covariance of the high-order color moments of each pixel in the multi-channel feature map and the directional entropy of the spatial co-occurrence matrix, and to classify the surface area of ​​the Chinese medicinal materials into normal texture areas and abnormal residue areas using the Mahalanobis distance classifier;

[0045] Spectral scoring module: used to perform spectral analysis on abnormal residue areas and generate spectral correlation scores reflecting the possibility of pesticide residues through preset band matching evaluation;

[0046] Intelligent decision-making module: used to input the geometric morphological features and spectral correlation scores of abnormal residue areas into the pre-trained classification model, and generate pesticide residue detection results based on nonlinear correlation decision-making.

[0047] On the other hand, the present invention provides an artificial intelligence-based Chinese herbal medicine pesticide residue detection medium, on which a program or instruction is stored. When the program or instruction is executed by a processor, an artificial intelligence-based Chinese herbal medicine pesticide residue detection method is implemented.

[0048] Compared with the prior art, the present invention has the following beneficial effects:

[0049] 1. Through the extraction of gradient direction distribution features and multi-scale fusion technology, combined with the multi-dimensional characteristics of the surface texture and color of Chinese medicinal materials, normal physiological characteristics and abnormal areas caused by pesticide residues can be effectively distinguished; gradient amplitude clustering processing based on local gradient direction distribution characteristics can accurately locate the edge contours of texture-dense areas, suppress natural texture interference through a dynamic threshold adjustment mechanism, and enhance the contour saliency of residual areas; at the same time, multi-channel feature maps fuse gradient edges, color saturation and multi-scale texture information to construct a feature expression that takes into account both local details and global distribution, overcoming the false detection problem caused by insufficient single feature representation in traditional methods; through covariance analysis of high-order color moments and directional entropy of spatial co-occurrence matrices, the coupling relationship between color and texture features is quantified from the statistical correlation level, and the Mahalanobis distance classifier is used to dynamically divide normal and abnormal areas, avoiding the insufficient adaptability of fixed threshold segmentation to complex texture medicinal materials and significantly improving the robustness of classification boundaries.

[0050] 2. The reliability of pesticide residue detection is further enhanced by combining the spectral correlation scoring mechanism with geometric morphological analysis. Spectral analysis based on preset band matching can capture the characteristic absorption peaks of pesticide molecules and balance the spectral response differences of different types of pesticides through dynamic weighting rules. The multi-dimensional fusion of geometric morphological features and spectral scores is input into the pre-trained classification model, and nonlinear correlation decision-making is used to fully explore the implicit relationship between features, solving the limitations of traditional linear models in classifying complex patterns. Through multi-dimensional feature collaborative analysis and intelligent decision-making mechanisms, the precise positioning and classification of pesticide residues on the surface of Chinese medicinal materials are achieved, providing a unified and adaptive detection framework for the complex surface characteristics of different types of medicinal materials, significantly improving the degree of automation of the detection process and the generalization ability of actual scenarios. BRIEF DESCRIPTION OF THE DRAWINGS

[0051] Figure 1 This is a flow chart of the method for detecting pesticide residues in traditional Chinese medicines based on artificial intelligence of the present invention;

[0052] Figure 2 A flow chart of the present invention for dividing the normal texture area and the abnormal residue area on the surface of a Chinese medicinal material;

[0053] Figure 3 The figure is a schematic diagram of the structure of the artificial intelligence-based Chinese herbal medicine pesticide residue detection system of the present invention. DETAILED DESCRIPTION

[0054] The following will provide a clear and complete description of the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. All other embodiments obtained by ordinary technicians in this field based on the embodiments of the present invention without making any creative efforts shall fall within the scope of protection of the present invention.

[0055] Example 1: Figure 1 The present invention provides an artificial intelligence-based method for detecting pesticide residues in traditional Chinese medicines, comprising the following steps:

[0056] S1. Obtain a high-resolution image of the surface area of ​​the Chinese medicinal material and extract the local gradient direction distribution characteristics of the pixel points in the high-resolution image;

[0057] S2, performing gradient amplitude clustering processing on adjacent pixel points in the texture-dense area of ​​the high-resolution image based on the local gradient direction distribution characteristics to generate a gradient feature map containing the texture edge contour;

[0058] S3, performing multi-scale fusion processing on the gradient feature map and the color channel data in the high-resolution image to obtain a multi-channel feature map;

[0059] S4. Based on the covariance analysis of the high-order color moment of each pixel in the multi-channel feature map and the directional entropy of the spatial co-occurrence matrix, the surface area of ​​the Chinese medicinal materials is divided into normal texture areas and abnormal residue areas using the Mahalanobis distance classifier;

[0060] S5. Spectral analysis is performed on the abnormal residue area, and a spectral correlation score reflecting the possibility of pesticide residue is generated by evaluating the matching degree of preset bands;

[0061] S6. The geometric morphological features and spectral correlation scores of the abnormal residue area are input into the pre-trained classification model, and the pesticide residue detection results are generated based on nonlinear correlation decision-making.

[0062] Intelligent detection of pesticide residues in traditional Chinese medicines is achieved through machine learning models. This is specifically reflected in the following steps: In steps S1-S3, gradient direction distribution feature extraction, gradient amplitude clustering, and multi-scale fusion techniques are used to construct a multi-channel feature map representing the correlation between texture and color. This is the feature learning process. In step S4, the statistical distribution differences of color-texture features are quantified through covariance analysis and Mahalanobis distance classifiers to achieve regional segmentation based on a probabilistic model. In steps S5-S6, spectral scores are integrated with geometric morphological features, and a pre-trained support vector machine classification model is used for nonlinear decision-making, optimizing classification boundaries through data-driven optimization. These steps rely on machine learning algorithms (such as SVM and Mahalanobis distance) to adaptively model multidimensional features, addressing the lack of generalization caused by traditional methods' reliance on artificial rules. This demonstrates the support of artificial intelligence technology for multi-source feature fusion and complex decision-making.

[0063] S1. Obtain a high-resolution image of the surface area of ​​the Chinese medicinal material and extract the local gradient direction distribution characteristics of the pixel points in the high-resolution image. The specific implementation is as follows:

[0064] RGB images of the surface area of ​​the Chinese medicinal material are collected using high-resolution imaging equipment with a resolution of at least 20 megapixels to ensure that the subtle texture of the medicinal material surface can be clearly captured. The collected RGB images are converted into the HSV color space, which contains hue, saturation, and lightness channels. The saturation channel is selected for subsequent processing, and a grayscale image of the saturation channel is extracted. The saturation channel reflects color purity information and can effectively distinguish between the natural texture of the Chinese medicinal material surface and color changes caused by pesticide residues. For example, pesticide residues may cause localized color fading or abnormal discoloration, while the color purity of natural textures changes relatively gradually.

[0065] The Sobel edge detection operator is used to calculate the gradient information of each pixel in the saturation channel grayscale image. The horizontal Sobel convolution kernel is used to detect horizontal edges, and the vertical Sobel convolution kernel is used to detect vertical edges. The matrix form of the horizontal Sobel convolution kernel is, for example, [-1, 0, 1; -2, 0, 2; -1, 0, 1], and the matrix form of the vertical Sobel convolution kernel is, for example, [1, 2, 1; 0, 0, 0; -1, -2, -1]. The horizontal gradient amplitude Gx and the vertical gradient amplitude Gy of each pixel are obtained through the convolution operation. The horizontal gradient amplitude Gx and the vertical gradient amplitude Gy are calculated by multiplying the convolution kernel by the pixel value of the corresponding image area according to the position and then summing them.

[0066] For each pixel, the ratio of the horizontal gradient amplitude Gx to the vertical gradient amplitude Gy is calculated, and the gradient direction angle θ is calculated by the inverse tangent function. The calculation formula of the gradient direction angle θ is θ = arctan(Gy / Gx). To avoid calculation errors caused by the denominator being zero, when the absolute value of the horizontal gradient amplitude Gx is less than the preset minimum value, for example, the minimum value is set to 1e-5, the gradient direction angle θ is directly assigned to 90 degrees. The range of the gradient direction angle θ from 0 degrees to 180 degrees is divided into multiple equally spaced intervals, for example, into 36 intervals, each interval spanning 5 degrees. The number of pixels in each interval whose gradient amplitude exceeds a preset threshold is counted. The preset threshold is, for example, the sum of the squares of the gradient amplitude Gx²+Gy² ≥ 50, to exclude noise interference in low gradient amplitude areas. A gradient direction distribution histogram is generated based on the statistical results. The horizontal axis of the gradient direction distribution histogram is the direction angle interval, and the vertical axis is the proportion of the number of pixels in the corresponding interval. The proportion of the number of pixels is obtained by normalization. Normalization is performed by dividing the number of pixels in each interval by the sum of the number of pixels in all intervals to eliminate the effects of image size differences. The gradient direction distribution histogram is used as a quantitative representation of the local gradient direction distribution characteristics and is used in the subsequent step of texture-dense area segmentation.

[0067] The saturation channel was chosen over the hue or lightness channels because color changes on the surface of Chinese medicinal materials have higher contrast in the saturation channel, while the hue channel is easily affected by changes in lighting and the lightness channel is easily affected by shadows. For example, when localized discoloration due to pesticide residues appears on the surface of a medicinal material, the grayscale value of the saturation channel will be significantly lower than that of the surrounding natural texture area. During implementation, the RGB to HSV conversion is achieved by calling the color gamut conversion function of the image processing library: cv2.cvtColor, with the parameter set to cv2.COLOR_RGB2HSV to ensure the reproducibility of the conversion process. The size of the Sobel convolution kernel in the horizontal and vertical directions is fixed at 3×3. This size strikes a balance between edge detection accuracy and computational efficiency, and is suitable for gradient analysis of the surface texture of Chinese medicinal materials.

[0068] The gradient amplitude threshold is, for example, the sum of the squares of the gradient amplitudes Gx²+Gy² ≥ 50, which is used to distinguish valid edges from smooth areas. The threshold is set based on experimental tests. When the sum of the squares of the gradient amplitudes is lower than 50, the texture changes in the corresponding area are insufficient to reflect the characteristics of pesticide residues. The reason for choosing 36 directional angle intervals is that a smaller number of intervals may lead to insufficient directional resolution, and a larger number of intervals may increase computational complexity. 36 intervals can achieve a balance between resolution and efficiency. Normalization ensures that the histograms of images of different sizes are comparable. For example, for medicinal samples of different sizes, the normalized histogram distribution can be directly used for subsequent analysis without additional adjustment.

[0069] S2. Perform gradient amplitude clustering on adjacent pixels in the texture-dense area of ​​the high-resolution image based on the local gradient direction distribution characteristics to generate a gradient feature map containing texture edge contours. The specific implementation is as follows:

[0070] Based on the gradient direction distribution histogram in the local gradient direction distribution feature, K-means clustering is performed on adjacent pixels in the texture-dense area to divide them into high gradient amplitude and low gradient amplitude areas. The horizontal axis of the gradient direction distribution histogram is the direction angle interval, and the vertical axis is the normalized pixel number ratio. The spatial distribution range of the texture-dense area is determined based on the pixel number ratio in each direction angle interval in the gradient direction distribution histogram. Gradient amplitude features are extracted from adjacent pixels in the texture-dense area. The gradient amplitude features are calculated as the square root of the sum of the squares of the horizontal gradient amplitude and the vertical gradient amplitude. The gradient amplitude is used as the input feature of K-means clustering. The initial cluster centers are set as the two pixels with the largest and smallest gradient amplitudes. The pixels are divided into high gradient amplitude areas and low gradient amplitude areas through iterative calculation. The high gradient amplitude areas correspond to texture edge contours, and the low gradient amplitude areas correspond to flat or weak texture areas.

[0071] According to the distribution density of the directional angle interval in the gradient direction distribution histogram, the cluster center threshold is dynamically adjusted to retain the pixels corresponding to the high gradient amplitude area. The distribution density of the directional angle interval is calculated by counting the proportion of the number of pixels in each interval. The higher the distribution density, the denser the texture of the directional angle interval. The rule for dynamically adjusting the cluster center threshold is: when the distribution density of the directional angle interval is higher than the preset density threshold, the cluster center threshold corresponding to the interval is lowered to retain more edge pixels; when the distribution density is lower than the preset density threshold, the cluster center threshold is increased to eliminate noise interference. The preset density threshold is determined based on experimental tests. For example, it is set to 0.15, which means that when the proportion of the number of pixels in the directional angle interval exceeds 15%, it is judged as a high-density area. By dynamically adjusting the threshold, a balance is ensured between the edge contour integrity and noise suppression effect in texture-dense areas.

[0072] The retained pixels are subjected to morphological closing operations to generate continuous and closed texture edge contours, forming a gradient feature map. The morphological closing operation includes dilation followed by erosion operations. The dilation operation is used to connect broken edge pixels, and the erosion operation is used to smooth the edge contours. A rectangular structural element is used for closing operations, and the size of the structural element is set according to the average width of the texture-dense area, for example, 3×3 pixels. Connected regions are extracted from the binary image after the closing operation, and isolated noise points with an area less than a preset threshold are removed. The preset area threshold is, for example, 10 pixels. The gradient feature map finally generated is a binary image containing continuous and closed texture edge contours, in which high gradient amplitude areas are marked as white and low gradient amplitude areas are marked as black. The gradient feature map is used as input data for subsequent multi-scale fusion processing to enhance the feature expression of color abnormality areas.

[0073] K-means clustering was chosen over fixed threshold segmentation because the gradient amplitude distribution of the surface texture of Chinese medicinal materials is non-uniform, and fixed thresholds are difficult to adapt to changes in texture density. For example, the gradient amplitude of the wrinkle texture of rhizomes is high and concentrated, while the gradient amplitude of the vein texture of leaves is low and dispersed. Dynamic clustering can adaptively delineate high and low gradient regions. The structural element size of the morphological closing operation is set to 3×3 pixels, which effectively connects common broken edges while avoiding edge blurring caused by excessive expansion. The gradient feature map is binarized by setting a gradient amplitude threshold. The threshold is dynamically determined based on the clustering results, for example, the first 10% of pixels in the high gradient amplitude region are marked white.

[0074] It is worth noting that texture-dense areas are determined by the distribution density of the angular intervals in the gradient directional distribution histogram. The distribution density is the proportion of the number of pixels in each angular interval. When the distribution density is higher than a preset threshold (for example, 0.15), it is determined to be a dense area. The preset threshold is optimized through experimental testing of multiple groups of Chinese medicinal materials. For example, the texture segmentation accuracy under different density thresholds is statistically analyzed in ginseng and astragalus samples, and the threshold that optimizes edge continuity is selected. The acquisition of texture-dense areas is based on the gradient amplitude clustering results, and the pixels corresponding to the high gradient amplitude areas are retained.

[0075] S3, performing multi-scale fusion processing on the gradient feature map and the color channel data in the high-resolution image to obtain a multi-channel feature map, which is specifically implemented as follows:

[0076] A Laplacian pyramid is constructed for the gradient feature map and color channel data, each undergoing a three-level decomposition to produce a multi-scale gradient feature map and a multi-scale color feature map. The gradient feature map contains continuous, closed texture edge contour information, while the color channel data is the extracted grayscale image of the saturation channel. The Laplacian pyramid construction process involves performing Gaussian pyramid decomposition on the gradient feature map and color channel data, generating three layers of images at different scales. Each layer is Gaussian filtered and downsampled using a convolution kernel size of 5×5 pixels and a standard deviation of 1.0. Each layer of the Gaussian pyramid is upsampled and subtracted from the previous layer to produce the feature maps for each layer of the Laplacian pyramid. For example, the third-level Laplacian pyramid feature map is obtained by upsampling the third-level Gaussian pyramid image to the second-level size and then performing pixel-wise subtraction with the second-level Gaussian pyramid image. The Laplacian pyramids for the gradient feature map and color channel data preserve edge details and color distribution characteristics at different scales, respectively.

[0077] A weighted fusion is performed on the gradient feature map and the color feature map of the same scale. The weights are dynamically adjusted based on the edge strength of the gradient feature map and the saturation difference of the color feature map. The edge strength is quantified by the gradient amplitude of the pixel in the gradient feature map. The gradient amplitude is calculated as the square root of the sum of the squares of the horizontal gradient amplitude Gx and the vertical gradient amplitude Gy. The saturation difference of the color feature map is calculated as the absolute difference between the saturation value of the current pixel and the mean saturation of the neighboring pixels, with the neighborhood being a 3×3 pixel region. The dynamic weight adjustment rule is that when the edge strength exceeds a preset threshold, the weight of the gradient feature map increases, while the weight of the color feature map decreases. When the saturation difference exceeds a preset threshold, the weight of the color feature map increases, while the weight of the gradient feature map decreases. The preset thresholds are determined through experimental testing. For example, the edge strength threshold is set as the sum of the squared gradient amplitudes Gx² + Gy² ≥ 50, and the saturation difference threshold is set as the absolute difference ≥ 20. Weighted fusion is calculated as follows: the fused feature map is equal to the gradient feature map multiplied by the weighted gradient plus the color feature map multiplied by the weighted color, where the sum of the weighted gradient and the weighted color is 1.0. By dynamically adjusting the weights, the joint feature expression of texture edges and color anomalies is enhanced.

[0078] The weighted fused features of each level of the Laplacian pyramid are inversely transformed and reconstructed to generate a fused multi-channel feature map. The inverse transformation and reconstruction process includes starting from the highest-level Laplacian pyramid feature map, upsampling layer by layer and adding it to the feature map of the next layer until the original image size is restored. Upsampling uses a bilinear interpolation method to enlarge the low-resolution image to the adjacent high-level size. For example, the third-level fusion feature map is upsampled and added to the second-level fusion feature map, and then upsampled again and added to the first-level fusion feature map, ultimately obtaining a multi-channel feature map with the same size as the original image. The multi-channel feature map contains gradient edges, color saturation, and multi-scale fusion features, which are used for adaptive segmentation processing in subsequent steps.

[0079] The reason for choosing a Laplacian pyramid over direct weighted fusion is that multi-scale decomposition can preserve texture and color details at different resolutions, avoiding information loss at a single scale. For example, the high-level Laplacian pyramid captures large-scale texture contours, while the lower levels retain subtle color changes, enhancing feature robustness through layered fusion. The preset threshold for dynamic weight adjustment was determined through testing on multiple groups of medicinal material samples. For example, the edge intensity threshold for ginseng rhizome samples was set to 50, and the saturation difference threshold for mint leaf samples was set to 20 to balance the differences in characteristics of different medicinal materials. The bilinear interpolation method of inverse transform reconstruction can reduce the edge jagged effect during the upsampling process and ensure the smoothness of the fused feature map.

[0080] Figure 2 A flowchart for dividing the normal texture area and abnormal residue area on the surface of Chinese medicinal materials is given. Based on the covariance analysis of the high-order color moment of each pixel point and the directional entropy of the spatial co-occurrence matrix in the multi-channel feature map, the normal texture area and abnormal residue area on the surface of Chinese medicinal materials are divided by the Mahalanobis distance classifier. The specific implementation is as follows:

[0081] The high-order color moments of each pixel in the saturation channel of the HSV color space in the multi-channel feature map are extracted to generate a high-order color moment feature vector. The multi-channel feature map contains gradient edges, color saturation, and multi-scale fusion features. The calculation object of the high-order color moment is the saturation channel in the HSV color space. The saturation channel reflects the color purity information and can effectively characterize the local color anomalies caused by pesticide residues. The high-order color moment includes the fourth-order moment, which is used to quantify the sharpness of the saturation distribution. The fourth-order moment is calculated as the fourth-order central moment of the saturation value divided by the fourth power of the standard deviation. Specifically, the fourth-order central moment of the saturation value is calculated for the neighborhood range of each pixel point. The neighborhood range is, for example, a 3×3 pixel area. The calculation formula of the fourth-order central moment is the fourth-power average value of the saturation value of each pixel in the neighborhood minus the neighborhood mean. The high-order color moment feature vector generated by the fourth-order moment calculation can distinguish the smooth saturation distribution of natural textures from the peaked distribution of pesticide residues. The saturation distribution of natural textures usually shows gentle fluctuations, while the saturation values ​​in pesticide residue areas deviate from the mean due to local pigment deposition or fading, and the fourth-order moment increases significantly.

[0082] The gray-level co-occurrence matrix of the multi-channel feature map is constructed. The entropy values ​​in multiple directions are calculated and the mean of the directional entropy is extracted to generate the directional entropy feature vector of the spatial co-occurrence matrix. The gray-level co-occurrence matrix is ​​constructed based on the gradient edge information in the multi-channel feature map. The gray-level co-occurrence matrix has four directions: 0°, 45°, 90°, and 135°, which are used to capture texture changes at different angles. The entropy value of the gray-level co-occurrence matrix is ​​calculated for each direction. The entropy value is calculated as the negative sum of the probability value of each element in the matrix multiplied by the natural logarithm of the probability value.

[0083] After the entropy values ​​in the four directions are calculated, the mean of the entropy values ​​in the four directions is taken as the directional entropy eigenvalue. The directional entropy mean reflects the directional complexity and randomness of the texture. Natural textures, such as rhizome wrinkles, have a higher mean directional entropy, while pesticide residue areas have a lower mean directional entropy due to structural damage. The directional entropy eigenvector of the spatial co-occurrence matrix generated by the directional entropy mean can quantify the differences in the directional characteristics of the texture. For example, the longitudinal folds of ginseng rhizomes have higher entropy values ​​at 0° and 180°, while the reticular veins of mint leaves have higher entropy values ​​at 45° and 135°. The directional entropy mean can integrate multi-directional features to avoid interference from a single direction.

[0084] Covariance matrix analysis is performed on the eigenvectors of the higher-order color moments and the eigenvectors of the directional entropy of the spatial co-occurrence matrix to calculate the covariance of the joint distribution of the two eigenvectors. Covariance matrix analysis is used to measure the statistical correlation between higher-order color moments and directional entropy. It specifically includes the following steps: Arrange the higher-order color moment eigenvectors and the directional entropy eigenvectors in a one-to-one correspondence by pixel to construct a two-dimensional feature matrix; calculate the covariance matrix of the two-dimensional feature matrix, where the diagonal elements of the covariance matrix represent the variances of the two features, and the off-diagonal elements represent the covariances of the two features; and determine the principal component contributions of the two features based on the eigenvalue decomposition results of the covariance matrix. For example, if the maximum eigenvalue of the covariance matrix accounts for more than 80% of the total eigenvalue sum, it indicates a strong correlation between the higher-order color moments and the directional entropy, and the classifier decision boundary needs to be adjusted to accommodate the feature distribution. Eigenvalue decomposition of the covariance matrix is ​​performed using the Jacobi iteration method to calculate the eigenvalues ​​and eigenvectors of the covariance matrix. The eigenvalues ​​are arranged in descending order, and the maximum eigenvalue reflects the dominant direction of the joint variation of the two features.

[0085] The decision boundary of the Mahalanobis distance classifier is dynamically adjusted based on the eigenvalue distribution of the covariance matrix. The adjusted decision boundary is then used to delineate normal texture regions from abnormal residual regions. The decision boundary of the Mahalanobis distance classifier is determined by the inverse of the covariance matrix and the eigenmean vector. The dynamic adjustment rule is as follows: when the proportion of the largest eigenvalue of the covariance matrix exceeds a preset percentage, the Mahalanobis distance threshold of the decision boundary is reduced to increase sensitivity to strongly correlated features; when the proportion of the largest eigenvalue falls below a preset percentage, the Mahalanobis distance threshold of the decision boundary is increased to enhance the generalization of the classifier. The preset percentage is determined through experimental testing. For example, a maximum eigenvalue threshold of 70% is set. When the maximum eigenvalue proportion exceeds 70%, the Mahalanobis distance threshold is adjusted to 0.8 times the original threshold; when the proportion falls below 70%, the threshold is adjusted to 1.2 times the original threshold. Each pixel is classified using the dynamically adjusted decision boundary. Pixels with a Mahalanobis distance below the threshold are classified as normal texture regions, while pixels with a Mahalanobis distance above the threshold are classified as abnormal residual regions. The calculation formula of Mahalanobis distance is the difference between the pixel feature vector and the feature mean vector of the normal texture area multiplied by the inverse matrix of the covariance matrix and then multiplied by the difference transpose. The calculation result is compared with the threshold to complete the classification.

[0086] The saturation channel of the HSV color space was chosen over the hue or lightness channels because pesticide residues often cause localized changes in color purity, such as fading or pigmentation. The hue channel is susceptible to light, while the lightness channel is susceptible to shadows. The fourth-order moment of higher-order color moments can quantify the sharpness of the saturation distribution. For example, when pesticide residues cause localized saturation values ​​to deviate from the mean, the fourth-order moment is significantly higher than that of naturally textured areas. The gray-level co-occurrence matrix uses four directions because the surface texture of traditional Chinese medicinal materials has multidirectional characteristics, such as the longitudinal wrinkles of rhizomes and the reticular veins of leaves. A single direction cannot fully represent the complexity of the texture. A dynamic adjustment mechanism for the eigenvalue distribution is introduced into the covariance matrix analysis to address the problem of misclassification caused by feature correlation in the traditional Mahalanobis distance classifier. For example, when color and texture features are highly correlated, a fixed threshold may misclassify normal texture as a residue area.

[0087] The preset proportion of the dynamic adjustment decision boundary is determined by testing multiple groups of medicinal material samples. For example, cross-validation is performed on samples such as ginseng, astragalus, and mint, and the optimal threshold scaling coefficient under different eigenvalue proportions is statistically calculated. The experiment found that when the maximum eigenvalue accounts for more than 70%, setting the threshold scaling coefficient to 0.8 can reduce the false detection rate by about 12%; when the proportion is less than 70%, setting the coefficient to 1.2 can reduce the missed detection rate by about 9%. The initial threshold of the Mahalanobis distance classifier is set according to the mean of the feature distribution of the training set samples. For example, the mean of the Mahalanobis distance of the normal texture area plus three times the standard deviation is used as the initial threshold. Through the dynamic adjustment mechanism, the classifier can adapt to the differences in texture and residual feature distribution of different medicinal materials, thereby improving detection robustness.

[0088] Step S4 analyzes the statistical correlation between high-order color moments and directional entropy using the covariance matrix, and dynamically adjusts the decision threshold using a Mahalanobis distance classifier to address the problem of missegmentation caused by the uneven distribution of surface texture and pesticide residue features in traditional Chinese medicines. Traditional methods often rely on fixed threshold segmentation for a single feature (such as color or texture), which is difficult to adapt to the texture complexity of different medicinal materials. Step S4 quantifies the joint distribution characteristics of color and texture using the covariance matrix, and dynamically adjusts the classification boundaries using the eigenvalue distribution to improve the accuracy of distinguishing natural textures from residual areas. For example, when color and texture features are highly correlated, the threshold is dynamically reduced to avoid false detections; when feature correlation is weak, the threshold is increased to reduce missed detections.

[0089] S5. Perform spectral analysis on the abnormal residue area and generate a spectral correlation score reflecting the possibility of pesticide residue by evaluating the matching degree of preset bands. The specific implementation is as follows:

[0090] Extract the spectral reflectance curve of the abnormal residue area in the visible to near-infrared band. The spectral reflectance curve of the abnormal residue area is collected by a hyperspectral imaging device, and the spectral resolution of the hyperspectral imaging device can cover the visible to near-infrared band. The extraction process of the spectral reflectance curve includes spectral scanning of each pixel point in the abnormal residue area to obtain its continuous spectral response data in the visible to near-infrared band. The visible to near-infrared band covers a wavelength of approximately 400 nanometers to 1000 nanometers, which can effectively capture the characteristic spectral absorption peaks caused by pesticide residues. For example, phosphorus-containing organic compounds will have obvious absorption valleys in specific bands, while ester-containing organic compounds may show a sudden change in reflectivity in the near-infrared band.

[0091] Preset characteristic pesticide bands are selected, including a first absorption band corresponding to Category 1 pesticides and a second absorption band corresponding to Category 2 pesticides. Category 1 pesticides are phosphorus-containing organic compounds, while Category 2 pesticides are ester-containing organic compounds. The first absorption band is determined based on the molecular structure of the phosphorus-oxygen bond in these compounds. The chemical bond formed by the phosphorus and oxygen atoms in these compounds exhibits specific absorption characteristics in the visible to near-infrared range. For example, the phosphorus-oxygen double bond (P=O) exhibits an absorption peak near wavelengths of 620 to 680 nanometers. The second absorption band is determined based on the functional group characteristics of ester-containing organic compounds. The carbonyl group (C=O) in the ester group (R-COO-R) exhibits a decrease in reflectivity near wavelengths of 850 to 920 nanometers in the near-infrared range. The selection of the preset characteristic pesticide bands is based on the spectral response patterns of the characteristic functional groups in the pesticide molecules, and the validity of the band ranges is verified through experimental testing. For example, by measuring the standard spectral data of a variety of phosphorus-containing organic compounds and ester-containing organic compounds, and statistically analyzing the distribution patterns of their absorption peaks, it was finally determined that the first absorption band was 620-680 nanometers and the second absorption band was 850-920 nanometers.

[0092] The correlation coefficient between the spectral reflectance curve and each pesticide's characteristic band is calculated to generate a band match score. The correlation coefficient is calculated using the Pearson correlation coefficient method, which measures the spectral similarity between the spectral reflectance curve of the abnormal residue area and the preset pesticide characteristic band. For the first absorption band, the Pearson correlation coefficient is calculated between the average reflectance curve of the abnormal residue area within the range of 620 to 680 nanometers and the reference standard spectral curve of phosphorus-containing organic compounds. For the second absorption band, the Pearson correlation coefficient is calculated between the average reflectance curve within the range of 850 to 920 nanometers and the reference standard spectral curve of ester-containing organic compounds. The Pearson correlation coefficient ranges from -1 to 1, with values ​​closer to 1 indicating a higher spectral match. The correlation coefficients of the two bands are normalized and added together to generate a composite band match score. For example, if the correlation coefficient of the first absorption band is 0.85 and the correlation coefficient of the second absorption band is 0.72, the normalized composite score is 1.57.

[0093] The spectral correlation score is generated based on the dynamic weighted sum of the correlation coefficient and the reflectance peak amplitude, with the weighting coefficient preset based on the pesticide type. The rules for the dynamic weighted sum are as follows: for phosphorus-containing organic compounds, the correlation coefficient has a higher weight and the reflectance peak amplitude has a lower weight; for ester-containing organic compounds, the reflectance peak amplitude has a higher weight and the correlation coefficient has a lower weight. For example, the weighting coefficients for phosphorus-containing organic compounds are set to a correlation coefficient weight of 0.7 and a reflectance peak amplitude weight of 0.3; the weighting coefficients for ester-containing organic compounds are set to a correlation coefficient weight of 0.4 and a reflectance peak amplitude weight of 0.6. The reflectance peak amplitude is calculated as the difference between the maximum and minimum reflectance values ​​within the pesticide's characteristic band and is used to quantify the spectral absorption intensity. The weighting coefficients are preset based on the spectral characteristics of the pesticide type, and the weight ratio is optimized through experimental testing to balance the differences in spectral response of different pesticides.

[0094] The final spectral correlation score is calculated as follows: Spectral correlation score = correlation coefficient × weight coefficient + reflectance peak amplitude × weight coefficient. For example, if the correlation coefficient for a phosphorus-containing organic compound residue region is 0.85 and the reflectance peak amplitude is 0.5, the spectral correlation score is 0.85 × 0.7 + 0.5 × 0.3 = 0.845.

[0095] The reason for choosing the visible to near-infrared wavelength range is that it can cover the characteristic absorption peaks of most pesticides. For example, the absorption peak of the phosphorus-oxygen bond of phosphorus-containing organic compounds is concentrated in the visible light band, while the absorption peak of the carbonyl group of ester-containing organic compounds extends into the near-infrared band. The division of the preset pesticide characteristic bands is based on the spectral fingerprint characteristics of key functional groups in the pesticide molecules, such as the vibrational absorption characteristics of the phosphorus-oxygen double bond and the carbonyl group. The effectiveness of the preset bands is verified through experimental testing. For example, standard spectral data of various phosphorus-containing and ester-containing pesticides are collected, and the distribution pattern of their absorption peaks is statistically analyzed to determine the characteristic band range. The dynamic weighting rules for the correlation coefficient and reflectance peak amplitude are determined through cross-validation of multiple groups of pesticide samples. For example, the weight coefficient is adjusted in the training set to achieve a balance between the sensitivity and specificity of the spectral correlation score for the detection of the target pesticide.

[0096] The logic behind the dynamic weighting coefficients preset based on pesticide type is that different pesticide categories have different spectral characteristics. The spectral characteristics of phosphorus-containing organic compounds are primarily characterized by strong absorption peaks, and the correlation coefficient better reflects their spectral matching. In contrast, the spectral characteristics of ester-containing organic compounds may include wide reflectance variations, and the reflectance peak amplitude is more sensitive to the detection of weak absorption peaks. The weighting coefficient optimization process involves testing the detection accuracy under different weighting coefficients in samples with known pesticide residues and selecting the weight combination that achieves the highest accuracy. For example, for phosphorus-containing organic compounds, a correlation coefficient weight of 0.7 improves detection accuracy by approximately 15% compared to a weight of 0.5. For ester-containing organic compounds, a reflectance peak amplitude weight of 0.6 reduces the missed detection rate by approximately 10%. The threshold for the spectral correlation score is set based on the score distribution of normal samples. For example, the mean spectral correlation score plus twice the standard deviation of a normal texture area is used as the judgment threshold. Areas with scores above the threshold are identified as high-risk areas for pesticide residues.

[0097] S6. Input the geometric features of the abnormal residue area and the spectral correlation score into the pre-trained classification model, and generate the pesticide residue detection results based on the nonlinear correlation decision. The specific implementation is as follows:

[0098] The geometric features of the abnormal residue area are combined with the spectral correlation score to form a multidimensional feature vector. The geometric features include the area ratio of discrete spots and the aspect ratio of continuous stripes. The geometric features of the abnormal residue area include the area ratio of discrete spots and the aspect ratio of continuous stripes. The area ratio of discrete spots is calculated as the ratio of the total area of ​​the discrete spots within the abnormal residue area to the total area of ​​the region. Discrete spots are defined as isolated connected regions with an area less than a preset threshold, which is determined through experimental testing. The aspect ratio of continuous stripes is the ratio of the average length to width of continuous stripe-like structures within the region. Continuous stripe-like structures are defined as connected regions with an aspect ratio greater than a preset threshold. For example, the preset threshold for the area ratio of discrete spots is set at 5% of the total area, and the preset threshold for the aspect ratio of continuous stripes is set at 10:1. The spectral correlation score reflects the degree of spectral matching of pesticide residues. The geometric features and spectral correlation scores are combined on a pixel-by-pixel basis to form a multidimensional feature vector containing the area ratio of discrete spots, the aspect ratio of continuous stripes, and the spectral correlation score.

[0099] The multidimensional feature vector is input into the pre-trained support vector machine classification model and mapped to a high-dimensional space through the kernel function for nonlinear decision making. During the training phase, the support vector machine classification model is pre-trained using a training set containing samples of surface residues of various Chinese medicinal materials. The multidimensional feature vectors of the training set samples include geometric morphological features and spectral correlation scores, and the true category of the pesticide residues is marked. The kernel function selects the radial basis function, which maps the low-dimensional feature vector to a high-dimensional space through the kernel function to solve the nonlinear separability problem of geometric morphology and spectral features. The decision function of the support vector machine classification model is a linear hyperplane of the feature vector in the high-dimensional space, and the hyperplane is determined by maximizing the class interval. For example, the bandwidth parameter of the kernel function is optimized through cross-validation during the training process to ensure the model's generalization ability for different medicinal material surface features.

[0100] Based on the comparison of the output confidence of the support vector machine classification model and the preset threshold, the presence of pesticide residues is determined and the test results are generated. The output of the support vector machine classification model is the confidence score of each pixel, and the confidence score represents the probability that the pixel belongs to the pesticide residue category. The preset threshold is determined by the receiver operating characteristic curve of the training set, and the optimal threshold that balances sensitivity and specificity is selected. For example, the preset threshold is set to 0.85, and when the confidence score is greater than or equal to 0.85, it is judged to be positive for pesticide residue, otherwise it is negative. The test result is a binary image, in which positive pixels are marked as pesticide residue areas and negative pixels are marked as normal texture areas. The test results are processed by morphological post-processing to remove isolated noise points. Isolated noise points are defined as positive areas with an area less than a preset threshold. The preset threshold is set to 5 pixels, for example.

[0101] The radial basis function kernel was chosen for the support vector machine classification model because there is a complex nonlinear relationship between the residual geometric morphology and spectral characteristics of traditional Chinese medicine surfaces, and the radial basis function can effectively capture such nonlinear patterns. For example, the morphological differences between discrete spots and continuous stripes may exhibit a nonlinear distribution in high-dimensional space, and the interaction between spectral correlation scores and morphological features requires kernel mapping for linear segmentation. The training set was constructed to include samples of various medicinal herbs, such as ginseng, astragalus, and mint, covering different surface texture types to ensure the model's adaptability to different medicinal herbs. The confidence threshold was optimized through cross-validation. For example, the training set was divided into five folds, and the classification performance at different thresholds was tested in each fold, and the threshold with the best average performance was selected.

[0102] The filtering of isolated noise points in morphological post-processing uses a morphological opening operation, with a rectangular structuring element whose size is set according to the minimum particle size of the normal texture. For example, setting the structuring element size to 3×3 pixels can effectively remove noise points with an area smaller than 5 pixels while retaining the true residue area. The final detection results are superimposed on the original high-resolution image and the pesticide residue areas are distinguished from the normal texture areas by color annotation. For example, the pesticide residue areas are marked in red, while the normal areas retain the original color. The output format of the detection results is structured data containing the location of the pesticide residue and the confidence score, which is used for subsequent quality assessment and circulation supervision.

[0103] Step S6 solves the problem of misjudgment caused by the limitations of single features in traditional detection methods by fusing geometric morphological features with spectral correlation scores and using a support vector machine classification model for nonlinear decision-making. Existing technologies usually analyze morphological or spectral features independently and ignore their interactions. In this step, the proportion of discrete spot area, the aspect ratio of continuous stripes and the spectral score are combined into multidimensional features, which are mapped to a high-dimensional space through a radial basis function kernel to capture the nonlinear correlation between features. For example, discrete spots in pesticide residue areas are separable from high spectral scores in nonlinear space, while continuous stripes of natural textures are associated with low scores. The classification confidence threshold is optimized through the ROC curve and combined with morphological post-processing to filter out isolated noise, ultimately improving the detection accuracy, which is better than traditional linear classification methods.

[0104] Example 2: Figure 3 The present invention provides a schematic structural diagram of the artificial intelligence-based Chinese herbal medicine pesticide residue detection system, which includes the following modules:

[0105] Gradient feature module: used to obtain high-resolution images of the surface area of ​​Chinese medicinal materials and extract the local gradient direction distribution characteristics of pixel points in the high-resolution image;

[0106] Feature clustering module: used to perform gradient amplitude clustering processing on adjacent pixel points in texture-dense areas in high-resolution images based on local gradient direction distribution characteristics, and generate a gradient feature map containing texture edge contours;

[0107] Feature fusion module: used to perform multi-scale fusion processing on the gradient feature map and the color channel data in the high-resolution image to obtain a multi-channel feature map;

[0108] Covariance classification module: It is used to analyze the covariance of the high-order color moments of each pixel in the multi-channel feature map and the directional entropy of the spatial co-occurrence matrix, and to classify the surface area of ​​the Chinese medicinal materials into normal texture areas and abnormal residue areas using the Mahalanobis distance classifier;

[0109] Spectral scoring module: used to perform spectral analysis on abnormal residue areas and generate spectral correlation scores reflecting the possibility of pesticide residues through preset band matching evaluation;

[0110] Intelligent decision-making module: used to input the geometric morphological features and spectral correlation scores of abnormal residue areas into the pre-trained classification model, and generate pesticide residue detection results based on nonlinear correlation decision-making.

[0111] Example 3: A medium for detecting pesticide residues in traditional Chinese medicines based on artificial intelligence, wherein a program or instruction is stored on the medium, and when the program or instruction is executed by a processor, a method for detecting pesticide residues in traditional Chinese medicines based on artificial intelligence is implemented.

[0112] The calculations involved in the embodiments are all dimensionless numerical calculations, and the preset parameters and thresholds in the calculations are set by those skilled in the art according to actual conditions.

[0113] It should be noted that the present invention can be deployed on the device itself to implement embedded applications, and can also be run on a PC or other terminal with a user interface, thereby meeting various hardware environments and usage requirements.

[0114] The above embodiments can be implemented in whole or in part via software, hardware, firmware, or any other combination. When implemented using software, the above embodiments can be implemented in whole or in part in the form of a computer program product. The computer program product comprises one or more computer instructions or computer programs. When loaded or executed on a computer, the processes or functions described in the embodiments of this application are fully or partially performed. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired means (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium accessible by a computer or a data storage device such as a server or data center that contains a collection of one or more available media. The available medium can be magnetic media (e.g., floppy disks, hard disks, tapes), optical media (e.g., DVDs), or semiconductor media. The semiconductor media can be a solid-state drive.

[0115] Those skilled in the art will clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and modules described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.

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

[0117] The modules described as separate components may or may not be physically separate, and the components shown as modules may or may not be physical modules, and may be located in one place or distributed across multiple network modules. Some or all of the modules may be selected to achieve the purpose of this embodiment according to actual needs.

[0118] In addition, each functional module in each embodiment of the present application may be integrated into one processing module, or each module may exist physically separately, or two or more modules may be integrated into one module.

[0119] If the functions are implemented in the form of software function modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.

[0120] The above description is merely a specific embodiment of the present application, but the scope of protection of the present application is not limited thereto. Any changes or substitutions that can be easily conceived by a person skilled in the art within the technical scope disclosed in this application should be included in the scope of protection of the present application. Therefore, the scope of protection of the present application should be based on the scope of protection of the claims.

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

Claims

1. A method for detecting pesticide residues in traditional Chinese medicines based on artificial intelligence, characterized in that: The steps include: S1. Obtain a high-resolution image of the surface area of ​​the Chinese medicinal material and extract the local gradient direction distribution characteristics of the pixel points in the high-resolution image; S2, performing gradient amplitude clustering processing on adjacent pixel points in the texture-dense area of ​​the high-resolution image based on the local gradient direction distribution characteristics to generate a gradient feature map containing the texture edge contour; S3, performing multi-scale fusion processing on the gradient feature map and the color channel data in the high-resolution image to obtain a multi-channel feature map; S4. Based on the covariance analysis of the high-order color moment of each pixel in the multi-channel feature map and the directional entropy of the spatial co-occurrence matrix, the surface area of ​​the Chinese medicinal materials is divided into normal texture areas and abnormal residue areas using the Mahalanobis distance classifier; S5. Perform spectral analysis on the abnormal residue area and generate a spectral correlation score reflecting the possibility of pesticide residue through preset band matching evaluation, including: Extract the spectral reflectance curve of the abnormal residual area in the visible to near-infrared band; Selecting preset pesticide characteristic bands, including a first absorption band corresponding to a first type of pesticide and a second absorption band corresponding to a second type of pesticide; Calculate the correlation coefficient between the spectral reflectance curve and each pesticide characteristic band to generate a band matching score; Generate spectral correlation scores based on the dynamic weighted sum of correlation coefficient and reflectance peak amplitude, with weighting coefficients preset based on pesticide type; S6. The geometric morphological features and spectral correlation scores of the abnormal residue area are input into the pre-trained classification model, and the pesticide residue detection results are generated based on nonlinear correlation decision-making.

2. The method for detecting pesticide residues in traditional Chinese medicines based on artificial intelligence according to claim 1, characterized in that: Obtain high-resolution images of the surface area of ​​Chinese medicinal materials and extract the local gradient direction distribution characteristics of the pixels in the high-resolution images, including: Obtain high-resolution images of the surface area of ​​Chinese medicinal materials and perform HSV color space conversion to extract the grayscale image of the saturation channel; Based on the grayscale image, the horizontal gradient amplitude and vertical gradient amplitude of the pixel point are calculated respectively by Sobel operator; According to the ratio of the transverse gradient amplitude to the longitudinal gradient amplitude, the local gradient direction distribution characteristics of each pixel point in the surface area of ​​the Chinese medicinal materials are generated, and the local gradient direction distribution characteristics are represented by the gradient direction distribution histogram.

3. The method for detecting pesticide residues in traditional Chinese medicines based on artificial intelligence according to claim 1, characterized in that: Based on the local gradient direction distribution characteristics, the gradient amplitude clustering process is performed on the adjacent pixel points in the texture-dense area of ​​the high-resolution image to generate a gradient feature map containing the texture edge contour, including: Based on the gradient direction distribution histogram in the local gradient direction distribution feature, K-means clustering is performed on adjacent pixels in the texture-dense area to divide the areas with high gradient amplitude and low gradient amplitude. According to the distribution density of the direction angle interval in the gradient direction distribution histogram, the cluster center threshold is dynamically adjusted to retain the pixels corresponding to the high gradient amplitude area; The retained pixels are processed by morphological closing operation to generate continuous closed texture edge contours and form a gradient feature map.

4. The method for detecting pesticide residues in traditional Chinese medicines based on artificial intelligence according to claim 1, characterized in that: The gradient feature map is fused with the color channel data in the high-resolution image at multiple scales to obtain a multi-channel feature map, including: Construct the Laplacian pyramid of gradient feature map and color channel data, perform three-layer decomposition respectively, and obtain multi-scale gradient feature map and multi-scale color feature map; Perform weighted fusion on the gradient feature map and color feature map of the same scale; The features at each level of the weighted fused Laplacian pyramid are inversely transformed and reconstructed to generate a fused multi-channel feature map.

5. The method for detecting pesticide residues in traditional Chinese medicines based on artificial intelligence according to claim 4, characterized in that: The weights in the weighted fusion of the gradient feature map and the color feature map of the same scale are dynamically adjusted according to the difference between the edge intensity of the gradient feature map and the saturation of the color feature map.

6. The method for detecting pesticide residues in traditional Chinese medicines based on artificial intelligence according to claim 1, characterized in that: Based on the covariance analysis of the high-order color moment of each pixel in the multi-channel feature map and the directional entropy of the spatial co-occurrence matrix, the Mahalanobis distance classifier is used to divide the normal texture area and abnormal residue area on the surface of the Chinese medicinal materials, including: Extract the high-order color moment of each pixel in the saturation channel of the HSV color space from the multi-channel feature map and generate a high-order color moment feature vector; Construct the gray-level co-occurrence matrix of the multi-channel feature map, calculate the entropy values ​​in multiple directions and extract the mean of the directional entropy to generate the directional entropy feature vector of the spatial co-occurrence matrix; Perform covariance matrix analysis on the high-order color moment eigenvectors and the spatial co-occurrence matrix directional entropy eigenvectors to calculate the joint distribution covariance of the two types of eigenvectors; The decision boundary of the Mahalanobis distance classifier is dynamically adjusted based on the eigenvalue distribution of the covariance matrix, and the normal texture area and the abnormal residual area are divided according to the adjusted decision boundary.

7. The method for detecting pesticide residues in traditional Chinese medicines based on artificial intelligence according to claim 1, characterized in that: The geometric features and spectral correlation scores of the abnormal residue area are input into the pre-trained classification model, and the pesticide residue detection results are generated based on nonlinear correlation decision-making, including: The geometric features of the abnormal residual area and the spectral correlation score are combined into a multidimensional feature vector. The geometric features include the area ratio of discrete spots and the aspect ratio of continuous stripes. The multi-dimensional feature vector is input into the pre-trained support vector machine classification model and mapped to the high-dimensional space through the kernel function for nonlinear decision making; Based on the comparison of the output confidence of the support vector machine classification model with the preset threshold, the presence of pesticide residues is determined and the detection results are generated.

8. An artificial intelligence-based Chinese herbal medicine pesticide residue detection system, used to implement the artificial intelligence-based Chinese herbal medicine pesticide residue detection method according to any one of claims 1 to 7, characterized in that: Includes the following modules: Gradient feature module: used to obtain high-resolution images of the surface area of ​​Chinese medicinal materials and extract the local gradient direction distribution characteristics of pixel points in the high-resolution image; Feature clustering module: used to perform gradient amplitude clustering processing on adjacent pixel points in texture-dense areas in high-resolution images based on local gradient direction distribution characteristics, and generate a gradient feature map containing texture edge contours; Feature fusion module: used to perform multi-scale fusion processing on the gradient feature map and the color channel data in the high-resolution image to obtain a multi-channel feature map; Covariance classification module: It is used to analyze the covariance of the high-order color moments of each pixel in the multi-channel feature map and the directional entropy of the spatial co-occurrence matrix, and to classify the surface area of ​​the Chinese medicinal materials into normal texture areas and abnormal residue areas using the Mahalanobis distance classifier; Spectral scoring module: used to perform spectral analysis on abnormal residue areas and generate spectral correlation scores reflecting the possibility of pesticide residues through preset band matching evaluation; Intelligent decision-making module: used to input the geometric morphological features and spectral correlation scores of abnormal residue areas into the pre-trained classification model, and generate pesticide residue detection results based on nonlinear correlation decision-making.

9. A storage medium for detecting pesticide residues in traditional Chinese medicines based on artificial intelligence, characterized in that: The storage medium stores a program or instruction, and when the program or instruction is executed by the processor, the method for detecting pesticide residues in traditional Chinese medicine based on artificial intelligence as described in any one of claims 1 to 7 is implemented.

Citation Information

Patent Citations

  • Fresh tobacco leaf pesticide residue category detection method and system based on hyperspectral technology

    CN117054358A

  • Bridge detection image recognition method and system based on artificial intelligence

    CN118823481A