PoreAnalyzer—An Open-Source Framework for the Analysis and Classiﬁcation of Defects in Additive Manufacturing

: Additive manufacturing processes offer high geometric ﬂexibility and allow the use of new alloy concepts due to high cooling rates. For each new material, parameter studies have to be performed to ﬁnd process parameters that minimize microstructural defects such as pores or cracks. In this paper, we present a system developed in Python for accelerated image analysis of optical microscopy images. Batch processing can be used to quickly analyze large image sets with respect to pore size distribution, defect type, contribution of defect type to total porosity, and shape accuracy of printed samples. The open-source software is independent of the microscope used and is freely available for use. This framework allows us to perform such an analysis on a circular area with a diameter of 5 mm within 10 s, allowing detailed process maps to be obtained for new materials within minutes after preparation.


Introduction
Additive manufacturing processes [1] build up a component through a continuous mass input. Typical processes are the FDM process (fused deposition modeling) [2], which is common for polymers, the LPBF process (laser powder bed fusion) [3] or the LMD process (laser metal deposition) [4]. All these processes have in common high geometric flexibility due to free-form modeling without a mold. In the field of additive processes for metals, potentials for new material concepts [5,6] arise from the use of the comparatively high cooling rates [7,8] in the range of 10 5 -10 6 K/s for the LPBF process [9]. However, process parameters that minimize defects in the printed component [10] must be determined at great expense for each new material. The search for optimized and robust parameter sets [11,12] is a time-consuming process.
Defects in additive manufacturing [13] result, on the one hand, from the material properties and properties of the powder (e.g., bulk density, flowability, particle size) and, on the other hand, from the process conditions, with particular emphasis on the importance of thermal conditions [7]. While for a given material the material properties and the resulting solidification kinetics are fixed, the various parameters of typical LPBF systems offer a wide range of possible process conditions. Two essential parameters are the scan speed v S at which the laser moves over the powder bed and the laser power P L (Figure 1).
With the layer thickness l Z and the hatch distance h S , the volume energy density is obtained.
If the chosen volume energy density is too low, not all of the particles can be completely melted and irregular pores are formed [14], which often may still contain loose particles. If, on the other hand, a volume energy density that is too high is selected, strong evaporation of the material in the keyhole will occur. As a result of the high solidification rate, the gas formed cannot be released from the keyhole entirely and remains as spherical pores in the solidified material [8]. Cracks [15] typically occur due to stresses caused by high local temperature gradients, phase transformation or shrinkage. Minimizing such defects is of great importance since defects will decrease mechanical properties [16] or lead to material failure [17]. While the average porosity of a sample may be determined by the Archimedes method, a determination of the shape of porosity to determine its origin requires image-based methods [18]. These include two-dimensional methods such as classic metallography, or may also feature three-dimensional methods such as micro tomography [19]. While three-dimensional methods offer the possibility to analyze volumetrics, their resolution is still lower than classical light microscopy or electron microscopy. Light microscopy allows the determination of spatial distributions of porosity in a cross-section, making it a very versatile and automated tool. The detailed analysis of pore size distribution has been shown to be an important quality measure for additively manufactured parts [20].
While many studies search for the porosity minimum from a combinatorial variation of scan speed and laser power [11,21], this work includes the defect type and pore size distribution to find good processing conditions for the ferritic steel 410L. These analyses are based on our open source framework "PoreAnalyzer" that is easily adaptable for custom applications.
ppl. Sci. 2021, 11, x FOR PEER REVIEW = ⋅ ℎ ⋅ If the chosen volume energy density is too low, not all of the particle pletely melted and irregular pores are formed [14], which often may still particles. If, on the other hand, a volume energy density that is too high is se evaporation of the material in the keyhole will occur. As a result of the high rate, the gas formed cannot be released from the keyhole entirely and remai pores in the solidified material [8]. Cracks [15] typically occur due to stres high local temperature gradients, phase transformation or shrinkage. Mi defects is of great importance since defects will decrease mechanical pro lead to material failure [17].
While the average porosity of a sample may be determined by th method, a determination of the shape of porosity to determine its origin re based methods [18]. These include two-dimensional methods such as cla raphy, or may also feature three-dimensional methods such as micro tom While three-dimensional methods offer the possibility to analyze volumetric tion is still lower than classical light microscopy or electron microscopy. Lig allows the determination of spatial distributions of porosity in a cross-sectio very versatile and automated tool. The detailed analysis of pore size distrib

Experimental Design
An Aconity Mini LPBF machine was used to build an exemplary array with cylindrical samples (diameter: 4 mm, height: 15 mm, distance between samples: 3 mm) on a stainless steel substrate. Parameters were varied according for each cylinder. Powder of the ferritic steel X2CrNi12 (AISI 410L) was used to generate samples with different defect structures to demonstrate the method. The alloy composition is given in Table 1. Laser power, scan speed and hatch distance were varied in a wide range to produce samples that contain different levels and types of defect in order to develop and demonstrate their morphological classification. Process parameter ranges are summarized in Table 2. The whole sample arrays ( Figure 2a) were embedded and metallographically prepared ( Figure 2b). Grinding papers from P80-P1500 were used with subsequent polishing with a 3 µm and 1 µm polycrystalline diamond suspension. Images were taken 1 mm below the original sample top surface, then the samples were grinded and polished again to take two more images 0.5 mm and 1 mm below to obtain a larger dataset for each sample (Figure 2c). morphological classification. Process parameter ranges are summarized in Table 2. The whole sample arrays ( Figure 2a) were embedded and metallographically prepared ( Figure 2b). Grinding papers from P80-P1500 were used with subsequent polishing with a 3 µm and 1 µm polycrystalline diamond suspension. Images were taken 1 mm below the original sample top surface, then the samples were grinded and polished again to take two more images 0.5 mm and 1 mm below to obtain a larger dataset for each sample ( Figure 2c).
Images of the whole samples were taken with a Zeiss AxioImager microscope with Zeiss ZenCore software at a 10× magnification (pixel size: 0.56 µm) in stitching mode.

Analysis Design
The analysis software was developed based on the free Python language with the Computer Vision Library [22] for image analysis methods. The samples were automatically detected and separated from the background for further analysis of the whole sample area.
First, a Gaussian filter was applied to the images to reduce noise. The images were then binarized, using the well-known Otsu algorithm [23] for thresholding. After binarization, image segmentation and morphological analysis of all detected defects was performed using the algorithms from the Computer Vision Library. The classification of defects was based on the defect circularity CD with AD and PD being the area and perimeter of the defect, respectively. Another shape factor was the aspect ratio ARD derived from the ratio of the two semi axes of a fitted ellipse = (3) Images of the whole samples were taken with a Zeiss AxioImager microscope with Zeiss ZenCore software at a 10× magnification (pixel size: 0.56 µm) in stitching mode.

Analysis Design
The analysis software was developed based on the free Python language with the Computer Vision Library [22] for image analysis methods. The samples were automatically detected and separated from the background for further analysis of the whole sample area.
First, a Gaussian filter was applied to the images to reduce noise. The images were then binarized, using the well-known Otsu algorithm [23] for thresholding. After binarization, image segmentation and morphological analysis of all detected defects was performed using the algorithms from the Computer Vision Library. The classification of defects was based on the defect circularity C D with A D and P D being the area and perimeter of the defect, respectively. Another shape factor was the aspect ratio AR D derived from the ratio of the two semi axes of a fitted ellipse with r major and r minor being the major and minor half axes. This approach was chosen since the classical elongation shape factor in the OpenCV-library does not allow the defect to be rotated at an arbitrary angle while the fitted-ellipse algorithm does. Furthermore, the hierarchy of objects was determined. This allowed us to determine if there were objects located within another object.
Currently implemented defect classifications are summarized in Table 3. Unmelted particles are particles which can be found inside a defect. For classification they are Appl. Sci. 2021, 11, 6086 4 of 9 assumed to be a pore with another object inside it. Gas pores are characterized by their high circularity of 95% or more. Cracks are elongated objects. A threshold of AR > 5 was set to characterize cracks. All other defects found in this study were irregular and are believed to be lack of fusion defects. However, defect types can be easily extended and their thresholds can be easily adjusted if necessary. Table 3. Currently implemented defect types.

Defect Type
Morphological Criterium unmelted particle if there were objects located within another object. Currently implemented defect classifications are summarized in Table 3. Unmelted particles are particles which can be found inside a defect. For classification they are assumed to be a pore with another object inside it. Gas pores are characterized by their high circularity of 95% or more. Cracks are elongated objects. A threshold of AR > 5 was set to characterize cracks. All other defects found in this study were irregular and are believed to be lack of fusion defects. However, defect types can be easily extended and their thresholds can be easily adjusted if necessary.
For circular sample geometries, shape accuracy is determined based on the actual perimeter PC from image analysis in relation to the theoretical perimeter = (Sample Diameter D). If the shape is irregular, PC will be much larger than Pth. This parameter is meant to help find optimized contour parameters for the LPBF process. This feature is implemented as well for rectangular geometries. The total sample porosity is determined as the ratio of the total area of all defects and the total sample area: The area of each defect is used to calculate its circle-equivalent diameter These diameters are used to calculate the pore size distribution as a number distribution of diameter q0 and an area-weighted distribution of diameter q2 to emphasize the effect of pore size on the mechanical properties. Pre-defined size classes between the minimum and maximum diameters dmin and dmax, respectively are summarized in Table 4. if there were objects located within another object. Currently implemented defect classifications are summarized in Table 3. Unmelted particles are particles which can be found inside a defect. For classification they are assumed to be a pore with another object inside it. Gas pores are characterized by their high circularity of 95% or more. Cracks are elongated objects. A threshold of AR > 5 was set to characterize cracks. All other defects found in this study were irregular and are believed to be lack of fusion defects. However, defect types can be easily extended and their thresholds can be easily adjusted if necessary.
For circular sample geometries, shape accuracy is determined based on the actual perimeter PC from image analysis in relation to the theoretical perimeter = (Sample Diameter D). If the shape is irregular, PC will be much larger than Pth. This parameter is meant to help find optimized contour parameters for the LPBF process. This feature is implemented as well for rectangular geometries. The total sample porosity is determined as the ratio of the total area of all defects and the total sample area: The area of each defect is used to calculate its circle-equivalent diameter These diameters are used to calculate the pore size distribution as a number distribution of diameter q0 and an area-weighted distribution of diameter q2 to emphasize the effect of pore size on the mechanical properties. Pre-defined size classes between the minimum and maximum diameters dmin and dmax, respectively are summarized in Table 4. Currently implemented defect classifications are summarized in Table 3. Unmelted particles are particles which can be found inside a defect. For classification they are assumed to be a pore with another object inside it. Gas pores are characterized by their high circularity of 95% or more. Cracks are elongated objects. A threshold of AR > 5 was set to characterize cracks. All other defects found in this study were irregular and are believed to be lack of fusion defects. However, defect types can be easily extended and their thresholds can be easily adjusted if necessary.
For circular sample geometries, shape accuracy is determined based on the actual perimeter PC from image analysis in relation to the theoretical perimeter = (Sample Diameter D). If the shape is irregular, PC will be much larger than Pth. This parameter is meant to help find optimized contour parameters for the LPBF process. This feature is implemented as well for rectangular geometries. The total sample porosity is determined as the ratio of the total area of all defects and the total sample area: The area of each defect is used to calculate its circle-equivalent diameter These diameters are used to calculate the pore size distribution as a number distribution of diameter q0 and an area-weighted distribution of diameter q2 to emphasize the effect of pore size on the mechanical properties. Pre-defined size classes between the minimum and maximum diameters dmin and dmax, respectively are summarized in Table 4. Currently implemented defect classifications are summarized in Table 3. Unmelted particles are particles which can be found inside a defect. For classification they are assumed to be a pore with another object inside it. Gas pores are characterized by their high circularity of 95% or more. Cracks are elongated objects. A threshold of AR > 5 was set to characterize cracks. All other defects found in this study were irregular and are believed to be lack of fusion defects. However, defect types can be easily extended and their thresholds can be easily adjusted if necessary.
For circular sample geometries, shape accuracy is determined based on the actual perimeter PC from image analysis in relation to the theoretical perimeter = (Sample Diameter D). If the shape is irregular, PC will be much larger than Pth. This parameter is meant to help find optimized contour parameters for the LPBF process. This feature is implemented as well for rectangular geometries. The total sample porosity is determined as the ratio of the total area of all defects and the total sample area: The area of each defect is used to calculate its circle-equivalent diameter These diameters are used to calculate the pore size distribution as a number distribution of diameter q0 and an area-weighted distribution of diameter q2 to emphasize the effect of pore size on the mechanical properties. Pre-defined size classes between the minimum and maximum diameters dmin and dmax, respectively are summarized in Table 4. For circular sample geometries, shape accuracy is determined based on the actual perimeter P C from image analysis in relation to the theoretical perimeter P th = πD (Sample Diameter D). If the shape is irregular, P C will be much larger than P th . This parameter is meant to help find optimized contour parameters for the LPBF process. This feature is implemented as well for rectangular geometries.
The total sample porosity is determined as the ratio of the total area of all defects and the total sample area: The area of each defect is used to calculate its circle-equivalent diameter These diameters are used to calculate the pore size distribution as a number distribution of diameter q 0 and an area-weighted distribution of diameter q 2 to emphasize the effect of pore size on the mechanical properties. Pre-defined size classes between the minimum and maximum diameters d min and d max , respectively are summarized in Table 4. The median diameter d 50 was calculated from both distributions as well as the characteristic values d 10 and d 90 , which can be used to calculate the span: of the pore size distribution. The maximum defect diameter is determined as well as a measure for the most critical pore regarding mechanical properties along with the feret diameter (longest length within defect) for every defect. A morphological description of each sample, its defect type, size distributions and summarizing characteristic values are written in a CSV (comma-separated values) and JSON (JavaScript object notation) file along with sorted images of each defect for further analyses. Standard graphs for pore size distributions are generated.

Results
A binarized image of the sample array is shown in Figure 3a along with the parameters chosen for each sample. Figure 3b shows the average porosity for each sample. Porosities between 0.37% and 1.58% have been achieved. The highest porosity yields from the coldest processing conditions are given by the highest scan speed (1400 mm/s) and lowest laser power (285 W). Decreasing the scan speed from the highest porosity decreases porosity to a value of 0.37% at a scan speed of 950 mm/s. However, other combinations, such as (1250 mm/s, 330 W), may lead to a slightly increased porosity of 0.43%.
The median diameter d50 was calculated from both distributions as well as the characteristic values d10 and d90, which can be used to calculate the span: of the pore size distribution. The maximum defect diameter is determined as well as a measure for the most critical pore regarding mechanical properties along with the feret diameter (longest length within defect) for every defect. A morphological description of each sample, its defect type, size distributions and summarizing characteristic values are written in a CSV (comma-separated values) and JSON (JavaScript object notation) file along with sorted images of each defect for further analyses. Standard graphs for pore size distributions are generated.

Results
A binarized image of the sample array is shown in Figure 3a along with the parameters chosen for each sample. Figure 3b shows the average porosity for each sample. Porosities between 0.37% and 1.58% have been achieved. The highest porosity yields from the coldest processing conditions are given by the highest scan speed (1400 mm/s) and lowest laser power (285 W). Decreasing the scan speed from the highest porosity decreases porosity to a value of 0.37% at a scan speed of 950 mm/s. However, other combinations, such as (1250 mm/s, 330 W), may lead to a slightly increased porosity of 0.43%. The mechanical properties of a component are weakened by defects. In addition to a low porosity, a small pore size is also to be targeted. Characteristic for the pore size distribution is the area median diameter d50,2 (Figure 4a) as well as the span value ( Figure  4b), which indicates the width of the distribution. For the previously discussed conditions that yielded 0.37% and 0.43% porosity, we obtained a d50,2 of 92 and 78 µm with a span of 1.18 and 1.27, respectively. The smaller median pore size diameter was related to a wider size distribution in this case. On the other hand, the largest median diameter of 248 µm yielded in the narrowest span value of 0.83, while the largest span value of 1.83 related to a small median diameter of 87 µm.
A large pore diameter with a small span value means that the porosity is governed The mechanical properties of a component are weakened by defects. In addition to a low porosity, a small pore size is also to be targeted. Characteristic for the pore size distribution is the area median diameter d 50,2 (Figure 4a) as well as the span value (Figure 4b), which indicates the width of the distribution. For the previously discussed conditions that yielded 0.37% and 0.43% porosity, we obtained a d 50,2 of 92 and 78 µm with a span of 1.18 and 1.27, respectively. The smaller median pore size diameter was related to a wider size distribution in this case. On the other hand, the largest median diameter of 248 µm yielded in the narrowest span value of 0.83, while the largest span value of 1.83 related to a small median diameter of 87 µm.  It is well known from high cycle fatigue studies that the largest defect in a part will usually initiate its failure. Not only the size, but also the shape of the defect plays a major role. For example, an existing crack will propagate more easily than a new crack will develop from a spherical pore. As a result, cracks should be avoided. Figure 5a shows the maximum pore size for each sample. For the larger pore sizes with low span values, the maximum pore diameter is slightly higher than the median value. The highest scan speed of 1400 mm/s with a maximum laser power of 315 W yields in the lowest maximum pore sizes of 116 µm. The porosity fraction of each defect is shown in Figure 5b. Lack of fusion defects and unmelted particles are the dominant defect types. There is no significant contribution of gas pores for this material and process conditions and cracks make a minor contribution to porosity. While many cracks were found at the condition (1400 mm/s, 285 W) with an area fraction of 415 ppm, their appearance was a magnitude less frequent in all other conditions.
Finally, we evaluate the shape accuracy of the samples from the ratio sample perim- A large pore diameter with a small span value means that the porosity is governed by large pores, which is very critical regarding material properties. In this case, there are many large pores which can act as an initiator for a crack. On the other hand, smaller diameters with a large span value result in a wide distribtion with few large pores.
It is well known from high cycle fatigue studies that the largest defect in a part will usually initiate its failure. Not only the size, but also the shape of the defect plays a major role. For example, an existing crack will propagate more easily than a new crack will develop from a spherical pore. As a result, cracks should be avoided. Figure 5a shows the maximum pore size for each sample. For the larger pore sizes with low span values, the maximum pore diameter is slightly higher than the median value. The highest scan speed of 1400 mm/s with a maximum laser power of 315 W yields in the lowest maximum pore sizes of 116 µm. It is well known from high cycle fatigue studies that the largest defect in a p usually initiate its failure. Not only the size, but also the shape of the defect plays role. For example, an existing crack will propagate more easily than a new cra develop from a spherical pore. As a result, cracks should be avoided. Figure 5a sho maximum pore size for each sample. For the larger pore sizes with low span valu maximum pore diameter is slightly higher than the median value. The highest scan of 1400 mm/s with a maximum laser power of 315 W yields in the lowest maximu sizes of 116 µm. The porosity fraction of each defect is shown in Figure 5b. Lack of fusion defe unmelted particles are the dominant defect types. There is no significant contribu gas pores for this material and process conditions and cracks make a minor contr to porosity. While many cracks were found at the condition (1400 mm/s, 285 W) w area fraction of 415 ppm, their appearance was a magnitude less frequent in a conditions. The porosity fraction of each defect is shown in Figure 5b. Lack of fusion defects and unmelted particles are the dominant defect types. There is no significant contribution of gas pores for this material and process conditions and cracks make a minor contribution to Appl. Sci. 2021, 11, 6086 7 of 9 porosity. While many cracks were found at the condition (1400 mm/s, 285 W) with an area fraction of 415 ppm, their appearance was a magnitude less frequent in all other conditions. Finally, we evaluate the shape accuracy of the samples from the ratio sample perimeter from image analysis and the theoretical sample perimeter (Figure 6). Since a larger value represents a higher deviation from the targeted shape due to surface roughness or surface defects, small values are to be aimed at. Cold conditions such as (1400 mm/s, 285 W) lead to a high value of 3.37 due to incomplete melting and powder bonding at the surface, hotter conditions such as (950 mm/s, 330 W) yield in the lowest value 2.34. In this study, we have not used specific contour parameters, so that the shape accuracy will be a result of porosity optimization.
pl. Sci. 2021, 11, x FOR PEER REVIEW study, we have not used specific contour parameters, so that the shap result of porosity optimization.

Discussion
We have previously discussed the effect of processing paramet pore size distribution and the fraction of each defect type. In genera parameter study is usually to minimize porosity and pore sizes (espec size) and to avoid cracks, which can easily expand when the material shown that not all these aims could be achieved at the same time. W process conditions, which are favorable regarding one or more defect Table 5 summarizes the descriptions of two different parameters ters (950 mm/s, 285 W) feature the lowest porosity of 0.37%, the para 315 W) lead to a lightly higher porosity of 0.43%. However, this c smaller pore median d50,2 (61 vs. 92 µm), a smaller maximum pore si and with a lower area fraction of cracks, which may be a critical iss loaded applications. The perimeter accuracy is lower which may be f specific contour parameters.  Figure 6. Shape and contour accuracy determined from the ratio of the actual sample perimeter and its theoretical perimeter P C /P th . Low values stand for a smooth sample surface.

Discussion
We have previously discussed the effect of processing parameters on porosity, the pore size distribution and the fraction of each defect type. In general, the aim of such a parameter study is usually to minimize porosity and pore sizes (especially maximum pore size) and to avoid cracks, which can easily expand when the material is stressed. We have shown that not all these aims could be achieved at the same time. We have selected five process conditions, which are favorable regarding one or more defects. Table 5 summarizes the descriptions of two different parameters. While the parameters (950 mm/s, 285 W) feature the lowest porosity of 0.37%, the parameters (1400 mm/s, 315 W) lead to a lightly higher porosity of 0.43%. However, this condition leads to a smaller pore median d 50,2 (61 vs. 92 µm), a smaller maximum pore size (116 vs. 126 µm) and with a lower area fraction of cracks, which may be a critical issue for mechanically loaded applications. The perimeter accuracy is lower which may be further optimized by specific contour parameters. The decision as to which of these conditions is used to build final parts depends greatly on the application. For very high cycle fatigue applications, a strict minimization of cracks and maximum pore diameter is crucial. For applications with minor stressing, the weighting of objectives may be different. In our opinion, it is important to be aware of these different targets quantitatively instead of focusing on the porosity level.
Such detailed data can now be acquired in much shorter time. Previous analysis methods took around 10 min for each sample, including determination of pore size distributions. Our integrated analysis solution now takes approximately 10 s per sample, resulting in a time decrease with a factor of 50-60.

Conclusions
In this work we have presented our approach "PoreAnalyzer" for the analysis of an example of the ferritic steel 410L. The Open Source software is freely available (download link under "Data Availability Statement") and can be easily extended and adapted to similar problems.
We have shown that the classification of the defect type gives more insight into the process and allows multi-objective decisions regarding most critical defects for a specific application. While a minimization of porosity based on volumetric energy density is common, quantitative measures of each defect type and probability allow knowledge to be obtained on the influence of each parameter. This has the potential to create large databases in the future to learn how to transfer parameter sets between materials by means of artificial intelligence techniques. Including online analyses data, such as surface temperature from a pyrometer, will help to maintain a low porosity even in complicated parts.