Soil Moisture Prediction from RGB image


I was working on analyzing the relation between the moisture and the spectral response of the soil to generate prediction of moisture. The photographs were taken under homogeneous light condition and with previous correction for the white balance of the digital photograph camera. The images were processed for extraction of the median values in the Red, Green and Blue bands of the RGB color space; Hue, Saturation and Value of the HSV color space; and values of the digital numbers of a panchromatic image obtained from the RGB bands. It was observed the darkening of the soil with the increase of moisture. For each type of soil, a model with best fit was observed and to use these models for prediction purposes.

Soil moisture estimation as a function of its spectral response by digital image processing proves promising.


Soil moisture is the measurement of the amount of water in liquid or gaseous state, present in the soil porous space at a given time. This characteristic is related to important hydro-logical processes such as infiltration rate, surface runoff and evapo - transpiration .


Six soils available in the database of the Federal University of Viçosa (UFV) were used in this study. Their physical characteristics, textural class, contents of organic matter and color, according to the visual interpretation of the Munsell chart.

Portions of soil were sieved (2 mm mesh) to remove gravel and roots, and dried in an oven (65 ºC) until reaching constant weight. Then, samples were prepared with gradual addition of distilled water (approximately 5%) varying from the constant weight (dry soil) until a value close to saturation. Three samples were prepared for each soil moisture. All samples were photographed, weighed and then dried in an oven at 105–110 °C for 24 h for the determination of gravimetric moisture (U(%)). U (%) was determined according to the methodology of EMBRAPA (2011)

The images were captured by NIKON Coolpix L810.White balancing is one of the best way to make proper color deviation.

The values of each one of the bands of the RGB color space were extracted for the calculation of the median. The use of the median is suggested by Persson (2005a) as a way to overcome the deviations caused by the shading of the microrelief formed on the surfaces of the soil samples. The images were converted from RGB to the HSV color space to obtain the median values of hue, saturation and value, and also converted to panchromatic images, obtaining the median value of the digital number.

In the HSV space, the colors are represented by the parameters: hue (tones), saturation (purity) and value (brightness), all varying between zero and one. The transformation from RGB to HSV followed the procedures presented by Hanbury (2002).

The DN values of the monochromatic images were obtained by Eq. 2, assuming the values of conversion of the National Television System Committee (NTSC), according to Solomon & Breckon (2013).


Linear deep learning models with independent variables were tested for each color space (RGB and HSV). A linear model using only the DNs of the panchromatic image was also evaluated. In the comparison between models, the RMSE value was evaluated. The addition of a third factor did not improve much the fit and, therefore, these models were not selected.

Results and Discussion

In order to test the calibration of the white balance, the white side of the grey chart was previously photographed. The RGB values of this photograph showed digital numbers (DNs) between 248 and 255, which indicated an efficient correction and homogeneity of illumination.

The darkening of the soil can be explained, in optical terms, by the variation in the refraction index of the dry soil and wet soil. When water is added, the contrast between soil particles and the surrounding medium decreases, because the refraction index on the water/particle interface is lower than the refraction index in these areas in dry soils.

Other factors that effect your model is offcourse sun light. It will work for places where light source is controlled.

If you know some of the method feel free to comment.

Special thanks to the paper and dataset I got.


Sushant kumar jha

Machine Learning enthusiast |Python |C++|JavaScript|Tensorflow|keras