1. Introduction
With the large-scale development of facility agriculture, real-time and precise monitoring of crop nutritional status has become a core aspect for optimizing fertilization decisions and improving resource utilization efficiency. As one of the most critical elements for plant growth, nitrogen is closely related to crop development [
1]. For fast-growing leafy vegetable crops like lettuce, accurate nitrogen management can effectively ensure yield, quality, and economic benefits [
2]. Traditional nitrogen detection relies on destructive chemical methods such as the Kjeldahl method [
3] and indophenol blue colorimetry [
4]. These approaches are time-consuming, costly, and unable to dynamically track physiological changes in individual plants, making continuous measurement impractical [
5]. To overcome this bottleneck, non-destructive detection technologies need to evolve toward multi-modal sensing fusion, synergistically leveraging the complementary advantages of different spectral and imaging techniques to achieve comprehensive analysis of crop biochemical parameters.
Spectroscopy technology, owing to its rapidity, efficiency, non-destructiveness, and wide applicability, has matured in the field of crop nutrient monitoring [
6,
7,
8]. It provides a viable pathway for the dynamic monitoring of nitrogen levels in lettuce, and its core advantage lies in spatial-spectral unified analysis capabilities, enabling simultaneous interpretation of both spatial distribution patterns of nitrogen-containing compounds in leaves and spectral response features across specific wavelength bands. In addition, a large number of researchers have found that spectroscopy has a high advantage in detecting the nitrogen content of leaves. Kühn applied different levels of nitrogen and phosphorus treatments to three plants and effectively utilized spectroscopy to achieve accurate predictions [
9]. Karoojee, S. sprayed foliar fertilizers with different N and P on Dendrobium officinale and effectively evaluated the changes in leaf nutrient elements using spectroscopy [
10], this confirms that using spectroscopy to evaluate the content of basic substances at the leaf scale is very reasonable [
11].
Near-infrared spectroscopy (NIR) and terahertz spectroscopy (THz) have become prominent research focuses due to their unique mechanisms. In recent years, extensive studies utilizing these technologies have established them as mainstream methods for quantitative and qualitative analysis of agricultural products and food [
12,
13,
14,
15]. A large number of researchers have conducted effective evaluations of the quality attributes of various fruits using near-infrared hyperspectral technology [
16,
17,
18]. Liu investigated the chlorophyll variation mechanism during matcha processing and achieved real-time and quantitative monitoring of chlorophyll using near-infrared (NIR) spectroscopy [
19]. Arslan combined near-infrared (NIR) spectroscopy with multiple algorithms to evaluate the antioxidant activity of black wolfberry (
Lycium ruthenicum) [
20]. Yang fused NIR hyperspectral imagery with deep features to effectively estimate nitrogen levels in wheat leaves at near-ground level [
21]. Shi mapped cucumber chlorophyll distribution via NIR hyperspectral data, correlating it with HPLC measurements to accurately diagnose nitrogen deficiency [
22]. Mao combined reflectance from selected wavelengths with image texture and morphological features for machine learning-based lettuce canopy nitrogen detection [
23]. Tang developed a BP-Adaboost model using NIR spectra to classify rubber tree leaf nitrogen with high accuracy [
24]. Azadnia R further established nonlinear in situ prediction models for apple tree nitrogen, phosphorus, and potassium by preprocessing visible-NIR spectra and extracting sensitive wavelengths [
25].
However, near-infrared spectroscopy is constrained by moisture absorption interference and shallow detection depth, resulting in limited capability in resolving internal leaf structures and dry matter distribution [
26], so people have shifted their focus to terahertz spectroscopy technology.
As a relatively novel and promising sensing technology, the emergence of Terahertz Time-Domain Spectroscopy (THz-TDS) offers a new pathway to overcome the aforementioned limitations; characterized by low energy, deep penetration, and fingerprint spectral characteristics, terahertz (THz) radiation has become a preferred method for rapid, non-destructive detection in agriculture, demonstrating excellent performance in quantitative and qualitative analysis of food [
27,
28]. As a more recent sensing technique, terahertz waves have seen extensive applications in diverse agricultural sectors including plant health monitoring [
29], leaf water content assessment [
30,
31], seed testing [
32,
33,
34], pesticide detection [
35,
36,
37], identification of hazardous substances [
38,
39,
40,
41], disease detection [
37] and soil composition analysis [
42]. Additionally, since terahertz pulses can effectively penetrate the surface structure of plant leaves to directly characterize rotational energy level transitions in nitrogen-related organic macromolecules [
43,
44], this provides opportunities for directly detecting internal leaf nutrients. Ziyi Zang utilized terahertz spectroscopic imaging to quantitatively monitor the spatial variability of leaf water, solids, and gas content, enabling non-destructive nutrient monitoring [
45]. Zhang collected terahertz spectral data from tomato leaves under varying nitrogen levels and established a machine learning model that enables the prediction of nitrogen content in tomato leaves [
46].
Given that a single sensing modality may not comprehensively reflect crop nutritional status, this study proposes to synergistically integrate terahertz spectroscopy’s strength in detecting internal crop traits with hyperspectral imaging’s capacity for capturing external characteristics. By combining feature information across these dual modalities, an innovative attempt will be made to obtain more holistic and effective detection methodology. After acquiring spectral data through near-infrared hyperspectral and terahertz imaging systems, the research will execute sample processing, dataset splitting, feature selection, and model construction. Subsequently, the fused terahertz-hyperspectral features will be trained within a deep learning framework, ultimately establishing a feature-fusion model that capitalizes on the complementary strengths of both terahertz and hyperspectral technologies.
2. Materials and Methods
2.1. Sample Cultivation, Processing, and Collection
The experimental samples used Italian annual bolt-resistant lettuce cultivated in a Venlo-type greenhouse at Jiangsu University (32.2° N, 119.5° E). Seeds were germinated uniformly under identical conditions, and seedlings at the 4–5 true leaf stage with consistent morphology were transplanted into 15 cm-diameter pots containing perlite substrate to ensure standardized initial growth conditions. Plants were subjected to four nitrogen stress gradients (20%, 60%, 100%, and 150% nitrogen levels), with the 100% group serving as the control using modified Yamazaki formula nutrient solution, totaling 100 plants (25 per gradient). Daily volume-equivalent differential-nitrogen irrigation was administered each morning while maintaining optimal greenhouse temperature and humidity. After 40 days of cultivation, 2–3 intact undamaged leaves per plant were excised and stored in sealed plastic bags, yielding 200 leaf samples for analysis.
2.2. Determination of Sample Nitrogen Content
The collected lettuce leaf samples underwent nitrogen content quantification via Kjeldahl nitrogen determination after terahertz data acquisition. To eliminate moisture interference with nitrogen detection while preserving sample structural integrity, samples were freeze-dried using a Christ Alpha 1-2 LD Plus instrument (Marin Christ Co., Ltd., Osterode, Germany). Following dehydration, samples were pulverized into powder with a German RETSCH MM400 ball (RETSCH Co., Ltd., Düsseldorf, Germany) mill, then digested into test solutions using a TD20-HG08SM-108G (Beijing Haifuda Technology Co., Ltd., Beijing, China) digestion furnace for subsequent total nitrogen measurement with a UDK159 Kjeldahl nitrogen analyzer (VELP Co., Ltd., Via Stazione, Italy). This sequential processing ensured accurate reference data acquisition while maintaining sample physicochemical stability.
2.3. Near Infrared Hyperspectral Imaging Data Acquisition
The hyperspectral data was collected using the HSI Analyzer system (Shanghai Wuling Optoelectronics Technology Co., Ltd., Shanghai, China). The overall structure diagram of the hyperspectral imaging system is shown in
Figure 1.
After being prepared, the lettuce sample was placed on the stage of the hyperspectral imaging system. Under illumination from a stable light source, it generated reflected light signals, which were collected by the lens and transmitted to the spectral splitting unit. Following spectral decomposition, these signals were sequentially acquired line by line by the detector. As the stage moved at a constant speed, the system continuously recorded and stitched together the spectral information, ultimately generating a hyperspectral volume of data that integrated both spatial and spectral details, thereby providing a foundation for subsequent data processing and modeling.
The spectral data acquired by this hyperspectral imaging system in the present study covers near-infrared wavelengths ranging from 871.607 nm to 1766.322 nm, capturing both the sample’s images and spectral intensity values. This system has a spectral resolution of 3.5 nm, with a total of 256 wavelength points within this range. For the near-infrared images collected, their RGB channels correspond to specific wavelengths: Band R at 1448.899 nm (wavelength index 166), Band G at 1376.352 nm (wavelength index 143), and Band B at 1307.224 nm (wavelength index 121).
2.4. Terahertz Spectral Imaging System Data Acquisition
This study employed the TAS7400 terahertz time-domain spectroscopy (THz-TDS) system developed by Advantest Corporation (Advantest Corporation Co., Ltd., Tokyo, Japan) for sample data acquisition. The system’s configuration and working principle are illustrated in
Figure 2. The THz frequency range covered 0–4 THz with a sampling interval of 0.0038 THz. To mitigate moisture interference during THz data collection, a dehumidifier was utilized to reduce the relative humidity within the sample scanning chamber to below 5% RH prior to measurements, with this humidity level rigorously maintained throughout the entire experimental process.
Prior to measurement, the system required preheating to ensure spectral signal stability, followed by sample transmittance spectral scanning. The experimental parameters were standardized according to sample dimensions: the scanning interval between X/Y axes was set to 1.5 mm with 80 steps each, totaling 6400 scanning points. Measurement frequency ranged from 0–4 THz with 3.8 GHz intervals, and sample thickness was configured at 1 mm. Post-scanning, the acquired data was generated as a three-dimensional image volume containing spatial-spectral information, as illustrated in
Figure 3.
2.5. Spectral Data Analysis and Model Evaluation
2.5.1. Spectral Preprocessing Method
After acquiring NIR (near-infrared hyperspectral) and THz (terahertz spectroscopy) data, this study employed the Savitzky–Golay (S-G) smoothing algorithm and multiplicative scatter correction (MSC) algorithm to process raw spectral data. These preprocessing steps aimed to enhance modeling efficiency and accuracy by reducing noise interference, emphasizing effective information, and improving the signal-to-noise ratio (SNR). Specifically, the S-G algorithm effectively suppressed random noise while preserving spectral features through polynomial fitting within sliding windows. Concurrently, MSC minimized baseline drift and scattering effects caused by sample heterogeneity by normalizing spectra relative to a reference mean spectrum. This dual approach ensured high-fidelity spectral data extraction, mitigated signal distortion and optimized modeling performance.
2.5.2. Dataset Splitting
After preprocessing the spectral data, to establish a suitable model and conduct data prediction, the sample set was divided into a calibration set (used for model development) and a prediction set (used for data prediction); this study employed the Random Sampling (RS) algorithm and the Sample set Partitioning based on joint X-Y distance (SPXY) algorithm to partition the dataset into these two sets with a ratio of 4:1, specifically 80 samples in the calibration set and 20 samples in the prediction set.
2.5.3. Selection of Characteristic Frequency Bands
Spectral raw data typically contains a large number of variables, and utilizing all variables for model establishment is not only time-consuming and resource-intensive but also prone to degrading model accuracy due to the inclusion of redundant or irrelevant information. Therefore, preprocessing the data to screen critical variables is essential for improving modeling efficiency and enhancing predictive precision.
In this study, Stability Competitive Adaptive Reweighted Sampling (SCARS), Interval Partial Least Squares (iPLS), and Iteratively Retained Informative Variables (IRIV) algorithms were employed to screen characteristic frequency bands in terahertz spectroscopy. Interval Combination Optimization (ICO), Successive Projections Algorithm (SPA), Random Frog (RF) were employed to screen characteristic frequency bands in near-infrared hyperspectral.
2.5.4. Modeling Algorithm
After dimensionality reduction and feature variable extraction from the two types of spectral data, separate prediction models for lettuce nitrogen content were established using the Least Squares Support Vector Machine (LS-SVM) and Kernel Extreme Learning Machine (KELM). For LS-SVM modeling of both spectral datasets, two different kernel functions—Linear Kernel and Radial Basis Function (RBF) Kernel—were employed, while KELM modeling exclusively adopted the RBF Kernel. Specifically, the regularization parameter (C) and kernel parameter (s) were set to 100 and 10 for near-infrared hyperspectral data, and to 100 and 0.1 for terahertz spectral data, respectively.
It is particularly noteworthy that after establishing the two spectral models, this study further integrates them through a small-sample learning approach. Specifically, partial crop samples’ terahertz and hyperspectral characteristic wavelengths were selected and normalized to eliminate the influence of different dimensions, after which they were concatenated into a single sample. The small-sample learning model employed a metric learning method, and the overall framework is illustrated in
Figure 4.
Considering that metric learning primarily requires image data as input, which are typically represented as two-dimensional matrices, whereas the extracted spectral features are one-dimensional data, a transformation method was adopted to convert them into two-dimensional form for subsequent processing. To achieve this, the one-dimensional spectral feature vector was multiplied by its transpose, thereby preserving both the form and spectral information, as expressed in the following Formula (3):
In the equation, represents the one-dimensional spectral feature data, and denotes its transpose.
For the label input, the corresponding nitrogen content values of the samples are used.
In the feature extractor module, a neural network framework is employed. Considering the limited sample size, a relatively shallow yet classical residual network, ResNet-18 with 18 layers, is selected.
In the metric space module, Euclidean distance is used to calculate the differences between features, and its formula is given as follows.
For the classification module, a Softmax classifier is adopted, as it is more suitable for multi-class classification tasks.
2.5.5. Model Evaluation Method
In this study, the model performance was evaluated using the coefficient of determination (
) and the root mean square error (RMSE), with the latter further distinguished as the root mean square error of calibration (RMSEC) and prediction (RMSEP). The calculation formulas are provided in Equations (3) and (4). Generally, R
2 values closer to 1 and RMSE values closer to 0 indicate better model performance. A smaller difference between RMSEC and RMSEP suggests greater model stability, while R
2 values near unity enhance prediction reliability.
In the equation, represents the measured true value of the lettuce sample; denotes the predicted value of the sample model; is the average of the true values of the samples; and n is the number of samples.
Herein, and refer to the coefficient of determination and root mean square error () of the calibration set, respectively, while and represent the coefficient of determination and RMSE of the prediction set, respectively. A larger coefficient of determination and a smaller RMSE indicate better performance of the established model.
4. Conclusions
This study employed terahertz (THz) and near-infrared (NIR) hyperspectral techniques to predict nitrogen content in lettuce. THz spectral analysis determined the effective detection range to be 0.2–1.2 THz. Background data were removed using the Canny edge detection operator, and preprocessing with SG smoothing and MSC algorithms improved both data quality and detection efficiency.
For THz feature selection, the preprocessed spectral data were divided into calibration and validation sets using the SPXY algorithm. Feature frequency bands were then screened using SCARS, iPLS, and IRIV algorithms. SCARS extracted key frequencies mainly at 0.24, 0.32, 0.40, 0.87, and 0.90 THz; iPLS selected the 12th interval (0.9384–0.9956 THz, 16 frequency points); IRIV retained 15 power spectra and 12 absorbance features. Based on these selected variables, predictive models were constructed using LS-SVM and KELM. The LS-SVM model achieved the best performance with the RBF kernel and SCARS-selected features, yielding calibration set R2 and RMSE of 0.96 and 0.19, and validation set R2 and RMSE of 0.96 and 0.20. Similarly, the KELM model performed best with SCARS-selected features, with calibration set R2 and RMSE of 0.97 and 0.19, and validation set R2 and RMSE of 0.96 and 0.20.
For NIR hyperspectral data, the spectral range was set to 1000–1600 nm. After SG smoothing and SNV preprocessing, and sample set division via SPXY, feature wavelengths were extracted using RF, SPA, and ICO algorithms. Both LS-SVM and KELM models achieved optimal performance using ICO-selected features. LS-SVM yielded calibration set R2 and RMSE of 0.9677 and 0.1938, and validation set R2 and RMSE of 0.9603 and 0.2620. KELM yielded calibration set R2 and RMSE of 0.9581 and 0.2383, and validation set R2 and RMSE of 0.9620 and 0.2628, indicating that ICO features provided the best predictive capability.
Then we fused THz and NIR models by Few-shot learning method, the model showed that the SCARS + ICO combination performed best, with calibration set accuracy of 90.25% and validation set accuracy of 85.24%. All fusion combinations achieved training accuracies above 70%, confirming the feasibility and effectiveness of this fusion approach.
In conclusion, combining THz and NIR hyperspectral data with feature extraction and modeling techniques, including LS-SVM, KELM, and fusion models, effectively predicts lettuce nitrogen content. Among the feature selection strategies, SCARS and ICO demonstrated the highest predictive performance, providing a reliable method for rapid and non-destructive nitrogen detection in lettuce.