## 3 Results and Discussion
### Performance of Segmentation Algorithm  
To evaluate the performance of segmentation algorithm, three criteria of sensitivity, specificity and accuracy were used. Based on definition, sensitivity expresses the wrong placement of the samples of the studied class and the specificity expresses the wrong placement of the other class samples in the studied class. Finally, the accuracy is the percentage of total placement of the correct samples in their classes. These three criteria are expressed using Equations 1 to 3. \[\text{Sensitivity}\;=\;\frac{\text{TP}}{\text{TP}+\text{FN}} \tag{3}\] \begin{table}
\begin{tabular}{c c c c c c} \hline \hline
**Class** & **Apples** & \begin{tabular}{c} **Background** \\ **Objects** \\ \end{tabular} & **All Data** & \
\begin{tabular}{c} **Total Percentage of** \\ **Wrong Diagnosis** \\ \end{tabular} &
\begin{tabular}{c} **Total Percentage of** \\ **Correct Diagnosis** \\ \end{tabular} \\ \hline Apples & 42,426 & 324 & 42,750 & 0.758 & 99.013\% \\ Background objects & 691 & 59,434 & 60,125 & 1.15 & \\ \hline \hline \end{tabular}
\end{table} 
Table 6: Confusion matrix and total percentage of proposed segmentation algorithm. \begin{table}
\begin{tabular}{c c} \hline \hline
**Main Segmentation Methods** &
\begin{tabular}{c} **The Average Percentage of Background Pixels** \\ **Removed by Each Method** \\ \end{tabular} \\ \hline The use of threshold in Luv color space & 36 \\ The use of texture feature & 26 \\ The use of morphological operators & 23 \\ The use of thresholding function & 15 \\ \hline \hline \end{tabular}
\end{table} 
Table 4: The average percentage of background pixels removed by each segmentation method. \begin{table}
\begin{tabular}{c c c c c} \hline \hline
**Predicted/Real** **Class** & **1** & **2** & **All Data** & \
\begin{tabular}{c} **Classification Error** \\ **by Class (\%)** \\ \end{tabular} &
\begin{tabular}{c} **Classification** \\ **Accuracy (\%)** \\ \end{tabular} \\ \hline
1 & 52,139 & 429 & 52,568 & 0.816 & 99.20\% \\
2 & 389 & 49,123 & 49,512 & 0.785 & \\ \hline \hline \end{tabular}
\end{table} 
Table 5: Confusion matrix of thresholding function. Classes correspond to: 1: Apple object pixels, 2: Background object pixels. \[\text{Specificity}\;=\;\frac{\text{TN}}{\text{FP}+\text{TN}} \tag{4}\]  
\[\text{Accuracy}=\frac{\text{TP}+\text{TN}}{\text{TP}+\text{TN}+\text{FP}+\text{ FN}} \tag{5}\]  
TP is the number of samples of each class that are correctly classified; TN is the number of samples on the main diameter of the confusion matrix minus the number of samples of the studied classes. FN is the sum of the horizontal samples of the class examined minus the number of samples of the studied class. Finally, FP is the sum of the vertical samples of the studied class minus the number of samples of the same class [13]. In Table 7 shows the results of the performance criteria of segmentation algorithm. Based on this table, it is shown that the highest sensitivity is related to the apple class with the value of 99.242 percent and the highest specificity is related to the class of background objects with a value of 99.458 percent. In Figure 7 shows a pseudo code of segmentation algorithm. In pseudo code explain final segmentation algorithm in 13 stages. \begin{table} \begin{tabular}{c c c c} \hline
**Class** & **Sensitivity** & **Accuracy** & **Specificity** \\ \hline Apples & 99.242 & 99.013 & 98.397 \\ Background objects & 98.851 & 99.013 & 99.458 \\ \hline \end{tabular}  for  
1. Input frame  
2. Converting image size to [300,600]  
3. Converting RGB frame to Lux color space  
4. Applying the first threshold as:  
Seg1=[Luv1(i)]+115 \& LuxV(3(i))+115 \& LuxV2(4(i))+115);  
if Seg1=1  
FR(i,i)=0;  
FG(i,i)=0;  
FB(i,i)=0;  
End  
Where FT, FG and FB are components of original frame. 5. Convert the resulting image from the before stage to grayscale image. 6. Applying the texture feature of local range over grayscale image  
7.