Defect Detection and Three Dimensional Reconstruction of Castings

There are defects inevitably in the production of castings. These defects will short the life of castings. In this paper, defects of the castings are detected by industrial CT non-destructive testing method and a series of CT slice images are obtained. Then edge extraction is realized through the Canny operator and the defects in the castings are found. Finally, surfaces and its internal defects are reconstructed for the casting based on secondary development of Unigraphics software and Visual Studio 2013. Experiments show that internal defects of the castings can be extracted by the Canny operator effectively. Internal position and shape of defects can be observed directly by three dimensional reconstruction.


Introduction
In the casting production process, defects are inevitable because of the characteristics of castings. Any casting defects will affect the quality of castings and short the life of castings. It will also affect the enterprise economic benefit and social benefit. With the rapid development of manufacturing industry, it is very necessary to detect and measure the position and shape of internal defects for complex castings. Identification and analysis of casting defects by non-destructive testing technique can detect the unqualified parts rapidly and improve the quality of castings.
Radiographic testing and ultrasonic testing are two ways to measure internal defects of parts. But Radiographic testing and ultrasonic testing are not applicable to complex and irregular casting in shape and internal structure.
Industrial CT is a non-destructive testing method which is very popular in recent years. When Industrial CT and traditional ray detection are compared, there are three advantages. The first is that industrial CT can directly observe the location and shape of interested targets. The second is that industrial CT has a good density resolution. The third is that industrial CT images are easy to save, transmit and analyze. Industrial CT can obtain all the space information and defect location of complicated castings. It can find defects more accurately and reduce error judgment of defects.
Industrial CT is used to detect castings in this paper. Industrial CT can detect the internal structure of objects and the defects clearly, accurately and intuitively without damage of the sample [1][2][3]. Many slice images along the same direction can be got by industrial CT scanning equipment. At present the appropriate operator is mainly choosed to detect defects of the image [4][5][6][7][8][9]. In this paper, Canny operator is used to identify the image contour and internal defects because of good denoising effect. Then curves are fitted for the contours of images and defects according to the image sequence. The curve group is got along the same direction. Finally the surface is reconstructed. The bounding box is used to represent the size of the defects.

Canny operator
Canny operator [10] is a good edge detection operator and it is one of the more widely used operators in graphic processing. The image contour can be detected clearly and the positioning accuracy is good. There is no problem which can not detect the direction of the edge. Canny operator can detect the edge direction effectively and has good anti noise ability. It include four steps which are image denoising, calculation of the gradient and direction, non maxima suppression, detection and connection edge based on double threshold algorithm The original image is smoothed by two dimensional Gauss function. Thus noise can be suppressed. The formula of two dimensional Gauss function is (1) The gradient magnitude and direction is calculated by first order partial derivative finite difference. The convolution operator is expressed by Non maxima suppression of the gradient magnitude is used to thin the image edge. If the gradient M(i, j) of the pixel is greater than or equal to the gradient magnitude of two adjacent pixels along the gradient direction, the pixel is the edge point. Canny operator can eliminate the false edge and intermittent edge by double threshold. Fig.1 is the flowchart of the Canny operator.

Three dimensional reconstruction
There are three kinds of methods to generate the surface based on Unigraphics software. The first is to generate surface by the point cloud, but the surface generated by this method is nonparametric. The second is to generate surface by the curve group. This method generates parameterized surfaces and can be used to construct large area surfaces. The third is to generate surface by the transition and connection between surfaces. This method is commonly used in the transition and connection between surfaces and surfaces.
A casting is scanned by an industrial CT equipment. Multi slice images are obtained. The point set of every image is in the same section plane. So point sets of all images are in a series of parallel section planes. Based on this characteristic, the average interval method is used to simplify the point set of every image in the environment of Visual Studio 2013. The principle of the average interval method is simple. From the original edge points, data points are selected according to the same interval. Thus simplified edge data set is formed. Simplified data of every slice image are imported based on Unigraphics secondary development. Then NURBS curves are fitted for edge points of every slice image. The NURBS curve is defined as: (6) In the formula, P i are control vertexes. W i are weight factors. N i,p (u) is pth B-spline basis functions. They are defined by De Boor-Cox formula.
Finally three dimensional surface is reconstructed for the curve group. A NURBS surface is obtained. The NURBS surface is defined as: In the formula, d i,j (i = 0,1…m; j=0,1…n) are control vertexes. They are arranged according to topological rectangular. ω i,j is weight factor connected with d i,j . Weight factor of four corner vertexes are ω 0,0 , ω m,0 , ω 0,n , ω m,n and they are set as positive number. Other ω i,j are greater than or equal to 0. N i,k (u) (i=0,1, …m) is kth Bspline basis in u direction. N j,l (v) (j=0,1, …n) is lth Bspline basis in v direction. They are determined by De Boor-Cox formula according to u directional knot vector By NURBS surface reconstruction, three dimensional model is reconstructed through the point set of external contour. Then three dimensional defect reconstruction is also finished by the point set of internal defects. After the Boolean reduction between the reconstruction model of the external contour and the reconstruction model of the internal defects, the final three-dimensional reconstruction results of the part can be obtained. The shape and internal structure of the casting can be observed intuitively.
The programme is finished based on Visual Studio 2013 and Unigraphics software. After Unigraphics secondarey development, all simplified points can be imported fast. Thus efficiency can be increased. This will prepare for the subsequent curve fitting. NURBS Curve is fitted according to points which are in the same section. So many NURBS Curves are fitted and these NURBS Curves are in parallel sections. Thus the curve set is formed. The NURBS surface can be reconstructed.When the NURBS surface is reconstructed, the directions of NURBS Curves should be consistent. Fig.2 is the flowchart of secondary development for three dimensional construction. This is the process of generating curves from points and generating surfaces by curves.

Bounding box of defects
The bounding box is an algorithm for solving the optimal encircling space of discrete point set. The basic idea is to replace complex geometric objects with a slightly large and simple geometric body. The most common bounding box algorithms include axis-aligned bounding box, the encircling sphere, oriented bounding box, and the fixed direction convex hull. Bounding boxes are widely used in virtual reality, computer aided design and manufacturing, games and robotics.
In this paper, the AABB bounding box is used to represent the defects. The AABB bounding box is defined as the smallest hexahedron which contain the part and is parallel to the coordinate axis. A AABB bounding box is describe by six scalars. The structure of the AABB bounding box is relatively simple. It has small storage space. The calculation time is short and the efficiency is high. It is suitable to represent the defects of the casting.
In order to obtain the size of internal defects more accurately, a cube bounding box can be built for internal defects. It can make the internal defects completely in the cube bounding box. Since the slice images are on the parallel sections, the minimum value and the maximum value along the X direction can be found in the internal defect region of each section. The minimum value and the maximum value along the Y direction can also be found in the internal defect region of each section. The minimum value and the maximum value along the Z direction can also be found in the defect area of all sections.
Suppose a defect has N cross sections. For the set of defect points on the ith section, the maximum value of the X direction is found and expressed in XMAX i . The minimum value of the X direction is found and expressed in XMIN i . The maximum value of the Y direction is found and expressed in YMAX i . The minimum value of the Y direction is found and expressed in YMIN i . Find the maximum value from the XMAX i collection and it is expressed by A. Find the minimum value from the XMIN i collection and it is expressed by B. Find the maximum value from the YMAX i collection and it is expressed by C. Find the minimum value from the YMIN i collection and it is expressed by D. Find the maximum value of Z direction from N cross section, and it is expressed by E. Find the minimum value of Z direction from N cross section, and it is expressed by F. So the bounding box (A, B, C, D, E, F) is built.

Experiment results
After a casting is scanned by an industrial CT equipment, a series of industrial CT slice images were obtained. Image scanning matrix is 1203 X 1270. The distance of two pixels is 0.08mm. An industrial CT image of the casting is showed in Fig.3. From the figure, the object and the background can be observed directly and internal structure and the image contour are clear. The location and size of internal defects can be observed. In fig.3, some defects can be found. There are some small defects that can't be observed by the naked eyes. So these defects need use the image processing method to identify. The extracted contour by Canny operator is showed in Fig.4. Two threshold of the image are 59 and 148. Internal and external contours can be obtained. Internal points and the contour points can be traced. The curve group is showed in Fig.6. From the figure, NURBS curves of every slice image are reconstructed. Three dimensional reconstruction model is showed in Fig.7. Hole defects of the casting are showed in Fig.8. The figure is a frame representation of three dimensional model. From the figure, many internal defects can be showed. This can help to test the quality of the casting. The position and size of internal defects can be observed. For the casting, there are many small internal defects from the frame representation of the model. Enlarged defects are shown in Fig.9. Three dimensional reconstruction method is also applicable to hole defects.   Figure 10. The total length of the defect bounding box which can be got is 0.24mm, the total width is 0.16mm, and the total height is 0.8mm. The bounding boxes can be built for all internal defects of the casting. The total length, the total width and total height of the bounding boxes can be obtained. It is possible to have a quantitative understanding of the size of all the defects.

Conclusion
In this paper, a casting is detected by an industrial CT equipment. Internal and external contours are identified by Canny operator. Then secondary development is finished by Visual Studio 2013 and Unigraphics software. The edge points are simplified by the average interval method for every slice image. All contour points are imported and NURBS curves are fitted based on the imported data for every slice image. The curve group is obtained. Finally the surface is reconstructed base on the curve group. Experiment results show that defects of the casting can be identified effectively.