Method for detecting quality grade of angelica dahurica medicinal and edible homologous decoction pieces based on ai vision
By decoupling the multidimensional features of Angelica dahurica slices using AI vision technology and performing cross-attention weighted fusion, combined with a multidimensional quality map database, the problem of single feature coupling and fusion methods in the quality grade detection of Angelica dahurica slices is solved, and more accurate quality grade determination is achieved.
Patent Information
- Application Number
- CN202610552600.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-04-24
- Publication Date
- 2026-05-29
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Existing technologies for quality grade detection of Angelica dahurica (a medicinal and edible herb) suffer from issues such as feature coupling, a single fusion method, and a lack of standardized feature cluster matching logic, making it difficult to guarantee the objectivity and accuracy of the test results.
Using an AI vision-based approach, the effective analysis area of Angelica dahurica slices is separated, multidimensional features are extracted and decoupled into feature vectors of appearance, internal texture and potential defects. A hierarchical decision fusion model is used for cross-attention weighted fusion, and similarity retrieval is performed in combination with a multidimensional quality map database to determine the final quality grade.
It enables the independent presentation and precise differentiation of characteristic information for the quality grade detection of Angelica dahurica slices, improves the objectivity and relevance of the test results, and provides a standardized quality evaluation system.
Smart Images

Figure CN122115425A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of AI detection technology for traditional Chinese medicine decoction pieces, and in particular to a method for detecting the quality grade of Angelica dahurica decoction pieces that are both food and medicine based on AI vision. Background Technology
[0002] Currently, the quality grading of Angelica dahurica slices, which are both medicinal and edible, largely relies on a combination of manual sensory evaluation and conventional machine vision inspection. Conventional machine vision inspection only extracts overall features from the Angelica dahurica slice image and directly outputs the quality grade using a single classification model. Some solutions only perform simple segmentation of the slice image and background, extracting superficial visual features before conducting routine classification, without refining image features or establishing a standardized multi-dimensional quality feature reference database. Manual inspection depends on the experience of the inspectors, making it difficult to standardize judgment criteria. Conventional machine vision inspection does not separate the appearance, texture, and defect features of the slices; various visual features are coupled together, making it impossible to accurately distinguish feature information from different quality evaluation dimensions. The feature fusion of conventional models often uses simple splicing or average weighting, which cannot adapt to the weight differences in multi-view quality evaluation and does not employ matching with standard feature clusters to complete the grade determination. Therefore, the objectivity and accuracy of the inspection results are difficult to guarantee.
[0003] To address the issues of feature coupling, single fusion method, and lack of standardized feature cluster matching logic in existing detection methods, it is necessary to independently decouple the multidimensional visual features of Angelica dahurica slices, extracting independent feature vectors corresponding to appearance, internal texture, and potential defects. It is also necessary to construct a parallel sub-network model adapted to multiple quality evaluation perspectives, perform cross-attention weighted fusion on the intermediate results of the model, and rely on a multidimensional quality map database to determine the quality grade of Angelica dahurica slices by matching with the cluster centers of standard feature clusters. Summary of the Invention
[0004] The purpose of this invention is to overcome the shortcomings of the existing technology and propose an AI vision-based method for detecting the quality grade of Angelica dahurica medicinal and edible slices.
[0005] To achieve the above objectives, the present invention adopts the following technical solution: a method for detecting the quality grade of Angelica dahurica (a medicinal and edible herb) slices based on AI vision, comprising:
[0006] Multiple batches of Angelica dahurica slices were collected under standard lighting conditions to form an original image library; Each original digital image of the surface in the original image library is segmented to separate the effective analysis area and the background area of Angelica dahurica slices, and an initial visual feature set is extracted from the effective analysis area. The initial visual feature set includes multidimensional features of texture, color, and shape; The initial visual feature set is processed by a pre-trained decoupling network for medicinal slices, and the multidimensional features are decoupled into appearance feature vector, internal texture feature vector and potential defect feature vector. The appearance feature vector, internal quality feature vector and potential defect feature vector are input into a hierarchical decision fusion model. The hierarchical decision fusion model contains multiple parallel sub-networks, each corresponding to a different quality evaluation perspective. Within the hierarchical decision fusion model, the intermediate results output by each sub-network are cross-attention weighted and fused to generate a comprehensive representation vector; Based on the comprehensive representation vector, a similarity search is performed in a multi-dimensional quality map database. According to the results of the similarity search, the matching degree between the comprehensive representation vector and the cluster center of each standard feature cluster is calculated, and the quality level associated with the standard feature cluster with the highest matching degree is determined as the final quality level of the Angelica dahurica slice.
[0007] As a further aspect of the present invention, each original digital image of a surface in the original image library is subjected to region segmentation to separate the effective analysis region and the background region of the Angelica dahurica slices, and an initial visual feature set is extracted from the effective analysis region, including: By employing a method combining edge detection and region growing, the main outline of the Angelica dahurica slices is located from the original digital image of the surface, and the region inside the outline is marked as the effective analysis region. Multiple sampling rings are uniformly divided radially within the effective analysis area; On each sampling ring, the gray-level co-occurrence matrix is calculated, and energy, entropy, and contrast features are extracted from the matrix to form a local texture feature sequence; Within the entire effective analysis area, the color space is converted, a statistical histogram of pixel values under the specified color channel is calculated, and the main peak position and hue saturation distribution characteristics are extracted from the statistical histogram to form a color feature sequence. The main outline is approximated by a polygon, and its area, perimeter, circularity and Fourier description value are calculated to form a shape feature sequence; The local texture feature sequence, color feature sequence and shape feature sequence are merged to form the initial visual feature set.
[0008] As a further aspect of the present invention, a pre-trained herbal medicine feature decoupling network is used to perform deep processing on the initial visual feature set, including: The decoupling network for medicinal slice features includes a shared encoder and three independent decoders; The shared encoder performs dimensionality reduction and abstraction on the initial visual feature set to obtain a high-dimensional hidden feature representation; The high-dimensional hidden feature representation is simultaneously input into three independent decoders; The first independent decoder is responsible for reconstructing the feature sequence of the surface gloss and color uniformity of the medicinal slices. The reconstructed feature sequence output by the decoder is mapped to become the appearance feature vector. The second independent decoder is responsible for reconstructing the internal structure compactness and fiber orientation local texture feature sequence of the medicinal slices. Its output reconstructed feature sequence is mapped to become the intrinsic texture feature vector. The third independent decoder is responsible for reconstructing the proportion of defective areas in spots, cracks, and moldy areas of the medicinal slices. The reconstructed proportion of defective areas output by the decoder is mapped to become the potential defective feature vector.
[0009] As a further aspect of the present invention, the training process of the pre-trained decoupling network for medicinal slice features includes: Construct a training dataset containing a large number of labeled images of Angelica dahurica slices and their corresponding physicochemical indicators; The initial visual feature set is extracted using images from the training dataset, and the corresponding physicochemical indicators are used as supervision signals. The surface color score is predicted using the appearance feature vector, the density and effective ingredient content are predicted using the internal texture feature vector, and the area ratio of defects is predicted using the potential defect feature vector. Design a multi-task loss function that simultaneously constrains the feature representation capability of the shared encoder and the feature decoupling and prediction capabilities of each independent decoder. The parameters of the decoupling network for medicinal slice features are optimized through backpropagation until the multi-task loss function converges.
[0010] As a further aspect of the present invention, the appearance feature vector, internal quality feature vector, and potential defect feature vector are input into a hierarchical decision fusion model. The hierarchical decision fusion model comprises multiple parallel sub-networks, each corresponding to a different quality evaluation perspective, including: The quality assessment subnetwork takes the appearance feature vector as its input. This subnetwork is composed of stacked fully connected layers and attention layers and is used to output the preliminary grade probability distribution from the perspective of quality. The texture assessment subnetwork takes the intrinsic texture feature vector as its input. The subnetwork structure is the same as the quality assessment subnetwork but the parameters are independent. It is used to output the preliminary grade probability distribution from the perspective of texture. The defect suppression subnetwork takes the potential defect feature vector as its input and consists of convolutional and pooling layers. It is used to output the negative impact weights of defect presence on the decision of each quality level.
[0011] As a further aspect of the present invention, within the hierarchical decision fusion model, the intermediate results output by each sub-network are cross-attention weighted and fused to generate a comprehensive representation vector, including: Key feature tensors are extracted from the intermediate layers of the appearance evaluation subnetwork and the texture evaluation subnetwork, respectively. Calculate the cross-correlation matrix between the key feature tensors, and generate a cross-attention weight map based on the cross-correlation matrix; The final hidden features of the appearance evaluation subnetwork and the final hidden features of the texture evaluation subnetwork are weighted and fused using the cross-attention weight map to obtain the fused features; The suppression coefficient vector is extracted from the output of the defect suppression sub-network, and the suppression coefficient vector is multiplied element-wise with the fused feature to weaken the feature strength corresponding to the defective feature. The weakened features are subjected to global average pooling and linear projection to generate the comprehensive representation vector.
[0012] As a further aspect of the present invention, based on the comprehensive representation vector, similarity retrieval is performed in a multi-dimensional quality graph database, including: The multi-dimensional quality map database pre-stores standard feature clusters corresponding to known quality levels; The multi-dimensional quality map database is constructed through pre-cluster analysis, where each standard feature cluster is formed by clustering the comprehensive characterization vectors of a large number of known grade medicinal slices, and records the cluster center coordinates and associated quality grade of the cluster. Calculate the cosine similarity between the comprehensive characterization vector of the medicinal slice to be tested and the cluster centers of all standard feature clusters in the multi-dimensional quality map database; One or more standard feature clusters with a cosine similarity exceeding a preset threshold are selected as candidate clusters; If multiple candidate clusters exist, the Mahalanobis distance from the comprehensive representation vector to the cluster center of each candidate cluster is calculated for further screening.
[0013] As a further aspect of the present invention, the construction and updating process of the multi-dimensional quality map database includes: Collect samples of Angelica dahurica slices and their images that have been confirmed by authoritative experts or physicochemical tests to be of different quality grades throughout history; For each sample image, perform the entire process from image acquisition to generating a comprehensive representation vector to obtain its corresponding historical comprehensive representation vector; Group all historical composite representation vectors according to their known quality levels; Cluster analysis is performed on the historical comprehensive representation vectors within each group to form multiple sub-clusters. The centroid of each sub-cluster is defined as the cluster center of a standard feature cluster. The cluster center of each sub-cluster, the statistical distribution of its historical comprehensive representation vectors, and the unique quality level information associated with that sub-cluster are all stored in the multi-dimensional quality map database. When new, confirmed samples are added, the grouping and clustering analysis steps are repeated to dynamically update the multidimensional quality map database.
[0014] As a further aspect of the present invention, based on the results of similarity retrieval, the matching degree between the comprehensive representation vector and the cluster centers of each standard feature cluster is calculated, including: For each selected candidate cluster, obtain the statistical distribution information of the candidate cluster stored in the multi-dimensional quality map database; Based on the statistical distribution information, the probability density value of the comprehensive characterization vector relative to the candidate cluster is calculated, and the probability density value is used as the initial matching degree. The preliminary matching degree is calibrated by combining the preliminary grade probability distribution of appearance and texture obtained in the graded decision fusion model. The calibrated matching degree is used as the final matching degree between the comprehensive representation vector and the candidate cluster.
[0015] As a further aspect of the present invention, the quality level associated with the standard feature cluster with the highest matching degree is determined as the final quality level of the Angelica dahurica slices, including: Compare the final matching degree of the comprehensive representation vector with all candidate clusters, and find the target candidate cluster with the highest final matching degree; Read the quality level information associated with the target candidate cluster from the multi-dimensional quality map database; The quality grade information is output as the judgment result to complete the quality grade detection of the current Angelica dahurica slices.
[0016] Compared with the prior art, the advantages and positive effects of the present invention are as follows: The pre-trained decoupling network for medicinal slices performs deep processing on the initial visual feature set, decoupling multi-dimensional features into appearance feature vectors, internal texture feature vectors, and potential defect feature vectors. These three independent feature vectors can isolate the mutual interference between features of different dimensions, allowing the representation content of each feature dimension to correspond to only a single quality evaluation dimension. Feature information related to appearance, texture, and defects can be presented independently, eliminating the confusion of feature information, improving the targeting of feature representation of each dimension, optimizing the refinement and distinguishability of features, and enabling the differences in medicinal slice features under different quality states to be presented more clearly.
[0017] The hierarchical decision fusion model sets up multiple parallel sub-networks corresponding to different quality evaluation perspectives. Within the model, the intermediate results output by each sub-network are cross-attention weighted and fused to form a comprehensive representation vector. The comprehensive representation vector is then searched for similarity in a multi-dimensional quality graph database. The matching degree between this vector and the cluster centers of each standard feature cluster is calculated, and the association level of the standard feature cluster with the highest matching degree is taken as the final quality level. The cross-attention weighted fusion can adjust the weights according to the feature importance of different evaluation perspectives. The fusion of intermediate results from multiple perspectives makes the comprehensive representation vector more in line with the actual quality status of the medicinal slices. The matching method of the cluster centers of standard feature clusters provides a standardized reference system for grade determination. The combination of similarity retrieval and cluster center matching makes the grade determination process more in line with the actual logic of medicinal slice quality grading, thus optimizing the reference and fit of the determination results. Attached Figure Description
[0018] Figure 1 This is a flowchart of the AI vision-based method for detecting the quality grade of Angelica dahurica medicinal and edible slices according to the present invention. Figure 2 A flowchart for deep processing of decoupling network features of medicinal slices; Figure 3 Heatmap of cross-attention weight distribution for the grading decision fusion model of Angelica dahurica slices; Figure 4 Box plot of cosine similarity distribution between standard feature clusters of each quality grade and the samples to be tested; Figure 5 Heatmap of the covariance matrix of the candidate clusters of primary medicinal slices. Detailed Implementation
[0019] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention.
[0020] In the description of this invention, it should be understood that the terms "length," "width," "upper," "lower," "front," "rear," "left," "right," "vertical," "horizontal," "top," "bottom," "inner," and "outer," etc., indicating orientation or positional relationships, are based on the orientation or positional relationships shown in the accompanying drawings and are only for the convenience of describing the invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation, and therefore should not be construed as a limitation of the invention. Furthermore, in the description of this invention, "a plurality of" means two or more, unless otherwise explicitly specified.
[0021] See Figure 1Multiple batches of raw digital images of Angelica dahurica slices under standard lighting conditions were collected to form a raw image library. Each raw digital image in the library was segmented to separate the effective analysis area from the background area. An initial visual feature set was extracted from the effective analysis area. A pre-trained slice feature decoupling network was used to perform deep processing on the initial visual feature set, decoupling the multidimensional features into appearance feature vectors, internal texture feature vectors, and potential defect feature vectors. These vectors were then input into a hierarchical decision fusion model, which contains multiple parallel sub-networks corresponding to different quality evaluation perspectives. Within the hierarchical decision fusion model, the intermediate results output by each sub-network were cross-attention weighted and fused to generate a comprehensive representation vector. Based on this comprehensive representation vector, a similarity search was performed in a multi-dimensional quality map database. The matching degree between the comprehensive representation vector and the cluster centers of each standard feature cluster was calculated based on the similarity search results. The quality level associated with the standard feature cluster with the highest matching degree was determined as the final quality level of the Angelica dahurica slice.
[0022] In one embodiment of the present invention, the initial visual feature set includes multidimensional features of texture, color, and shape. A method combining edge detection and region growing is used to locate the main outline of the Angelica dahurica slices from the original digital image of the surface, and the region inside the outline is marked as the effective analysis area. In some embodiments, edge detection can employ the Canny algorithm, and the seed points of the region growing algorithm can be automatically selected within the outline based on the edge detection results. Iterative growth fills the entire slice area, effectively separating the background. Within the effective analysis area, multiple sampling rings are uniformly divided radially. The width of each sampling ring is adaptively determined according to the slice size, and the division direction radiates from the outline center to the edge to ensure coverage of different regions from the medulla to the cortex.
[0023] In practical implementation, a gray-level co-occurrence matrix (GLCM) is calculated for each sampling ring. This GLCM is constructed based on the co-occurrence frequency of gray values for pixel pairs at specific directions and distances. Energy, entropy, and contrast features are extracted from the GLCM to form a local texture feature sequence. Energy features reflect the uniformity of the image's gray-level distribution, entropy features characterize the randomness and complexity of the texture, and contrast features measure the degree of variation in local gray levels within the image. These features describe the texture structure within the sampling ring from different dimensions. The local texture features of all sampling rings are arranged sequentially to form a local texture feature sequence. Within the overall effective analysis area, the color space is converted from RGB to HSV. A statistical histogram of pixel values is calculated for the specified color channels, including hue and saturation channels. The main peak position and hue / saturation distribution features are extracted from the statistical histogram to form a color feature sequence. The main peak position corresponds to the pixel value corresponding to the maximum peak value in the statistical histogram, reflecting the main hue of the herbal color. The hue / saturation distribution features are obtained by calculating the cumulative distribution within a specific interval of the histogram, describing the concentration of the color distribution.
[0024] In some embodiments, the optional color space also includes the Lab color space, used to extract color features that better match human visual perception. The main outline is approximated using polygons, and the Douglas-Peucker algorithm is used to simplify the outline points, calculating their area, perimeter, circularity, and Fourier descriptor values to form a shape feature sequence. The area and perimeter of the polygonally approximated shape are calculated using the simplified vertex coordinates, the circularity is calculated using the relationship between area and perimeter, and the Fourier descriptor is obtained by performing a discrete Fourier transform on the outline point coordinates and selecting the low-frequency components. These geometric and spectral features together describe the macroscopic shape and outline complexity of the medicinal slices. The formula for calculating circularity is as follows:
[0025] Where: symbol Indicates roundness, symbol This represents the area of the effective analytical region of Angelica dahurica slices calculated after polygon approximation, with the symbol […]. This represents the perimeter of the effective analysis area of the Angelica dahurica slices calculated after polygon approximation. It can be understood that the local texture feature sequence, color feature sequence, and shape feature sequence are merged to form an initial visual feature set. The merging operation uses vector concatenation, connecting the feature values of different sequences in a predetermined order into a high-dimensional feature vector.
[0026] In one embodiment of the present invention, see [reference] Figure 2The pre-trained decoupling network for medicinal slice features includes a shared encoder and three independent decoders. The shared encoder performs dimensionality reduction and abstraction on the initial visual feature set to obtain a high-dimensional hidden feature representation, which is simultaneously input into the three independent decoders. The shared encoder can be composed of multiple fully connected layers, batch normalization layers, and activation function layers stacked alternately, with the dimension of the high-dimensional hidden feature representation being lower than the dimension of the initial visual feature set. The first independent decoder is responsible for reconstructing the feature sequences of the surface gloss and color uniformity of the medicinal slices. Its output reconstructed feature sequence is mapped to become the appearance feature vector. The second independent decoder is responsible for reconstructing the feature sequences of the internal structure compactness and fiber orientation of the medicinal slices. Its output reconstructed feature sequence is mapped to become the internal texture feature vector. The third independent decoder is responsible for reconstructing the proportion of defective areas such as spots, cracks, and moldy areas of the medicinal slices. Its output reconstructed defective area proportion is mapped to become the potential defect feature vector. The structures of the three independent decoders can be the same or similar, but their parameters are independent and not shared.
[0027] In some embodiments, the optional decoder structure may include a reverse fully connected layer or an upsampling layer for recovering feature information from a specific perspective from a high-dimensional hidden feature representation. A training dataset containing a large number of labeled Angelica dahurica slice images and corresponding physicochemical indicators is constructed. The physicochemical indicators associated with each Angelica dahurica slice image in the training dataset include at least surface color score, density, effective ingredient content, and defect area percentage. An initial visual feature set is extracted from the images in the training dataset, and the corresponding physicochemical indicators are used as supervisory signals. The surface color score is predicted using the appearance feature vector, the density and effective ingredient content are predicted using the internal texture feature vector, and the defect area percentage is predicted using the potential defect feature vector. The surface color score can be obtained by experts scoring according to a standard color chart; density is measured using the water displacement method; effective ingredient content is determined by high-performance liquid chromatography; and the defect area percentage is calculated statistically from the pixels of the labeled defective areas.
[0028] In practical implementation, a multi-task loss function is designed, which simultaneously constrains the feature representation ability of the shared encoder and the feature decoupling and prediction capabilities of each independent decoder. The multi-task loss function can include a reconstruction loss term and a prediction loss term. The reconstruction loss term measures the difference between the reconstructed features output by the independent decoder and the original features extracted from the original image at the corresponding viewpoint. The prediction loss term measures the difference between the physicochemical index values predicted from the decoupled feature vector and the true labeled values. It can be understood that the reconstruction loss can use mean squared error, the prediction loss can use smoothed L1 loss, and the multi-task loss function is a weighted sum of the various losses. All parameters of the herbal slice feature decoupling network are optimized through backpropagation until the multi-task loss function converges. The optimization algorithm can use the Adam optimizer, and the learning rate can employ an exponential decay strategy. The overall expression of the multi-task loss function is as follows:
[0029] Where: symbol Represents the total loss value of the multi-task loss function, symbol The symbol represents the reconstruction loss shared by the shared encoder and all independent decoders. This represents the total prediction loss generated by predicting physicochemical indicators using the appearance feature vector, internal texture feature vector, and potential defect feature vector, respectively. The symbol is... It is a reconstruction loss term The weighting coefficients, sign It is the predicted loss item The weighting coefficients.
[0030] In one embodiment of the present invention, the hierarchical decision fusion model includes multiple parallel sub-networks, each corresponding to a different quality evaluation perspective. These include a condition assessment sub-network, whose input is an appearance condition feature vector. The condition assessment sub-network is composed of stacked fully connected layers and attention layers, and outputs a preliminary grade probability distribution from the condition perspective. The texture assessment sub-network receives an intrinsic texture feature vector as input. The texture assessment sub-network has the same structure as the condition assessment sub-network but independent parameters, and outputs a preliminary grade probability distribution from the texture perspective. The defect suppression sub-network receives a potential defect feature vector as input. The defect suppression sub-network is composed of convolutional layers and pooling layers, and outputs the negative impact weights of defect presence on each quality grade decision. In some embodiments, the attention layer can be a self-attention mechanism or a multi-head attention mechanism, used to capture the dependencies within the features. The combination of convolutional layers and pooling layers is used to extract spatial context information from the potential defect feature vector and generate a suppression coefficient vector with the same number of dimensions as the quality grades.
[0031] In practical implementation, within the hierarchical decision fusion model, the intermediate results output by each sub-network are cross-attention weighted and fused to generate a comprehensive representation vector. Specifically, this involves extracting key feature tensors from the intermediate layers of the appearance assessment sub-network and the texture assessment sub-network. These key feature tensors can come from the outputs before the last fully connected layer or attention layer in the sub-network. The cross-correlation matrix between the key feature tensors is calculated, and a cross-attention weight map is generated based on this matrix. The cross-correlation matrix is obtained by calculating the dot product between each feature element in one key feature tensor and all feature elements in the other key feature tensor. The final hidden features of the appearance assessment sub-network and the texture assessment sub-network are weighted and fused using the cross-attention weight map to obtain the fused features. A suppression coefficient vector is extracted from the output of the defect suppression sub-network, and element-wise multiplication is performed between this vector and the fused features to weaken the feature strength corresponding to the defective features. Global average pooling and linear projection are then applied to the weakened features to generate the comprehensive representation vector. The linear projection operation is implemented through a fully connected layer, mapping the pooled features to a fixed-dimensional vector space.
[0032] In some embodiments, the optional method for generating the cross-attention weight map can employ scaled dot product attention computation. The calculation of the cross-attention weight map can be expressed as:
[0033] Where: symbol The generated cross-attention weight graph matrix is represented by the symbol. The query matrix is obtained by linearly transforming the key feature tensor of the condition assessment subnetwork. The symbol is... The key matrix is obtained by linearly transforming the key feature tensor of the texture evaluation subnetwork. The symbol is... The transpose operation of a matrix is represented by the symbol. Representing the query matrix Bond matrix Feature dimensions, symbols Indicates the feature dimension Performs square root operation; softmax indicates a normalized exponential function operation along the specified dimension. Optional, key matrix. With query matrix The roles can be interchanged for computation. In practice, a cross-attention weight graph is used. The weighting operation on the final hidden features can be represented by transforming the final hidden features of the quality assessment sub-network with a weighted graph matrix, and then concatenating or adding them with the final hidden features of the appearance assessment sub-network.
[0034] See Figure 3This study presents the weight distribution patterns between different attention types and the quality grades of Angelica dahurica slices. The vertical dimension defines four attention interaction modes: appearance → texture (the guiding weight of appearance features on texture features), texture → appearance (the guiding weight of texture features on appearance features), appearance self-attention (internal dependency of appearance features), and texture self-attention (internal dependency of texture features). The horizontal dimension corresponds to four quality grades of the slices: premium, grade one, grade two, and grade three. Numerical distribution reveals that self-attention weights exhibit strong intra-grade coupling characteristics: the self-attention weights for each quality grade remain in the range of 0.80 to 0.99. Specifically, the cross-attention weights for appearance → texture (0.98 / 0.95) and texture → appearance (0.95 / 0.99) between premium and grade one are close to their peak values, indicating a strong interdependence between appearance and texture features in high-grade slices, maintaining high synergy even after feature decoupling. Cross-grade attention weights show a gradient change with quality decay: from premium to grade three, the cross-attention weights for appearance → texture and texture → appearance... The weights gradually decreased from 0.98-0.99 to 0.60-0.65, reflecting the weakened correlation between appearance and texture characteristics in lower-grade medicinal slices. The model relied more on single-perspective self-attention to complete feature modeling. Self-attention and cross-attention formed a complementary decision logic: in the second and third quality levels, the weights of appearance self-attention (0.98 / 0.80) and texture self-attention (0.80 / 0.99) were significantly higher than the corresponding cross-attention weights. This indicates that when the cross-feature correlation weakened, the model maintained the integrity and discriminativeness of feature expression by strengthening the self-attention mechanism within a single feature. The heatmap provides a quantitative basis for the effectiveness of the cross-attention weighted fusion strategy in the hierarchical decision fusion model, intuitively revealing the differences in the interaction patterns between appearance and texture characteristics under different quality levels, and providing a visual reference for model parameter optimization and dynamic adjustment of the attention mechanism.
[0035] In one embodiment of the present invention, a multi-dimensional quality map database pre-stores standard feature clusters corresponding to known quality levels. The cosine similarity between the comprehensive characterization vector of the sample to be tested and the cluster centers of all standard feature clusters in the multi-dimensional quality map database is calculated. Cosine similarity measures the difference in direction between two vectors. One or more standard feature clusters with a cosine similarity exceeding a preset threshold are selected as candidate clusters. The preset threshold is determined based on historical data during the model validation phase and is used to initially screen standard feature clusters that are similar in direction to the sample to be tested. If multiple candidate clusters exist, the Mahalanobis distance from the comprehensive characterization vector to the cluster center of each candidate cluster is calculated for further screening. The Mahalanobis distance considers the covariance structure of the feature vectors and can more accurately reflect the true distance between the sample to be tested and the distribution of feature clusters.
[0036] In some embodiments, the preset threshold can be set to 0.85, and the Mahalanobis distance is calculated based on the covariance matrix of the corresponding candidate cluster stored in the database. The construction and updating process of the multi-dimensional quality map database includes collecting samples of Angelica dahurica slices and their images that have been confirmed by authoritative experts or physicochemical testing as having different quality grades in the past. For each sample image, the entire process from image acquisition to the generation of a comprehensive characterization vector is performed to obtain its corresponding historical comprehensive characterization vector. All historical comprehensive characterization vectors are grouped according to their known quality grades, for example, into groups such as "Special Grade", "First Grade", "Second Grade", and "General Grade". Cluster analysis is performed on the historical comprehensive characterization vectors within each group to form multiple sub-clusters. The cluster analysis can use the K-means algorithm or the DBSCAN algorithm, and the centroid of each sub-cluster is defined as the cluster center of a standard feature cluster. The cluster center of each sub-cluster, the statistical distribution of its contained historical comprehensive characterization vectors, and the unique quality grade information associated with the sub-cluster are jointly stored in the multi-dimensional quality map database. When new, confirmed samples are added, the grouping and clustering analysis steps are re-executed to dynamically update the multidimensional quality map database. The update operation can be set to be performed in batches periodically or triggered after a certain number of new samples are reached.
[0037] In practice, calculating cosine similarity is the first step in the retrieval process. The formula for calculating the cosine similarity between the comprehensive representation vector and the cluster centers of the standard feature clusters is as follows:
[0038] Where: symbol The cosine similarity value between the comprehensive representation vector of the medicinal slice to be tested and the cluster center of the c-th standard feature cluster in the database is represented by the symbol. This represents the comprehensive characterization vector of the medicinal slices to be tested, with the symbol... This represents the cluster center vector of the c-th standard feature cluster stored in the multidimensional quality map database, with the symbol... The dot product operation of vectors is represented by the symbol. Represents the comprehensive representation vector The Euclidean norm, symbol Represents the cluster center vector The Euclidean norm. Optionally, similarity comparisons can also use Euclidean distance, but cosine similarity is not sensitive to the absolute numerical value of vectors, focusing more on similarities and differences along feature directions. All... After the value is calculated, it will be compared with a preset threshold to filter candidate clusters. See Table 1.
[0039] Table 1: Example fragment of a multi-dimensional quality map database
[0040] Table 1 shows an example of the storage information for some standard feature clusters in the multidimensional quality map database. Optionally, in some embodiments, the database also stores the covariance matrix or variance vector of each standard feature cluster's historical comprehensive representation vector for subsequent calculation of Mahalanobis distance. The formula for calculating Mahalanobis distance is as follows:
[0041] Where: symbol The Mahalanobis distance from the comprehensive representation vector of the tested medicinal slice to the center of the c-th candidate cluster is denoted by the symbol. This represents the comprehensive characterization vector of the medicinal slices to be tested, with the symbol... Let the cluster center vector of the c-th candidate cluster be denoted by the symbol . The transpose operation of a vector is represented by the symbol. Let represent the covariance matrix of the c-th candidate cluster stored in the multidimensional quality map database, denoted by . Represents the covariance matrix The inverse matrix. It can be understood that the Mahalanobis distance calculation considers the correlation between features, when the covariance matrix... When the matrix is an identity matrix, the Mahalanobis distance is equivalent to the Euclidean distance. The Mahalanobis distances for each candidate cluster are calculated. Then, the candidate cluster with the smallest distance can be selected for further analysis.
[0042] See Figure 4In the AI vision-based method for detecting the quality grade of Angelica dahurica (a medicinal and edible herb), the statistical analysis of the cosine similarity distribution between the tested sample and the standard feature clusters of each quality grade can be visually presented in this figure. The figure uses a box plot to show the statistical distribution of the cosine similarity between the standard feature clusters of the four quality grades—"Special Grade," "First Grade," "Second Grade," and "General Grade"—and the tested sample. The red dashed line marks the baseline value of the cosine similarity of the tested sample (1.00), used to visually compare the matching degree between the tested sample and the feature clusters of each grade: Special Grade: The median cosine similarity is approximately 0.92, and the interquartile range is concentrated in the 0.90–0.93 interval. The overall distribution is closest to the baseline and has the smallest dispersion, indicating that the tested sample has the highest consistency in feature direction and the strongest matching stability with the Special Grade standard feature cluster. First-tier level: The median cosine similarity is approximately 0.87, and the interquartile range is 0.84–0.89. Its distribution position and dispersion are both lower than the top-tier level, indicating that the tested sample still maintains a high degree of matching with the first-tier feature cluster, but the consistency of feature direction is weaker than that of the top-tier level. Second-tier level: The median cosine similarity is approximately 0.81, and the interquartile range is 0.77–0.83. The distribution shifts further downwards, and the dispersion increases somewhat, with a significantly lower matching degree than the first two levels. Mixed goods level: The median cosine similarity is approximately 0.72, and the interquartile range is 0.69–0.76. This is the group with the distribution furthest from the baseline and the greatest dispersion among the four levels, indicating that the tested sample has the most significant difference in feature direction and the lowest matching degree with the mixed goods standard feature cluster. The statistical distribution pattern suggests that the cosine similarity between the comprehensive representation vector of the sample under test and the special-grade standard feature cluster is the highest and most concentrated among all grades. Combined with the preset threshold screening rules, the sample is more likely to be judged as a special-grade quality. At the same time, the median gradient change of the box plots of each grade (special grade > first grade > second grade > general grade) also verifies the discriminative power of the feature clusters of different grades in the multi-dimensional quality map database and the effectiveness of the hierarchical logic.
[0043] In one embodiment of the present invention, based on the similarity retrieval results, the matching degree between the comprehensive characterization vector and the cluster centers of each standard feature cluster is calculated. For each selected candidate cluster, the statistical distribution information of the candidate cluster stored in the multi-dimensional quality map database is obtained. The statistical distribution information includes the mean vector and covariance matrix of all historical comprehensive characterization vectors within the candidate cluster. Based on the statistical distribution information, the probability density value of the comprehensive characterization vector relative to the candidate cluster is calculated, and the probability density value is used as the preliminary matching degree. Combining the preliminary grade probability distribution of appearance and texture obtained in the hierarchical decision fusion model, the preliminary matching degree is calibrated, and the calibrated matching degree is used as the final matching degree between the comprehensive characterization vector and the candidate cluster. The final matching degrees of the comprehensive characterization vector and all candidate clusters are compared, and the target candidate cluster with the highest final matching degree is found. The quality grade information associated with the target candidate cluster is read from the multi-dimensional quality map database, and the quality grade information is output as the judgment result, thus completing the quality grade detection of the current Angelica dahurica slices.
[0044] In some embodiments, the statistical distribution information of candidate clusters assumes that their historical comprehensive representation vectors follow a multidimensional normal distribution, and the probability density values are calculated based on the probability density function of a multidimensional Gaussian distribution. The preliminary grade probability distribution comes from the appearance assessment subnetwork and the texture assessment subnetwork in the hierarchical decision fusion model, and is a probability vector in two dimensions. The calibration operation can be represented by weighted fusion of the preliminary matching degree with the preliminary probability values of the corresponding candidate clusters associated with the quality grades from the appearance assessment subnetwork and the texture assessment subnetwork. It can be understood that the comprehensive representation vector... Compared to the first probability density values of candidate clusters The calculation formula is as follows:
[0045] Where: symbol The comprehensive representation vector is relative to the first... The initial matching degree (probability density value) of each candidate cluster, symbol This represents the comprehensive characterization vector of the Angelica dahurica slices to be tested, with the symbol... This represents the first dimension of the multidimensional quality map database. The mean vector (i.e., cluster center) of each candidate cluster, denoted by . Indicates the first The covariance matrix of candidate clusters, denoted by . Represents the covariance matrix Determinant, symbol Represents the covariance matrix The inverse matrix, symbol Represents the comprehensive representation vector Dimensions, symbols Pi (π) is represented by the symbol π. Represents the natural exponential function, symbol This represents the transpose operation of a vector. The calculated probability density value is... This is used directly as the initial matching score.
[0046] In practical implementation, the initial matching degree The calibration is achieved through a calibration function, which receives the initial matching degree. The output of the quality assessment sub-network is aimed at the first The probability value of the associated quality level of each candidate cluster And the probability values for the same level output by the texture evaluation subnetwork. Final matching degree after calibration The calculation method involves taking the geometric mean or weighted arithmetic mean of these three items. For example, a feasible calibration method is to calculate the weighted arithmetic mean:
[0047] in: These are the weight coefficients for each item, and their sum is 1. Optionally, the weight coefficients can be set based on the reliability of different evaluation perspectives, or optimized through a validation set during model training. Compare the final matching degrees of all candidate clusters. Find the maximum value The corresponding candidate clusters are used as target candidate clusters. In some embodiments, if the difference between the highest final matching degree and the second highest final matching degree is less than a preset minimum threshold, a review mechanism can be triggered, such as outputting "pending" or simultaneously outputting two associated quality levels for manual reference.
[0048] See Figure 5The figure presents the linear correlation and variance contribution of eight core visual features. The values on the diagonal represent the variance of each feature, reflecting the dispersion of the features themselves: Feature 6 has the largest variance (3.38), indicating that its distribution in the sample set is the most dispersed and its contribution to the overall feature space is the strongest; Features 1 (2.53), 3 (2.59), 4 (2.69), 5 (2.64), 7 (2.34), and 8 (2.69) are next, and Feature 2 (2.77) also has a high variance, indicating that all features carry strong discriminative information. The off-diagonal elements represent the covariance between features, directly reflecting the linear correlation between pairs of features: positive values represent positive correlation, negative values represent negative correlation, and the larger the absolute value, the stronger the correlation. For example, features 2 and 5 (0.29) and features 3 and 4 (0.27) show strong positive correlations, while features 3 and 5 (-0.26), features 4 and 7 (-0.31), and features 2 and 8 (-0.30) show significant negative correlations. This correlation information provides a crucial basis for the subsequent construction of feature clusters and the removal of redundant features: highly correlated features can be integrated into the same feature cluster to reduce dimensionality and retain core discriminative information, while weakly correlated or negatively correlated features help improve the discriminative power of the feature clusters. In the construction of the multi-dimensional quality map database, this covariance matrix will be directly used to calculate the Mahalanobis distance between the comprehensive characterization vector of the tested medicinal slices and the cluster centers of the candidate clusters, to more accurately measure the distribution differences of samples in the feature space, thereby improving the reliability of quality grade matching.
[0049] The above are merely preferred embodiments of the present invention and are not intended to limit the present invention in any other way. Any person skilled in the art may make changes or modifications to the above-disclosed technical content to create equivalent embodiments that can be applied to other fields. However, any simple modifications, equivalent changes, and modifications made to the above embodiments based on the technical essence of the present invention without departing from the scope of the present invention shall still fall within the protection scope of the present invention.
Claims
1. A method for detecting the quality grade of Angelica dahurica (a medicinal and edible herb) slices based on AI vision, characterized in that, The method includes: Multiple batches of Angelica dahurica slices were collected under standard lighting conditions to form an original image library; Each original digital image of the surface in the original image library is segmented to separate the effective analysis area and the background area of Angelica dahurica slices, and an initial visual feature set is extracted from the effective analysis area. The initial visual feature set includes multidimensional features of texture, color, and shape; The initial visual feature set is processed by a pre-trained decoupling network for medicinal slices, and the multidimensional features are decoupled into appearance feature vector, internal texture feature vector and potential defect feature vector. The appearance feature vector, internal quality feature vector and potential defect feature vector are input into a hierarchical decision fusion model. The hierarchical decision fusion model contains multiple parallel sub-networks, each corresponding to a different quality evaluation perspective. Within the hierarchical decision fusion model, the intermediate results output by each sub-network are cross-attention weighted and fused to generate a comprehensive representation vector; Based on the comprehensive representation vector, a similarity search is performed in a multi-dimensional quality map database. According to the results of the similarity search, the matching degree between the comprehensive representation vector and the cluster center of each standard feature cluster is calculated, and the quality level associated with the standard feature cluster with the highest matching degree is determined as the final quality level of the Angelica dahurica slice.
2. The method for detecting the quality grade of Angelica dahurica (a medicinal and edible herb) slices based on AI vision as described in claim 1, characterized in that, For each raw digital image of a surface in the original image library, region segmentation is performed to separate the effective analysis region and the background region of the Angelica dahurica slices. An initial visual feature set is then extracted from the effective analysis region, including: By employing a method combining edge detection and region growing, the main outline of the Angelica dahurica slices is located from the original digital image of the surface, and the region inside the outline is marked as the effective analysis region. Multiple sampling rings are uniformly divided radially within the effective analysis area; On each sampling ring, the gray-level co-occurrence matrix is calculated, and energy, entropy, and contrast features are extracted from the matrix to form a local texture feature sequence; Within the entire effective analysis area, the color space is converted, a statistical histogram of pixel values under the specified color channel is calculated, and the main peak position and hue saturation distribution characteristics are extracted from the statistical histogram to form a color feature sequence. The main outline is approximated by a polygon, and its area, perimeter, circularity and Fourier description value are calculated to form a shape feature sequence; The local texture feature sequence, color feature sequence and shape feature sequence are merged to form the initial visual feature set.
3. The method for detecting the quality grade of Angelica dahurica (a medicinal and edible herb) slices based on AI vision as described in claim 2, characterized in that, The initial visual feature set is processed using a pre-trained herbal slice feature decoupling network, including: The decoupling network for medicinal slice features includes a shared encoder and three independent decoders; The shared encoder performs dimensionality reduction and abstraction on the initial visual feature set to obtain a high-dimensional hidden feature representation; The high-dimensional hidden feature representation is simultaneously input into three independent decoders; The first independent decoder is responsible for reconstructing the feature sequence of the surface gloss and color uniformity of the medicinal slices. The reconstructed feature sequence output by the decoder is mapped to become the appearance feature vector. The second independent decoder is responsible for reconstructing the internal structure compactness and fiber orientation local texture feature sequence of the medicinal slices. Its output reconstructed feature sequence is mapped to become the intrinsic texture feature vector. The third independent decoder is responsible for reconstructing the proportion of defective areas in spots, cracks, and moldy areas of the medicinal slices. The reconstructed proportion of defective areas output by the decoder is mapped to become the potential defective feature vector.
4. The method for detecting the quality grade of Angelica dahurica (a medicinal and edible herb) slices based on AI vision as described in claim 3, characterized in that, The training process of the pre-trained decoupling network for medicinal slice features includes: Construct a training dataset containing a large number of labeled images of Angelica dahurica slices and their corresponding physicochemical indicators; The initial visual feature set is extracted using images from the training dataset, and the corresponding physicochemical indicators are used as supervision signals. The surface color score is predicted using the appearance feature vector, the density and effective ingredient content are predicted using the internal texture feature vector, and the area ratio of defects is predicted using the potential defect feature vector. Design a multi-task loss function that simultaneously constrains the feature representation capability of the shared encoder and the feature decoupling and prediction capabilities of each independent decoder. The parameters of the decoupling network for medicinal slice features are optimized through backpropagation until the multi-task loss function converges.
5. The method for detecting the quality grade of Angelica dahurica (a medicinal and edible herb) slices based on AI vision as described in claim 4, characterized in that, The appearance feature vector, internal quality feature vector, and potential defect feature vector are input into a hierarchical decision fusion model. This model contains multiple parallel sub-networks, each corresponding to a different quality evaluation perspective, including: The quality assessment subnetwork takes the appearance feature vector as its input. This subnetwork is composed of stacked fully connected layers and attention layers and is used to output the preliminary grade probability distribution from the perspective of quality. The texture assessment subnetwork takes the intrinsic texture feature vector as its input. The subnetwork structure is the same as the quality assessment subnetwork but the parameters are independent. It is used to output the preliminary grade probability distribution from the perspective of texture. The defect suppression subnetwork takes the potential defect feature vector as its input and consists of convolutional and pooling layers. It is used to output the negative impact weights of defect presence on the decision of each quality level.
6. The method for detecting the quality grade of Angelica dahurica (a medicinal and edible herb) slices based on AI vision as described in claim 5, characterized in that, Within the hierarchical decision fusion model, the intermediate results output by each sub-network are cross-attention weighted and fused to generate a comprehensive representation vector, including: Key feature tensors are extracted from the intermediate layers of the appearance evaluation subnetwork and the texture evaluation subnetwork, respectively. Calculate the cross-correlation matrix between the key feature tensors, and generate a cross-attention weight map based on the cross-correlation matrix; The final hidden features of the appearance evaluation subnetwork and the final hidden features of the texture evaluation subnetwork are weighted and fused using the cross-attention weight map to obtain the fused features; The suppression coefficient vector is extracted from the output of the defect suppression sub-network, and the suppression coefficient vector is multiplied element-wise with the fused feature to weaken the feature strength corresponding to the defective feature. The weakened features are subjected to global average pooling and linear projection to generate the comprehensive representation vector.
7. The method for detecting the quality grade of Angelica dahurica (a medicinal and edible herb) slices based on AI vision as described in claim 6, characterized in that, Based on the comprehensive representation vector, a similarity search is performed in a multi-dimensional quality graph database, including: The multi-dimensional quality map database pre-stores standard feature clusters corresponding to known quality levels; The multi-dimensional quality map database is constructed through pre-cluster analysis, where each standard feature cluster is formed by clustering the comprehensive characterization vectors of a large number of known grade medicinal slices, and records the cluster center coordinates and associated quality grade of the cluster. Calculate the cosine similarity between the comprehensive characterization vector of the medicinal slice to be tested and the cluster centers of all standard feature clusters in the multi-dimensional quality map database; One or more standard feature clusters with a cosine similarity exceeding a preset threshold are selected as candidate clusters; If multiple candidate clusters exist, the Mahalanobis distance from the comprehensive representation vector to the cluster center of each candidate cluster is calculated for further screening.
8. The method for detecting the quality grade of Angelica dahurica (a medicinal and edible herb) slices based on AI vision as described in claim 7, characterized in that, The construction and updating process of the multi-dimensional quality map database includes: Collect samples of Angelica dahurica slices and their images that have been confirmed by authoritative experts or physicochemical tests to be of different quality grades throughout history; For each sample image, perform the entire process from image acquisition to generating a comprehensive representation vector to obtain its corresponding historical comprehensive representation vector; Group all historical composite representation vectors according to their known quality levels; Cluster analysis is performed on the historical comprehensive representation vectors within each group to form multiple sub-clusters. The centroid of each sub-cluster is defined as the cluster center of a standard feature cluster. The cluster center of each sub-cluster, the statistical distribution of its historical comprehensive representation vectors, and the unique quality level information associated with that sub-cluster are all stored in the multi-dimensional quality map database. When new, confirmed samples are added, the grouping and clustering analysis steps are repeated to dynamically update the multidimensional quality map database.
9. The method for detecting the quality grade of Angelica dahurica (a medicinal and edible herb) slices based on AI vision as described in claim 8, characterized in that, Based on the similarity retrieval results, the matching degree between the comprehensive representation vector and the cluster centers of each standard feature cluster is calculated, including: For each selected candidate cluster, obtain the statistical distribution information of the candidate cluster stored in the multi-dimensional quality map database; Based on the statistical distribution information, the probability density value of the comprehensive characterization vector relative to the candidate cluster is calculated, and the probability density value is used as the initial matching degree. The preliminary matching degree is calibrated by combining the preliminary grade probability distribution of appearance and texture obtained in the graded decision fusion model. The calibrated matching degree is used as the final matching degree between the comprehensive representation vector and the candidate cluster.
10. The method for detecting the quality grade of Angelica dahurica (a medicinal and edible herb) slices based on AI vision as described in claim 9, characterized in that, The quality level associated with the standard feature cluster with the highest matching degree is determined as the final quality level of the Angelica dahurica slice, including: Compare the final matching degree of the comprehensive representation vector with all candidate clusters, and find the target candidate cluster with the highest final matching degree; Read the quality level information associated with the target candidate cluster from the multi-dimensional quality map database; The quality grade information is output as the judgment result to complete the quality grade detection of the current Angelica dahurica slices.