Method and system for identifying sorghum variety based on spectrum reconstruction and storage medium
By processing hyperspectral data using the ASTE-MST++ model and the spectral adaptive feature enhancement module, and combining a random forest model optimized by the sparrow search algorithm, the problems of low acquisition efficiency and noise in sorghum variety detection using hyperspectral imaging technology have been solved. This has enabled rapid and accurate identification of sorghum varieties and improved the technical level of the liquor industry.
Patent Information
- Application Number
- CN202510977387.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-16
- Publication Date
- 2025-12-09
AI Technical Summary
Existing hyperspectral imaging technology suffers from low acquisition efficiency, high hardware costs, and environmental sensitivity in sorghum variety detection, resulting in Gaussian-Poisson mixed noise in the data, which affects the accuracy of reconstructed spectra and subsequent variety identification precision.
The ASTE-MST++ model, combined with a spectral adaptive feature enhancement module and a multi-level spectral converter network, is used to process hyperspectral data through dynamic threshold denoising and frequency domain attention enhancement to construct a spectral reconstruction model. A random forest model optimized by the sparrow search algorithm is then used for sorghum variety identification.
It improves the accuracy and efficiency of sorghum variety identification, reduces the difficulty of acquiring hyperspectral data, provides a high-precision, low-cost industrial solution, and promotes technological progress and quality control in the liquor industry.
Smart Images

Figure CN121095616A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of sorghum variety identification technology, specifically involving a method, system, and storage medium for identifying sorghum varieties based on spectral reconstruction. Background Technology
[0002] Sorghum, as a crucial raw material for brewing, exhibits significant differences in starch content, tannin levels, and protein composition among different varieties. These differences directly impact the growth of starter culture and fermentation efficiency, thus affecting the stability of baijiu's flavor and quality. Therefore, rapid and accurate detection and identification of sorghum varieties is a key step in ensuring the stability of brewing processes and product quality. Hyperspectral imaging technology, by simultaneously acquiring the spatial information and continuous spectral characteristics of the analyte, is widely used in crop quality testing, demonstrating significant advantages in agricultural product quality inspection. However, limitations such as low acquisition efficiency, high hardware costs, and environmental sensitivity of hyperspectral equipment restrict its widespread application. To address these issues, researchers have proposed various spectral reconstruction methods. However, during sorghum image acquisition, factors such as illumination fluctuations and sensor thermal noise introduce Gaussian-Poisson mixed noise into the data. Directly applying traditional reconstruction algorithms can lead to spectral artifacts and frequency band distortion, severely affecting the accuracy of subsequent variety identification. Therefore, developing a rapid sorghum variety detection technology that combines high efficiency, accuracy, and environmental adaptability is of significant practical importance for promoting the intelligent upgrading of the brewing industry. Summary of the Invention
[0003] The purpose of this invention is to address the aforementioned shortcomings of the prior art by providing a method, system, and storage medium for identifying sorghum varieties through spectral reconstruction, thereby enabling rapid and accurate detection and identification of sorghum varieties used in brewing.
[0004] To achieve the above objectives, the present invention adopts the following technical solution: The primary objective of this invention is to provide a method for identifying sorghum varieties based on spectral reconstruction, comprising the following specific steps: S1. Obtain sorghum grain samples. Obtain the original hyperspectral data and corresponding RGB images of the sorghum grain samples through a hyperspectral imaging system, and eliminate the influence of illumination and camera dark current instability through black and white correction. S2. The hyperspectral data obtained in step S1 is resampled, and the resampled hyperspectral data and its corresponding RGB image are input into the ASTE-MST++ model to establish the mapping relationship between the two and construct a spectral reconstruction model. The ASTE-MST++ model integrates the spectral adaptive feature enhancement module into a multi-level spectral converter network and uses the synergistic processing of dynamic threshold denoising and frequency domain attention enhancement to improve the quality of sorghum reconstructed hyperspectral data. S3. Take a real RGB image of the sorghum grain sample, input the real RGB image into the spectral reconstruction model, obtain the reconstructed hyperspectral data, then select the region of interest of sorghum and extract the spectral data of sorghum grains; S4. After labeling the spectral data extracted in S3 with variety tags, the data is further input into a random forest model optimized by the sparrow search algorithm for training, and a variety identification model is constructed. S5. Input the spectral data obtained after processing the sorghum grain sample in step S3 into the variety identification model in step S4 to achieve visual identification of sorghum varieties.
[0005] Furthermore, in step S1, the hyperspectral imaging system acquires hyperspectral data of sorghum grain samples through push-broom linear scanning, and performs black-and-white correction on the acquired hyperspectral data. The relative reflectance of the corrected sorghum hyperspectral data is then calculated. The calculation is as follows:
[0006] In the formula: It represents the intensity of reflected light from the hyperspectral data of sorghum before correction; and These are the reflectance of the all-white calibration image and the reflected light intensity of the all-black calibration image, respectively.
[0007] Furthermore, in step S2, the resampled hyperspectral data band ranges from 400nm to 700nm, with an interval of 10nm; the Adam algorithm is selected as the gradient descent optimization algorithm in the multi-level spectral converter network, and β1=0.9, β2=0.999, the initial learning rate is 0.0004, the batch size is 1, and each epoch iterates 1000 times until all training samples are trained. Here, the Adam algorithm is the gradient descent optimization algorithm, β1 and β2 are the hyperparameters in the Adam algorithm, the batch size is the total number of training samples, and the epoch is a complete cycle.
[0008] Furthermore, in step S2, the ASTE-MST++ model uses a spectral multi-head self-attention mechanism to construct a spectral attention block (SAB). The spectral attention block consists of layer normalization, a spectral multi-head self-attention block (S-MSA), a first spectral adaptive feature enhancement block (ASTE), a feedforward network, and a second spectral adaptive feature enhancement block (ASTE). Its structure is as follows: first, layer-by-layer normalization, then the spectral multi-head self-attention block (S-MSA), and the first spectral adaptive feature enhancement block (ASTE); then, layer-by-layer normalization, the feedforward network (FFN), and the second spectral adaptive feature enhancement block (ASTE).
[0009] Furthermore, both the first spectral adaptive feature enhancement block and the second spectral adaptive feature enhancement block construct a dual-path adaptive filtering architecture by introducing a frequency domain compression excitation mechanism.
[0010] Furthermore, the samples used to construct the spectral reconstruction model are divided into a training set, a test set, and a validation set in a ratio of 8:1:1.
[0011] Furthermore, the performance metrics for evaluating the spectral reconstruction model include MRAE, RMSE, and PSNR, calculated using the following formulas:
[0012]
[0013]
[0014] In the formula: MRAE is the mean relative absolute error; RMSE is the root mean square error; PSNR is the peak signal-to-noise ratio; N is the total number of pixels. and These represent the i-th pixel in the reconstructed hyperspectral data and the real spectral image, respectively. H and W represent the height and width of the spatial resolution of the hyperspectral data, respectively. G (i,j) represents the actual spectral data of the pixel located at spatial coordinates (i,j) in the hyperspectral data. R (i,j) represents the reconstructed hyperspectral data of the pixel located at spatial coordinates (i,j) in the hyperspectral data, and MAX1 represents the maximum value of the reconstructed hyperspectral data.
[0015] Furthermore, in step S4, the XY distance algorithm is used to divide the spectral data extracted in S3 into a training set and a test set in a 4:1 ratio. The training set is used to train the sorghum variety recognition model with different combinations, and the test set is used to test the performance of the trained sorghum variety recognition model. In addition, a validation set is prepared for each variety, for a total of 5 validation sets, to further verify the model's performance. Each validation set contains approximately 100 sorghum grains.
[0016] A second objective of this invention is to provide a system for identifying sorghum varieties, the system being based on the aforementioned method and comprising at least the following components built into the system: The data acquisition module is configured to acquire the original hyperspectral image and the corresponding pseudo-RGB image of sorghum grain samples, and process the acquired data through black and white correction. The spectral reconstruction module is configured to resample the hyperspectral data acquired by the data acquisition module, and input the resampled hyperspectral data and its corresponding pseudo-RGB image into the ASTE-MST++ model to establish a mapping relationship between the two and construct a spectral reconstruction model. The ASTE-MST++ model integrates the spectral adaptive feature enhancement module into a multi-level spectral converter network, and uses the synergistic processing of dynamic threshold denoising and frequency domain attention enhancement to improve the quality of sorghum reconstructed hyperspectral data. The feature extraction module is configured to capture real RGB images of sorghum grain samples, input the real RGB images into the spectral reconstruction model, obtain the reconstructed hyperspectral data, and select the region of interest from the hyperspectral data reconstructed from the real RGB images and extract the spectral data of the corresponding sorghum grains. The variety identification model construction module is configured to label the extracted spectral data with variety labels and then input it into a random forest model optimized by the sparrow search algorithm for training to construct a variety identification model. The identification module is configured to input the spectral data obtained by reconstructing the sorghum grain sample to be tested and processing it through the feature extraction module into the variety identification model, thereby realizing the visual identification of sorghum varieties.
[0017] A third objective of this invention is to provide a computer-readable storage medium storing a program that can be executed by one or more processors to implement the aforementioned method for identifying sorghum varieties.
[0018] The English abbreviations used in this invention are explained as follows: RGB: A digital image format whose name refers both to the color space (red, green, and blue) used by the image format and to the image itself, which contains the pixel values of the red, green, and blue color channels.
[0019] ROI: Region of Interest; ASTE-MST++: Multi-level spectral converter network based on spectral adaptive feature enhancement module; HSCNN-D: Deep convolutional neural network; MST++: Multi-level spectral converter network; PLS-DA: Partial Least Squares Discriminant Analysis; SVM: Support Vector Machine; RF: Random Forest; SSA-RF: Random Forest optimized by Sparrow Search algorithm; RMSE: Root Mean Square Error; MRAE: Mean Relative Absolute Error; PSNR: Peak Signal-to-Noise Ratio.
[0020] Compared with the prior art, the beneficial effects of the technical solution provided by the present invention are as follows: (1) This invention provides a method for identifying sorghum varieties based on spectral reconstruction. This method combines the Spectral Adaptive Feature Enhancement Module (ASTE) with the MST++ network to construct the ASTE-MST++ model, improving the overall model's dynamic threshold denoising and frequency domain attention enhancement through collaborative design, thereby optimizing detail recovery and spectral reconstruction quality. This model outperforms the MST++ and HSCNN-D spectral reconstruction networks in sorghum variety identification tasks. PLS-DA, SVM, RF, and SSA-RF classification models were selected and compared based on the full wavelength of the reconstructed and original spectra, respectively. The results show that the SSA-RF model based on the data reconstructed by the ASTE-MST++ network exhibits the best performance in the identification task (ACC of 92.66%). Moreover, this method can reduce the difficulty of acquiring hyperspectral data, improve detection efficiency, provide new ideas and approaches for sorghum variety identification, and promote technological progress and quality control in the liquor industry.
[0021] (2) The identification method provided by the present invention significantly improves detection efficiency while ensuring accuracy, and provides a high-precision, low-cost and timely industrial solution for online sorting of brewing sorghum. It has important application value for ensuring the stability of liquor production quality and provides technical support for the intelligent sorting of brewing raw materials. Attached Figure Description
[0022] Figure 1 A flowchart of the method for identifying sorghum varieties based on spectral reconstruction provided by the present invention; Figure 2 This is a schematic diagram of the ASTE-MST++ model, which consists of a cascaded spectral adaptive feature enhancement module and a single-stage spectral converter. Figure 3 This is a schematic diagram of a U-shaped SST module structure consisting of an encoder, a bottleneck, and a decoder. Figure 4 This is a schematic diagram of the spectral attention block structure in the ASTE-MST++ model; Figure 5 This is a schematic diagram of the feedforward network structure; Figure 6 A schematic diagram of a single-stage spectral conversion network for spectral adaptive feature enhancement; Figure 7 This is a schematic diagram of the structure of the spectral adaptive feature enhancement module; Figure 8 Heatmaps of average relative absolute error for sorghum reconstruction based on the ASTE-MST++ model under different wavebands; Figure 9Heatmaps of average relative absolute error of sorghum reconstruction based on the MST++ model under different wavebands; Figure 10 Heatmaps of average relative absolute error for sorghum reconstruction based on the HSCNN-D model under different wavelength bands; Figure 11 To generate spectral curves of sorghum grain samples from different varieties using the ASTE-MST++ model; Figure 12 To generate spectral curves of sorghum grain samples from different varieties using the MST++ model; Figure 13 To generate spectral curves of sorghum grain samples from different varieties using the HSCNN-D model; Figure 14 A comparison of the reconstructed spectrum and the actual spectrum of dwarf sorghum (AK); Figure 15 A comparison of the reconstructed spectrum and the actual spectrum of glutinous sorghum (HT); Figure 16 A comparison of the reconstructed spectrum and the actual spectrum of Red Star Sorghum (HX); Figure 17 A comparison of the reconstructed spectrum and the actual spectrum of HYZ sorghum; Figure 18 A comparison of the reconstructed spectrum and the actual spectrum of glutinous sorghum (ZN); Figure 19 The visualization results of five sorghum varieties under the SSA-RF network are shown in the figure. Red dots represent dwarf sorghum (AK), green dots represent sticky glutinous sorghum (HT), blue dots represent red star sorghum (HX), yellow dots represent red cherry sorghum (HYZ), and purple dots represent glutinous superior sorghum (ZN). Figure 20 This is a schematic diagram of a system structure for identifying sorghum varieties provided by the present invention. Detailed Implementation
[0023] To make the objectives, technical solutions, and advantages of this invention clearer, the specific embodiments and accompanying drawings are described in further detail below. Where specific techniques or conditions are not specified in the embodiments, they are performed in accordance with the techniques or conditions described in the literature in this field or according to the product manual.
[0024] Unless otherwise specified, the raw materials, equipment, and methods used in this invention are all commonly used in the field.
[0025] like Figure 1 The diagram shows a flowchart of the method for identifying sorghum varieties based on spectral reconstruction according to the present invention, which includes the following steps: (1) Sorghum grain samples: The hyperspectral data and corresponding pseudo-RGB images of sorghum grain samples were obtained by a hyperspectral imaging system, and the effects of illumination and camera dark current instability were eliminated by black and white correction. (2) The hyperspectral data of the training samples are resampled, and the resampled hyperspectral data and their corresponding pseudo-RGB images are input into the ASTE-MST++ model to establish the mapping relationship between the two and construct the spectral reconstruction model. The ASTE-MST++ model integrates the spectral adaptive feature enhancement module into the multi-level spectral converter network and uses the synergistic processing of dynamic threshold denoising and frequency domain attention enhancement to improve the quality of sorghum reconstruction hyperspectral data. (3) Take real RGB images of sorghum grain samples, input the real RGB images into the spectral reconstruction model, reconstruct the hyperspectral data of sorghum, and then select the region of interest of sorghum and extract the spectral data; (4) After labeling the spectral data extracted in step (3), the data is further input into the random forest model (SSA-RF) optimized by the sparrow search algorithm for training to build a variety identification model; Using the joint XY distance algorithm, the spectral data extracted in step (3) was divided into a training set and a test set in a 4:1 ratio. The training set was used to train the sorghum variety recognition model with different combinations, and the test set was used to test the performance of the trained sorghum variety recognition model. In addition, a validation set was prepared for each variety, for a total of 5 validation sets, to further verify the performance of the model. Each validation set contained approximately 100 sorghum grains.
[0026] (5) Input the spectral data obtained after the sorghum grain sample to be tested is processed by the feature extraction module into the variety identification model in step (4) to realize the visual identification of sorghum varieties.
[0027] Example 1 This invention provides a method for identifying sorghum varieties based on spectral reconstruction, specifically including the following steps: 1. Data Collection 1.1 Sample Preparation The sorghum samples were mainly produced in Sichuan, Shandong, and Guizhou, and included five varieties: dwarf sorghum (AK), glutinous sorghum (HT), red star sorghum (HX), red cherry sorghum (HYZ), and glutinous superior sorghum (ZN). According to the distillery's standards, the above five varieties of sorghum were divided into two categories: (1) three types of high-quality sorghum (HT, HYZ, ZN); and (2) two types of ordinary sorghum (AK, HX). During the sample preparation process, 50 samples were prepared for each variety of sorghum, and each sample contained 100 sorghum grains, for a total of 5,000 sorghum grains for each variety, and a total of 25,000 sorghum grains for the five varieties. All samples were divided into training set, test set, and validation set in a ratio of 8:1:1. The training set and test set samples were used for training and testing the spectral reconstruction model, and the validation set samples were used for RGB images and reconstructing hyperspectral data.
[0028] 1.2 Acquisition of Hyperspectral Data and Pseudo-RGB Images The hyperspectral imaging system used in this invention consists of a hyperspectral camera (Specim FX10E, Finland), two 150W halogen lamp light sources (OSRAM, Germany), a high-precision electrically controlled moving platform with a 400 mm stroke (Specim, Finland), a computer equipped with hyperspectral acquisition software (DELL, USA), and an auxiliary support. The FX10E hyperspectral camera has a spatial resolution of 630×1024 pixels and a spectral resolution of 5 nm. This camera can acquire hyperspectral data of 448 consecutive wavelengths in the visible / shortwave near-infrared (400-1000 nm) range and also capture RGB images of the corresponding spatial pixels. Before data acquisition, the halogen lamp light sources are turned on, the camera and the electrically controlled moving platform are connected, and the system is warmed up for 15 minutes before the relevant acquisition parameters are set. After the parameters are set, each sorghum sample is placed in the designated area, and the platform is moved at a constant speed by the software control, allowing the hyperspectral camera to scan the sample line by line, ultimately acquiring the hyperspectral data and RGB image of the sorghum sample.
[0029] This invention relates to a hyperspectral camera system for data acquisition, which is an integrated system capable of simultaneously acquiring RGB image data and 448 consecutive hyperspectral image data with a resolution of 5 nm within the wavelength range of 397.01–1004.52 nm. Before data acquisition, the halogen lamp is first turned on and a connection is established between the camera and the moving platform. After the system warms up for 15 minutes, the acquisition parameters are set: scanning frequency (50 Hz), exposure time (8.8 ms), and platform movement speed (10.84 mm / s). Each sorghum sample is placed in the designated imaging area, and the platform is moved at a uniform speed under software control, allowing the hyperspectral camera to scan line by line to acquire hyperspectral data and RGB images.
[0030] Because the halogen light source used in the experiment has uneven light intensity distribution in different wavelengths and spatial locations, and because the charge-coupled device (CCD) acquisition module in the hyperspectral camera has dark current fluctuations, the final acquired hyperspectral data cannot reflect the actual situation of the sorghum. Therefore, black-and-white correction is needed to correct the acquired hyperspectral data. Thus, to eliminate the interference of these factors, it is necessary to perform black-and-white correction on the acquired hyperspectral image data. The relative reflectance Rc of the corrected sorghum hyperspectral data is calculated as shown in equation (1): (1) In the formula: R r It represents the intensity of reflected light from the hyperspectral data of sorghum before correction; R w and R d These are the reflectance of the all-white calibration image and the reflected light intensity of the all-black calibration image, respectively.
[0031] Since the reconstructed hyperspectral data includes spectral data from both the background and the grain region, and there may also be instances of grain adhesion, the accuracy of the grain spectral data will be affected. Therefore, an image processing method is used to obtain the region of interest (ROI) of the grain from the RGB image, and the spectral data of the grain is extracted from the three reconstructed hyperspectral data based on the ROI.
[0032] 1.3 Acquisition of Real RGB Images RGB images (true RGB images) of sorghum grains were captured using an industrial camera. The RGB image acquisition system consisted of an industrial camera (Daheng), a ring light source, a frame, a power supply, and an industrial computer. Before shooting, the light source was turned on and the illumination intensity was adjusted to 1.1. The camera and computer were connected, and the relevant camera shooting parameters were set as follows: exposure time 50,000 ms, gain 1.00 dB, continuous automatic white balance, and white balance coefficient 1.0. During shooting, each sorghum grain sample was placed in the designated shooting area. The camera was controlled by the acquisition software to complete the acquisition of RGB image data and saved as a PNG format. To facilitate subsequent hyperspectral data reconstruction, the true RGB images were cropped to 1680×1680 pixels.
[0033] 2. Spectral Reconstruction The MST++ network achieves joint modeling of spectral and spatial dimensions through a cascaded multi-scale Transformer architecture, achieving state-of-the-art performance on public datasets. However, during the capture of sorghum images, complex mixed noise (such as Gaussian-Poisson noise) exists due to factors such as illumination fluctuations and sensor thermal noise. Direct application of this noise will lead to artifacts and frequency band distortion in the reconstructed spectrum. To address this, this invention proposes a Spectral Adaptive Feature Enhancement (ASTE) module. Through a collaborative design of dynamic threshold denoising and frequency domain attention enhancement, the ASTE-MST++ network is constructed to improve the high-frequency detail recovery capability. The network architecture is as follows: Figure 2 As shown, in the ASTE-MST++ network, input data first undergoes initial feature extraction through a Conv3x3 (3×3 convolutional) layer. This layer captures local spatial information using 3×3 convolutional kernels. The data then flows into the ASTE-SST module for joint spatial-frequency modeling, extracting cross-domain features. Next, the data passes through another Conv3x3 layer to further transform feature dimensions and extract deeper local information. Following the arrow direction, the data is then branched to multiple parallel Conv3x3 layers, each branch independently performing multi-scale feature extraction to capture contextual information from different receptive fields. Finally, the features from all branches are output through a fusion operation.
[0034] like Figure 3 The diagram shows the structure of the Spectral Adaptive Feature Enhancement Single-Stage Spectral Transformer (ASTE-SST) network module, illustrating the U-shaped SST module consisting of an encoder, a bottleneck, and a decoder. In the SST module, the embedding and mapping block is a 3×3 convolutional layer. The feature mapping in the encoder sequentially undergoes one downsampling operation (a 4×4 convolutional layer spanning multiple rows), N1 Spectral-wise Attention Blocks (SABs), another downsampling operation, and N2 SABs. The bottleneck consists of N3 SABs. The decoder employs a symmetrical structure, with the upsampling operation being a deconv2×2 layer. To avoid information loss during downsampling, jumpers are used to connect the encoder and decoder. The Single-Stage Spectral Transformer (SST) uses an encoder-bottleneck-decoder architecture to achieve efficient spectral data processing and conversion.
[0035] Figure 4This paper demonstrates the workflow of the spectral attention block in the ASTE-MST++ model, with data flow following a bottom-up path. Input features are first standardized through the bottom Layer Norm (layer normalization) layer to ensure the stability of the feature distribution, thus mitigating gradient fluctuations during training. The normalized features then flow upwards into the S-MSA module, which models global dependencies in the spatial dimension using a multi-head self-attention mechanism, capturing long-range contextual information of the input features. Next, the data enters the ASTE (Adaptive Feature Enhancement) layer, which enhances detail recovery and spectral reconstruction quality by utilizing dynamic thresholding denoising and frequency domain attention. The optimized features are then normalized again through Layer Norm to maintain the stability of the feature distribution and provide good initial conditions for subsequent nonlinear transformations. Afterwards, the data flows into the FFN (Feedforward Neural Network) module, which consists of two fully connected layers with a GELU activation function in between. This further expands the model's feature representation capability through nonlinear mapping, thereby improving the network's fitting capacity. Finally, the data undergoes a final adaptive spatial transformation through the top ASTE layer, generating the module's output features. Figure 5 The structure of the Feed-Forward Network (FFN) is shown, consisting of two 1×1 convolutional layers (Conv 1×1), two GELU activation functions, and one 3×3 depthwise separable convolutional layer (DW Conv 3×3). The specific structure is as follows: first, a 1×1 convolutional layer, followed by a GELU activation function, then a 3×3 depthwise separable convolutional layer, then another GELU activation function, and finally a 1×1 convolutional layer. The feed-forward network is used to further process spectral features. The fully connected layers perform dimensionality transformation on the features through activation functions. Residual connections can maintain gradient flow and enhance the model's expressive power. Layer normalization can stabilize the training process.
[0036] The introduced Spectral-wise Multi-head Self-Attention (S-MSA) module is the core feature extraction module for hyperspectral characteristics. Compared to traditional spatial domain self-attention mechanisms, S-MSA restructures its architecture to address the inherent "spatially sparse - spectrally dense" characteristics of hyperspectral images. Traditional attention mechanisms focus on modeling spatial pixel relationships, while hyperspectral data exhibits sparsity in spatial distribution and strong coupling in the spectral dimension. By establishing a cross-band correlation matrix, S-MSA dynamically learns the global dependencies and contribution weights of different spectral channels. Figure 6As shown, when the input Xin(H×W×C) enters the module, the input dimension is first transformed into a feature matrix of (H×W)×C, and then the feature matrix is projected onto the query matrix Q, the index matrix K, and the content matrix V respectively. The matrix operations of Q, K, and V are shown in equation (2): (2), In the formula: , , ∈ As learnable parameters, Q, K, and V are then divided into N heads along the spectral channel direction, and the self-focus score of each head along the spectral channel is calculated. The calculation formula is shown in equation (3): (3) In the formula: j∈1,...,N, express The transpose matrix, and because the spectral density varies significantly with wavelength, learnable parameters are used. and The matrix is reweighted to accommodate self-focus, and then the outputs of the N heads are concatenated for linear projection. Position embedding is added to encode the position information of different spectral channels. The calculation formula is shown in Equation (4): (4) In the formula: j ∈1,..., N F( X ) represents the calculated attention value. This is a position embedding function, and the output is finally reconstructed back into H×W×C for output.
[0037] Adaptive Spectral Transform (AST) is a core component of frequency domain feature denoising. It addresses the high noise sensitivity of traditional threshold functions through a dynamic threshold learning mechanism. The traditional soft thresholding operation is shown in equation (5): (5) In the formula: x is the input feature, y is the thresholded output, and τ is the fixed threshold. Noise distribution in hyperspectral images exhibits channel heterogeneity (e.g., sensor thermal noise varies with wavebands), making it difficult for a single threshold to adapt to global features. The ASTE module introduces a frequency domain compression excitation mechanism (FSE) to construct a dual-path adaptive filtering architecture (e.g., ... Figure 7 As shown in the diagram, this module achieves synergistic optimization of noise suppression and feature enhancement. The Frequency Domain Compressed Excitation Branch (FSE) is a noise adaptive calibration module based on a frequency domain attention mechanism, capable of dynamically adjusting channel weights according to frequency domain energy distribution characteristics. The ASTE module achieves automated learning of threshold parameters by combining a soft threshold function with the FSE branch.
[0038] 3. Construction of a sorghum variety identification model This invention establishes four machine learning models—Partial Least Squares Discriminant Analysis (PLS-DA), Support Vector Machine (SVM), Random Forest (RF), and Random Forest Optimized by Sparrow Search Algorithm (SSA-RF)—to perform classification and predictive analysis on high-dimensional and complex data. PLS-DA reduces dimensionality by extracting latent variables and captures information related to class differences, achieving effective classification of high-dimensional data. SVM utilizes optimal hyperplane and kernel function mapping to enhance its ability to handle nonlinear problems and high-dimensional data, while exhibiting strong noise robustness. RF, based on decision tree ensemble and Bootstrap sampling, improves model stability and accuracy, and reveals key variables through feature importance assessment. SSA-RF, combined with the Sparrow Search Algorithm to optimize RF parameters, further improves prediction accuracy and generalization ability, overcomes the empirical dependence of traditional RF parameter selection, and is suitable for high-dimensional, nonlinear, and noisy data scenarios.
[0039] 4. Evaluate the accuracy of the spectral reconstruction model MRAE, RMSE, and PSNR were selected as evaluation indicators. MRAE calculates the pixel-by-pixel difference between each band of the reconstructed spectral image and the real spectral image, and the calculation formula is shown in Equation (6). RMSE calculates the root mean square error between the reconstructed spectral image and the real spectral image, and the calculation formula is shown in Equation (7). PSNR calculates the peak signal-to-noise ratio between the reconstructed spectral image and the real spectral image, and the calculation formula is shown in Equation (8).
[0040] (6) (7)
[0041] In the formula: N is the total number of pixels, and These represent the i-th pixel in the reconstructed hyperspectral data and the real spectral image, respectively. H and W represent the height and width of the spatial resolution of the hyperspectral data, respectively. G (i,j) represents the actual spectral data of the pixel located at spatial coordinates (i,j) in the hyperspectral data. R (i,j) represents the reconstructed hyperspectral data of the pixel located at spatial coordinates (i,j) in the hyperspectral data. MAX1 represents the maximum possible value of the reconstructed hyperspectral data. Since the reflectance of hyperspectral data is between 0 and 1, MAX1 is set to 1 by default. Generally, the smaller the values of RMSE and MARE, the larger the value of PSNR, indicating higher reconstruction accuracy and better model performance.
[0042] In addition, to explore the classification effect of the sorghum variety detection model on spectral data, the ACC of the test set was selected to evaluate the model effect. The larger the corresponding value, the higher the detection accuracy and the better the model performance. The ACC is calculated as the proportion of correctly identified sorghum grains to the total number of sorghum grains, and the calculation formula is as shown in equation (9): (9) In the formula: TP represents the number of correct samples predicted as correct; FN represents the number of correct samples predicted as incorrect; FP represents the number of incorrect samples predicted as correct; TN represents the number of incorrect samples correctly predicted as incorrect.
[0043] 5. Experimental Training Setup Model training utilized the PyTorch deep learning framework. The experimental computer featured an Intel Xeon Gold 6234 CPU, 128GB of RAM, and an NVIDIA GeForce RTX 2080 Ti GPU. Paired RGB images and hyperspectral data (31 bands) were used to train three networks. Adam, with β1 = 0.9 and β2 = 0.999, was chosen as the gradient descent optimization algorithm. The initial learning rate was set to 0.0004, the batch size to 1, and each epoch iterated 1000 times until all samples were trained. Training data was augmented through random rotation and flipping.
[0044] For the sorghum variety detection model, this invention uses the joint XY distance (SPXY) algorithm to divide the reconstructed spectral data into training and test sets in a 4:1 ratio.
[0045] 6. Results and Analysis 6.1 Performance Comparison and Analysis of Spectral Reconstruction Networks Four reconstruction networks were used to build sorghum spectral reconstruction models using the sorghum spectral reconstruction dataset. The reconstruction accuracy results on the validation set are shown in Table 1. Table 1 shows that the ASTE-MST++ model has a Test MRAE (Mean Relative Absolute Error) of 0.0129, a Test RMSE (Root Mean Square Error) of 0.0064, and a Test PSNR (Peak Signal-to-Noise Ratio) of 42.8181. Compared to the MST++ network, the Test MRAE is reduced by 9.3%, the Test RMSE by 11.6%, and the Test PSNR by 1%. The reason why the ASTE-MST++ model is superior to MST++ is the introduction of the Adaptive Spectral Transformation (AST) module and the Feature Selection Enhancement (FSE) module. These modules enable the model to better capture long-range dependencies in spectral data and have stronger resistance to interference factors such as noise, illumination changes, and occlusion, maintaining stable performance even in complex environments.
[0046] Compared to the HSCNN-D network, the MRAE was reduced by 24.6%, RMSE by 27.0%, and Test PSNR was improved by 15.7%. The main drawbacks of HSCNN-D compared to the ASTE-MST++ model are as follows: HSCNN-D struggles to capture long-range dependencies in spectral data, while ASTE-MST++ effectively addresses this issue through a self-attention mechanism; HSCNN-D's spatial-spectral feature fusion method is simple and cannot fully utilize the correlation between the two features as ASTE-MST++ does; the training process for HSCNN-D is complex, requiring more computational resources and time. It is evident that the hyperspectral data reconstructed by ASTE-MST++ has higher accuracy compared to the other two reconstruction models. In conclusion, the ASTE-MST++ model can reconstruct high-precision hyperspectral data with a smaller dataset.
[0047] Table 1. Performance of different reconstruction networks.
[0048]
[0049] 6.2 Comparative Analysis of Spectral Reconstruction Errors To visually compare the reconstruction errors of different algorithms for different sorghum varieties, five different sorghum varieties were randomly selected from the sorghum sample test set. The three algorithms mentioned above were used for spectral reconstruction, and MRAE heatmaps were plotted at a wavelength of 600 nm. (Heatmap) Figures 8-10 As shown in the diagram, the bluer the color, the lower the reconstruction error and the higher the overall spectral quality. From... Figure 8 As can be seen, among the five sorghum varieties, compared with the other three networks, the MRAE heatmap generated by the ASTE-MST++ network shows that the sorghum grain color is closer to dark blue, and the grain outline is almost indistinguishable, indicating that its reconstruction error is significantly lower. In contrast, the MRAE heatmaps generated by the other three networks show that the sorghum grains are mostly light blue, with some grains even appearing blue-green in the reconstruction results of the HSCNN-D and MST++ networks, indicating that these spectral images have larger errors. In conclusion, the ASTE-MST++ network exhibits the lowest reconstruction error across all five varieties.
[0050] Further analysis revealed that the HSCNN-D network lost significant feature information during upsampling and downsampling, resulting in high reconstruction error. While the MST++ network efficiently extracted features between spectral channels using the S-MSA module, it failed to denoise useless noise in the data, leading to still substantial reconstruction error. Building on this, the ASTE-MST++ network introduced dedicated optimization modules (such as the FSE module), effectively mitigating the impact of noise and other useless information, improving the efficiency of feature information utilization, and thus significantly enhancing the fidelity of the reconstructed spectrum.
[0051] like Figures 11-13 As shown, by randomly selecting 5 sorghum varieties and randomly selecting one pixel from each variety, 31-band spectral curves with 10 nm intervals were plotted in the 400-700 nm range for both the original and three reconstructed hyperspectral data. For different sorghum varieties, the original spectral curves and the spectral curves reconstructed by the three networks showed a certain similarity and generally consistent trends. The ASTE-MST++ method exhibited the best reconstruction performance in the 400-700 nm spectral range. The ASTE-MST++ method reconstructed the spectral data with the smallest error compared to the original spectral data, followed by the MST++ method, while the HSCNN-D method showed the worst reconstruction effect. This indicates that compared to the MST++ and HSCNN-D methods, the ASTE-MST++ method has advantages in terms of average relative absolute error and peak signal-to-noise ratio, resulting in higher quality reconstructed hyperspectral data. Furthermore, in the 400-500 nm band, the spectral data reconstructed by the three methods deviated significantly from the original spectral data. This may be due to the influence of noise on the spectral data in the 400-500 nm band, leading to larger prediction deviations.
[0052] 6.3 Spectral Curve Analysis of Sorghum This invention selected five sorghum varieties—AK, HX, NT, HYZ, and ZN—for spectral curve evaluation. By analyzing the spectral curves of these different sorghum varieties, the sorghum varieties can be identified.
[0053] like Figures 14-18As shown in the graph, the average spectral response curves of the five sorghum varieties in the 400-700 nm wavelength range exhibit spectral differentiation characteristics. The average spectral reflectance of each variety generally increases with increasing wavelength, but specific spectral morphologies show significant variety-specificity. This spectral differentiation can be attributed to differences in the protein, oil, and starch content of the grains of different varieties and the interaction of their characteristic absorption bands. The differences in spectral response are particularly significant in the 530-680 nm wavelength range. The average spectral reflectance of AK and HX varieties differs significantly from the other two varieties, while the increasing trends of spectral reflectance for HT, HYZ, and ZN varieties are more consistent. However, there is little overlap in the spectral reflectance of different varieties. The differences in reflectance of different sorghum varieties in different wavelength ranges provide an effective basis for the sorghum variety detection model. Because the average spectral reflectance of AK and HX varieties differs significantly, they are easier to identify using the model. HT, HYZ, and ZN varieties may be misidentified during identification.
[0054] 6.4 Accuracy Analysis of Sorghum Variety Identification To verify the classification performance of spectral reconstruction data in variety identification models, this invention systematically constructed SSA-RF, PLS-DA, SVM, and RF sorghum variety detection models based on original and reconstructed data. As shown in Table 2, the SSA-RF model, constructed based on original hyperspectral data, exhibited the best identification performance, with a test set accuracy (ACC) of 95.95%, followed by PLS-DA (93.24%), SVM (92.23%), and RF (90.88%) models. Notably, the SSA-RF model constructed using ASTE-MST++ reconstructed spectra still maintained an ACC of 92.66%, representing an improvement of 2.49% and 5.19% in identification accuracy compared to the MST++ and HSCNN-D network reconstructed spectra, respectively, and significantly outperforming other comparative models (PLS-DA: 85.74%; SVM: 85.96%; RF: 90.71%). This result fully demonstrates the superior performance of the ASTE-MST++ network in spectral reconstruction. The ASTE-MST++ network achieves such superior performance primarily by combining the strengths of the Adaptive Spectral Transformation (AST) module and the Feature Selection Enhancement (FSE) module. While the AST module excels at establishing global spectral correlations through adaptive band reconfiguration, it may overlook the representational power of key local features. The FSE module, on the other hand, complements this deficiency by excelling at dynamically selecting and enhancing local discriminative features. The collaborative global feature sharing between the AST and FSE modules allows the model to maintain the spatiotemporal continuity of spectral data while enhancing the robustness and discriminativeness of feature representation. It achieves deep fusion of the "physical-statistical" dual attributes of spectral features under complex background interference, ultimately resulting in significant improvements in feature interpretability and model generalization ability. Therefore, the ASTE-MST++ network provides more accurate variety identification for sorghum.
[0055] In terms of comprehensive classification indicators, the results of modeling using the ASTE-MST++ reconstructed data combined with the SSA-RF model show only a slight difference of 3.29% compared to the original spectral data. It is particularly noteworthy that, compared to the sophisticated spectroscopic equipment required for modeling with the original data, the detection scheme based on reconstructed spectra maintains high classification performance (ACC difference <3.29%) while significantly reducing hardware costs (equipment costs reduced by approximately 60%) and environmental sensitivity (expanding the operating temperature range by 15 degrees Celsius). This balance between performance and cost makes the ASTE-MST++ reconstruction technology demonstrate significant engineering application value in the rapid on-site detection of sorghum varieties.
[0056] Table 2. Effects of different classification models based on raw and reconstructed sorghum grain data.
[0057]
[0058] To more directly evaluate the reconstruction performance of the ASTE-MST++ network, five sorghum varieties were collected, and each variety was identified using four different recognition networks. The recognition results were represented by a confusion matrix, which clearly shows the recognition accuracy of each variety under the four different networks. The results show that the original hyperspectral data-driven model exhibits excellent classification performance on the five sorghum varieties, with an overall accuracy (ACC) exceeding 90%. However, due to misclassification caused by the similarity of spectral features among HT, HYZ, and ZN varieties, their accuracy decreased. Figures 11-13 As can be seen, the HT and HYZ varieties are easily identified as ZN varieties, which is consistent with... Figures 11-13 The analysis results of the spectral reflectance diagrams confirm that HX and AK have spectral response characteristics that are significantly different from other varieties. One has the highest average spectral reflectance, and the other has the second highest average spectral reflectance. Therefore, the number of misidentified varieties in the confusion matrix is significantly less. Figures 11-13 Analysis of spectral reflectance diagrams in Figure 19 The visualization results corroborate this, showing that the SSA-RF model based on the reconstructed spectra using ASTE-MST++ maintains 99.4% and 97.2% recognition rates for varieties HX and AK in the test set, while achieving classification accuracies of 93.9%, 94.1%, and 95.7% for HT, ZN, and HYZ, respectively. Comparison of the two matrices reveals a high degree of agreement between the reconstructed and original spectra in their classification decision boundaries, confirming that the ASTE-MST++ network effectively preserves the spectral characteristics of the varieties. Although the reconstruction process leads to slight information loss, it significantly reduces equipment costs while maintaining classification accuracy, providing a theoretical basis and technical support for constructing an economical online detection system.
[0059] Example 2 This embodiment, based on the design of Embodiment 1, discloses a system for identifying sorghum varieties, such as... Figure 20 As shown, this system, based on the aforementioned method for identifying sorghum varieties using spectral reconstruction, includes at least the following components built into the system: The data acquisition module is configured to acquire hyperspectral images of sorghum grain samples and obtain corresponding corrected pseudo-RGB images through black-and-white correction. The spectral reconstruction module is configured to resample the hyperspectral data acquired by the data acquisition module, and input the resampled hyperspectral data and its corresponding pseudo-RGB image into the ASTE-MST++ model to establish a mapping relationship between the two and construct the spectral reconstruction model. The ASTE-MST++ model integrates the spectral adaptive feature enhancement module into the multi-level spectral converter network, and uses the synergistic processing of dynamic threshold denoising and frequency domain attention enhancement to improve the quality of sorghum reconstructed hyperspectral data. The feature extraction module is configured to capture real RGB images of sorghum grain samples, input the real RGB images into the spectral reconstruction model, obtain reconstructed hyperspectral data, and extract spectral data by selecting regions of interest from the real RGB images. The variety identification model construction module is configured to label the spectral data extracted above and then input it into a random forest model optimized by the sparrow search algorithm for training to construct a variety identification model. The identification module is configured to input the spectral data obtained after the feature extraction module processes the sorghum grain sample to be tested into the variety identification model mentioned above, so as to realize the visual identification of sorghum varieties.
[0060] Example 3 Based on the design of Embodiments 1 and 2, this embodiment discloses a computer-readable storage medium storing a program that can be executed by one or more processors to implement the above-described detection method for identifying sorghum varieties.
[0061] Where there is no conflict, the above embodiments and features described herein can be combined with each other.
[0062] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A method for identifying sorghum varieties based on spectral reconstruction, characterized in that, The specific steps include the following: S1. Obtain sorghum grain samples. Obtain the original hyperspectral data and corresponding pseudo-RGB images of sorghum grain samples through a hyperspectral imaging system, and eliminate the influence of illumination and camera dark current instability through black and white correction. S2. Input the processed hyperspectral data and its corresponding pseudo-RGB image into the ASTE-MST++ model to establish the mapping relationship between the two and construct a spectral reconstruction model. The ASTE-MST++ model integrates the spectral adaptive feature enhancement module into a multi-level spectral converter network and uses the synergistic processing of dynamic threshold denoising and frequency domain attention enhancement to improve the quality of sorghum reconstructed hyperspectral data. S3. Take a real RGB image of the sorghum grain sample, input the real RGB image into the spectral reconstruction model, obtain the reconstructed hyperspectral data, and then select the region of interest and extract the spectral data of the sorghum grain. S4. After labeling the spectral data extracted in S3 with variety tags, the data is further input into a random forest model optimized by the sparrow search algorithm for training, and a variety identification model is constructed. S5. Input the spectral data obtained after processing the sorghum grain sample in step S3 into the variety identification model in step S4 to achieve visual identification of sorghum varieties.
2. The method according to claim 1, characterized in that, In step S1, the hyperspectral imaging system acquires hyperspectral data of sorghum grain samples through push-broom linear scanning, and performs black-and-white correction on the acquired hyperspectral data. The relative reflectance of the corrected sorghum hyperspectral data is then calculated. The calculation is as follows: In the formula: It represents the intensity of reflected light from the hyperspectral data of sorghum before correction; and These are the reflectance of the all-white calibration image and the reflected light intensity of the all-black calibration image, respectively.
3. The method according to claim 1, characterized in that, In the multi-level spectral converter network, the Adam algorithm is selected as the gradient descent optimization algorithm, and β1=0.9, β2=0.999, initial learning rate is 0.0004, batch size is 1, and each epoch iterates 1000 times until all training samples are trained. Here, Adam algorithm is the gradient descent optimization algorithm, β1 and β2 are the hyperparameters in Adam algorithm, batch size is the total number of training samples, and epoch is a complete cycle.
4. The method according to claim 3, characterized in that, In step S2, the ASTE-MST++ model uses a spectral multi-head self-attention mechanism to construct a spectral attention block. The spectral attention block consists of layer normalization, a spectral multi-head self-attention block, a first spectral adaptive feature enhancement block, a feedforward network, and a second spectral adaptive feature enhancement block. Its structure is as follows: first, layer normalization, then spectral multi-head self-attention block, and then the first spectral adaptive feature enhancement block. Then comes a series of normalization layers, feedforward network, and second spectral adaptive feature enhancement block.
5. The method according to claim 4, characterized in that, Both the first and second spectral adaptive feature enhancement blocks construct a dual-path adaptive filtering architecture by introducing a frequency domain compression excitation mechanism.
6. The method according to claim 5, characterized in that, The samples used to construct the spectral reconstruction model were divided into training set, test set and validation set in a ratio of 8:1:
1.
7. The method according to claim 6, characterized in that, The performance metrics for evaluating the spectral reconstruction model include MRAE, RMSE, and PSNR, calculated using the following formulas: In the formula: MRAE is the mean relative absolute error; RMSE is the root mean square error; PSNR is the peak signal-to-noise ratio; N is the total number of pixels. and These represent the i-th pixel of the reconstructed hyperspectral data and the real spectral image, respectively; H and W represent the height and width of the spatial resolution of the hyperspectral data, respectively, and I... G (i,j) represents the actual spectral data of the pixel located at spatial coordinates (i,j) in the hyperspectral data. R (i,j) represents the reconstructed hyperspectral data of the pixel located at spatial coordinates (i,j) in the hyperspectral data, and MAX1 represents the maximum value of the reconstructed hyperspectral data.
8. The method according to claim 1, characterized in that, In step S4, the XY distance algorithm is used to divide the spectral data extracted in S3 into training and testing sets in a 4:1 ratio.
9. A system for identifying sorghum varieties, characterized in that, The system, based on the method of any one of claims 1-8, includes at least the following components built within the system: The data acquisition module is configured to acquire the raw hyperspectral data of sorghum grain samples and obtain the corresponding corrected pseudo-RGB image through black and white correction; The spectral reconstruction module is configured to resample the hyperspectral data acquired by the data acquisition module, and input the resampled hyperspectral data and its corresponding pseudo-RGB image into the ASTE-MST++ model to establish a mapping relationship between the two and construct a spectral reconstruction model. The ASTE-MST++ model integrates the spectral adaptive feature enhancement module into a multi-level spectral converter network, and uses the synergistic processing of dynamic threshold denoising and frequency domain attention enhancement to improve the quality of sorghum reconstructed hyperspectral data. The feature extraction module is configured to capture real RGB images of sorghum grain samples, input the real RGB images into the spectral reconstruction model, obtain the reconstructed hyperspectral data, and select the region of interest from the hyperspectral data reconstructed from the real RGB images and extract the spectral data of the corresponding sorghum grains. The variety identification model construction module is configured to further input the extracted spectral data and sample labels of different sorghum varieties into a random forest model optimized by the sparrow search algorithm for training, and construct a variety identification model. The identification module is configured to input the spectral data obtained after the feature extraction module processes the sorghum grain sample to be tested into the variety identification model, thereby realizing the visual identification of sorghum varieties.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a program that can be executed by one or more processors to implement the method of any one of claims 1-8.
Citation Information
Cited By
Method and equipment for predicting storage quality of chilled fresh pork based on visible spectrum reconstruction
CN121678557A