## 2 Materials and Methods
### Image Processing Method and Feature Extraction
However, knowing absolute dimensions is not very useful since it is more important to know the relative leaf area that has been infected. The number of spots can be estimated as follows. The image matrix of Figure 1b is scanned row by row, top-down and from left to right. When a spot pixel is found it is assigned with an identifier. The neighboring top-left, top, top-right and the adjacent pixel on the left that have already been visited are examined to see if they are spot pixels. If at least one of them is indeed a spot pixel, its identity is also given to the current pixel otherwise it is assigned with the higher identity that has already been used, incremented by 1. In this way, all pixels belonging to the same spot are marked with the same identity and the highest identity used indicates the number of spots. The result of this procedure is shown in Figure 1c. However, as can be seen from Figure 1c it is possible that adjacent spot pixels can be assigned with different identities (the spot No. 3 at the fourth row is adjacent to the spot No. 1). For this reason, it is necessary to iteratively check if there are adjacent spots with different identity. Figure 1: Spot identification method. Separation of the background (**a**), spot identification (**b**), initial spot numbering (**c**) and final spot numbering (**d**). Notations: BG-background pixel, LF-normal leaf, SP-lesion spot. In this case, they should be merged (assigned with the lowest identity of the two) and the rest of the spots should be renumbered. This iterative procedure stops if no further modifications are needed. The final map (henceforth this matrix will be called BNS) shown in Figure 1d can be used to estimate the number of spots (\(N_{g}\)) which is the maximum identity used when the numbering is finalized. The pixels that are mapped to a normal plant part like LF in Figure 1 can be used to estimate the average gray level of the normal leaf (\(G_{l}\)). Similarly, the gray level of the lesion spots (\(G_{s}\)) and the halo (\(G_{h}\)) are estimated by the spot and the halo pixels. Additional features related with the weather conditions like the average moisture (\(M_{d}\)), and minimum (\(T_{n}\)) and maximum (\(T_{x}\)) temperature, are retrieved by weather metadata available on the internet as will be explained in the next section. If a spot consists of a very small number of pixels it can be ignored since it may be a result of noise. Three ways are supported for the identification of the spot pixels on a leaf. The first way (spot separation method 1, SSM1) uses the representation of the image in the gray scale and focuses on the leaf pixels. The average gray level \(G_{av}\) of all the leaf pixels is estimated and then, the pixels that their gray level deviates from \(G_{av}\) by more than a threshold \(T_{h}\), are assumed to be lesion spots. Formally, it can be stated that each pixel \(BNS\)(\(i\),\(j\)) in the matrix shown in Figure 1b can be defined by its corresponding one in the gray image \(G_{r}\)(\(i\),\(j\)) under the following conditions that hold if the background is white:  
\[\text{BNS}(\text{i},\text{j})= \begin{cases}BG,\ Gr(i,j)\geq B_{g}\\ SP,G_{av}+T_{h}<Gr(i,j)<B_{g},\ \text{\it{Invert}}=\text{\it{true}}\\ SP,G_{av}-T_{h}>Gr(i,j),\ \text{\it{Invert}}=\text{\it{false}},\\ LF,G_{av}+T_{h}>Gr(i,j),\ \text{\it{Invert}}=\text{\it{true}}\\ LF,G_{av}-T_{h}<Gr(i,j)<B_{g},\ \text{\it{Invert}}=\text{\it{false}}\end{cases}  \tag{2}\]  
If the lesion is brighter than the normal leaf, the user sets the flag \"Invert\" as will be shown in the following sections. The user also defines manually the thresholds \(B_{g}\) and \(T_{h}\). Although it may be frustrating for a user to calibrate in real-time these parameters, this method is quite accurate in mapping correctly the leaf, spot and background regions. The user can interactively verify that he has selected appropriate values for the \(B_{g}\) and \(T_{h}\) parameters by comparing the segmented with the original image.