Defect Recognition in Radioscopic Image Sequences based on Bag-of-Words

Digital X-ray real-time imaging is a new technology in non-destructive detection using image sequences. At present, manual identification of defects is mainly used in practice, which is expertise-dependent and prone to errors. The existing automatic recognition method based on radiographic images mainly recognizes a single defect type for a single radiographic image, which is easy to produce a large number of false detections in non-defect areas, and cannot correctly identify images containing multiple types of defects. A defect recognition method based on Bag-of-Words is proposed, which uses the inter-frame difference method to obtain the moving target area, namely the defect area, and uses the SIFT operator based on the Bag-of-Words model to extract the defect features, and then the trained support vector machine (SVM) performs recognition. Experimental results show that the proposed method can effectively reduce false detections in non-defective areas. The defect recognition method correctly recognizes the defect category with a probability of 85.3%.


Introduction
Various defects often occur in the casting process, which seriously affect the quality of the product and pose safety hazards [1]. Common internal defects of castings are shrinkage porosity, shrinkage cavity, bubbles, slag inclusion, and cracks, as shown in Figure1 a) to e) respectively. It is significant for repairing the castings and improving casting quality to identifying the type of defects.

Figure1 Defect types in castings
In the field of non-destructive testing, radiographic inception has a wide range of applications due to its high sensitivity, high detection efficiency, and the ability of visually display detects [2]. The digital x-ray real-time detection technology can obtain real-time ray image sequences [3]. As shown in Figure  2, the vehicle drives the castings to rotate and move axially, after x-ray irradiation, radioscopic image sequence is captured and transfer to the computer. At present, many scholars have researched on the automatic defect recognition technology of radiographic images. LiLi Jiang [4] uses a weakly supervised convolutional neural network model to identify the types of casting defects; Mery [5] uses a convolutional neural network (CNN) combined with a sliding window to detect the types of defects in a single casting radiographic image. However, the defect recognition method based on deep learning requires a large number of samples to achieve the satisfied effect, and has high requirements for computer hardware, which is difficult to apply to the detection and recognition of real-time ray image sequences.
A defect recognition method based on Bag-of-Words model is proposed. First, determine changes between the current frame and the previous frame, then do the same on the current frame and the next frame. Perform bitwise AND operation on two binary images obtained above. The boundary of the result represents the defect area. Second, features are extracted from defects, then SVM is used for identifying the defect type. After experimental testing, the proposed method can accurately find the defect area and identify the defect type, and can satisfy the real-time requirements. The technical route of this article is shown in Figure 3.

Potential Defect Region Extraction:
The inter-frame difference method [6] is often used in the detection of moving targets in video image processing. Its principle is to obtain the contours of moving targets through determining the changes between two adjacent frames. In the radiographic image sequences, the defect area can be regarded as the foreground target, and the defect-free area can be regarded as the background, so we can use the inter-frame difference method to obtain the contours of defects. In order to improve the accuracy of defect detection, firstly, determine changes between current frame and previous frame according to Eq.(1), then determine changes between current frame and next x y represent the current frame, the previous frame and the next frame; T represent the threshold; After obtaining the difference image of the defect, calculate the minimum bounding rectangle of each enclosed area, and merge according to the distance between the centers of the two rectangles. The potential defect area in binary image is shown in Figure 5a), and the potential defect area in radioscopic image is shown in Figure 5b). In the algorithm for extracting potentially defective regions, the threshold is set to be larger in order to reduce missed detections. However, due to the large noise of the radiographic image and low image contrast, reducing missed detections will inevitably increase false detections. Identifying the authenticity of potential defects can effectively reduce false defects. The gray value contrast between the defect area and its neighborhood is high, while the gray value contrast between the false defect area and its neighborhood is low. Taking the 10-pixel wide area around the potential defect area as the neighborhood, the gray value contrast of the potential defect and its neighborhood can be calculated by Eq. (4). where, ( , ) P x y represent the gray value of the pixels in the area after expanding the potential defect area by 10 pixels, ( , ) f x y represent the gray value of pixels in the potential defect area.  [7][8][9]; from the range of features, the defect features are point features, local features, and global features [10]. Gray-scale features (contrast), geometric features (area, circularity, spatial distance) and point features (SIFT operator) are combined to describe defects.
(1) Contrast. The gray difference between the defect area and its neighborhood, namely the contrast.
(3) Circularity. The circularity of the defect indicates how close the defect area is to the circle, namely the circularity.
(4) Spatial distance. The average distance between defective areas in the radiographic image, namely the spatial distance.
(5) SIFT operator. There are large differences in the scale of similar defects in casting defects, and the difference in thin and thick walls leads to differences in the brightness of the radiographic image, these factors all affect the accuracy of classification. The SIFT feature has strong robust to scaling, rotation and illumination change [11]. The calculation steps are as follows: STEP1: Calculate the convolution of the Gaussian function in different scales and the original image to obtain the scale space, then calculate the difference between the adjacent scale spaces to obtain the Difference of Gaussian (DOG), the calculate equation is defined as Eq. (9). Finally obtain the extreme points in the space as candidate feature points.
( , , ) ( ( , , ) ( , , )) ( , ) The bag-of-words model [12] uses a set of independent keywords (visual words) to describe a set of images, and an image can be described by the frequency of these visual words. Using the bag-of-words model can reduce the dimension of the feature vector and enhance the description ability of the feature vector. The principle of the bag-of-words model is shown in Figure 6. The steps are as follows: STEP1: Extract the SIFT feature description operator of each image in the training set and merge it into a feature set.
STEP2: Generating distance centers as visual words by K-Means clustering. STEP3: Calculating the frequency of each image's feature description operator belonging to every visual words, then compose the frequency into a vector, and normalize them.
STEP4: Combining contrast, area, circularity, spatial distance with the vector obtained from STEP3 into a new feature vector.
STEP5: Establish SVM model. STEP6: Train the SVM model using train set, and evaluate the model using the test set.  The result is shown in Table 1  It takes 30 minutes to manually detect a workpiece, with high false-detection and false-recognition. The proposed algorithm takes an average of 10 minutes to detect a workpiece, and the recognition accuracy is 85.3%.

Conclusion
Digital X-ray real-time detection is one of important Non-Destructive Testing (NDT) methods for casting defect detection. Manual interpretation of defects is mainly used in practice, which is highly subjective and prone to make false-detection and false-classification. A defect recognition method based on Bag-of-Words model is proposed. Compared with the manual recognition and other automatic recognition method based on single frame, the proposed method can effectively reduce false-detection and have a higher accuracy rate.