# Plant Disease Diagnosis in the Visible Spectrum
## 3 Materials and Methods
### Segmentation Using GMM
#### 3.1.2 Classify the Pixels in Two Segments Using a GMM Model  
A GMM model is used to separate the plant from the background, and the model is the following.  
\[p(x)=\pi_{p}\mathcal{N}(x|\mu_{p}\sigma_{p}^{2})+\pi_{f}\mathcal{N}(x|\mu_{f} \sigma_{f}^{2}), \tag{1}\]  
where \(\pi_{p},\mu_{p},\text{ and }\sigma_{p}^{2}\) are the weight, mean, and variance, respectively, for the distribution that represents the plant, \(\pi_{f},\mu_{f},\text{ and }\sigma_{f}^{2}\) are the weight, mean, and variance respectively for the distribution that represents the background.  
In order to find the optimal value of the parameters of the model, given \(n\) pixels \(X=\{x_{1},x_{2},\dots,x_{n}\}\), the log likelihood function is used; in order to be maximized with the objective of finding the value of the parameters that best fit into the data, the log likelihood function is the following  
\[\begin{split}\ln p(X|\pi_{p},\mu_{p},\sigma_{p}^{2},\pi_{f},\mu_{ f},\sigma_{f}^{2})=\\ \sum_{n=1}^{N}\ln(\pi_{p}\mathcal{N}(x_{n}|\mu_{p}\sigma_{p}^{2}) +\pi_{f}\mathcal{N}(x_{n}|\mu_{f}\sigma_{f}^{2})).\end{split} \tag{2}\]  
The Expectation Maximization (EM) algorithm is used to find the optimal (local) values of the parameters.  
* Expectation Step In this step, the weights that the distributions belonging to the plant \(\gamma(z_{np})\) or the background have \(\gamma(z_{nf})\) for each of the observations \(x_{n},z_{np}\) is a latent binary variable that takes the value of 1 when it is understood that \(x_{n}\) is the result of sampling from  
Figure 1: Diagram describing the general strategy.  
the distribution that belongs to the plant, with a probability or weight \(\gamma(z_{np})\), and the same applies to the background.  
\[\gamma(z_{np})=\frac{\pi_{p}\mathcal{N}(x_{n}|\mu_{p},\sigma_{p}^{2})}{\pi_{p} \mathcal{N}(x_{n}|\mu_{p},\sigma_{p}^{2})+\pi_{f}\mathcal{N}(x_{n}|\mu_{f}, \sigma_{f}^{2})}, \tag{3}\]  
\[\gamma(z_{nf})=\frac{\pi_{f}\mathcal{N}(x_{n}|\mu_{f},\sigma_{f}^{2})}{\pi_{p} \mathcal{N}(x_{n}|\mu_{p},\sigma_{p}^{2})+\pi_{f}\mathcal{N}(x_{n}|\mu_{f}, \sigma_{f}^{2})}, \tag{4}\]  
where \(\gamma(z_{np})\) is the weight that the (p) distribution of the plant has for the \(n\) observation, and \(\gamma(z_{nf})\) is the weight that the (b) distribution of the background has for the \(n\) observation.
* Maximization Step The means are calculated \[\mu_{p}^{new}=\frac{1}{N_{p}}\sum_{n=1}^{N}\gamma(z_{np})x_{n},\] (5) \[\mu_{f}^{new}=\frac{1}{N_{f}}\sum_{n=1}^{N}\gamma(z_{nf})x_{n}.\] (6) New variances are calculated. \[\sigma_{p}^{2^{new}}=\frac{1}{N_{p}}\sum_{n=1}^{N}\gamma(z_{np})(x_{n}-\mu_{p }^{new})^{2},\] (7) \[\sigma_{k}^{2^{new}}=\frac{1}{N_{f}}\sum_{n=1}^{N}\gamma(z_{nf})(x_{n}-\mu_{f }^{new})^{2}.\] (8) The values of the weights of each distribution are updated. \[\pi_{p}^{new}=\frac{N_{p}}{N},\] (9) \[\pi_{f}^{new}=\frac{N_{f}}{N},\] (10) where, \[N_{p}=\sum_{n=1}^{N}\gamma(z_{np}),\] (11) \[N_{f}=\sum_{n=1}^{N}\gamma(z_{nf}).\] (12)
* Log likelihood evaluation With the new parameters, the log likelihood function is evaluated, and the Expectation and Maximization steps are repeated until reaching convergence or a stop criteria. \[\ln p(X|\pi_{p},\mu_{p},\sigma_{p}^{2},\pi_{f},\mu_{f},\sigma_{f}^{2})=\] (13) \[\sum_{n=1}^{N}\ln(\pi_{p}\mathcal{N}(x_{n}|\mu_{p}\sigma_{p}^{2})+\pi_{f} \mathcal{N}(x_{n}|\mu_{f}\sigma_{f}^{2})).\]