Traditional Chinese medicine pesticide residue detection method and system based on artificial intelligence and medium
Through artificial intelligence-based detection methods, the local gradient direction distribution characteristics of the surface of traditional Chinese medicinal materials are extracted and multi-scale fusion is performed. Combined with the Mahayana distance classifier and spectral correlation score, the problem of low detection accuracy of pesticide residues under complex textures of traditional Chinese medicinal materials is solved, and high-precision pesticide residue detection is achieved.
Patent Information
- Application Number
- CN202510658057.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-21
- Publication Date
- 2025-06-20
- Estimated Expiration
- 2045-05-21
AI Technical Summary
When using the complex texture of traditional Chinese medicinal materials, it is difficult to distinguish between normal surface features and abnormal areas caused by pesticide residues, resulting in reduced recognition accuracy, misjudgment or missed inspection.
Using an artificial intelligence-based detection method, the high-resolution image of the surface of Chinese medicinal materials is obtained, the local gradient direction distribution characteristics are extracted, the gradient amplitude clustering process is performed, the gradient feature map is generated, and the color channel data is fused multi-scale. The Mahayana distance classifier and spectral correlation score are used to divide the normal texture and abnormal residue areas to generate pesticide residue detection results.
Effectively distinguish the normal texture of the surface of traditional Chinese medicinal materials from abnormal areas of pesticide residues, significantly improve the identification accuracy of detection, reduce misjudgment and missed detection, and improve the robustness and automation of detection.
Smart Images

Figure CN120182729A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image processing and intelligent detection, and more specifically, to a method, system, and medium for detecting pesticide residues in Chinese herbal medicines based on artificial intelligence. Background Art
[0002] In the production and circulation of Chinese herbal medicines, the detection of pesticide residues is an important step to ensure the quality and safety of the medicines. At present, detection technologies based on image analysis have been applied to the rapid screening of pesticide residues, which locate and classify residues by collecting surface images of the medicines and identifying abnormal areas. However, during the natural growth and processing of Chinese herbal medicines, complex texture structures and color changes often form on their surfaces. These features are determined by the physiological morphology and processing technology of the medicines and belong to the normal physical properties of the medicines. Existing image analysis methods have difficulty effectively distinguishing normal surface features from abnormal areas caused by pesticide residues when dealing with such complex textures, and the detection results are easily interfered.
[0003] Due to the high similarity in visual features between the natural textures on the surfaces of Chinese herbal medicines and pesticide residue areas, the recognition accuracy of existing image detection methods for pesticide residues significantly decreases in the context of complex texture backgrounds, resulting in misjudgment or missed detection. Traditional methods lack the ability to effectively distinguish the inherent features of the medicine surfaces from the features of pesticide residues and are difficult to adapt to the complex and variable surface morphologies of Chinese herbal medicines. Summary of the Invention
[0004] To overcome the above-mentioned defects of the prior art, embodiments of the present invention provide a method, system, and medium for detecting pesticide residues in Chinese herbal medicines based on artificial intelligence to solve the problems raised in the above background art.
[0005] To achieve the above object, the present invention provides the following technical solutions: A method for detecting pesticide residues in Chinese herbal medicines based on artificial intelligence, comprising the following steps: S1. Obtain a high-resolution image of the surface area of the Chinese herbal medicine, and extract the local gradient direction distribution features of the pixel points in the high-resolution image; S2. Perform gradient magnitude clustering processing on adjacent pixel points in the texture-dense areas of the high-resolution image according to the local gradient direction distribution features to generate a gradient feature map containing texture edge contours; S3. 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; S4. Based on the covariance analysis of the high-order color moments and the direction entropy of the spatial co-occurrence matrix of each pixel point in the multi-channel feature map, divide the normal texture area and the abnormal residue area of the surface area of the Chinese herbal medicine through a 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 the evaluation of the preset band matching degree; S6. Input the geometric morphological features of the abnormal residue area and the spectral correlation score into the pre-trained classification model, and generate the pesticide residue detection result based on the non-linear correlation decision.
[0006] In a preferred embodiment, obtain the high-resolution image of the surface area of the Chinese medicinal material, and extract the local gradient direction distribution features of the pixel points in the high-resolution image, including: Obtain the high-resolution image of the surface area of the Chinese medicinal material and perform HSV color space conversion, and extract the grayscale image of the saturation channel; Based on the grayscale image, calculate the horizontal gradient amplitude and the vertical gradient amplitude of the pixel points respectively through the Sobel operator; According to the ratio of the horizontal gradient amplitude to the vertical gradient amplitude, generate the local gradient direction distribution features of each pixel point in the surface area of the Chinese medicinal material, and the local gradient direction distribution features are characterized by the gradient direction distribution histogram.
[0007] In a preferred embodiment, perform gradient amplitude clustering processing on the adjacent pixel points in the texture-dense area of the high-resolution image according to the local gradient direction distribution features, and generate a gradient feature map containing the texture edge contour, including: Based on the gradient direction distribution histogram in the local gradient direction distribution features, perform K-means clustering on the adjacent pixel points in the texture-dense area, and divide the high-gradient amplitude area and the low-gradient amplitude area; According to the distribution density of the direction angle intervals in the gradient direction distribution histogram, dynamically adjust the clustering center threshold, and retain the pixel points corresponding to the high-gradient amplitude area; Perform morphological closing operation processing on the retained pixel points to generate a continuous and closed texture edge contour, and form a gradient feature map.
[0008] In a preferred embodiment, 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, including: Construct the Laplacian pyramid of the gradient feature map and the color channel data, and perform three-layer decomposition respectively to obtain the multi-scale gradient feature map and the multi-scale color feature map; Perform weighted fusion on the gradient feature map and the color feature map of the same scale; Perform inverse transformation reconstruction on the features of each level of the Laplacian pyramid after weighted fusion to generate the fused multi-channel feature map.
[0009] In a preferred embodiment, the weights in the weighted fusion of gradient feature maps and color feature maps of the same scale are dynamically adjusted according to the edge intensity of the gradient feature maps and the saturation difference of the color feature maps.
[0010] In a preferred embodiment, based on the covariance analysis of the high-order color moments and the spatial co-occurrence matrix directional entropy of each pixel point in the multi-channel feature map, the normal texture area and the abnormal residue area of the surface area of traditional Chinese medicine materials are divided by a Mahalanobis distance classifier, including: Extract the high-order color moments of each pixel point in the saturation channel of the HSV color space in the multi-channel feature map to 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 directional entropy to generate a spatial co-occurrence matrix directional entropy feature vector; Conduct covariance matrix analysis on the high-order color moment feature vector and the spatial co-occurrence matrix directional entropy feature vector, and calculate the joint distribution covariance of the two types of feature vectors; Dynamically adjust the decision boundary of the Mahalanobis distance classifier based on the eigenvalue distribution of the covariance matrix, and divide the normal texture area and the abnormal residue area according to the adjusted decision boundary.
[0011] In a preferred embodiment, spectral analysis is performed on the abnormal residue area, and a spectral correlation score reflecting the possibility of pesticide residues is generated through the evaluation of the preset band matching degree, including: Extract the spectral reflectance curve of the abnormal residue area in the visible light to near-infrared band range; Select the preset pesticide characteristic bands, including the first absorption band corresponding to the first type of pesticide and the second absorption band corresponding to the second type of pesticide; Calculate the correlation coefficient between the spectral reflectance curve and each pesticide characteristic band to generate a band matching degree score; Generate a spectral correlation score according to the dynamic weighted sum of the correlation coefficient and the peak amplitude of the reflectance, and the weighting coefficient is preset according to the pesticide type.
[0012] In a preferred embodiment, the geometric morphological features and the spectral correlation score of the abnormal residue area are input into a pre-trained classification model, and a pesticide residue detection result is generated based on non-linear association decision-making, including: Combine the geometric morphological features and the spectral correlation score of the abnormal residue area into a multi-dimensional feature vector, and the geometric morphological features include the proportion of the discrete spot area and the aspect ratio of the continuous stripe length to width; Input the multi-dimensional feature vector into a pre-trained support vector machine classification model, and perform non-linear decision-making through kernel function mapping to a high-dimensional space; Determine the existence of pesticide residues and generate a detection result according to the comparison between the output confidence of the support vector machine classification model and the preset threshold.
[0013] On the other hand, the present invention provides an artificial intelligence-based traditional Chinese medicine pesticide residue detection system, including the following modules: Gradient feature module: used to obtain a high-resolution image of the surface area of traditional Chinese medicine, and extract the local gradient direction distribution features of pixel points in the high-resolution image; Feature clustering module: used to perform gradient amplitude clustering on adjacent pixel points in the texture-dense area of the high-resolution image according to the local gradient direction distribution features, 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: used to perform covariance analysis on the high-order color moments and the direction entropy of the spatial co-occurrence matrix of each pixel point in the multi-channel feature map, and divide the normal texture area and the abnormal residue area of the surface area of traditional Chinese medicine through a Mahalanobis distance classifier; Spectral scoring module: used to perform spectral analysis on the abnormal residue area, and generate a spectral correlation score reflecting the possibility of pesticide residue through a preset band matching degree evaluation; Intelligent decision-making module: used to input the geometric shape features and spectral correlation scores of the abnormal residue area into a pre-trained classification model, and generate a pesticide residue detection result based on non-linear correlation decision-making.
[0014] On the other hand, the present invention provides an artificial intelligence-based traditional Chinese medicine pesticide residue detection medium, on which a program or instruction is stored, and when the program or instruction is executed by a processor, an artificial intelligence-based traditional Chinese medicine pesticide residue detection method is realized.
[0015] Compared with the prior art, the present invention has the following beneficial effects: 1. Through gradient direction distribution feature extraction and multi-scale fusion technology, combining multi-dimensional features of the surface texture and color of traditional Chinese medicine, it can effectively distinguish normal physiological features from abnormal areas caused by pesticide residues; the gradient amplitude clustering processing based on local gradient direction distribution features can accurately locate the edge contours of texture-dense areas, and suppress natural texture interference through a dynamic threshold adjustment mechanism, strengthening the contour significance of the residue area; at the same time, the multi-channel feature map fuses gradient edges, color saturation and multi-scale texture information to construct a feature expression that takes into account local details and global distribution, overcoming the misdetection problem caused by insufficient single feature representation in traditional methods; through covariance analysis of high-order color moments and direction entropy of spatial co-occurrence matrices, the coupling relationship between color and texture features is quantified from the statistical correlation level, and the normal and abnormal areas are dynamically divided through a Mahalanobis distance classifier, avoiding the insufficient adaptability of fixed threshold segmentation to complex texture traditional Chinese medicine, and significantly improving the robustness of the classification boundary.
[0016] 2. The reliability of pesticide residue detection is further enhanced by combining a spectral correlation scoring mechanism with geometric shape analysis. Spectral analysis based on the preset band matching degree can capture the characteristic absorption peaks of pesticide molecules, and the spectral response differences of different categories of pesticides are balanced through dynamic weighting rules. The multi-dimensional fusion of geometric shape features and spectral scores is input into a pre-trained classification model, and the implicit relationships between features are fully mined using non-linear correlation decision-making to solve 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 herbal medicines are achieved, providing a unified and adaptive detection framework for the complex surface characteristics of different types of medicinal materials, and significantly improving the automation level of the detection process and the generalization ability in actual scenarios. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Figure 1 is a flowchart of the method for detecting pesticide residues on Chinese herbal medicines based on artificial intelligence according to the present invention; Figure 2 is a flowchart of dividing the normal texture area and the abnormal residue area on the surface of Chinese herbal medicines according to the present invention; Figure 3 is a schematic structural diagram of the system for detecting pesticide residues on Chinese herbal medicines based on artificial intelligence according to the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0018] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention.
[0019] Embodiment 1: Figure 1 A method for detecting pesticide residues on Chinese herbal medicines based on artificial intelligence according to the present invention is given, including the following steps: S1. Obtain a high-resolution image of the surface area of the Chinese herbal medicine, and extract the local gradient direction distribution characteristics of the pixel points in the high-resolution image; S2. Perform gradient amplitude clustering processing on adjacent pixel points in the texture-dense area of the high-resolution image according to the local gradient direction distribution characteristics to generate a gradient feature map containing texture edge contours; S3. 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; S4. Based on the covariance analysis of the high-order color moments and the spatial co-occurrence matrix direction entropy of each pixel point in the multi-channel feature map, divide the normal texture area and the abnormal residue area on the surface area of the Chinese herbal medicine through a 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 the evaluation of the preset band matching degree; S6. Input the geometric shape features and spectral correlation score of the abnormal residue area into the pre-trained classification model, and generate the pesticide residue detection result based on the non-linear correlation decision.
[0020] The intelligent detection of pesticide residues in traditional Chinese medicinal materials is realized through a machine learning model, which is specifically reflected in the following steps: in steps S1 - S3, gradient direction distribution feature extraction, gradient magnitude clustering and multi-scale fusion technology are used to construct a multi-channel feature map representing the correlation between texture and color, which is a feature learning process; in step S4, the statistical distribution difference of color-texture features is quantified through covariance analysis and Mahalanobis distance classifier to realize region segmentation based on a probability model; in steps S5 - S6, spectral scores and geometric shape features are fused, and a pre-trained support vector machine classification model is used for non-linear decision-making to optimize the classification boundary through data-driven. The above steps rely on machine learning algorithms (such as SVM, Mahalanobis distance) for adaptive modeling of multi-dimensional features, solve the problem of insufficient generalization caused by traditional methods relying on artificial rules, and verify the support of artificial intelligence technology for multi-source feature fusion and complex decision-making.
[0021] S1. Obtain a high-resolution image of the surface area of traditional Chinese medicinal materials, and extract the local gradient direction distribution features of the pixel points in the high-resolution image. The specific implementation is as follows: Collect the RGB image of the surface area of traditional Chinese medicinal materials through a high-resolution imaging device. The resolution of the high-resolution imaging device is not less than 20 million pixels to ensure that the fine texture on the surface of the medicinal materials can be clearly captured. Convert the collected RGB image into the HSV color space. The HSV color space contains a hue channel, a saturation channel and a value channel. Select the saturation channel for subsequent processing and extract the grayscale image of the saturation channel. The saturation channel reflects the purity information of the color, and can effectively distinguish the natural texture on the surface of traditional Chinese medicinal materials from the color changes caused by pesticide residues. For example, pesticide residues may cause local area color fading or abnormal color change, while the color purity change of natural texture is relatively gentle.
[0022] For the grayscale image of the saturation channel, the Sobel edge detection operator is used to calculate the gradient information of each pixel. The Sobel convolution kernel in the horizontal direction is used to detect horizontal edges, and the Sobel convolution kernel in the vertical direction is used to detect vertical edges. The matrix form of the Sobel convolution kernel in the horizontal direction is, for example, [-1, 0, 1; -2, 0, 2; -1, 0, 1], and the matrix form of the Sobel convolution kernel in the vertical direction is, for example, [1, 2, 1; 0, 0, 0; -1, -2, -1]. Through convolution operation, the horizontal gradient magnitude Gx and the vertical gradient magnitude Gy of each pixel are obtained. The calculation methods of the horizontal gradient magnitude Gx and the vertical gradient magnitude Gy are to sum the products of the convolution kernel and the pixel values in the corresponding image area according to positions.
[0023] For each pixel, calculate the ratio of the horizontal gradient magnitude Gx to the vertical gradient magnitude Gy, and calculate the gradient direction angle θ through the arctangent 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 magnitude Gx is less than a preset minimum value, for example, the minimum value is set to 1e-5, the gradient direction angle θ is directly assigned 90 degrees. Divide the range of the gradient direction angle θ from 0 degrees to 180 degrees into multiple equally spaced intervals, for example, divide it into 36 intervals, and the span of each interval is 5 degrees. Count the number of pixels whose gradient magnitude exceeds a preset threshold in each interval. The preset threshold is, for example, the sum of the squares of the gradient magnitudes Gx² + Gy² ≥ 50 to exclude noise interference in the low-gradient magnitude area. Generate a gradient direction distribution histogram according to 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 through normalization processing. The normalization method is to divide the number of pixels in each interval by the total number of pixels in all intervals to eliminate the influence of image size differences. The gradient direction distribution histogram, as a quantitative representation form of the local gradient direction distribution characteristics, is used for the subsequent texture dense area division.
[0024] The reason for choosing the saturation channel instead of the hue or value channel is that the color change on the surface of traditional Chinese medicinal materials has a higher contrast in the saturation channel. The hue channel is easily affected by light changes, and the value channel is easily affected by shadows. For example, when there is local fading on the surface of the medicinal material caused by pesticide residues, the grayscale value of the saturation channel will be significantly lower than that of the surrounding natural texture area. During implementation, the conversion from RGB to HSV is achieved by calling the color space conversion function of the image processing library. The specific function is cv2.cvtColor, and the parameter is set to cv2.COLOR_RGB2HSV to ensure the reproducibility of the conversion process. The sizes of the Sobel convolution kernels in the horizontal and vertical directions are fixed at 3×3. This size achieves a balance between edge detection accuracy and calculation efficiency and is suitable for the gradient analysis of the surface texture of traditional Chinese medicinal materials.
[0025] The gradient magnitude threshold is, for example, the sum of the squares of the gradient magnitudes Gx² + Gy² ≥ 50, which is used to distinguish effective edges from smooth regions. The threshold is set based on experimental tests. When the sum of the squares of the gradient magnitudes is less than 50, the texture changes in the corresponding region are not sufficient to reflect the characteristics of pesticide residues. The reason for choosing 36 direction angle intervals is that a smaller number of intervals may lead to insufficient direction resolution, while a larger number of intervals will increase the computational complexity. 36 intervals can achieve a balance between resolution and efficiency. The normalization process ensures the comparability of histograms for images of different sizes. For example, for medicinal material samples of different sizes, the normalized histogram distributions can be directly used for subsequent analysis without additional adjustment.
[0026] S2. Perform gradient magnitude clustering on adjacent pixel points in the texture-dense regions of the high-resolution image according to the local gradient direction distribution characteristics to generate a gradient feature map containing texture edge contours. The specific implementation is as follows: Based on the gradient direction distribution histogram in the local gradient direction distribution characteristics, perform K-means clustering on adjacent pixel points in the texture-dense regions to divide the high-gradient magnitude and low-gradient magnitude regions. The horizontal axis of the gradient direction distribution histogram is the direction angle interval, and the vertical axis is the proportion of the normalized number of pixel points. Determine the spatial distribution range of the texture-dense regions according to the proportion of the number of pixel points in each direction angle interval in the gradient direction distribution histogram. Extract the gradient magnitude features for adjacent pixel points in the texture-dense regions. The calculation method of the gradient magnitude feature is the square root of the sum of the squares of the horizontal gradient magnitude and the vertical gradient magnitude. Use the gradient magnitude as the input feature for K-means clustering, and set the initial cluster centers as the two pixel points with the maximum and minimum gradient magnitudes. Through iterative calculations, divide the pixel points into high-gradient magnitude regions and low-gradient magnitude regions. The high-gradient magnitude regions correspond to texture edge contours, and the low-gradient magnitude regions correspond to flat or weak texture regions.
[0027] Dynamically adjust the cluster center threshold according to the distribution density of the direction angle intervals in the gradient direction distribution histogram, and retain the pixel points corresponding to the high-gradient magnitude regions. The distribution density of the direction angle intervals is calculated by statistically analyzing the proportion of the number of pixel points in each interval. The higher the distribution density, the denser the texture in the corresponding direction angle interval. The rule for dynamically adjusting the cluster center threshold is: when the distribution density of the direction angle interval is higher than the preset density threshold, lower the cluster center threshold corresponding to this interval to retain more edge pixel points; when the distribution density is lower than the preset density threshold, raise the cluster center threshold to exclude noise interference. The preset density threshold is determined based on experimental tests. For example, it is set to 0.15, indicating that when the proportion of the number of pixel points in the direction angle interval exceeds 15%, it is determined as a high-density region. By dynamically adjusting the threshold, ensure the balance between the integrity of the edge contours of the texture-dense regions and the noise suppression effect.
[0028] Perform morphological closing operation on the retained pixel points to generate a continuous and closed texture edge contour, forming a gradient feature map. The morphological closing operation includes dilation followed by erosion. The dilation operation is used to connect broken edge pixel points, and the erosion operation is used to smooth the edge contour. A rectangular structuring element is used for the closing operation, and the size of the structuring element is set according to the average width of the texture-dense area, for example, set to 3×3 pixels. Extract the connected regions from the binary image after the closing operation, and remove the isolated noise points with an area smaller than a preset threshold. The preset area threshold is, for example, 10 pixels. The finally generated gradient feature map is a binary image containing a continuous and closed texture edge contour, where the high-gradient amplitude regions are marked white and the low-gradient amplitude regions are marked black. The gradient feature map is used as the input data for subsequent multi-scale fusion processing to enhance the feature expression of color-abnormal regions.
[0029] The reason for choosing K-means clustering instead of fixed-threshold segmentation is that the gradient amplitude distribution of the surface texture of traditional Chinese medicinal materials is non-uniform, and it is difficult for a fixed threshold to adapt to the changes in different texture densities. For example, the gradient amplitude of the wrinkled texture of rhizome medicinal materials is relatively high and concentrated, while the gradient amplitude of the vein texture of leaf medicinal materials is relatively low and dispersed. Dynamic clustering can adaptively divide the high- and low-gradient regions. The size of the structuring element for the morphological closing operation is set to 3×3 pixels, which can effectively connect common broken edges and avoid edge blurring caused by excessive dilation. The binarization of the gradient feature map is achieved by setting a gradient amplitude threshold, and the threshold is dynamically determined according to the clustering results. For example, the top 10% pixel points in the high-gradient amplitude regions are marked white.
[0030] It should be noted that the texture-dense area is determined by the distribution density of the direction angle intervals in the gradient direction distribution histogram. The distribution density is the proportion of the number of pixel points in each direction angle interval. When the distribution density is higher than a preset threshold (for example, 0.15), it is determined as a dense area. The preset threshold is optimized through experiments on multiple groups of traditional Chinese medicinal material samples. For example, in ginseng and astragalus samples, the texture segmentation accuracy at different density thresholds is statistically analyzed, and the threshold that makes the edge continuity the best is selected. The acquisition of the texture-dense area is based on the gradient amplitude clustering result, and the pixel points corresponding to the high-gradient amplitude regions are retained.
[0031] S3. 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. The specific implementation is as follows: Construct the Laplacian pyramids of the gradient feature map and the color channel data, perform three-layer decomposition respectively, and obtain the multi-scale gradient feature map and the multi-scale color feature map. The gradient feature map contains continuous and closed texture edge contour information, and the color channel data is the grayscale image of the extracted saturation channel. The construction process of the Laplacian pyramid includes performing Gaussian pyramid decomposition on the gradient feature map and the color channel data respectively to generate three images of different scales. Each layer of the image is obtained through Gaussian filtering and downsampling. The convolution kernel size of the Gaussian filter is 5×5 pixels, and the standard deviation is set to 1.0. Upsample each layer of the Gaussian pyramid image and perform pixel difference with the previous layer image to obtain the feature maps of each layer of the Laplacian pyramid. For example, the third-layer Laplacian pyramid feature map is obtained by upsampling the third-layer Gaussian pyramid image to the size of the second layer and then performing pixel difference with the second-layer Gaussian pyramid image. The Laplacian pyramids of the gradient feature map and the color channel data respectively retain the edge details and color distribution features of different scales.
[0032] Perform weighted fusion on the gradient feature map and the color feature map of the same scale. The weights are dynamically adjusted according to the edge intensity of the gradient feature map and the saturation difference of the color feature map. The edge intensity is quantified by the gradient amplitude of the pixel points in the gradient feature map. The calculation method of the gradient amplitude is 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 by the absolute difference between the saturation value of the current pixel point and the average saturation of the neighboring pixels. The neighborhood range is a 3×3 pixel area. The rule for dynamic weight adjustment is that when the edge intensity is higher than the preset threshold, the weight of the gradient feature map increases and the weight of the color feature map decreases; when the saturation difference is higher than the preset threshold, the weight of the color feature map increases and the weight of the gradient feature map decreases. The preset threshold is determined according to experimental tests. For example, the edge intensity threshold is set to Gx² + Gy² ≥ 50 for the sum of the squares of the gradient amplitudes, and the saturation difference threshold is set to the absolute difference ≥ 20. The calculation method of weighted fusion is that the fused feature map is equal to the gradient feature map multiplied by the weight gradient plus the color feature map multiplied by the weight color, and the sum of the weight gradient and the weight color is 1.0. By dynamically adjusting the weights, the joint feature expression of the texture edge and the color abnormal area is enhanced.
[0033] Inverse transform reconstruction is performed on the features of each level of the Laplacian pyramid after weighted fusion to generate a fused multi-channel feature map. The process of inverse transform reconstruction starts from the highest-level Laplacian pyramid feature map, upsamples layer by layer and adds it to the feature map of the next layer until the original image size is restored. Bilinear interpolation is used for upsampling to enlarge the low-resolution image to the size of the adjacent higher level. For example, the fused feature map of the third layer is upsampled and added to the fused feature map of the second layer, and then upsampled and added to the fused feature map of the first layer, finally 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.
[0034] The reason for choosing the Laplacian pyramid instead of direct weighted fusion is that multi-scale decomposition can preserve texture and color details at different resolutions and avoid information loss at a single scale. For example, the high-level Laplacian pyramid captures large-scale texture contours, and the low level retains subtle color changes, enhancing the robustness of features through hierarchical fusion. The preset threshold for dynamic weight adjustment is determined through tests on multiple groups of medicinal material samples. For example, the edge intensity threshold for ginseng rhizome samples is set to 50, and the saturation difference threshold for mint leaf samples is set to 20 to balance the characteristic differences of different medicinal materials. The bilinear interpolation method for inverse transform reconstruction can reduce the edge jagged effect during upsampling and ensure the smoothness of the fused feature map.
[0035] Figure 2 The flowchart for dividing the normal texture area and the abnormal residue area on the surface of traditional Chinese medicinal materials is given. Based on the covariance analysis of the high-order color moments and the direction entropy of the spatial co-occurrence matrix of each pixel point in the multi-channel feature map, the normal texture area and the abnormal residue area on the surface of traditional Chinese medicinal materials are divided by a Mahalanobis distance classifier. The specific implementation is as follows: Extract the high-order color moments of each pixel in the saturation channel of the HSV color space in the multi-channel feature map to generate a high-order color moment feature vector. The multi-channel feature map includes 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 color purity information and can effectively characterize local color abnormalities 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 calculation method of the fourth-order moment is the fourth-order central moment of the saturation value divided by the fourth power of the standard deviation. Specifically, calculate the fourth-order central moment of the saturation value for the neighborhood range of each pixel. The neighborhood range is, for example, a 3×3 pixel area. The calculation formula for the fourth-order central moment is the average of the fourth powers of the saturation values of each pixel in the neighborhood minus the neighborhood mean. The high-order color moment feature vector generated by calculating the fourth-order moment can distinguish the smooth saturation distribution of natural textures from the spike-like distribution of pesticide residues. The saturation distribution of natural textures usually shows smooth fluctuations, while in the pesticide residue area, due to local pigment deposition or fading, the saturation value deviates significantly from the mean, and the fourth-order moment increases significantly.
[0036] Construct the gray-level co-occurrence matrix of the multi-channel feature map, calculate the entropy values in multiple directions and extract the mean direction entropy to generate the spatial co-occurrence matrix direction entropy feature vector. The construction of the gray-level co-occurrence matrix is based on the gradient edge information in the multi-channel feature map. The directions of the gray-level co-occurrence matrix include 0°, 45°, 90°, and 135°, which are used to capture texture changes at different angles. Calculate the entropy value of the gray-level co-occurrence matrix for each direction. The calculation method of the entropy value is the negative sum of the product of the probability values of each element in the matrix and the natural logarithm of the probability value.
[0037] After the entropy values in the four directions are calculated, take the mean of the entropy values in the four directions as the direction entropy eigenvalue. The mean direction entropy reflects the direction complexity and randomness of the texture. For example, the mean direction entropy of natural textures such as root and stem folds is relatively high, while in the pesticide residue area, due to structural damage, the mean direction entropy decreases. The spatial co-occurrence matrix direction entropy feature vector generated by the mean direction entropy can quantify the differences in the direction characteristics of textures. For example, the longitudinal folds of ginseng roots have higher entropy values in the 0° and 180° directions, while the reticular veins of mint leaves have higher entropy values in the 45° and 135° directions. The mean direction entropy can synthesize multi-directional features to avoid interference from a single direction.
[0038] Perform covariance matrix analysis on the high-order color moment feature vector and the spatial co-occurrence matrix direction entropy feature vector, and calculate the joint distribution covariance of the two types of feature vectors. Covariance matrix analysis is used to measure the statistical correlation between the high-order color moment and the direction entropy, and specifically includes the following steps: Arrange the high-order color moment feature vector and the direction entropy feature vector in one-to-one correspondence according to pixel points to construct a two-dimensional feature matrix; Calculate the covariance matrix of the two-dimensional feature matrix. The diagonal elements of the covariance matrix are the variances of the two types of features, and the non-diagonal elements are the covariances of the two types of features; According to the eigenvalue decomposition result of the covariance matrix, determine the principal component contribution degrees of the two types of features. For example, if the largest eigenvalue of the covariance matrix accounts for more than 80% of the sum of the total eigenvalues, it indicates that the high-order color moment and the direction entropy have a strong correlation, and the decision boundary of the classifier needs to be adjusted to adapt to the feature distribution. The eigenvalue decomposition of the covariance matrix is implemented by the Jacobi iteration method, calculate the eigenvalues and eigenvectors of the covariance matrix, and the eigenvalues are arranged in descending order. The largest eigenvalue reflects the dominant direction of the joint variation of the two types of features.
[0039] Dynamically adjust the decision boundary of the Mahalanobis distance classifier based on the eigenvalue distribution of the covariance matrix, and divide the normal texture region and the abnormal residue region according to the adjusted decision boundary. The decision boundary of the Mahalanobis distance classifier is determined by the inverse matrix of the covariance matrix and the feature mean vector. The dynamic adjustment rule is: when the proportion of the largest eigenvalue of the covariance matrix exceeds the preset proportion, reduce the Mahalanobis distance threshold of the decision boundary to improve the sensitivity to strongly correlated features; when the proportion of the largest eigenvalue is lower than the preset proportion, increase the Mahalanobis distance threshold of the decision boundary to enhance the generalization of the classifier. The preset proportion is determined through experimental tests. For example, set the proportion threshold of the largest eigenvalue to 70%. When the proportion of the largest eigenvalue exceeds 70%, the Mahalanobis distance threshold is adjusted to 0.8 times the original threshold; when the proportion is lower than 70%, the threshold is adjusted to 1.2 times the original threshold. Classify each pixel point through the dynamically adjusted decision boundary. Pixel points with a Mahalanobis distance less than the threshold are determined as the normal texture region, and pixel points greater than the threshold are determined as the abnormal residue region. The calculation formula of the Mahalanobis distance is the difference between the pixel point feature vector and the normal texture region feature mean vector multiplied by the inverse matrix of the covariance matrix and then multiplied by the transpose of the difference. The calculation result is compared with the threshold to complete the classification.
[0040] The reason for choosing the saturation channel instead of the hue or value channel in the HSV color space is that pesticide residues often cause changes in local color purity, such as fading or pigment deposition. The hue channel is easily affected by light, and the value channel is easily interfered by shadows. The fourth-order moment of the high-order color moment can quantify the sharpness of the saturation distribution. For example, when pesticide residues cause the saturation values in a local area to deviate from the mean value, the fourth-order moment is significantly higher than that in the natural texture area. The reason for choosing four directions in the gray-level co-occurrence matrix is that the surface texture of traditional Chinese medicine materials has multi-directional characteristics, such as the longitudinal folds of rhizomes and the reticular veins of leaves. A single direction cannot comprehensively represent the texture complexity. In the covariance matrix analysis, a dynamic adjustment mechanism of eigenvalue distribution is introduced to solve the misclassification problem caused by feature correlation in the traditional Mahalanobis distance classifier. For example, when the color and texture features are highly correlated, a fixed threshold may misclassify normal textures as residue areas.
[0041] The preset ratio for dynamically adjusting the decision boundary is determined through tests on 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 ratios is statistically analyzed. It is found in the experiment that when the ratio of the maximum eigenvalue exceeds 70%, the threshold scaling coefficient is set to 0.8, which can reduce the false detection rate by about 12%; when the ratio is lower than 70%, the coefficient is set to 1.2, which can reduce the missed detection rate by about 9%. The initial threshold of the Mahalanobis distance classifier is set according to the mean value of the feature distribution of the training set samples. For example, the mean value of the Mahalanobis distance in 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 the texture and residue feature distributions of different medicinal materials and improve the detection robustness.
[0042] In step S4, the statistical correlation between the high-order color moment and the directional entropy is analyzed through the covariance matrix, and the decision threshold is dynamically adjusted in combination with the Mahalanobis distance classifier to solve the problem of mis-segmentation caused by uneven distribution of the surface texture and pesticide residue features of traditional Chinese medicine materials. Traditional methods mostly rely on fixed threshold segmentation of a single feature (such as color or texture) and are difficult to adapt to the texture complexity of different medicinal materials. Step S4 quantifies the joint distribution characteristics of color and texture through the covariance matrix, and uses the eigenvalue distribution to dynamically adjust the classification boundary to improve the discrimination accuracy between natural textures and residue areas. For example, when the color and texture features are highly correlated, the threshold is dynamically reduced to avoid false detection; when the feature correlation is weak, the threshold is enlarged to reduce missed detection.
[0043] S5. Perform spectral analysis on the abnormal residue area, and generate a spectral correlation score reflecting the possibility of pesticide residue through the evaluation of the preset band matching degree. The specific implementation is as follows: Extract the spectral reflectance curve of the abnormal residue area in the visible to near-infrared band range. 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 range. 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 range. The visible to near-infrared band range covers wavelengths from about 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 show obvious absorption valleys in specific bands, while ester group-containing organic compounds may exhibit reflectance mutations in the near-infrared band.
[0044] Select preset pesticide characteristic bands, including the first absorption band corresponding to the first type of pesticide and the second absorption band corresponding to the second type of pesticide. The first type of pesticide is a phosphorus-containing organic compound, and the second type of pesticide is an ester group-containing organic compound. The first absorption band is determined according to the molecular structure characteristics of the phosphorus-containing organic compound. The chemical bond formed by the phosphorus atom and the oxygen atom in the phosphorus-containing organic compound has specific absorption characteristics in the visible to near-infrared band. For example, the phosphorus-oxygen double bond (P=O) has an absorption peak near wavelengths of 620 nanometers to 680 nanometers. The second absorption band is determined according to the functional group characteristics of the ester group-containing organic compound. The carbonyl group (C=O) in the ester group (R-COO-R) shows a characteristic of decreasing reflectance near 850 nanometers to 920 nanometers in the near-infrared band. The selection of the preset pesticide characteristic bands is based on the spectral response law of the characteristic functional groups in the pesticide molecules, and the effectiveness of its band range is verified through experimental tests. For example, by measuring the standard spectral data of various phosphorus-containing organic compounds and ester group-containing organic compounds, and statistically analyzing the distribution law of their absorption peaks, the first absorption band is finally determined to be 620 - 680 nanometers, and the second absorption band is 850 - 920 nanometers.
[0045] Calculate the correlation coefficients between the spectral reflectance curve and each pesticide characteristic band to generate a band matching degree score. The calculation of the correlation coefficient uses the Pearson correlation coefficient method to measure the spectral similarity between the spectral reflectance curve of the abnormal residue area and the preset pesticide characteristic bands. For the first absorption band, calculate the Pearson correlation coefficient between the average reflectance curve of the abnormal residue area in the range of 620 nanometers to 680 nanometers and the standard spectral curve of the reference phosphorus-containing organic compound; for the second absorption band, calculate the Pearson correlation coefficient between the average reflectance curve in the range of 850 nanometers to 920 nanometers and the standard spectral curve of the reference ester group-containing organic compound. The value range of the Pearson correlation coefficient is from -1 to 1, and the closer the value is to 1, the higher the spectral matching degree. Add the correlation coefficients of the two bands after normalization to generate a comprehensive band matching degree 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 comprehensive score after normalization and addition is 1.57.
[0046] Generate a spectral correlation score based on the dynamic weighted sum of the correlation coefficient and the peak amplitude of the reflectivity. The weighting coefficients are preset according to the pesticide type. The rule of the dynamic weighted sum is as follows: for organophosphorus compounds, the weighting coefficient of the correlation coefficient is relatively high, and the weighting coefficient of the peak amplitude of the reflectivity is relatively low; for organic compounds containing ester groups, the weighting coefficient of the peak amplitude of the reflectivity is relatively high, and the weighting coefficient of the correlation coefficient is relatively low. For example, the weighting coefficients for organophosphorus compounds are set as the correlation coefficient weight of 0.7 and the peak amplitude weight of the reflectivity of 0.3; the weighting coefficients for organic compounds containing ester groups are set as the correlation coefficient weight of 0.4 and the peak amplitude weight of the reflectivity of 0.6. The calculation method of the peak amplitude of the reflectivity is the difference between the maximum and minimum values of the reflectivity within the characteristic wavelength band of the pesticide, which is used to quantify the spectral absorption intensity. The weighting coefficients are preset according to the spectral characteristics of the pesticide type, and the weight ratio is optimized through experimental tests to balance the spectral response differences of different pesticides.
[0047] The calculation formula for the final spectral correlation score is: spectral correlation score = correlation coefficient × weighting coefficient + peak amplitude of the reflectivity × weighting coefficient. For example, if the correlation coefficient of a residue area of an organophosphorus compound is 0.85 and the peak amplitude of the reflectivity is 0.5, then the spectral correlation score is 0.85×0.7 + 0.5×0.3 = 0.845.
[0048] The reason for selecting the visible to near-infrared wavelength band range is that this range can cover the characteristic absorption peaks of most pesticides. For example, the absorption peak of the phosphorus-oxygen bond of organophosphorus compounds is concentrated in the visible wavelength band, while the absorption peak of the carbonyl group of organic compounds containing ester groups extends to the near-infrared wavelength band. The division of the preset pesticide characteristic wavelength band is based on the spectral fingerprint characteristics of the key functional groups in the pesticide molecule, such as the vibration absorption characteristics of the phosphorus-oxygen double bond and the carbonyl group. The effectiveness of the preset wavelength band is verified through experimental tests. For example, the standard spectral data of various organophosphorus and ester-containing pesticides are collected, and the distribution law of their absorption peaks is statistically analyzed to determine the characteristic wavelength band range. The dynamic weighting rule of the correlation coefficient and the peak amplitude of the reflectivity is determined through cross-validation of multiple groups of pesticide samples. For example, the weighting coefficients are adjusted in the training set to balance the detection sensitivity and specificity of the spectral correlation score for the target pesticide.
[0049] The logic of presetting the dynamic weighting coefficient according to the pesticide type lies in the fact that there are differences in the spectral characteristics of different types of pesticides. The spectral characteristics of phosphorus-containing organic compounds are mainly strong absorption peaks, and the correlation coefficient can better reflect their spectral matching degree; while the spectral characteristics of ester-group-containing organic compounds may include broad reflectance changes, and the peak amplitude of the reflectance is more sensitive to the detection of weak absorption peaks. The optimization process of the weighting coefficient includes: testing the detection accuracy under different weight coefficients in known pesticide residue samples respectively, and selecting the weight combination with the highest accuracy. For example, for phosphorus-containing organic compounds, when the weight of the correlation coefficient is 0.7, the detection accuracy is increased by about 15% compared with the weight of 0.5; for ester-group-containing organic compounds, when the weight of the peak amplitude of the reflectance is 0.6, the missed detection rate is reduced by about 10%. The threshold of the spectral correlation score is set according to the score distribution of normal samples. For example, the mean value of the spectral correlation score of the normal texture area plus twice the standard deviation is used as the judgment threshold, and the area with a score higher than the threshold is determined as the high-risk area of pesticide residue.
[0050] S6. Input the geometric shape characteristics and spectral correlation score of the abnormal residue area into the pre-trained classification model, and generate the pesticide residue detection result based on the non-linear correlation decision. The specific implementation is as follows: Combine the geometric shape characteristics and spectral correlation score of the abnormal residue area into a multi-dimensional feature vector. The geometric shape characteristics include the proportion of the area of discrete spots and the aspect ratio of the length to width of continuous stripes. The geometric shape characteristics of the abnormal residue area include the proportion of the area of discrete spots and the aspect ratio of the length to width of continuous stripes. The calculation method of the proportion of the area of discrete spots is the ratio of the total area of discrete spots in the abnormal residue area to the total area of the area. The discrete spot is defined as an isolated connected area with an area smaller than the preset threshold, and the preset threshold is determined through experimental tests. The aspect ratio of continuous stripes is the ratio of the average length to the width of the continuous stripe-like structure in the area. The continuous stripe-like structure is defined as a connected area with an aspect ratio greater than the preset threshold. For example, the preset threshold of the proportion of the area of discrete spots is set to 5% of the total area of the area, and the preset threshold of the aspect ratio of continuous stripes is set to 10:1. The spectral correlation score reflects the spectral matching degree of pesticide residues. Combine the geometric shape characteristics and spectral correlation score one by one according to pixel points to form a multi-dimensional feature vector including the proportion of the area of discrete spots, the aspect ratio of the length to width of continuous stripes, and the spectral correlation score.
[0051] Input the multi-dimensional feature vector into the pre-trained support vector machine classification model, and perform non-linear decision-making by mapping it to a high-dimensional space through a kernel function. The support vector machine classification model is pre-trained in the training stage using a training set containing various traditional Chinese medicine surface residue samples. The multi-dimensional feature vectors of the training set samples include geometric morphological features and spectral correlation scores, and the true categories of pesticide residues are labeled. The radial basis function is selected as the kernel function, and the low-dimensional feature vector is mapped to a high-dimensional space through the kernel function to solve the non-linearly separable problem of geometric morphology and spectral features. The decision function of the support vector machine classification model is a linear hyperplane in the high-dimensional space, and the hyperplane is determined by maximizing the class interval. For example, during the training process, the bandwidth parameter of the kernel function is optimized through cross-validation to ensure the generalization ability of the model to different medicinal material surface features.
[0052] Determine the existence of pesticide residues and generate detection results based on the comparison between the output confidence of the support vector machine classification model and a preset threshold. The output of the support vector machine classification model is the confidence score for each pixel point, and the confidence score represents the probability that the pixel point 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. When the confidence score is greater than or equal to 0.85, it is determined as positive for pesticide residues, otherwise it is negative. The detection result is a binary image, where positive pixels are marked as pesticide residue areas and negative pixels are marked as normal texture areas. The detection result removes isolated noise points through morphological post-processing. The definition of an isolated noise point is a positive area with an area smaller than the preset threshold, and the preset threshold is set to 5 pixels, for example.
[0053] The reason for the support vector machine classification model to select the radial basis function kernel is that there is a complex non-linear relationship between the geometric morphology and spectral features of the surface residues of traditional Chinese medicines, and the radial basis function can effectively capture such non-linear patterns. For example, the morphological differences between discrete spots and continuous stripes may show non-linear distributions in the high-dimensional space, and the interaction between spectral correlation scores and morphological features needs to be linearly segmented through kernel function mapping. The construction of the training set includes various medicinal material samples, such as ginseng, astragalus, and mint, covering different surface texture types to ensure the adaptability of the model to different medicinal materials. The optimization process of the confidence threshold is completed through cross-validation. For example, the training set is divided into five folds, and the classification performance under different thresholds is tested in each fold, and the threshold with the optimal average performance is selected.
[0054] In the morphological post - processing, the isolated noise points are filtered using morphological opening operation. The structuring element is a rectangle, and its size is set according to the minimum particle size of the normal texture. For example, when the structuring element size is set to 3×3 pixels, it can effectively remove noise points with an area less than 5 pixels while retaining the real residual area. The final detection result is superimposed on the original high - resolution image, and the pesticide residue area and the normal texture area are distinguished by color annotation. For example, the pesticide residue area is marked in red, and the normal area retains its original color. The output format of the detection result is structured data containing the positions of pesticide residues and confidence scores, which is used for subsequent quality assessment and circulation supervision.
[0055] In step S6, by fusing geometric morphological features and spectral correlation scores and using a support vector machine classification model for non - linear decision - making, the misjudgment problem caused by the limitations of single features in traditional detection methods is solved. Existing technologies usually analyze morphological or spectral features independently, ignoring their interaction. In this step, the proportion of discrete spot area, the aspect ratio of continuous stripes, and the spectral score are combined into multi - dimensional features, which are mapped to a high - dimensional space through a radial basis function kernel to capture the non - linear correlation between features. For example, the discrete spots in the pesticide residue area and the hyperspectral score show separability in the non - linear space, while the 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.
[0056] Embodiment 2: Figure 3 The structural schematic diagram of the traditional Chinese medicine pesticide residue detection system based on artificial intelligence of the present invention is given. The traditional Chinese medicine pesticide residue detection system based on artificial intelligence includes the following modules: Gradient feature module: used to obtain the high - resolution image of the surface area of traditional Chinese medicine, and extract the local gradient direction distribution features of pixel points in the high - resolution image; Feature clustering module: used to perform gradient amplitude clustering on adjacent pixel points in the texture - dense area of the high - resolution image according to the local gradient direction distribution features, 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: used to perform covariance analysis based on the high - order color moments and the direction entropy of the spatial co - occurrence matrix of each pixel point in the multi - channel feature map, and divide the normal texture area and the abnormal residue area of the surface area of traditional Chinese medicine through a Mahalanobis distance classifier; Spectral scoring module: used to perform spectral analysis on the abnormal residue area, and generate a spectral correlation score reflecting the possibility of pesticide residue through the evaluation of the preset band matching degree; Intelligent decision-making module: It is used to input the geometric morphological features of the abnormal residue area and the spectral correlation score into a pre-trained classification model, and generate pesticide residue detection results based on non-linear correlation decision-making.
[0057] Embodiment 3: A medium for detecting pesticide residues in traditional Chinese medicinal materials based on artificial intelligence, on which programs or instructions are stored, and when the programs or instructions are executed by a processor, a method for detecting pesticide residues in traditional Chinese medicinal materials based on artificial intelligence is implemented.
[0058] The calculations involved in the embodiments are all dimensionless numerical calculations, and the preset parameters and threshold selections in the calculations are set by those skilled in the art according to the actual situation.
[0059] It should be noted that the present invention can be deployed on the device itself to achieve embedded applications, or can run on a PC or other terminals with a user interface, so as to meet various hardware environments and usage requirements.
[0060] The above embodiments can be implemented in whole or in part by 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 includes one or more computer instructions or computer programs. When the computer instructions or computer programs are loaded or executed on a computer, the processes or functions described in the embodiments of the present application are generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from one website, computer, server or data center to another website, computer, server or data center by wire (such as infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that the computer can access or a data storage device such as a server or data center that contains one or more sets of available media. The available medium can be a magnetic medium (such as a floppy disk, hard disk, magnetic tape), an optical medium (such as a DVD), or a semiconductor medium. The semiconductor medium can be a solid-state drive.
[0061] Those skilled in the art can clearly understand that for the convenience and simplicity of description, the specific working processes of the systems, devices and modules described above can refer to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0062] In several embodiments provided by the present 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 illustrative. For example, the division of the modules is only a logical function division. In actual implementation, there may be other division methods. For example, 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 displayed or discussed couplings or direct couplings or communication connections to each other can be through some interfaces. The indirect couplings or communication connections of the devices or modules can be in electrical, mechanical, or other forms.
[0063] The modules described as separate components may or may not be physically separated. The components displayed as modules may or may not be physical modules. They can be located in one place or distributed to multiple network modules. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0064] In addition, in each embodiment of the present application, the functional modules can be integrated into one processing module, or each module can exist physically alone, or two or more modules can be integrated into one module.
[0065] If the above 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, in essence, or the part that contributes to the prior art, or part of this technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in each embodiment of the present application. The aforementioned storage medium includes: USB flash drives, mobile hard disks, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical discs, etc., which can store program codes.
[0066] As described above, it is only the specific implementation manner of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art within the technical scope disclosed by the present application can easily think of changes or substitutions, which should all be covered by the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.
[0067] Finally, the above are only the preferred embodiments of the present invention and are not intended to limit the present invention. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present invention shall be included within the protection scope of the present invention.
Claims
1. A method for detecting pesticide residues in traditional Chinese medicine based on artificial intelligence, characterized in that: The steps include: S1, 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; S2, performing gradient amplitude clustering processing on adjacent pixel points in the texture-dense area in the high-resolution image according to the local gradient direction distribution characteristics, and generating 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 residual areas through the Mahalanobis distance classifier; S5, performing spectral analysis on the abnormal residue area, and generating a spectral correlation score reflecting the possibility of pesticide residue by evaluating the matching degree of preset bands; S6. The geometric morphological features and spectral correlation scores of the abnormal residue area are input into the pre-trained classification model to generate the pesticide residue detection results based on nonlinear correlation decision.
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 pixel points in the high-resolution image, 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 the vertical gradient amplitude of the pixel point are calculated respectively by the 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 the 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 pixel points 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, and perform three-layer decomposition respectively to 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 the abnormal residual 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 in 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 eigenvector and the directional entropy eigenvector of the spatial co-occurrence matrix, and 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 Chinese herbal medicines based on artificial intelligence according to claim 1, characterized in that: Spectral analysis is performed on abnormal residue areas, and a spectral correlation score reflecting the possibility of pesticide residue is generated 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; 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.
8. The method for detecting pesticide residues in traditional Chinese medicines based on artificial intelligence according to claim 1, characterized in that: The geometric features of the abnormal residue area and the spectral correlation score are input into the pre-trained classification model to generate pesticide residue detection results 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, and 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 between the output confidence of the support vector machine classification model and the preset threshold, the presence of pesticide residues is determined and the detection results are generated.
9. A Chinese herbal medicine pesticide residue detection system based on artificial intelligence, used to implement the Chinese herbal medicine pesticide residue detection method based on artificial intelligence according to any one of claims 1 to 6, 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 the texture-dense area of the high-resolution image according to the local gradient direction distribution characteristics, and generate a gradient feature map containing the texture edge contour; 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 divide the surface area of Chinese medicinal materials into normal texture area and abnormal residue area through Mahalanobis distance classifier 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; 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 decisions.
10. The artificial intelligence-based Chinese herbal medicine pesticide residue detection medium is characterized by: The medium stores programs or instructions, and when the programs or instructions are executed by the processor, the method for detecting pesticide residues in traditional Chinese medicines based on artificial intelligence as described in any one of claims 1 to 8 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
Metal surface defect detection method, device and equipment and storage medium
CN119125301A
Online quality monitoring method and system based on optical multispectral fusion
CN119198566A
Hyperspectral traditional chinese medicine identification method based on adaptive random block convolutional kernel network
WO2023115682A1
Cited By
Deposit pesticide residue image recognition method based on deep learning
CN120894776A
Sediment pesticide residue image recognition method based on deep learning
CN120894776B
Hyperspectral screening method for pesticide residues of crops
CN121476084A
Method and system for extracting disease and insect pest area of agricultural image based on artificial intelligence
CN122391896A
