Machine Learning Predicts Soil Nutrients From Lab Extract Photos
Researchers tested whether computer vision can classify nitrogen, phosphorus, and potassium levels from standardized images of prepared soil samples.
Soil nutrient analysis in agricultural regions across Punjab relies heavily on slow laboratory tests, but a newly tested machine learning approach predicts nitrogen, phosphorus, and potassium levels using photographs of chemically prepared soil extracts. Traditional soil testing requires specialized equipment and handling hazardous reagents, which can delay fertilizer recommendations for farmers working in remote areas.
To bypass these bottlenecks, researchers developed a standardized black box imaging enclosure equipped with a 12-watt white light-emitting diode bulb and a fixed mobile holder. The study, published in PLOS One by Umair Maqsood and colleagues, investigated whether computer algorithms could evaluate soil fertility through visual traits alone.
How Chemical Extractions Transform Into Digital Data
The research team gathered 50 independent physical soil samples from agricultural lands at two distinct depths, spanning zero to 15 centimeters and 15 to 30 centimeters. After drying the soil in an oven at 105 degrees Celsius for 24 hours, the samples were ground and sieved through a 2-millimeter mesh. Each 10-gram soil sample was mixed with 20 grams of an extracting solution containing Diethylene triaminepentaacetic acid, sodium bicarbonate, potassium chloride, and calcium chloride.

The mixtures were agitated on a digital shaker for 20 minutes at 190 revolutions per minute before being filtered through paper to yield a clear liquid extract. These extracts were placed in white ceramic dishes inside the black box chamber. A Xiaomi Redmi Note 10 smartphone camera captured high-resolution images under constant lighting monitored by a lux meter, generating a series of visual records from U1.jpg to U50.jpg.
Comparing Classical Machine Learning and Deep Learning Models
For the classical machine learning pipeline, the team cropped the central 50 percent of each extract image and extracted a total of 185 color and texture descriptors. These numerical features captured statistical metrics from red-green-blue, hue-saturation-value, CIELAB, and YCbCr color spaces, alongside grayscale statistics, Local Binary Patterns, and Gray-Level Co-occurrence Matrix properties. The authors also tested a compact convolutional neural network for automated feature learning directly from the cropped red-green-blue images.
Using nested cross-validation with five outer sample folds, the algorithms classified the nutrient concentrations into low, medium, or high status categories based on established laboratory reference thresholds. For nitrogen, the K-nearest neighbors model achieved an accuracy of 60 percent. For phosphorus, a Random Forest algorithm reached an 82 percent accuracy rate, though the authors noted this matched the majority-class baseline because 41 of the 50 samples fell into the low category. For potassium, Logistic Regression achieved a 48 percent accuracy, outperforming its 44 percent majority-class baseline.

Understanding the Limits and Future of Digital Soil Assessment
The study found that classical machine learning models slightly outperformed the deep learning convolutional neural network across the nutrient categories. The authors point out that overall performance was constrained by a small sample size and significant class imbalance, particularly for minority nutrient ranges such as the single low-nitrogen sample and the three high-phosphorus samples. Furthermore, ablation experiments revealed that extra data augmentation techniques did not uniformly improve predictions across all three nutrients.
Despite these current limitations, the findings demonstrate that chemical soil extracts contain measurable visual patterns linked to nutrient concentrations. The research team suggests that with future validation on larger, more balanced datasets spanning diverse geographical regions, similar image-assisted frameworks could eventually transition to portable smartphone applications for rapid agricultural monitoring.
The research was published in PloS one on January 1, 2026.
This article has been fact checked for accuracy, with information verified against reputable sources. Learn more about us and our editorial process.
Last reviewed on .
Article history
- Latest version
Reference(s)
- Maqsood, Umair., et al. “Controlled image-based prediction of soil nutrient concentrations (NPK) using machine and deep learning.” PLOS One, vol. 21, no. 10, October 27, 2026, pp. e0360517 Public Library of Science (PLoS), doi: 10.1371/journal.pone.0360517. <https://doi.org/10.1371/journal.pone.0360517>.
Cite this page:
- Posted by Raj Joshi