1 Introduction

Water plays an important role in the life activities of plants. The excessive or low water content of the plant will affect the normal growth of the plant, so the moisture content of the leaves can be used to reflect water status and physiological information of the plant [1].Artificial neural network prediction of potato leaf water potential was constructed by digital image, color space transformation and RGB vegetation index. And the results show that the predicted value of leaf water potential and the measured value is almost the same [2].In this study, the water content of wheat leaves can be predicted directly by Matlab, without affecting the maturity of wheat, the water content and leaf information of plants can be detected in real time and the field capacity can be understood timely. It is helpful to the study and implementation of the intelligent and water-saving irrigation of plants, conduct precise irrigation to plants and greatly improve the utilization efficiency of agricultural water. The study has an important guiding significance to the global green agriculture.

2 Working principle

First of all, conduct image collection of the wheat leaf, and during the collection process, try to avoid the noise, keep the shooting angle and distance is basically in the same. Measure the moisture content of the leaves by the oven drying method, and pay attention to the number of leaves. And then conduct pretreatment of the image, thereby reducing the impact of noise on subsequent processing. In order to extract the features of the leaves, we need to extract the leaves from the background. We divide the images with the image binarization of the Ostu maximum interclass variance method based on the gray level processing. In the color feature part, the color images of RGB, HIS and Lab are analyzed by using the analysis function of Matlab image. For the appearance features, the area feature of the leaf image and the width feature are extracted, and the values of the eigenvalues are obtained. For texture features, the texture mean value, entropy and consistency of the three characteristics are mianly analyzed, and finally, according to the moisture content of the leaves, analyze the correlation between it and the eigenvalues, and then obtain the relevant coefficient. The eigenvalues with a greater correlation with the water content are taken as parameters for the subsequent water content prediction. Finally, the BP neural network is used to the training of 80 samples. After the training is completed, the test data is loaded and tested with the trained BP neural network. Then, the output of the prediction result is simulated and compared with the actual expected output. Error graph and error percentage map are drawn. Finally, the prediction model is validated.

The working flow of this research is shown in Fig. 1.

Fig. 1
figure 1

Working wireframes

3 Image acquisition and detection of water content

3.1 Image acquisition

Use mobile phones in the greenhouses under natural light conditions to conduct image acquisition of wheat leaf. During the collection, try to avoid the body and other objects on the occlusion of wheat leaves and the shadow, try to ensure that the shooting light intensity is basically in the same which is convenient to the image processing at the late stage (the angle to shoot the leaves, the height between camera and the leaves, shooting time should be consistent everytime). After shooting, cut the corresponding shooting leaves with scissors, put them into the numbered plastic bag, and take them back to the laboratory for leaf moisture measurement.

3.2 Detection of water content

In this experiment, the moisture content of the leaves was measured by oven drying method. The collected leaves were weighed firstly and the wet weight of the leaves was measured with a 0.0001 precision test analytical balance. Each leaf was weighed three times to take the average [3]. After the leaves are weighed, put them into the drying paper bag, and each paper bag corresponds to a leaf, and then the bagged leaves are placed in a drying box. The temperature is first adjusted to 115 °C, and time is counted until the temperature rises to 115 °C, and bake the leaves for 15 min, the purpose is to kill out the leaves, and then the drying temperature is adjusted to 80 °C, bake the leaves for 6 h. After the leaves are dried, weigh the dried leaves for three times and take their average value. Finally, the moisture content of the leaf can be calculated according to the formula.

$$w = \frac{{w_{0} - w_{1} }}{{w_{0} }} \times 100$$
(1)

In the formula: w is the water rate of the leaves, w0 is the fresh weight of the leaves, w1 is the dry weight of the leaves.

4 Image preprocessing

Image preprocessing mainly includes image cut, image graying processing, image enhancement and denoising and image segmentation process, as shown in Fig. 2. Before preprocessing the image. First, the image is cut with Matlab, because it is difficult to guarantee that the picture is the desired image of the leaves during the process of shooting, but also some unwanted parts in the picture, so it is necessary to cut the imagine with imcrop function firstly to remain the neccessary part, as shown in Fig. 3. The image (a) is the image before the shear, and the image (b) is the image after shear.

Fig. 2
figure 2

Image processing flow chart

Fig. 3
figure 3

Wheat leaves shear image

4.1 Image gray processing

In order to improve the processing speed of the leaves, it is necessary to convert the color image into a grayscale image with only luminance information. The gray image of the color image, there are four methods, the average method, the maximum value method, the component value method and the weighted average method [4]. Weighted average method to convert the image can retain the details of the original image information, so the study selected weighted average method of gray image processing, the processing chart shown in Fig. 4.

Fig. 4
figure 4

Wheat leaves grayscale

4.2 Image enhancement

Image enhancement refers to highlighting some of the information needed in an image according to a certain need, while removing or weakening some processing that does not require information. Its main purpose is to make the image after processing to obtain some of the characteristics of the specific application than the previous image is more applicable [5]. In this study, after comparing several enhancement methods, the final selection of the median image filtering, because the median filter image is almost no noise, the image of the target image contour is relatively clear, but the image target and background contrast Low, so this study decided to use the median filter to deal with the image, and then directly enhance the contrast of the image to achieve the edge of the target contour clear, while the target and background images are significantly contrast, easy to the next step in image processing. Processing effect shown in Fig. 5.

Fig. 5
figure 5

Image enhancement

4.3 Image segmentation

Image segmentation refers to the area of interest in the image is divided, these areas are not overlapping, each region to meet the gray, texture and other characteristics of a similarity criteria [6].Image segmentation is the most important step in the image processing process, and the segmented image area can be extracted as a feature. In the process of processing the leaves, the effective information is the image of the leaves, so need to capture the image segmentation. After image enhancement, there is a significant difference between the target image and the background in the gray image. Therefore, the image segmentation of this study adopts the Ostu maximum interclass variance method based on gray level processing. The result of the image processing is shown in Fig. 6(a) is a picture after image sequential processing, and Fig. 6(b) is a separate picture after image segmentation.

Fig. 6
figure 6

Wheat leaves image segmentation

5 Feature extraction

Feature extraction is the most critical step in image analysis. In this study, the color features, shape features and texture features were extracted, and the obtained eigenvalues were stored in excel, which was helpful for subsequent processing.

5.1 Color feature extraction

In order to extract the leaf area of the color component of the mean, we should pay attention to select the correct algorithm. If you choose the mean2 () function to calculate the result is wrong, because the mean () default is the entire jpg all the pixels and the sum, including the leaf area and the sum of the area of the background, more background area, so the mean is not Only the mean value of the RGB component of the leaf, the program running out is also less than the correct RGB value, so use the sun (sun ()) function to all the components and out of the total after the total non-zero elements The number of leaf area to get the weight of the weight of the [7]. Table 1 is a partial data value for each color component of a different water content leaves. The correlation coefficient between water content and H is 0.9216, and the correlation between water content and other color components is not significant. The specific correlation coefficient is shown in Table 2.

Table 1 Part of the sample characteristic value data
Table 2 The correlation coefficient

5.2 Extraction of shape features

There is an important feature in the image is the shape features, people usually according to the shape of the image to determine the recognition and understanding of objects. In this study, the width, perimeter and area regarded as the eigenvalue.Table 3 shows the characteristic components of the leaf shape features extracted from different water content leaves. Through the correlation analysis of the obtained data, the correlation coefficient between leaf area and water content was 0.9887 (Table 4). Other parameters and water content is not relevant, not repeat them one by one. Where the calculated area is the area of the pixel, can also be replaced by the actual area of the leaves, but this study uses the pixel area does not affect the correlation analysis [8].so no conversion. Specific parameters in Table 3.

Table 3 Shape feature parameters
Table 4 The correlation coefficient

5.3 Extraction of texture features

Texture is an important feature for the analysis of multiple images, and the perception of texture plays an important role in the recognition and interpretation of human vision. Texture analysis is an important field of image processing and recognition and computer vision. In this study, we mainly extracted three characteristic parameters of consistency, mean and entropy. The specific parameters are shown in Table 5, and the correlation coefficients are 0.6527, 0.6549 and 0.7148 respectively.

Table 5 Texture feature parameters

In order to facilitate the late prediction of wheat leaves, there will be a significant correlation between the five characteristic parameters and the water content values, as shown in Table 6, and the specific correlation coefficients are shown in Table 7.

Table 6 Characteristic parameters
Table 7 The correlation coefficient

6 Neural network prediction model

6.1 BP neural network training

Neural network is a pre-determined technology developed in the 1940s because it has a particularly strong nonlinear dynamic decision function, so it is widely used in many fields. The study used BP neural network to establish the leaf feature model, and used this model to predict the water content of wheat leaves [9].

  1. 1.

    First use the format long function to set the variable precision, making it accurate to the decimal point after 15; And then read 100 sets of leaf eigenvalues and water content table, extract the first 80 lines in the table, the first five columns of eigenvalue parameters as input p; the first 80 lines, the sixth column eigenvalue parameter as output t.

  2. 2.

    Transpose and normalization. In the design of BP neural network, it should to normalize after get the input and output variables to prevent the input data between the various dimensions of the magnitude difference is too large. This can be followed for the convenience of processing, and can ensure that the program running to accelerate convergence. Training data normalization is limited to a certain range of data processing. The normalization of the test data is carried out according to the normalization of the training data so that the test data and the training data are carried out according to the same normalization rule. In this study, the input and output data are normalized by the premnmx () function in Matlab, and the data is normalized to [− 1, 1], so that the effect of the prediction will not be affected by the floating of individual data.

  3. 3.

    Training the data. First, a neural network is established, which consists of five inputs, ten hidden layers and one output. The transfer functions are tansig, tansig, purelin, and the training function is trainlm. Then set the training parameters. Set the training step to 1000, the training error is 0.0001, the learning rate is set to 0.1. Transferred to the training of the network model, the network training. The training process is shown in Fig. 7.

    Fig. 7
    figure 7

    The training process

6.2 The test and simulation

The test data is loaded and tested using the trained BP neural network. Then, the output of the prediction result is compared with the actual expected output. The code is net = train (net, pn, tn), and finally the error graph is drawn and the percentage of error. The error figure and the error percentage are shown in Figs. 8 and 9.

Fig. 8
figure 8

Error figure

Fig. 9
figure 9

The percentage error

6.3 The model validation

Twenty sets of data after the transfer, according to the above steps to simulate the output, the output and the actual water content were compared, the results shown in Table 8, Fig. 10 is the results of the comparison chart. It can be seen from the table that the predicted results are not very different from the actual moisture content, so the model can be applied to the actual prediction of leaf water content.

Table 8 Results contrast
Fig. 10
figure 10

Results contrast

7 Conclusion

Based on Matlab mathematical software, the prediction model of water content of wheat leaves was established, and several experiments were carried out by using the established prediction model. The results show that the prediction accuracy of up to 96%, fully meet the set goals. It can be seen that it is feasible to predict the water content of wheat leaves based on Matlab.