A ginseng grade classification method based on hyperspectral two-dimensional angle field fusion
Patent Information
- Application Number
- CN202611156405.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-31
- Publication Date
- 2026-10-20
AI Technical Summary
然而,现有高光谱人参分类方法多以一维光谱序列、特征波长筛选和传统机器学习模型为主,通常关注单个波段或局部波段组合的反射率变化,对波段间全局相关关系、光谱曲线整体结构以及深层判别信息利用不足
其一,本发明将一维高光谱序列转换为二维角场图像,使光谱变化趋势、波段间全局相关关系和波段差异关系能够以图像结构形式表达,增强了高光谱数据的深层特征表达能力。
Smart Images

Figure FT_1 
Figure FT_2 
Figure SMS_1
Abstract
Description
Technical Field
[0001] This invention relates to the fields of quality evaluation of Chinese medicinal materials, hyperspectral data processing, and deep learning classification technology, and in particular to a method for classifying ginseng grades using hyperspectral reflectance data, Gram angle field two-dimensional coding, dual-channel convolutional neural network, and CBAM attention mechanism. Background Technology
[0002] Ginseng is an important traditional Chinese medicinal material and a plant used for both food and medicine. Its grade is usually closely related to its appearance, internal components, tissue structure, and economic value. Traditional ginseng grading mainly relies on manual experience, observation of appearance, or a small number of physicochemical tests. This has problems such as strong subjectivity, low testing efficiency, inconsistent evaluation standards, and difficulty in large-scale application, making it difficult to meet the needs of rapid and objective grading for the circulation and intelligent quality control of Chinese medicinal materials.
[0003] Hyperspectral technology can acquire sample reflectance information across a continuous wavelength range, reflecting differences in color, tissue structure, moisture state, and chemical composition. It has been increasingly applied to scenarios such as ginseng age identification, disease detection, origin identification, and quality evaluation. However, existing hyperspectral ginseng classification methods primarily rely on one-dimensional spectral sequences, characteristic wavelength screening, and traditional machine learning models. These methods typically focus on reflectance changes in single or local band combinations, failing to adequately utilize global correlations between bands, the overall structure of the spectral curve, and deeper discriminative information.
[0004] Because the quality differences between different grades of ginseng are subtle, samples from adjacent grades may have high similarity in appearance and spectral response. Relying solely on one-dimensional spectral features or a single two-dimensional representation can easily lead to incomplete feature representation and misclassification between categories. Therefore, it is necessary to provide a classification method that can convert one-dimensional hyperspectral sequences into two-dimensional feature maps with greater structural expressive power and can integrate complementary information from different angular fields to improve the accuracy and stability of ginseng grade classification. Summary of the Invention
[0005] The purpose of this invention is to provide a ginseng grade classification method, system, and storage medium based on hyperspectral two-dimensional angular field fusion. By converting the one-dimensional hyperspectral sequence of ginseng into GASF and GADF images respectively, and performing channel-level pairing fusion of the two types of angular field images of the same sample, combined with CNN deep feature extraction and CBAM attention enhancement, a rapid and objective grade identification of subtle differences in ginseng grades can be achieved.
[0006] To achieve the above objectives, the present invention adopts the following technical solution.
[0007] S1: Obtain the hyperspectral reflectance data of the ginseng sample to be classified, and construct a one-dimensional spectral sequence according to wavelength order. The hyperspectral reflectance data can be acquired by a ground-based spectrometer or a hyperspectral imaging device, preferably with an acquisition range of 350–2500 nm.
[0008] S2: Preprocess the one-dimensional spectral sequence. The preprocessing includes: screening effective bands based on the effective response range of the spectrometer and the stability of the spectral curve, preferably retaining the 400–2400 nm range; performing linear interpolation correction on missing values or abnormal fluctuation points; using Savitzky-Golay smoothing filtering to reduce random noise; and normalizing the processed spectral data to the [-1,1] interval.
[0009] S3: The Gram angular field method is used to convert the preprocessed spectral sequence into a two-dimensional angular field image. Specifically, the normalized spectral sequence is mapped to angular space, and Gram angular field sum field (GASF) images and Gram angular difference field (GADF) images are constructed respectively.
[0010] S4: Align and channel-level fuse the GASF and GADF images corresponding to the same sample to form a dual-channel GAF feature map, enabling the model to simultaneously utilize the overall spectral information expressed by GASF and the band difference information expressed by GADF.
[0011] S5: Construct and train a dual-channel GAF-CNN-CBAM classification model. The model takes the dual-channel GAF feature map as input and passes it sequentially through a convolutional feature extraction module, a CBAM attention module, a global average pooling layer, and a classification output layer to obtain the probability of the human analyte sample belonging to each level of the category.
[0012] S6: In the prediction stage, the hyperspectral data of the ginseng sample to be tested is processed according to S2–S4 and then input into the trained model, and the ginseng grade is determined based on the output probability of Softmax.
[0013] The present invention also provides a ginseng grading system for implementing the above method, the system comprising a spectral acquisition module, a spectral preprocessing module, a GAF image construction module, a dual-channel fusion module, a classification and recognition module, and a result display or storage module.
[0014] The present invention also provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, is capable of implementing the steps of the above-described ginseng grade classification method.
[0015] Compared with the prior art, the present invention has at least the following beneficial effects: Firstly, this invention converts a one-dimensional hyperspectral sequence into a two-dimensional angular field image, enabling the expression of spectral variation trends, global correlations between bands, and band differences in the form of an image structure, thereby enhancing the ability to express deep features of hyperspectral data.
[0016] Secondly, the present invention adopts a dual-channel pairing fusion method of GASF and GADF to maintain the one-to-one correspondence between the two types of angular field images of the same sample, avoiding the problem that the sample correspondence is weakened when different angular field images are mixed as ordinary images for training, which is conducive to making full use of complementary spectral information.
[0017] Third, this invention introduces the CBAM attention mechanism on the basis of CNN feature extraction, which enhances the model's ability to focus on key feature channels and important band combination regions from the channel dimension and spatial dimension, suppresses redundant information and noise interference, and improves the ability to distinguish subtle differences in ginseng grades.
[0018] Fourth, this invention can reduce the impact of imbalanced sample levels on the training process by using class weights, making it suitable for practical application scenarios where the number of high-level ginseng samples is limited. Attached Figure Description
[0019] Figure 1 This is a schematic diagram of the GAF two-dimensional angular field construction and GASF / GADF dual-channel pairing and fusion in this invention; Figure 2 This is a schematic diagram of the structure of the dual-channel GAF-CNN-CBAM classification model in this invention. Detailed Implementation
[0020] The specific embodiments of the present invention will be described below with reference to the accompanying drawings. It should be understood that the following embodiments are only used to explain the technical solutions of the present invention and are not intended to limit the scope of protection of the present invention. Equivalent substitutions or conventional adjustments made by those skilled in the art to the sample type, band range, image size, number of network layers, training parameters, or evaluation methods without departing from the concept of the present invention should all fall within the scope of protection of the present invention.
[0021] This embodiment provides a ginseng grading method based on hyperspectral two-dimensional angular field fusion. The object to be classified is a ginseng root sample, and the grading categories may include top-grade ginseng, first-grade ginseng, second-grade ginseng, and ordinary ginseng. The sample can be an unprocessed, dried ginseng root, or other ginseng samples from which a stable hyperspectral reflectance curve can be obtained.
[0022] I. Spectral Data Acquisition and Sample Labeling In this embodiment, a ground-based spectrometer was used to collect hyperspectral reflectance data of ginseng samples in the range of 350–2500 nm. During the acquisition, a relatively stable lighting environment and probe distance were maintained to reduce the impact of changes in external lighting, sample surface inhomogeneity, and geometric differences in the acquisition on the reflectance data.
[0023] As a preferred implementation, four types of samples—special grade, first grade, second grade, and ordinary grade—can be collected, and the categories can be labeled by experienced personnel or according to the corresponding ginseng grading standards. For the same ginseng sample, spectral data can be collected at multiple representative sampling points, with multiple spectra collected repeatedly at each sampling point to form a hyperspectral dataset for model training and validation.
[0024] In one verification embodiment, a total of 49 forest ginseng samples were included, comprising four categories: superior, first-class, second-class, and ordinary ginseng, and 1660 hyperspectral data points were collected. The above sample quantity and grade settings are merely illustrative of embodiments of the present invention and do not constitute a limitation on the scope of protection of the present invention.
[0025] II. Spectral Preprocessing Since the two ends of hyperspectral data are prone to strong noise, this embodiment eliminates the low signal-to-noise ratio bands at both ends based on the effective response range of the spectrometer and the quality of the spectral curve, and preferably retains the spectral data in the range of 400–2400 nm for subsequent analysis.
[0026] For individual missing values or abnormal fluctuations, linear interpolation is used for correction to ensure the continuity and integrity of the spectral sequence. Subsequently, Savitzky-Golay smoothing filtering is applied to smooth the spectral curves to reduce random noise interference and preserve the overall shape and local variation characteristics of the spectral curves.
[0027] To meet the requirements of GAF conversion, the preprocessed spectral sequence is normalized to the interval [-1, 1]. Let the normalized spectral sequence be X = {x1, x2, ..., x...}. N}, where N is the number of effective bands, x i is the normalized reflectance value corresponding to the i-th band.
[0028] III. Construction of GAF Two-Dimensional Angular Field Image like Figure 1 As shown, this embodiment uses the Gram angular field method to convert a one-dimensional spectral sequence into a two-dimensional angular field image. First, the normalized spectral sequence is mapped to the angular space, and the mapping relationship can be expressed as: Where, φ i r represents the angle value corresponding to the i-th band. i t represents the radius term in polar coordinates.i This indicates the sequential position of the i-th band in the spectral sequence, and N represents the total number of bands.
[0029] After completing the angle space mapping, GASF and GADF images are constructed respectively. The GASF image can be constructed according to the following relationship: GASF can reflect the overall trend of spectral sequence changes and the global correlation between any two bands, and its main diagonal can retain the transformation information of the original spectral sequence.
[0030] GADF images can be constructed according to the following relationship: GADF places greater emphasis on the differences between different bands, complementing GASF's shortcomings in expressing the details of spectral changes. Therefore, GASF and GADF characterize the original hyperspectral sequence from the perspectives of overall spectral correlation and band differences, respectively, thus exhibiting complementarity.
[0031] IV. Dual-channel fusion and classification model construction This embodiment pairs the GASF and GADF images corresponding to the same sample and fuses them along the channel dimension to form a dual-channel GAF feature map. Preferably, the first channel of the dual-channel GAF feature map is the GASF image, and the second channel is the GADF image. Unlike training by mixing GASF and GADF images as ordinary images, dual-channel fusion can maintain the one-to-one correspondence between different angular field representations of the same sample, enabling the model to simultaneously learn overall spectral information and band difference information in the same forward propagation.
[0032] like Figure 2 As shown, the dual-channel GAF-CNN-CBAM classification model includes a convolutional feature extraction module, a CBAM attention module, a global average pooling layer, a fully connected layer, and a Softmax classification layer. The convolutional feature extraction module may include multiple sets of convolutional layers, batch normalization layers, ReLU activation function layers, and pooling layers, used to extract deep texture structure features formed by GAF images.
[0033] The CBAM attention module comprises a channel attention submodule and a spatial attention submodule. The channel attention submodule obtains channel description information through global average pooling and global max pooling, and then uses a shared multilayer perceptron and a sigmoid function to obtain channel weights, thereby enhancing key feature channels. The spatial attention submodule obtains a spatial description map through average pooling and max pooling along the channel dimension, and then uses convolution and a sigmoid function to obtain spatial weights, thereby highlighting important band combination regions.
[0034] The feature maps weighted by CBAM are fed into a global average pooling layer and a fully connected layer, and finally a softmax classification layer outputs the probability of each ginseng grade. During prediction, the category with the highest probability value is taken as the grade classification result of the ginseng sample to be tested.
[0035] V. Model Training and Evaluation During model training, the labeled hyperspectral data can be divided into training, validation, and test sets. For each spectral sequence in the training set, paired GASF and GADF images are generated following the steps described above, and combined into a dual-channel GAF feature map as model input.
[0036] During training, the cross-entropy loss function can be used to optimize the model parameters. Considering the potential imbalance in the number of human parameter samples at different levels, class weights can be set according to the number of samples at each level, so that the class with fewer samples receives a relatively higher weight in the loss function, thereby reducing the impact of class imbalance on model training.
[0037] Model evaluation metrics may include accuracy, precision, recall, F1 score, and confusion matrix. Accuracy measures the overall proportion of correct classifications; precision and recall evaluate the recognition performance of each category; the F1 score comprehensively reflects the balance between precision and recall; and the confusion matrix analyzes the misclassification rate between different levels.
[0038] In one embodiment, compared to one-dimensional spectral sequence input, single GASF image input, single GADF image input, and ordinary GASF / GADF mixed image input, the model achieves better ginseng grade classification results by employing GASF / GADF paired dual-channel fusion and introducing the CBAM attention mechanism. This verification result demonstrates that the two-dimensional GAF representation, dual-channel paired fusion, and attention enhancement mechanism of this invention can effectively improve the model's ability to discriminate subtle differences in ginseng grades.
[0039] VI. System Implementation This invention can also be implemented as a ginseng grading system. The system includes a spectral acquisition module, a spectral preprocessing module, a GAF image construction module, a dual-channel fusion module, a classification and recognition module, and a result display or storage module.
[0040] The spectral acquisition module is used to acquire the hyperspectral reflectance data of ginseng samples; the spectral preprocessing module is used to complete effective band selection, interpolation correction, smoothing filtering and normalization; the GAF image construction module is used to convert one-dimensional spectral sequences into GASF and GADF images respectively; the dual-channel fusion module is used to fuse the GASF and GADF images of the same sample into a dual-channel GAF feature map; the classification and recognition module is used to call the trained dual-channel GAF-CNN-CBAM model and output the ginseng grade category probability; the result display or storage module is used to display, export or store the classification results.
[0041] The above modules can be implemented by computer programs, graphics processing units, central processing units, embedded processors, servers or edge computing devices, or they can be implemented by a combination of software and hardware.
[0042] VII. Implementation Method of Computer-Readable Storage Media This invention can also be implemented as a computer-readable storage medium storing a computer program. When the computer program is executed by a processor, it can perform steps such as spectral preprocessing, GAF image construction, dual-channel fusion, model inference, and hierarchical classification output. The computer-readable storage medium can be a hard disk, solid-state drive, flash memory, read-only memory, random access memory, mobile storage device, or cloud storage device.
Claims
1. A ginseng grading method based on hyperspectral two-dimensional angular field fusion, characterized in that, The steps include: S1: Obtain the hyperspectral reflectance data of the ginseng sample to be classified, and construct a one-dimensional spectral sequence of the hyperspectral reflectance data according to the wavelength order; S2: Preprocess the one-dimensional spectral sequence, the preprocessing including at least effective band selection, interpolation correction, smoothing filtering and normalization; S3: Use the Gram angle field method to convert the preprocessed one-dimensional spectral sequence into Gram angle sum field GASF image and Gram angle difference field GADF image respectively. S4: Align the GASF and GADF images corresponding to the same sample and fuse them according to the channel dimension to form a dual-channel GAF feature map; S5: Input the dual-channel GAF feature map into the dual-channel GAF-CNN-CBAM classification model, extract the ginseng grade discrimination features and output the probability of each grade category; S6: Determine the ginseng grade of the ginseng sample to be classified according to the category probability.
2. The method according to claim 1, characterized in that, The ginseng sample mentioned in step S1 is an unprocessed dried ginseng root sample. The ginseng grade includes at least two of the following: special grade, first grade, second grade, and ordinary grade. The hyperspectral reflectance data is acquired by a ground object spectrometer or a hyperspectral imaging device, with a wavelength range of 350–2500 nm.
3. The method according to claim 1, characterized in that, In step S2, the effective band selection is to retain spectral data in the range of 400–2400 nm; the interpolation correction adopts the linear interpolation method; the smoothing filtering adopts the Savitzky-Golay smoothing filtering method; and the normalization processing is to normalize the spectral reflectance data to the interval [-1,1].
4. The method according to claim 1, characterized in that, The Gram angle field method described in step S3 includes mapping the normalized spectral sequence to an angle space, where the angle space mapping satisfies: Where, x i φ is the normalized reflectivity value of the i-th band. i Let t be the angle value corresponding to the i-th band. i Let represent the sequential position of the i-th band in the spectral sequence, and N be the total number of bands.
5. The method according to claim 4, characterized in that, The GASF image described in step S3 is according to A framework is constructed to characterize the overall variation trend of spectral sequences and the global correlation between any two bands. The GADF image is according to A construct is used to characterize the differences between different bands.
6. The method according to claim 1, characterized in that, In step S4, the first channel of the dual-channel GAF feature map is a GASF image, and the second channel is a GADF image. The GASF image and the GADF image are derived from the same spectral sequence to maintain a one-to-one correspondence between different two-dimensional angular field expressions of the same sample.
7. The method according to claim 1, characterized in that, The dual-channel GAF-CNN-CBAM classification model in step S5 includes a convolutional feature extraction module, a CBAM attention module, a global average pooling layer, a fully connected layer, and a Softmax classification layer connected in sequence; the convolutional feature extraction module includes at least one set of convolutional layers, batch normalization layers, activation function layers, and pooling layers.
8. The method according to claim 7, characterized in that, The CBAM attention module includes a channel attention submodule and a spatial attention submodule. The channel attention submodule calculates channel weights based on global average pooling features and global max pooling features, while the spatial attention submodule calculates spatial weights based on the average feature map and the maximum feature map of the channel dimension. The dual-channel GAF-CNN-CBAM classification model is trained using labeled ginseng hyperspectral data and employs a cross-entropy loss function and class weights to reduce the impact of sample class imbalance on model training.
9. A ginseng grading system for implementing the method according to any one of claims 1-8, characterized in that, include: The spectral acquisition module is used to acquire hyperspectral reflectance data of ginseng samples; The spectral preprocessing module is used to perform effective band selection, interpolation correction, smoothing filtering, and normalization. The GAF image construction module is used to convert one-dimensional spectral sequences into GASF and GADF images; the dual-channel fusion module is used to fuse the GASF and GADF images corresponding to the same sample into a dual-channel GAF feature map. The classification and recognition module is used to call the dual-channel GAF-CNN-CBAM classification model to output the physician level classification results; And a result display or storage module for displaying or saving the classification results.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1–8.