Introduction

Potassium (K) significantly influences plant growth and development1. It is absorbed by plants from two primary sources: soil and fertilizers2. With the current increase in crop yields and multi-cropping indices, coupled with the imbalance in nutrient inputs under traditional agricultural management practices, soil potassium has substantially declined, leading to an overall potassium deficit3,4. Soil potassium depletion and a shortage of potassium fertilizers have become major limiting factors for agricultural production development5,6. These limitations emphasis on exploration of effective strategies to meet plant potassium demands with minimal fertilizer application and to move toward sustainable and green agricultural production7. Potassium is one of the most abundant mineral cations that acts as an activator of numerous important enzymes8,9. This element is crucial for cell growth10. In terms of growth-promoting mechanisms, potassium primarily functions by stimulating and controlling the plasma membrane Adenosine Triphosphatase (ATPase). This process induces acid stimulation, loosens the cell wall, and activates hydrolases11. Due to its high mobility in plants, potassium plays a significant role in regulating cell osmotic pressure and balancing cations and anions in the cytoplasm12,13,14. It also participates in various physiological processes such as stomatal opening and closing and cell elongation. It plays a key role in increasing yield and improving crop quality11,15,16. Jin et al.17 reported that the highest yield and fruit quality of Fuji red apple were achieved with the application of 600 kg of potassium per hectare. Wang et al.18 demonstrated that a 6 mM potassium improved pear growth and enhanced photosynthetic efficiency. Lu et al.19 reported an increase in production and improve in fruit quality parameters in navel orange with the application of less than 500 kg of potassium per hectare. Reversely, the interactive effects of potassium with other nutrients are significant. For instance, high potassium concentrations in soil solution can reduce magnesium uptake, potentially causing magnesium deficiency in plants20. Its deficiency can increase the uptake of sodium (Na+) and calcium (Ca2+) in plants like maize21 and inhibit nitrogen uptake, significantly reducing nitrate (NO3) content in cotton leaves22. Potassium substantially influences the uptake and utilization of other nutrients, and its optimal levels intensively depends on the crop type23.

To move on the sustainable production path, quality inspection of products is a necessary24. However, determining chemical compositions of fertilizers such as potassium is a vital process in their production lines to achieve high quality products. Laboratory methods for determining chemical composition of fertilizers are destructive, time-consuming, and require a significant number of chemical materials. Standard methodologies include gas chromatography (GC), high-performance liquid chromatography (HPLC), gas chromatography–mass spectrometry (GC–MS), polymerase chain reaction (PCR), and enzyme-linked immunosorbent assay (ELISA). These are recognized as highly accurate and powerful tools for the identification and quantification of sample components25. Nevertheless, their widespread application in large-scale or real-time contexts is often constrained by high costs, time-consuming procedures, the need for skilled personnel, and complex sample preparation protocols.

Recently, imaging as a rapid and accurate technology has attracted attention to assess different materials26,27,28,29. Imaging is widely used to assess different materials because it is nondestructive30,31. Its extensive applications are attributed to its high speed, high accuracy, low cost, and the absence of the need for laboratory specialists to perform tests32,33. Among these technology, hyperspectral imaging (HSI) or chemical imaging technique can combine conventional imaging and spectroscopy to simultaneously obtain spatial and spectral information from samples and create accurate distribution maps at the pixel level34,35,36. HSI is an advanced, non-destructive analytical technique that integrates the spectral capabilities of spectroscopy with the spatial information provided by optical imaging30,31. This method enables the simultaneous acquisition of spatial and spectral data across the surface of a sample, allowing for comprehensive and high-resolution chemical characterization. Specifically, the obtained HSI data are represented as a 3D data consisting of 2D spatial images superimposed along the third dimension of wavelengths37,38. Each pixel in the image is associated with a specific spectrum, which enables pixel-wise analysis of an objects intrinsic39,40. Operating primarily in the visible (VIS) and near-infrared (NIR) regions of the electromagnetic spectrum, HSI has emerged as one of the most cutting-edge imaging modalities for the qualitative and quantitative assessment of diverse materials41,42. One of its key advantages lies in its capacity to detect subtle spectral differences that are imperceptible to conventional visual imaging techniques43,44,45. The method has been used to assess different materials such as water46, wheat flour47, cucumber48, pistachio49, and strawberry50. Related to fertilizers, Malounas et al.,51 detected the fertilization levels in broccoli using HSI technique.

Unlike conventional spectroscopic techniques—such as infrared or microwave spectroscopy—which typically perform point-based measurements, HSI captures spectral information for all points in an image. The result is a three-dimensional data structure known as a hypercube or data cube, which combines two spatial dimensions with one spectral dimension52. The utility of spectroscopic techniques in detecting chemical elements and compounds has been extensively demonstrated in previous studies. For instance53, investigated the detection of chlorine in cement samples using Laser-Induced Breakdown Spectroscopy (LIBS) within the infrared (IR) and ultraviolet (UV) spectral ranges. Ilguth et al.54 utilized microwave spectroscopies to detect chlorine in cement matrices, while Thorwirth et al.55 applied gas-phase infrared spectroscopies to investigate CH₂Cl⁺ and CH₃ClH⁺ ions in the context of chlorine astrochemistry. However, the primary limitation of these techniques lies in their inability to provide continuous surface-level information, a challenge effectively addressed by hyperspectral imaging.

Till now, HSI was not used to determine potassium oxide in potassium sulfate fertilizer. As a novel goal, the present research was conducted to survey the ability of HSI and artificial neural networks (ANN) method in the determination of potassium oxide levels in potassium sulfate fertilizers. This innovative approach offers a faster cheaper, and more efficient alternative to the used laboratory methods.

Materials and methods

Fertilizer specimens

Potassium sulfate specimens with different K2O contents were obtained from Eyvan Chemical Industries Complex Company, Ilam Province, Iran. The samples were prepared in 50 g weight and packaged in separate bags (Fig. 1).

Fig. 1
figure 1

The potassium sulfate specimens with different levels of potassium oxide.

Chemical laboratory measurements

After preparing the test specimens, the K2O content in potassium sulfate was determined using a flame photometer (Model: jenway, PFP7/C) in December 2024 (Fig. 2, Table 1). The specimens were then stored in specified packaging to be utilized in the hypercube acquisition stage.

Fig. 2
figure 2

Flame flowmeter.

Table 1 Characteristics of fertilizers used in the research.

Hypercube acquisition

An HSI system consists of essential components that capture and analyze precise spectral data. Unlike conventional cameras that capture only three-color layers (channels), a hyperspectral sensor records data across narrow and continuous spectral bands30,56. The setup of an advanced desktop HSI systems includes a light source, wavelength-spreading devices, and area detectors and a computer equipped with software for managing image acquisition and data processing57,58.

In this study, a HSI system operating in the wavelength range of 400–950 nm (Model: Specam, Parto Sanat Company, Zanjan, Iran) was used to capture hyperspectral images of the samples. The system was equipped with four 25-W LED lamps serving as the illumination source (Fig. 3). The system was equipped with a line scan motorized camera to capture hyperspectral images over specific areas. The system’s components were a hyperspectral camera, a lighting source (four white LED lamps), and a personal computer. These components, supported by a software to control the imaging process and subsequent operations including digitization and storage.

Fig. 3
figure 3

The used hyperspectral imaging system.

The imaging step was conducted in the Image Processing Laboratory of Ilam University, Ilam, Iran. For each potassium oxide levels, three repetitions (specimens) were performed and six hypercubes’ images were captured from each repetition. Thus, a total of 18 hypercubes were obtained for each potassium oxide level. In total, 126 hypercubes were captured from all potassium oxide levels.

Pre-processing

The hypercubes of a white paper were recorded before and after each imaging section and the system subtracts the images of the white paper from the samples’ hypercube, automatically. No further noise reduction was used in the present study. A hypercube processing algorithm was developed in MATLAB software, version 2016 (MatWorks, Carlsbad, California, USA). To remove the effect of the edges of the sample container under the camera lens, the center of the hypercubes was separated. Based on the size of the sample container under the camera, lens the algorithm cropped a rectangular region )70 × 110 pixels (in the center of each hypercube to be used in further processing steps.

To enhance predictive performance and reduce computational complexity, it was necessary to reduce the volume of input data. In this regard, the most effective wavelengths were selected from the full hypercube to optimize the prediction process32,59,60.

Principal component analysis

Principal component analysis (PCA) method was employed to analyze the high-dimensional hypercubes. The primary objective of this analysis was to reduce the dimensionality of the data while preserving the maximum variance, thereby enabling the identification of key spectral bands. This method provided a comprehensive basis for evaluating model performance and ensured that the obtained results were both reliable and generalizable61.

In this approach, the mean of the first and second principal components (PC1 and PC2, respectively) of the spectra were calculated and the effective wavelengths were selected based on the peaks in the PC1 and PC2 diagrams62,63. The optimal number of selected bands was determined based on the location of spectral peaks and their ability to discriminate between different levels of K₂O concentration.

Extraction of features

Different statistical image features—including mean, minimum, maximum, variance, median, and standard deviation—were extracted from the corresponding spectral layers64. The extracted features were then used as inputs for the development of predictive models.

Selection of discriminative features

Before prediction/classification, dimensionality reduction techniques were applied in cases where a large number of features had been extracted. Reducing the number of input variables—especially when they are numerous—is essential for optimizing the performance of predictive models. In this study, sequential feature selection (SFS) method was employed to identify a subset of the most informative features from the extracted set corresponding to the selected wavelengths65,66. This method selects efficient features based on the generalized residual sum of squares (GRSS) criterion67,68.

Prediction

The determination of various K₂O concentration levels in potassium fertilizer samples was investigated by developing a model based on the artificial neural networks method. In this study, relevant spectral features were first extracted from hyperspectral images and selected to be used as input vectors in predictive modeling. These features, which capture spectral patterns associated with different K₂O levels, play a crucial role in enhancing classification accuracy and prediction performance. ANN-based models were trained using these input features to accurately classify and predict the K₂O content in new samples. The application of machine learning algorithms particularly artificial neural networks for hyperspectral data analysis has been widely reported in the literature due to their strong capability in modeling complex and nonlinear relationships69,70. In this approach, the extracted features were fed into the neural network as input data, while the K₂O concentration levels were encoded as target data for training and prediction purposes.

For this purpose, the database was divided into three parts: train, validation, and test sets. For prediction using ANN, 60% of the data was used for train, 20% for validation, and 20% for the test phase. The first step in creating an optimal predictive model is to select a suitable network architecture. After determining the architecture, the network is trained using the data selected from the images. In this study, the Levenburg-Marquardt (LM) learning algorithm was used. This algorithm is one of the fastest methods for training backpropagation neural networks due to the use of the Hessian matrix method41,71,72.

The number of neurons in the hidden layer(s) of the network depends on the level of convergence and the reduction of the output error during the training process. An excessive abundance of neurons may lead to overfitting or memory errors in the database, while an insufficient number of neurons may limit the network’s ability to effectively simulate the process. This process highlights the importance of maintaining a proper balance between model complexity and performance accuracy. The optimal number of neurons was determined through trial and error, as too many neurons can negatively affect the performance of the network. The network used was of the error backpropagation or feedforward type, with the activation function of tangent sigmoid (tansig) for the hidden layer and linear function (purelin) for the output layer.

Results and discussion

Effective hypercube layers

The plots of the first (PC1) and second (PC2) principal components corresponding to all layers of hyperspectral images (comprising 665 layers) of potassium sulfate samples with varying K₂O concentrations are shown in Fig. 4. Out of the 665 wavelengths in the hyperspectral data cubes, seven effective layers were selected for identifying different levels of K₂O. Based on principal component analysis, the selected layers were 65, 327, 470, and 595 for PC1 and 319, 542, and 568 for PC2. The corresponding wavelengths of these selected layers for potassium sulfate with different K₂O levels are: 453.32, 669.95, 778.19, and 891.55 nm for PC1; and 663.34, 847.72, and 869.32 nm for PC2. Therefore, the layers associated with these wavelengths were utilized for feature extraction in the analysis.

Fig. 4
figure 4

First (PC1) and second (PC2) principal components graphs of potassium sulfate with different levels of K2O.

Efficient features

Six features were extracted from each effective hypercube layer. As seven hypercube layers were selected, total of 42 features were extracted. The features extracted from the effective layers included mean, minimum, maximum, variance, median, variance, and standard deviation. Among the extracted features, seven features were selected as efficient features based on SFS method (Table 2). The efficient features were used for prediction and the rest of the features were eliminated.

Table 2 The selected features for detecting K2O levels in potassium sulfate.

Modeling results

The results of the prediction of the amount of K2O in potassium sulfate were presented in Fig. 5. Different percentages of K2O of potassium sulfate were predicted using all the features extracted from the hypercubes, i.e. without feature selection step. In selecting the most appropriate network structure, the number of neurons in the hidden layer started from 2 neurons and continued up to a maximum of 20 neurons. Given that a smaller number of neurons in the middle layer reduces the size of the network and increases the learning speed. By examining different models, the optimal structure 42-12-1 was obtained (Fig. 5a). This model has 12 neurons in the hidden layer. The correlation coefficients of the optimal network for the train, validation, test, and total data were calculated to be 1.00, 0.88, 0.76, and 0.92, respectively (Fig. 5b). Figure 5c shows the performance of the neural network during the validation stage for different numbers of epochs. The results showed that the lowest validation error was achieved in epoch number 22 with a value of 0.0208.

Fig. 5
figure 5

Detecting different percentages of K₂O based on all extracted features, (a) optimized artificial neural network architecture, (b) regression plots of the optimized artificial neural network, and (c) performance of the artificial neural network during the validation phase.

The prediction results for K2O content in potassium sulfate were presented in Fig. 6. In this study, various percentages of K2O in potassium sulfate were predicted using selected features extracted from hypercubes. The optimal network was determined to be 7-4-1 structure (Fig. 6a), which included 4 neurons in the hidden layer. The correlation coefficients of the optimal structure during train, validation, test, and overall data were 0.93, 0.83, 0.78, and 0.88, respectively (Fig. 6b). The evaluation of network’s performance during the validation stage indicated that the lowest validation error (0.022) was achieved at epoch number 100 (Fig. 6c).

Fig. 6
figure 6

Detecting different percentages of K₂O based on the selected efficient features, (a) optimized artificial neural network architecture, (b) regression plots of the optimized artificial neural network, and (c) performance of the artificial neural network during the validation phase,

The results of the present research showed that the prediction of K2O without feature selection step (r = 0.92) was higher than with conducting the step. Caporaso et al.73 predicted protein content in single wheat kernels using HSI. They reported that the performances (R2) over calibration and validation datasets for single kernel protein content were of 0.82 and 0.79, respectively, with RMSE of 0.86 and 0.94%, respectively. Malonas et al.51 detected the fertilization levels in broccoli with 91.0% accuracy using a portable HSI system.

Implementing high-speed processing systems integrated with the developed hypercube processing and artificial neural predictive model can enable real-time and precise monitoring of K2O levels in potassium sulfate. This online approach not only enhances the accuracy and speed of quality control but also improves production processes and reduces human errors. Considering the high efficiency and accuracy of the predictive model used in this study, it is suggested to apply such models for predicting other parameters related to chemical substances used in agriculture. This initiative can optimize the use of chemicals, minimize environmental impacts, and improve productivity in the agricultural sector. Furthermore, developing and customizing these models for broader applications can open new horizons for smart resource management and sustainable production in agriculture and related industries.

Conclusions

The present study was conducted to evaluate the capability of the HSI technique and ANN model in predicting the K2O of potassium sulfate. In this research, the effective wavelengths were found from hypercubes and utilized for feature extraction. The data were analyzed in two scenarios: with and without the selection of efficient features. The results indicated that the prediction accuracies in these two cases were 87.83 and 92.19%, respectively, highlighting the high capability of artificial neural networks in prediction of K2O in potassium sulfate based on HSI technique. Various artificial neural network architectures were evaluated and compared, among which the 42-12-1 structure demonstrated the best performance. This architecture achieved the lowest error (0.0208) and the highest correlation (0.92), yielding reliable results in the model’s predictions. These findings suggest that a system based on multispectral imaging can be designed to process spectral images of samples and predict them using artificial neural networks. Such a system could significantly reduce detection time by developing a real-time system in industrial applications. To enhance analytical accuracy and improve the performance of the artificial neural network model, it is recommended to utilize a larger dataset during the training and evaluation phases in future research. It seems that providing samples with same Na, Cl, Ca, and pH compositions gave higher accuracy in determining K2O levels. Also, the authors suggest using hyperspectral imaging in other wavelengths ranges such ultraviolet to assess fertilizer components in future researches.