Use of digital images to estimate soil moisture

Uso de imagens digitais para estimar a umidade do solo R E S U M O Objetivou-se, neste trabalho, analisar a relação entre a umidade e a resposta espectral do solo para gerar modelos de predição. Amostras com diferentes umidades foram preparadas e fotografadas. As fotografias foram tomadas em condição de luz homogênea e com correção prévia do balanço de brancos na câmera fotográfica digital. As imagens foram processadas para extração dos valores medianos nas bandas Vermelho, Verde e Azul do espaço de cores RGB; Matiz, Saturação e Valor do espaço de cores HSV; e valores dos números digitais de uma imagem pancromática obtida das bandas RGB. A umidade das amostras foi determinada com o método termogravimétrico. Modelos de regressão foram avaliados para cada tipo de imagem: RGB, HSV e pancromática. Observou-se o escurecimento do solo com aumento da umidade. Para cada tipo de solo houve um modelo com melhor ajuste. Para que modelos de predição possam ser utilizados é necessário escolher previamente o melhor modelo em função das características do solo. A estimativa da umidade do solo em função de sua resposta espectral por meio do processamento de imagens digitais mostra-se promissora.


Introduction
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 hydrological processes such as infiltration rate, surface runoff and evapotranspiration (Su et al., 2014). In the agricultural field, this parameter directly influences the yield of a crop (Kaleita et al., 2005). Still in times of water rationing, the adequate irrigation management depends on the good knowledge about soil moisture (Hanson et al., 2000). Dobriyal et al. (2012) present various approaches to determine soil moisture. For local scales, the thermogravimetric method is the most used procedure; this methodology, although precise and safe, is little practical, because it requires the collection of a large number of samples and a long drying time to achieve the results.
Moisture is also a factor that influences the spectral response of the soil (Dalmolin et al., 2005). For different water contents, the electromagnetic energy reflected by the soil surface is viewed as different tones of a color space. Thus, models for moisture prediction based on the spectral response of the soil can be obtained, for example, through spectrophotometry and orbital remote sensing (Kaleita et al., 2005;Ben-Dor et al., 2009;Bertoldi et al., 2014) or by the use of images from portable digital cameras (Kuchenbuch & Ingram, 2002;Persson, 2005a;Zhu et al., 2010;2011;Cumbrera et al., 2012). This latter approach can generate instantaneous results and use devices that are generally easy to purchase, such as common digital cameras.
This study aimed to determine equations to estimate soil moisture using variables of color spaces obtained from images of a portable digital camera.

Material and Methods
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, are presented in Table 1.
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) using Eq. 1.

Physical analysis
Textural class where: U (%) -gravimetric moisture, %; Wd -weight of dry sample, g: Ww -weight of wet sample, g; and, Wc -weight of the container used, g.
Attention was paid to homogenizing the portion of soil with the distilled water, i.e., guaranteeing that the entire soil sample had the same moisture content. When necessary, a crucible with a mortar was used to break up the aggregates. The surfaces of the samples were leveled to minimize the effects of shading by microrelief or by the edge of the container.
The images were captured with a NIKON Coolpix L810 digital photographic camera with lens of 4-104 mm. In order not to have pixels with saturated values (digital numeric value of 255) in the soil portion of the captured image, pre-tests were conducted with different adjustments of diaphragm opening, exposure time and ISO (International Standards Organization) sensitivity of the camera. Under the conditions the images were captured for this experiment, the following camera parameters were defined in these pre-tests: diaphragm opening equal to f/3.1; exposure time of 1/30s and ISO sensitivity of 200. The camera was positioned on the nadir at approximately 23 cm from the surface of the samples. The geometric resolution of 1600 x 1200 pixels was used.
In order to achieve the local control of the illumination, it was necessary to correct the white balance of the digital camera. The white balance refers to the adjustments performed by the photographer (manual mode) or by the photographic camera (automatic mode) to obtain images with colors close to those the objects have under specific illumination. The adequate white balance helps to avoid distortions in the colors and, in order to apply it correctly, one must consider the color of the light source.
In this experiment, the white balance was adjusted using the pre-setting option available in the camera. A grey chart was used as the base for the correction of the illumination. The illumination of the laboratory was performed with fluorescent lamps. The grey chart was also useful to evaluate the illumination homogeneity, since, when the illumination is homogeneous, all pixels of a photograph of the chart have the same value. (1) The image processing steps were performed in the software Matlab (version 6.5 R13). After photographing the soil samples, the central region of the images was cropped. This action was necessary to disregard the white background and the region influenced by the edges of the containers with the samples. Therefore, a central square area of approximately 150 x 150 pixels was used, according to the recommendation of Persson (2005a).
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).
RGB values of this photograph showed digital numbers (DNs) between 248 and 255, which indicated an efficient correction and homogeneity of illumination.
There was negative correlation between the values of the red, green, blue bands and soil moisture (Table 2), indicating that the soils became darker always when soil moisture increased. As a general spectral characteristic, the soils reflected more the red wavelengths, followed by green and blue (Figure 1). For this same reason, Kuchenbuch & Ingram (2002) used only red band values to predict soil moisture in an experiment with maize growth in transparent pots.
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 (Twomey et al., 1986).
In the HSV color space, the response to moisture variation was different for each soil. Therefore, there is no response pattern of the soils in this color space to the variation of moisture. The behavior of soils 1 and 6 was different from that of the others. While the values of Hue and Value decreased, the Saturation increased ( Figure 2) and, therefore, it showed positive correlation with soil moisture (Table 2). Saturation is the measurement of color purity; hence, the higher the value, The quality of the models was evaluated using validation samples, which were processed in a similar way as those used in the construction of the models. The estimates obtained with the models were confronted with the reference values (obtained by the thermogravimetric method) for the calculation of the root mean squared error (RMSE).

Results and Discussion
In order to test the calibration of the white balance, the white side of the grey chart was previously photographed. The  the purer and less grey the image. The soils 1 and 6 have similar proportions of silt, sand and clay, besides a similar color (Table  1). The soil with highest organic matter content (Soil 2) showed the lowest variation in the HSV parameters. For all soils, the parameter Value decreased on average by 0.2 units between the dry samples and the saturated samples. For the panchromatic image, the correlations varied from -0.64 (soil 3) to -0.92 (soils 1 and 6, respectively). It is possible to note that the variation in DNs due to the increase in soil moisture differs between the types of soils (Figure 3). These differences are attributed to characteristics such as texture, mineralogical composition and organic matter content, because these variables influence soil reflectance (Dalmolin et al., 2005). Zhu et al. (2010), for example, studied soils with similar mineralogy and organic matter contents, varying only the texture. These authors concluded that there is a negative exponential variation between the water content and the DNs of a panchromatic image and that the roughness of the samples, influenced by the texture, significantly interferes with the spectral response of this image.
Soil 2 differs from the others regarding the increased content of organic matter (Table 1). Despite its higher content, this soil has a reddish color (5 YR 4/4 dry and 5 YR 3/3 wet). This soil possibly contains high content of hematite, a mineral that tends to mask the effects of organic matter on soil color (Resende, 1976). Due to its high opacity, hematites tend to stabilize the reflectance of the soils even with variation of moisture (Stoner et al., 1991).
At moisture values close to the saturation of the samples, i.e., when the entire porous space was filled by water, the DNs  tended to increase. This behavior can be explained by the formation of a layer of water on the surface of the samples, which increases the reflectance. A similar behavior was observed by Kuchenbuch & Ingram (2002), Persson (2005a) and Zhu et al. (2011). In practical terms, it is possible to conclude that the relationship between the spectral response and soil moisture is well explained by the images of common digital cameras for moisture values below saturation. In order to reduce the effect of the reflection by the layer of water, the interval of moisture values used for the analyses varied among the studied soils (Figures 1, 2 and 3). Since sand particles are larger than clay particles, the capacity of water adsorption in sandy soils (smaller specific surface) is lower in comparison to clayey soils and, therefore, they saturate with a smaller amount of water. Hence, sandier soils showed lower range of evaluation compared with more clayey soils. The specific surface also explains why the color of sandy soils is more easily altered by the presence of organic matter.
The highest deviations in relation to the mean in the values of the parameters (RGB, HSV and panchromatic image) were observed in the samples totally dried or close to saturation. In these two ranges, it was difficult to level the surface of the samples.
Linear models with 1, 2 and 3 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.
The equations with the best fits are presented in Table 3. Among the tested models, the variables Saturation (S) and Value (V) of the HSV color space stood out for the soils 1, 3 and 5. Thus, the model proposed by Persson (2005a) represents a good form to estimate the moisture of these soils. A satisfactory fit was obtained with the use of this model, although it was inferior to those found by this author. Since the red band has higher DNs and according to the relationships of conversion from RGB to HSV (Hanbury, 2002), the parameter Value, for all soils, was obtained by making R/255. Hence, the correlation of the red band (Table 2) was incorporated into this model. Additionally, this model has the contribution of the Saturation band, which varied as a function of soil characteristics (Figure 2).
For the soils 2 and 6, the best model was the one in which only the parameter Value was used as independent variable. In these cases, the same results are found when using only the Red band, as proposed by Kuchenbuch & Ingram (2002). The DNs of the panchromatic image were also useful to determine the moisture of soil 6. For soil 4, a model that considers the Blue and Green bands of the RGB color space demonstrated superior performance; however, in this case, there was also significance when the S and V bands were considered as independent variables.
The results demonstrate that, in order to estimate the moisture of soils analyzed as a function of the variation in the spectral response, the characteristics of the soil must be previously analyzed so that the most satisfactory model is selected. There is still the need for complementary studies with different soil classes to understand the relationship between soil moisture and the spectral response of the soil.
Moisture determination through digital images is a nondestructive method that must be improved for the in loco determination without the need for collecting samples. One disadvantage of the method is that it determines only the moisture on the surface of the samples.
The present study shows that it is possible to estimate soil moisture based on the spectral response of samples, provided that some precautions are taken, such as the correction of illumination and white balance. It should be pointed out that the electromagnetic energy reflected by the soil surface is a property of the sensor of the camera and, therefore, without the proper corrections, the results will vary from camera to camera (Persson, 2005b).
In future studies, evaluations should be performed using reflectance values, photographic cameras with bands on the infrared spectrum and hyperspectral cameras.

Conclusions
1. Images from common digital cameras, with adequate processing, can be used to estimate moisture of different soil classes.
2. For each type of soil, different linear models must be tested, with bands of the color spaces RGB, HSV and digital numbers of a panchromatic image as independent variables, in order to find the most adequate.
3. The methodology of the present study allowed an efficient correction of the white balance of the digital camera, a fundamental step for the standardization of the photographs.  Table 3. Equations to estimate soil moisture (Y) as a function of color variables through digital images and the respective determination coefficients (R²)