## 4 Predicting the Porosity in Selective Laser Melting Parts
### Predicting the Porosity Using Image Binarization  
There is a problem related to accurately assessing the porosity in SLM parts [21]. The problem is the difficulty and subjectivity in selecting an appropriate grayscale threshold for binary image conversion to highlight defective regions and determine the true level of porosity, as mentioned previously in Section 2.5. The first version of created artificial images presented in the previous section were binarized using an adaptive thresholding algorithm provided in the MATLAB platform, which selects the threshold based on local mean intensity in the pixel neighborhood, and is determined by a sensitivity factor, between 0 and 1, that indicates the sensitivity toward thresholding more pixels as a foreground [29]. This sensitivity factor is selected manually. The following Figure 21 shows the first version of the artificial image, along with the binarized image with an arbitrarily selected sensitivity factor of 0.66. Figure 20: Real image (**Left**) vs. final version of artificial image (**Right**). As can be seen in the figure, there are tiny undesired black spots in different positions in the binarized image, and the undesired spots also appear in slices with no pores, as shown in the following Figure 22.  
The average actual percent of pore for 3000 slices was 0.0134, while the average percent of pore for 3000 binarized images is overestimated with a value of 0.0578, so the absolute error is 0.0444. The prediction accuracy with a difference of less than a threshold of 0.02 (percent of observations with error less than 0.02) is 64.47%. The same approach was followed for the final version of artificial porosity images, and the following Figure 23 shows the artificial image along with the binarized image, with a sensitivity factor of 0.66. Figure 21: First version of artificial image (**Left**) vs. binarized artificial image (**Right**). Figure 22: First version of artificial image with no pore (**Left**) vs. binarized artificial image (**Right**). As can be seen in the figure, there are tiny undesired black spots in different positions in the binarized image, confirming the problem stated in [21], which is a result of inconsistent grayscale in CT scan slices because of the mutual influence of CT setup and radiodensity variation. Removing these spots using image processing is time-consuming since they appear in different positions in each slice without a simple pattern, so the processing needs to be performed image by image to distinguish between the undesired black spots and the pores first. Following that, unwanted spots need to be replaced with a white background because they are counted in the porosity calculation which overestimates the percent of porosity. Such an issue also occurs in the pores, as tiny white spots would alter their morphological feature and slightly reduce the percentage of porosity. However, the effect of this on porosity calculations is negligible when compared to the effect of the small black spots occurring in the large background. Depending on the sensitivity factor used, the black spots also appear in slices with no pores, as shown in the following Figure 24.  
Experimenting with different sensitivity factors between 0.63 to 0.74 resulted in the following binary images with different percentages of porosity as shown in Figure 25.  
Figure 23: Final version of artificial image (**Left**) vs. binarized artificial image (**Right**). Figure 24: Final version of artificial image with no pore (**Left**) vs. binarized artificial image (**Right**). As can be seen from the images, increasing the sensitivity factors reduces the black spots resulting from the noisy background, but it alters the pore's morphological features dramatically. A sensitivity factor of 0.69 seems relatively better and it will be selected to binarize all 3000 slices since it yielded the most accurate percent of porosity of 0.17%, which is close to the actual percent of pore for the original slice with a value of 0.1785%.