1 Introduction

One additive manufacturing (AM) is a fast-evolving technology for producing three-dimensional (3D) items from materials like powder, plastics, and rubber [1, 2]. It is no longer in doubt today that the potential of this technology will be the next industrial revolution due to its numerous advantages. Some of the advantages include geometrical constraint reduction, production lead-time reduction due to computer-aided design (CAD), the flexibility of the material used depending on the application of the manufactured item, labor cost reduction, waste reduction, and flexibility of customization. This manufacturing method has attracted increasing attention over the years, and advancement in this technology has seen a positive shift from just rapid prototyping of parts, which is mostly known for the production of complex components parts. Although 3D printing has been widely used for the development of materials and structures with complex geometry, the employment of this manufacturing method is still limited in attaining or ensuring uniformity of workpieces mechanical properties and shapes, especially in mass production [3,4,5]. Presently, Components are manufactured one after the other to avoid mistakes. The 3D printer is stopped intermittently to check the quality of printed materials. Materials are wasted if they do not meet design requirements. Time is wasted executing a fresh print in the outcome of mistakes discovered (time to do the materials all over again if it does not meet design requirements) and many more undesirable tendencies. Hence, this necessitates the need for an in situ and real-time quality monitoring system currently sparsely available that can breach this deficiency in the 3D printing process. The main challenge in coming up with such a system that ensures real-time investigation to make the manufacturing process more efficient stems from the wide range of time-scaled events and their complexities. The 3D printing process does not entirely entail material heating, melting, and solidification as it can be observed physically during the component production operation. Also, thermodynamic phase transitions and residual stress distributions during the final stage of the formation of a component which help in cooling and solidification to a large extent determine the end shape and quality of the component [5,6,7]. These parameters above are not alien to engineers. Still, a closer study shows they have properties that can be linked to mechanical, laser optics, thermal, electrical particle distribution, and material properties. Expert knowledge of these properties can be harnessed to explain the quality of components characterized by cracks, porosity, residual stress distribution, and built-up edges. Table 1 gives a brief description of different defects encountered during the printing of parts on a 3D printer, which compromises the quality and reliability of parts produced using this technology [7, 9, 10].

Table 1 Types of defects in 3D printing and their corresponding causes [8]

Quite a several types of research have been done, and a lot are ongoing regarding optimization and defect detection/control in the field of additive manufacturing. The primary reason for this is to improve the quality of products emanating from this form of production [10,11,12]. A wide variety of in situ methods developed by different researchers had implemented different in situ sensors and other data capture devices, which include RGB cameras, laser scanners, thermal imaging cameras, piezoceramic, RGB cameras, CCD cameras, pyrometers, microbolometers, and acoustic sensors. The work of the devices in the research that were utilized is to provide real-time information of process parameters during the build process to halt the printing process and scrap the faulty component or make necessary adjustments and continue the build. In the light of a review conducted on this subject matter, this research builds upon these existing works. Still, it focuses on harnessing a simple microscopic camera and its acquired data in describing ongoing work on the in situ monitoring and control operations in additive manufacturing [8, 12, 13].

Much of the early work focusing on in situ inspection has adopted an in-line camera-based setup which includes that of the more recent work of Shevchik et al. work, which investigates the feasibility of using acoustic emission for real-time quality monitoring [14,15,16]. Here, a sensitive acoustic emission sensor was used to obtain data from the heat zone. A fiber Bragg grating sensor was used to record the acoustic signals during the powder bed additive manufacturing processing [16,17,18]. The process parameters were strategically manipulated to create different processing regimes that led to the generation of different concentrations and types of pores and contours that aid in the classification process. The classifier utilized was trained to distinguish between the acoustic features of dissimilar quality, based on spectral convolutional neural network. However, this method was restricted to the melt pool region; hence, other parts of the printed component cannot be analyzed for defect detection. Furomoto et al. investigated the consolidation mechanism of metal powders during additive manufacturing operations by assembling a high-speed camera as part of the set up to monitor the consolidation of the powder during irradiation [19,20,21]. The effect of altering the thickness in this work was further investigated by interpreting camera images captured at the different frame rate and sampling time. Although this work was carried out with the view of controlling the melt pool behavior during the printing process through active monitoring of the temperature on the surface, real-time interpretation of the data generated was not possible. Some researchers investigated the limits for detecting pores and irregularity in the manufactured surface using an IR camera at a long-wave infrared wavelength band and a specific sampling rate [21,22,23]. In this work, pores and irregularities in surfaces were caused by insufficient heat dissipation during the processing of laser-PBF. This study was aimed at the identification of deviations encountered during the build process, mainly caused by a shift in process parameters or random errors introduced in the process. In their work, the additional camera approach implemented did not allow for inspection across the entire build area. A lot of shielding of the IR camera has to be done to prevent contaminations from high-level specks of dust and smoke, thereby reducing the accuracy of the data collected. High-speed cameras were also utilized by Craeghs et al. to check for inconsistency mainly caused by curling up of parts due to induced stresses with the build-in course of monitoring the powder bed [1, 23, 24]. The camera was mounted at an angle to the build area axis, and a simple algorithm was implemented to avoid perspective distortion.

Some researchers, in their work, equipped an electron beam-PBF system with an IR camera with a processing resolution up to 320 × 240 pixels [25,26,27]. The camera, in this case, was also placed at an angle of 15 degrees to the bed and shielded by a zinc-selenide (ZnSe) to protect equipment from metallization [28,29,30]. A snapshot of each layer was taken after meeting before the next powder layer was raked across. This image is then compared with the model of a ground sample. Areas of materials with higher heat radiation correspond to flaws or irregularities. An automated process would be required to progress from just detecting to implementing a closed-loop structure that assures repairs of errors detected [29,30,31,32].

An IR camera was also incorporated by Rodriguez into an electron-PBF machine to do a surface temperature analysis for each build layer processed. The information obtained during the analysis is then incorporated into the dictate of the build settings for the subsequent layer. This research was carried out mainly to analyze captured images manually, and measuring the emitted radiation from the surface of the component being printed, reflected emission from sources at ambient temperature and atmospheric emission. The cumulative temperature was then converted to a relative temperature reading. The idea of the cumulative temperature helped in the identification of material discontinuities caused by “over melting” as observed from IR generated images [32,33,34]. Incorporation of a thermal imaging camera is an effective way of monitoring each layer printed during additive manufacturing operation, as described in the work of other researchers highlighted in the literature. Still, it compromises on its ability to distinguish between objects of interest due to its dependence on heat concentrations in components.

Like previous work, this research attempted to identify key parameters of interest of the objects under manufacture to modify printer behavior in real-time. Engineers out there in different disciplines utilizing hardware for design synthesis require component not only with good aesthetic quality but also with optimum mechanical properties to meet quality assurance demand. Nowadays, 3D-printed materials are finding its way into core engineering applications that were meant for steel and other metallic alloys with desired properties; hence, a grave necessity is laid on additive manufacturers to improve on the quality of the manufactured components. One of the many ways to achieve this is the institution of a system that analyzes the quality of the printed parts for defects that may affect their overall workability in the areas of application, hence the primary objectives of this research study. This research is an ongoing work that seeks to develop a software algorithm that can determine the locations of pores and crack concentration on each layer of a 3D-printed product. With the image processing algorithm developed in this paper, the extraction of porosity information from raw quality inspection data, such as tomography datasets of cross-sectional images, can be automated.

2 Methodology

An experiment is carried out by printing a model shape using a 3D printer to identify layers which have pores as well as other deformation that goes beyond an acceptable range. Base on the 3D printer settings, each layer that represents a specified thickness is completely printed before proceeding to a new layer. The moment a layer is completely printed, the CCD camera takes the image of the print and sends the result to the image-processing system. The image-processing system processes the sent image from the camera using a developed algorithm and compares it with the design model image. Layers captured during intermittent layer prints are compared with layers without defect. Those layers were noted and analyzed to give a command to the 3D printer to continue or stop printing to avoid material wastage if the defect is not within acceptable limits. The following methodological approach was adopted in aiding this research. The object to be printed using the 3D printer was designed and modeled using solid works software [33,34,35,36]. This modeled design serves as the input variable and setpoint for which the printer is meant to replicate during production. An experimental setup was arranged using the in situ configuration with one CCD camera at the top view of the printed object to obtain real-time images of each layer once printer and send an image to the monitoring system to analyze using the developed algorithm. The 3D printer was set to print a total of 10 layers for the object due to the design dimension (thickness) of the model design of which should reflect the actual 3D printed object. Each image layer was analyzed and compared with the designed solid works model using an algorithm. At layers having defects, the defective layers were compared with the layers without defects. Result obtained was evaluated and discussed to obtain a conclusion and suggest areas for further research.

2.1 Model design and experimental setup

Solid works software was used to design an object model for use in experimenting. The object shape, as seen in Fig. 2, shows the CAD design and its corresponding dimensions. Based on the thickness of the modeled object, a total of ten layers was created from it of which these serve as a reference for the 3D printer when executing the printing command [29,30,31]. Due to the uniformity of the object being printed, each layer has the same dimensions and shape. One-layer dimension was used for all layer model reference during the production process. To bring the aim of this study into actualization, an experimental set has been realized to aid the investigation. As shown in Fig. 1, the setup incorporates a CCD camera which acquires the data of each layer of a part printed at regular intervals. Two light sources are placed at strategic locations in the printing chamber to enable the defocused and homogeneous illumination of partly printed. The setup is extended by a memory drive that saves all the images acquired by the CCD camera, and then it is accessed directly by the software in the computer used for the processing. Table 2 gives information regarding the specification of the camera, software used, and the additive manufacturing machine utilized for the experiment.

Fig. 1
figure 1

Experimental setup of the cameral process to detect the defect in the printing object

Table 2 Details datasheet of support devices

2.2 Porosity measurement

This is a software-based comparative study of printed scaffolds of 3D-printed material with visible defects and those without visible defects. An exhaustive literature review and experimental examinations were done to achieve the objectives of this research. A MATLAB model porosity identifier algorithm was further developed, which can be implemented in real-time to give an idea of the porosity gradient of a printed component. Before employing a technique to construct the porosity in situ monitoring model, the image of parts printed on the bed of the 3D printer collected by an appropriate sensor camera needs to be compared with the porosity data collected from the component that is analyzed. A set of image processing algorithms has been developed in MATLAB to generate porosity information from the raw images of cross-sections under investigation, as discussed in Fig. 5. The cross-sectional images acquired consecutively are not concatenated or post-processed like some other research carried out. Here, the images captured are diagnosed by the developed algorithm in its raw state. The image is then cropped from during the processing to exclude areas of the sample holder and other accessories captured during the operation, which are not parts of the region of interest. After the cropping, the image is binarized using Otsu’s thresholding algorithm, and the dark patches represent pointers of porosities on the image’s cross-section. In the cause of this study, two types of dark patches were observed. One was due to contour cracks, and the other is due to pores spaces of different magnitude. The sequential steps of processing the image are discussed below and illustrated in Figs. 7 and 8.

3 Evaluation of defect detection

In this study, a sample test CAD model was created, as shown in Fig. 2 below. The G-code of the model was then generated, and a total of ten layers were printed using the 3D printer to determine the layer at which the defect could no longer be acceptable. Each printed layer samples were suitable for the analysis intended. These samples were selected to be used to test the validity of the software program algorithm. The Fig. 2a below represents one of the layered sample printed on the 3D printer with some defects on it, while Fig. 2b represents another layer sample without defect as recorded by the CCD camera during the experiment.

Fig. 2
figure 2

Measurement object (a) CAD design of sample. b Image of additive manufactured sample with defects. c Image of additive manufactured sample without defect

When these samples were analyzed using the software algorithm developed, the following operational sequence shown in Fig. 3 was carried out at different stages of the simulation. Each of the operation represented on the flow chart yielded specific results which are collectively used to make a final loop in the identifications of pores/defect/contours in printed components. The image results (Figs. 5 and 6) in the succeeding page show the series of operation as explained in the flow chart that was done on the digital input image before a final result is generated stating the existence or non-existence of pores/defect/contours in the additively manufactured component (Fig. 4).

Fig. 3
figure 3

Method of pores/contour/defect detection algorithm, where β1 converts the grey scale image to binary image. β2 complements the binary image. β3 fills holes identified in the image. β4 calculates the boundary area of the image. β5 draws a boundary line on the image. β6 displays holes and numbered too. β7 calculates boundaries of regions with pores in the image. β8 displays the image with pores and contours represented in random colours

Fig. 4
figure 4

Flowchart of the model detection process

4 Result and discussions

Thresholding of the image acquired is necessary to aid the subtraction of foreground components from the background as the first step before implementing other classifications to facilitate defect detector computations. This section shows the result of the images analyzed by the algorithm to detect the presence of pores. In Figs. 5 and 6 below, a, b, c, d, and e represent the intermediate image processing results obtained during analysis. The end product of this analysis, which is, of course, the porosity information image, is one that depends on other processes for it to be successfully achieved. Figures 5 and 6 show a vivid comparison between the image results of the layer generated by the simulation of the algorithm developed on a component with defect/contours/pores and another without a defect. This will aid in examining the efficacy of the algorithm for further investigations and approval for general use. In this simulation, some errors were accounted for that were mainly due to the image quality obtained, component sacrificial scaffold support finishing, and illumination. These sources of errors can be neglected in this study as the aim is just towards defect identification on a photographic scale. In the case where a feedback system will be implemented for information regarding defects detected, these errors will be filtered or ignored as the support is only a component which is usually discarded when the actual component is successfully manufactured. Figure 7 shows the nature of the histogram distribution of the pixels in the image.

Fig. 5
figure 5

Processing steps of pore’s detection for an image with defect (a) Input image. b Complemented image of a sample. c Binary image of sample exposing every defect. d Complemented images of samples with all holes/defect filled. e Outline of the boundaries of samples traced by code. f Result of local pore detection

Fig. 6
figure 6

Processing steps of pore’s detection for an image without defect. a Input image. b Complemented image of a sample. c Binary image of sample exposing every defect. d Complemented images of samples with all holes/defect filled. e Outline of the boundaries of samples traced by code. f Result of local pore detection

Fig. 7
figure 7

Histogram distribution of Grey level images of samples pixels. a Grey level image of a sample without defect. b Grey level image of sample with defects. c Histogram distribution of the grey level image of a sample without defect. d Histogram distribution of the grey level image of a sample with defects

4.1 Pixel distribution and segmentation

The captured images of both specimens (the layer with defect Fig. 5(a) and the layer without defect Fig. 6(a)) were then normalized into a greyscale pixel intensity map which ranges from 0 (dark patches on image) to 1 (white) for image segmentation. This step taken allowed us to identify the pattern of pixel intensity mapping within each frame of interest for spatial and layer variation analysis rather than acquiring pixel values using a point-wise approach.

The image processing was done using the MATLAB image toolbox viz-a-viz, a specially designed algorithm. The pore detection of this additive manufactured sample poses some challenges arising from foreground objects around the sample evaluated, the image quality of the captured sample, and a shadow cast on any side of the sample due to light position. In general, in situ detection of sintered contours is easier than a post-process analysis of a molten and solidified workpiece because of its higher contrast between the molten area and the unmolten powder. Consequently, the following optical analysis may be transferred directly to comparable in situ edge detection measurements.

For optical measurements and evaluation to be carried out, three basic steps are undertaken during the process, which involves utilizing both hardware and software, respectively. Firstly, the object layers being manufactured on the 3D printer are captured with an appropriate camera in a well-illuminated condition after completing each successive layer. Secondly, the image is transferred to the workstation via the adapted camera. Lastly, the acquired data in the form of a digital image is then processed with the software algorithm developed for quality assessment and measurement. In this study, the software algorithm developed performed series of operations on the digital image, as shown above, before the desired result is reached. To suitably track the edges of any image analyzed by the algorithm, the grey sample is first generated. The grey values obtained are then binarized, complemented, and filled with revealing the entire area covered by the image to aid in dimension extraction. During the printing process and from an image captured by the CCD camera, it was discovered that layers from 1 to 7 had no defect, but layers from 8 to 10 had defects in them, which have been analyzed and compared with layers without defects. The equation below represents the spatial objective function for pores identification of a squared error function

$$ F(U)={\sum}_{i=1}^K\kern0.5em {\sum}_{j=1}^{Ki}{\left(\left\Vert {x}_i-{u}_j\right\Vert \right)}^2 $$
(1)

where x = {x1, x2, x3, …., xn} is the set of defect points and u = {u1, u2, …., uc} be the set of centres of defect clusters. (‖xi − vj‖) is the Euclidean distance between xi and ujki Is the number of pores/defects in the cluster. K is the number of cluster centers.

The equation can be further experience as a model spatial function for pore’s center identification.

$$ {u}_i=\left(\raisebox{1ex}{$1$}\!\left/ \!\raisebox{-1ex}{${k}_i$}\right.\right){\sum}_{j=1}^{k_i}{x}_i $$
(2)

where ki is the number of pores in the cluster. This formula is used to recalculate the new pores/defect cluster center to aid reassignment in the algorithm to achieve a better result during simulation of layers under consideration. The pore detection was based on K means clustering algorithm used predominantly for medical imaging in most biomedical applications. From the results obtained as shown in Fig. 6, the sample without pores did not have the random colors displayed on its surface, which invariably shows that no visible pores were identified on its surface when analyzed by the image process algorithm. However, it will be observed that there are some colors displayed at the side (support) due to the relative roughness of the support. In essence, this algorithm has further proved its validity in total agreement with what is observed physically by our eyes. In the sample with pores (Fig. 5), it will be observed that there are random colors scattered around its surface. This simply shows the presence of pores and discontinuities on the surface. This was achieved by K means clustering concept, as stated earlier, via the investigation of the pixel values of pores and any other discontinuities/defects and their size distributions.

4.2 Edge detection and background subtraction

This is one of the processes embedded in the software algorithm to mark out the boundary of the sample to aid in the measurement of the sample dimensions. This process is most times affected by the presence of shadow in a digital image captured. Hence, the result obtained tends to be obscured like the sample analyzed in Fig. 8 below, thereby giving a false judgment regarding sample size on the build plate of the 3D printer. This limitation is similar to the first limitation, which can be solved by improving the illumination of the sample. Still, in this case, an appropriate angle of incidence selected will improve the quality of the sample image greatly.

Fig. 8
figure 8

Shadow effects on algorithm

This is another challenge as a decisive selection cannot be made regarding what is captured and what is blanked out when the camera is placed facing a particular direction. In the capturing of the sample under manufacture, the camera also tends to capture other accessories of the 3D printer. It becomes difficult to carry out a foreground (other accessories) subtraction when there is a similarity between some of the accessories and the sample underbuild. This, however, was solved by thresholding and image segmentation options in the image processing algorithm before binarization of the sample image.

5 Limitation

It was noticed that the presence of shadows around the image or on the digital image to be analyzed caused some deviations from the expected results obtained, as observed in Fig. 8. This was so because the pixel value of the shadow interfered with the pixel values of pores included in the algorithm for pore investigation and detection. To cub this anomaly in this research study, pictures of samples were taken in an adapted optical environment. The algorithm requires an iterative apriority specification of the number of cluster centers. Since it is highly probable to have two overlapping pixel data of defects identified on images, the algorithm simulation result may be tilted slightly from accuracy based on this kind of input. This, however, can be solved by intelligent machine learning techniques that can identify close matching data sets. Also, the algorithm is not invariant to non-linear representations. The measure of Euclidean distance between sets of defect points and cluster centers can unequally weight underlying factors like shadows and other noisy data and outliers.

6 Conclusion

This algorithm proposed in this research study can aid this material to be effectively utilized in different sectors with low to zero risks regarding component mechanical property or quality. In no distant time, 3D-printed material has the potential of replacing expensive high-quality materials already invoke in the industrial sector. The need is to explore the tendency of using 3D-printed components that meet mechanical and quality standards for more sophisticated applications. This development will undoubtedly increase the usage of 3D-printed materials since a material property validity test procedure now breaches the gap created by uncertainties. In the future, a video editing of layers printed during the additive manufacturing process will give a better result and ensure optimum quality in the process. We recommend in this research work for further analysis of the thickness of the printed object for any form of defect.