# Segmentation and Classification of Zn-Al-Mg-Sn SEM BSE Microstructure
## 4 Discussion  
Noise filter--In addition to the NLM filter (see Section 2, Noise and technical filter), the other options had been considered for noise removal. From the Matlab menu wiener2, medfilt2, modefilt and imboxfit blurred the edges of shapes, as did imbialtaffil when entering larger sigma values. The couple imdiffuressed + imdiffuresift, when used multiple times in a row, provided relatively nice results, but still there was a slight blurring of the edges. On the contrary, several precipitates were still maintained. Two options, localcontrast and locallapfit, referred to as edge-aware processing [28], provided a pleasant contrast improvement for the human eye, but in fact they violated the condition of the same intensity value during further processing, e.g., for the histogram [43]. After verification, a finer NLM filter had been chosen with multiple sequential uses. Thus, the task of homogenising the segments in the form of removing noise and almost all precipitates was fulfilled, and it was possible to proceed to the next processing step. The segmentation logic for the inclusion or exclusion of the precipitates must be clarified in advance. The isolated occurrences of the precipitates within the background could be correctly reclassified in block 5, Corrections (see Figure 7). Segmentation and classification--For the BW shapes, the level thresholding with the morphological operations had been chosen. Subsequently, for the BG, L and D segments, the histogram thresholding was used. In the case of morphology, sufficiently accurate results had been achieved. In this way, texture analysis [44,45] for the BW shapes, which took on too diverse forms, could be avoided. The histogram thresholding played a central role in segmentation and classification, and at the same time was a stumbling block. The histograms can be used in a segmentation process, provided that the objects can be distinguished from each other based on their intensity values [46]. In general, the threshold is placed in a distinct deep valley in the histogram [47]. However, if such a valley does not exist, the placement of the threshold is difficult (especially in the case of algorithmisation for a computer). Most real images are not characterised by ideal histograms; on the contrary, several challenges can appear [48, 49, 50]:  
* Flat and wide valleys;
* Two peaks characterised by significantly different heights (a problematically detectable valley);
* Noise in the histogram; \begin{table}
\begin{tabular}{c c c c} \hline \hline
**Sn [\%]** & **Images** & **PQ \(\pm\) Std.Dev [\%]** & **XRD \(\pm\) Std.Dev [\%]** \\ \hline \multirow{4}{*}{0} & \multirow{4}{*}{45} & BG: 66.01 \(\pm\) 2.01 & BG: 66.30 \(\pm\) 1.50 \\  & & BW: 3.37 \(\pm\) 0.95 & BW: 5.50 \(\pm\) 0.40 \\  & & L: 30.62 \(\pm\) 2.23 & L: 28.30 \(\pm\) 0.50 \\  & & Accuracy: \({}^{98.12}\)\(\pm\) 0.74 & \\ \hline \multirow{4}{*}{1} & \multirow{4}{*}{45} & BG: 72.31 \(\pm\) 3.78 & BG: 73.10 \(\pm\) 1.00 \\  & & BW: 3.16 \(\pm\) 0.82 & BW: 4.90 \(\pm\) 0.10 \\  & & L: 19.19 \(\pm\) 3.52 & L: 19.20 \(\pm\) 0.20 \\  & & D: 5.34 \(\pm\) 1.40 & D: 2.80 \(\pm\) 0.30 \\  & & Accuracy: 95.43 \(\pm\) 3.64 & \\ \hline \multirow{4}{*}{2} & \multirow{4}{*}{45} & BG: 75.58 \(\pm\) 4.17 & BG: 78.90 \(\pm\) 1.80 \\  & & BW: 3.29 \(\pm\) 0.69 & BW: 5.00 \(\pm\) 0.10 \\  & & L: 12.93 \(\pm\) 4.60 & L: 11.80 \(\pm\) 0.60 \\  & & D: 8.21 \(\pm\) 1.50 & D: 4.30 \(\pm\) 0.50 \\  & & Accuracy: 95.22 \(\pm\) 3.39 & \\ \hline \multirow{4}{*}{3} & \multirow{4}{*}{45} & BG: 78.93 \(\pm\) 2.63 & BG: 83.60 \(\pm\) 2.00 \\  & & BW: 5.20 \(\pm\) 1.08 & BW: 4.20 \(\pm\) 0.50 \\ \cline{1-1}  & & L: 7.05 \(\pm\) 1.65 & L: 5.30 \(\pm\) 1.10 \\ \cline{1-1}  & & D: 8.82 \(\pm\) 1.64 & D: 6.90 \(\pm\) 0.80 \\ \cline{1-1}  & & Accuracy: 95.56 \(\pm\) 1.94 & \\ \hline \hline \end{tabular}
\end{table} 
Table 9: Comparison of results with XRD. * Noisy spikes;
* Overlapping distributions of BG and the object;
* The object represented in a small percentage;
* BG consisting of several regions.