Accurate and timely quantification of soil total nitrogen (TN) and organic matter (OM) is critical for sustaining crop growth, improving yield, and supporting smart agriculture. Near-infrared spectroscopy (NIRS) has demonstrated strong potential as a rapid, non-destructive, and efficient technique for in-situ soil analysis. However, the inherent heterogeneity of solid soils—including variations in particle size, color, and composition—combined with subtle nutrient gradients within the same region, poses significant challenges for NIRS-based prediction. To address these limitations, this study introduces Mix-Soil-Spectra, a novel detection framework that integrates contrastive learning and ensemble learning for soil TN and OM prediction. The method enhances spectral robustness by injecting noise into raw spectra, generating dual augmented datasets, and extracting stable spectral representations. These features are subsequently used across multiple predictive models, whose outputs are stacked to achieve optimal performance. Experimental results demonstrate that Mix-Soil-Spectra effectively mitigates spectral interference and matrix effects by filtering out redundant noise and isolating stable, information-rich spectral features. These extracted features can be consistently captured and utilized by multiple base models, thereby enhancing model complementarity and generalization. Moreover, by integrating the predictive strengths of various base models through an optimized aggregation strategy, Mix-Soil-Spectra achieves superior accuracy, robustness, and transferability compared with conventional detection frameworks. In conclusion, Mix-Soil-Spectra provides a reliable and generalizable solution for NIRS-based soil property assessment, offering valuable support for smart agriculture and sustainable land management. • Mix-Soil-Spectra is proposed for stable and effective soil spectral feature mining. • A contrastive learning method captures stable spectral features under noise conditions. • Various noises are designed to simulate un-modeled variations in soil spectra. • A stacking model extracts effective features via base models and meta-learning.
Wang et al. (2026) studied this question.