## 5 Image Processing  
The objective of the image processing is to obtain a measure of the amount of bad leaves in the area where the vineyard is placed, which depending on this value would mean that the plant has a problem and need to be watched. The difficulty is that the bad leaves can be confused with the ground in many cases, because they can have similar colors, and then other processing is needed. Another problem is that the images are not taken from the same distance to the vines, and this implies that the size of the leaves is different from image to image. At the end of the process we will get a mask with all the pixels that are estimated to be part of the bad leaves. The system has been deployed in Spain, where the mean value for the hours of sun varies from 1,584 to 3,433 depending on the region. Concretely the system is deployed to be used from 1 May to 30 September (when the vineyard plants grow, depending on the variety of the grapes). In Spain, there is usually an outdoor environment with good illumination conditions. Spring and summer seasons have a mean value between 11 and 12 hours per day, which provide good clarity to ensure an accurate image processing and obtain good decisions. Although we have not included illumination compensations in order to correct the brightness changes, the system is developed with the objective of adding new features. In future works we will add chromaticity-based approaches [49,50] in order to correct the brightness changes due, for example, to the presence of clouds or rain. We show an example of the detection problem in Figure 8. When the plants are distant, probably we won't have enough resolution to accomplish with the entire processing, but we can use image processing to detect where the leaves are. In a further step, by using the camera zoom that enables to get images with a higher resolution, we could be able to detect the bad leaves, although they must be first distinguished from the ground. Figure 9 shows the process followed. It has been separated into five stages. In the first, two conditions based on the color of the pixels are applied to the images. The first one is used to detect where the good leaves are, and will be used also to estimate an average leaf size that will be used in later stages. Then, a threshold is applied to the remaining pixels in order to discard those that don't match a color condition corresponding with the bad leaves. After this stage, we get a detection mask composed of groups of pixels which their color is similar to the bad leaves, but there will be some groups that are not interesting because they don't correspond to what we want to detect. The next stage is a set of operations in order to reduce the noise in the detection mask that happens when a group is too small or there are two groups too close. An important issue to take into account for these operations is the leaf size in the image, because when it is small, the operations should not delete small but significant groups, and when it's large there is a bigger margin to smooth the mask. In the detection stage, another threshold, based on the leaf size too, is imposed to each group of pixels to differentiate between the ground and the interesting part. Groups that are higher than this threshold are discarded, and the others make up the final detection mask. Figure 8: Detection of brown leaves in vines. Figure 9: General schema followed in the image processing stage. Finally, a parameter, that is called _number of bad leaves_ (NBL), is calculated as the number of pixels in this final mask relative to the leaf size. Then, this parameter is used by the node in order to take a decision about the level of bad leaves on the image and to generate the alarm in the corresponding case. This is done by means of a threshold that could be fixed experimentally attending to each particular case.