## 2 Materials and Methods
### Improved LK-SVD Sparse Dictionary Learning Method
#### 2.3.2 Improved LK-SVD Dictionary Learning  
The initial dictionary is not usually the optimal one, and there will be considerable error between the data represented by the sparse matrix that meets the sparseness with the original data. The K-SVD algorithm takes the principle of minimum error as the basic idea [25] to update the dictionary, and its objective equation is Equation (2):  
\[\min_{D,X}\left\{\left\|Y-DX\right\|_{F}^{2}\right\}s.t.\forall i,\left\|x_{i }\right\|_{0}\leq T_{0} \tag{2}\]  
where \(T_{0}\) represents the upper limit of the non-zero sparse coefficient.  
The K-SVD algorithm can effectively reduce the within-class deviation, but its learning process is only effective for a certain category and cannot increase the between-class variance for multi-class problems. Therefore, an LK-SVD algorithm based on category labeling was proposed, which integrates the category information to modify the K-SVD. This study involved a three-category classification issue: diseased, nectarine, and background parts. For this, sparse reconstruction mainly judges the type of test samples by solving the position where the minimum value of the residual appears in the sparse expression. Thus, the above problems can be replaced by a linear classifier, and then, the classification can be expressed as Equation (3):  
\[H=WX+b \tag{3}\]  
where \(H\in[0,1,2]\) represents the three categories, \(W\) represents the linear classification matrix, and \(b\) is the bias term. By integrating this into the process of dictionary learning, the optimization of solving \(W\) can be converted to Equation (4):  
\[\min_{H,W}\left\|H-WX-b\right\|_{2}^{2}+\beta\left\|W\right\|_{F}^{2} \tag{4}\]  
Combined with the formula in Equation (2), the above formula can be converted to Equation (5):  
\[\min_{D,X,H,W}\left\|Y-DX\right\|_{2}^{2} +\lambda\left\|H-WX-b\right\|_{2}^{2}+\beta\left\|W\right\|_{F}^{2} \tag{5}\] \[s.t.\forall i\left\|x_{i}\right\|_{0}\leq T_{0}\]  
where \(\left\|W\right\|_{F}^{2}\) is the regular term and \(\lambda\) and \(\beta\) are the contribution values of the corresponding terms. A dictionary can be considered a combination of the primitive atom \(Y\) and thus can be expressed as \(D=Y\cdot\Omega\), in which \(\Omega\) is the transformation matrix. Then, the above formula can be simplified as Equation (6):  
\[\min_{D,X,  
By solving the above problems, the obtained \(H\) is the measured category. According to the above description, we obtain the implementation pseudocodes of the LK-SVD algorithm, as shown in Algorithm 1.  
```
Input: original sample matrix \(Y\), transformation matrix \(\Omega\), label matrix \(H\). Output: over-complete dictionary \(D\), linear classification matrix \(W\). Initialization: initialize \(\Omega\) and \(W\).
1: Stage 1: Model building
2: Build a sparse representation model: \(Y=DX\)
3: Build a Linear classification model: \(H=WX+b\)
4: Stage 2: Dictionary and classifier optimization
5: Model fusion: Combining two optimization problems into one
6:\(\underset{D,X,H,W}{\min}\big{\|}\left[\begin{array}{c}Y\\ \sqrt{\lambda}H\end{array}\right]-\left[\begin{array}{c}Y\cdot\Omega\\ \sqrt{\lambda}W\end{array}\right]X\big{\|}_{F}^{2}\)\(s.t.\forall i\|x_{i}\|_{0}\leq T_{0}\)
7: Apply K-SVD dictionary learning to solve the above optimization problem
```  
**Algorithm 1** LK-SVD algorithm