# Segmentation and Classification of Zn-Al-Mg-Sn SEM BSE Microstructure
## 2 Materials and Methods
Therefore, the technical filter levelling is applied twice (see Figure 7)--first time for all rows (first image) and second time for all columns (second image). After averaging (the arithmetic mean of both images) and subsequent filtering, the result of technical filtering is available in the form of the red curve. It is clear from Figure 6 that such a result is between the original denoised waveform (solid blue) and the levelling in one direction (dashed magenta). The purpose of the entire operation is obvious when assessing the distance of the individual blue bent segments to the imaginary green threshold compared to the more 'horizontal' courses of the same segments in red--the section, e.g., between rows 1 to about 500. In more demanding images (see Figure 11), the distance is quite small, or even disappears. Table 6 shows the total typical running times of the individual steps: preprocessing, noise filter at Zoom4000 (influenced by the NLM filter specific value of SearchWindowSize (SWS)) and technical filter for an image 1:960 \(\times\) 1280. As the value of SWS configuration parameter decreases--see blocks 2 and 11 in Figure 7--the running times of the given filter also decrease. Decision methods--Figure 7 shows the overall overview scheme of segmentation and classification. The green blocks 1, 2, 3, 4, 5, 6 represent the procedure without applying the technical filter; the red blocks 7, 8, 9, 10, 11 represent just the technical filter. The black arrows between 1, 2, 3 are a common route for both procedures, and then either blue or red continue. Depending on the percentage of Sn content, block 6 is present or not. The purple dots indicate the places in the algorithm where the configuration values are present. These  
Figure 6: Operation of the technical filter levelling. had been preset based on the expertise during the algorithm development. For most of the images, they worked sufficiently. In occasional cases, they could be manually tuned. The choice between the procedure A or B and how to tune the configuration values depends on the user's experience. Description of the individual blocks:  
1. Initial steps--the selection of the pure image information, its conversion to the single-precision floating point type and extraction of the zoom and %Sn information;
2. NLM filter--the applying of several consecutive NLM filters to remove noise. Function: immlmit. The incorrectly selected configuration values result in poor noise removal or, on the contrary, loss of important edges of shapes. It is therefore necessary to pay sufficient attention to this step. Configuration values: DegreeOfSmoothing (DOS), SWS, ComparisonWindowSize (CWS);
3. BW--the classification of the first BW segment. The classification of the BW shapes can be divided first into level thresholding, when according to a priori statistically obtained value, which is sufficiently low, the dark BW components are identified. These are subsequently expanded using the morphological operations imfill and imclose with a suitably chosen structuring element, completed and closed with the white BW components. Configuration values: intensity level threshold to black, type and size of the structuring element;
4. BG/Shapes--the separation and classification of the BG background from L + D shapes. Method: histogram thresholding. Configuration values: intensity histogram threshold, moving average (MA) filter parameters and number of sequential filtering;
5. Corrections--the optional step where some pixels can be swapped between the BG segments and L + D Shapes (such as precipitates). Functions: bwconncomp to obtain the connected components with the default connectivity 8, regionprops('Area') for obtaining the number of pixels in connected shapes. Configuration values: number of pixels in connected shapes;
6. L/D--this step occurs only in case of nonzero Sn content. Method: histogram thresholding. The data, left over from the previous segmentations, are divided into the L and