Abstract
BACKGROUND:
X-ray imaging plays an important role in security inspection. However, the objects are complex, which makes it difficult to automatically detect prohibited and restricted objects.
OBJECTIVE:
This study aims to develop and test a detection method based on a new image segmentation scheme to solve the problem of detecting prohibited and restricted objects from pseudo-color X-ray images with complex backgrounds.
METHODS:
The internal mechanism of the influence of different color spaces on image segmentation effect is explored, and the color space component Hi is studied. Furthermore, the mechanism of the new Hi component and the influence law of its adjustable coefficient are revealed. Additionally, a detection method based on Hi color space segmentation for pseudo-color X-ray images is proposed. The segmentation and detection methods are then tested on actual X-ray images.
RESULTS:
The results show that hue has the greatest influence on image segmentation effect of the pseudo-color X-ray images. For different pseudo-color X-ray images with complex backgrounds, applying the proposed new Hi color space segmentation method achieves overall accuracy of 0.974 and 1.0 in detecting the gun and knife, respectively.
CONCLUSION:
The new X-ray image detection method based on the Hi color space segmentation proposed in this paper enables to better solve the complex background problem including object overlap and adhesion and thus more effectively meet the requirements of actual security inspection.
Introduction
X-ray imaging systems have been widely used in security inspection scenarios such as customs, airports, and subways, and have played an important role in maintaining public security. However, the complex and numerous natures of the objects being inspected has made it difficult to automatically segment and detect prohibited and restricted objects.
The research on X-ray image segmentation and detection mainly focuses on medical and industrial applications [1–3], there are relatively few studies on baggage and cargo inspection areas. Some scholars have applied threshold segmentation to X-ray images. Deng Wenfeng [4] conducted research on X-ray security inspection images of knives and guns and used an iterative thresholding algorithm for image segmentation. Cao Jinbo [5] studied the identification of contraband in the scanned images of X-ray security inspection system, and segmented RGB images by combining threshold selection with region growth method. However, the objects studied in the above research are single and arranged in a regular manner without considering the problems of overlap and adhesion.
Some researchers have used clustering algorithms to segment X-ray images. Jimin Liang et al. [6] used the Radon transform to determine the optimal number of clusters. Noeleene Mallia-Parfitt et al. [7] applied semi-supervised spectral clustering to segment firearms. Taimur Hassan et al. [8] adopted a clustering algorithm to segment dangerous goods in luggage. Krzysztof Dmitruk et al. [9] applied clustering algorithms to high and low energy grayscale images respectively and focused on material classification.
Mohamed Chouai et al. [10] applied machine learning to segment pseudo-color X-ray images obtained from dual-energy inspection equipment, and to separate organics and inorganics, multilayer perceptron, support vector machine, random forest, naive Bayes, k-nearest neighbor, and linear discriminant analysis are applied, with naive Bayes performing best. Deep learning is one of the current hotspots, and convolutional neural networks are widely used. Many scholars [11–13] have used convolutional neural networks to detect contraband in luggage. Yao Shaoqing et al. [15] utilized 1883 images, including guns, knives, power banks, lighters, and other objects to study the segmentation of contraband based on Visual Geometry Group Network. Since the prohibited and restricted objects in the actual security inspection are rare, such as guns, knives, endangered animals and plants, the X-ray image detection method studied in this paper is aimed at small samples. However, deep learning methods require many training samples, which is one of their notable shortcomings. Therefore, the deep learning methods are not suitable for the research in this paper.
Considering the pseudo-color characteristics of the X-ray images obtained by dual-energy systems, it is particularly important to study the color space of X-ray images, which can greatly improve the image segmentation effect. Although there are many segmentation methods, segmentation of the objects of interest from complex backgrounds is always attractive [16].
For color image segmentation by using clustering algorithms, Chen Kun et al. [17] combined the histogram threshold with the K-means method to find the peaks of three components R, G, and B, and then divided the pixels into the cluster with the closest distance. After removing the clusters with fewer pixels, the regions with similar colors are merged, and the K-means method is used to increase the region density. Due to the problem of low accuracy in RGB color space segmentation, Shi Haibin et al. [18] converted the image to Yuv color space. In Yuv color space, luminance and chromaticity are independent of each other, and these two components can represent color. In addition, K-means and maximum expectation algorithms were combined to reduce over-segmentation and speed up the segmentation process. Zhang Hongxia et al. [19] converted the image to Lab color space, then, a and b components are extracted. The Euclidean distance is used to discriminate the similarity. And K-means clustering is used, which can improve the accuracy and stability of segmentation. Bian Yongming et al. [20] considered the saturation component of the HSI model based on the RGB model and used K-means clustering to obtain the segmented area, which is more effective than using RGB or HSI model alone.
The images obtained by dual-energy X-ray systems and CT baggage inspection systems have pseudo-color characteristics. Fortunately, humans have a better perception of color images. Most color image segmentation techniques are derived from grayscale image segmentation techniques, but direct application of grayscale image segmentation methods to color images is ineffective. Therefore, the research on image segmentation is carried out on pseudo-color X-ray images with overlapping and adhesive backgrounds. Mainly three parts are studied in this paper. In the first part, the influence of color space on the segmentation effect, and the internal influence mechanism are analyzed. In the second part, a new color component Hi is proposed while considering the characteristics of pseudo-color radiation images. Then, a Hi color space segmentation algorithm is proposed, which can efficiently solve the segmentation problem of complex background X-ray images. Finally, an X-ray image detection method based on Hi color space segmentation is proposed in this paper, and the effectiveness is verified through actual X-ray image detection.
Influence of the color space on the segmentation effect
The object studied is the original baggage X-ray image shown in Fig. 1, and the gun needs to be segmented from the background. Figure 2 is the denoised image. In this paper, the pseudo-color X-ray image is converted from RGB to other color spaces, and the influence of different color spaces on the clustering effect is studied. Figure 3 shows the experimental results of the K-means clustering method for RGB, XYZ, Yuv, YCbCr, Luv, Lab, HSI, and HSV color spaces respectively. The experimental results show that HSI and HSV color space clustering is easier to separate the gun from the complex background. Yuv and YCbCr can separate the gun from the background of plates, but not separate it from the background of mobile phones. While RGB and XYZ spaces have the worst effect.

Noise X-ray image.

Denoised X-ray image.

Different color space clustering results.
Figure 3(a) and (b) are the experimental results of the effect of RGB and XYZ color spaces. The internal mechanism is that the two-color spaces belong to mixed color models. Therefore, the three components are highly correlated, and each color comes from the joint action of the three components. The segmentation results also show that RGB and XYZ are not suitable for segmenting pseudo-color X-ray images. However, as the most used color model, in which images are generally stored and displayed, RGB is usually a starting point for conversion to other color spaces.
The segmentation results obtained by mapping RGB to Yuv and YcbCr color spaces are shown in Fig. 3(c) and (d) respectively. The segmentation results are better compared with RGB and XYZ, but the effect is not significant. Guns and mobile phones still overlap with each other and cannot be segmented effectively.
In the Yuv and YCbCr color spaces, Y represents luminance, while u/v and Cb/Cr both represent chrominance. The Yuv and YCbCr color spaces are mapped from the RGB space by Equations (2) [21].
As shown in Equations (2), the Yuv and YCbCr color spaces are both linearly transformed from RGB, and there is a correlation between the components. Colors can be determined by two specific components. Therefore, the segmentation of the pseudo-color X-ray image in Yuv and YCbCr requires only two components. Due to the strong correlation relationship in RGB, it is not applicable to the K-means clustering algorithm, but since the correlation of components in Yuv and YCbCr is not as strong as that in RGB, their segmentation results are better.
The segmentation results obtained by mapping RGB to Lab and Luv color spaces are shown in Fig. 3(e) and (f), where guns are separated from the background. In Lab and Luv color spaces, L denotes luminance, a/b and u/v are chrominance components. RGB needs to be converted to XYZ, and then mapped to Lab or Luv color space.
where X ref , Y ref , Z ref are the values of white.
The RGB color space is transformed into HSI and HSV space by Equations (7)–(12). Where H is hue, S represents saturation, V is value, and I denotes intensity. It can be seen in Fig. 3(g) and (h) that the gun can be separated from the background, and the clustering effects of these two-color spaces are the best.
When RGB is mapped to HSI space, the calculation of H is the same as in HSV.
The three components of the HSI and HSV color spaces are most consistent with the color perception of human eyes. S, I or V components are completely decoupled from H. In pseudo-color X-ray images, different types of substances, such as organic, inorganic and mixture are mainly determined by hue which makes the H component works effectively in image segmentation. However, there also exists a disadvantage when using HSV and HSI spaces. The hue ranges from 0 to 2π, but if the extreme value of 0 or 2π is taken, the hue is actually very similar.
Luminance and chrominance of HSV, HSI, Lab, Luv, Yuv and YCbCr color space are not coupled, which plays an important role in image segmentation, and avoids the negative effect of image luminance on segmentation. HSV, HSI, Lab and Luv are more suitable for pseudo-color X-ray image processing. The color space must be selected according to the characteristics of the pseudo-color images.
In summary, in RGB and XYZ, colors are obtained by mixing three components, which gives the worst effect. In Lab, Luv, Yuv and YCbCr, two components are used to describe different chrominance and one component is used to describe luminance. The influence of luminance on clustering is removed, and the segmentation effect is better than RGB and XYZ. There is no coupling between all the three components in HSV and HSI, which is more conducive to image processing and achieves the best segmentation effect. Therefore, for pseudo-color X-ray images, the order of segmentation effect is HIS = HSV > Luv > Lab > Yuv = YCbCr > RGB > XYZ. Hue has the greatest influence on the segmentation effect of pseudo-color X-ray images, and is completely independent of other components, which contributes most to the segmentation effect.
Design and analysis of the Hi color space component
Through the above analysis, K-means clustering segmentation is applied based on the H component of the HSI color space, and the resulting binarization image is shown in Fig. 4. Although the gun can be separated from the background, there are still many holes, which is not conducive to further processing. This section deals with how to improve the segmentation method.

H component clustering results.
The H, S and I components of the denoised pseudo-color X-ray image are shown in Fig. 5.

H, S and I components of the X-ray image.
The values of H, S and I are all between 0 and 1. According to national standards, dual-energy X-ray images are assigned orange for organic matter with an equivalent atomic number of less than 10, blue for inorganic matter with an equivalent atomic number of more than 18, and green for mixtures whose equivalent atomic number is between 10 and 18. The histograms of the H, S and I components of the gun in this X-ray image are shown in Fig. 6.

Histogram of H, S and I components of the gun.
The H component of the gun is mainly between 0.55 and 0.65, while for the holes, H is mainly concentrated in the range of less than 0.55. In the H and S component images, there are holes on the gun and has poor continuity. The I component concentrates on the interval from 0 to 0.4, and the corresponding image is continuous without holes, but it is still difficult to separate from the background.
The results show that the value of the H component separates over a wide range, while the value of the I component has a smaller range. Since the H component performs best in X-ray image segmentation, and holes can be removed by using the I component, then a new color space component Hi based on the H component and improved by the I component is proposed. The following improvement methods are considered in this paper.
where m, n, p are the adjustable coefficients and m, n, p > 0.

Hi, clustering images and segmentation results corresponding to different m, p, n values.

Evaluation indexes corresponding to different m, p, n values.
From the experimental results, with the increase of m and n, there are growing holes but less adhesion with surrounding objects in the clustering images. I component has a great influence when the Equation (15) is applied, so the adhesion is serious, and the gun cannot be segmented well from the background. Therefore, when m is 3, the gun can be better separated from the background with fewer holes, and the evaluation indexes are highest.
Different construction methods of Hi have been evaluated by applying them to various pseudo-color X-ray images. A part of the segmentation results is shown in Fig. 9. Dice and Jaccard are used to evaluate the image segmentation quality, which are shown in Fig. 10. The results show that Equation (13) can obtain the highest Dice and Jaccard, that is, the best segmentation effect can be achieved. Therefore, the construction method of Equation (13) is suitable for pseudo-color X-ray image segmentation.

Results of different construction methods of Hi.

Evaluation indexes corresponding to different construction methods of Hi.
The reason for different m clustering results is analyzed below. When m ranges from 1 to 4, the histogram of the reconstruction component Hi of the gun is shown in Fig. 11. When m is 1, the Hi component is most affected by I, and the histogram becomes flat. As m increases, the histogram becomes closer to the H component, where the Hi value decreases, the distribution range is narrower, and the change in the Hi is more drastic.

Histograms of the Hi component of the gun.
When m is 1 to 4, the histograms of the reconstructed component Hi of the whole X-ray image are shown in Fig. 12, As the value of m increases, the value of Hi decreases, the range becomes narrower, and the change of the histogram becomes steeper. There are four peaks in each histogram. The orange organic matter with the lowest Hi value occupies the largest part of the image, and it forms the leftmost peak. The two peaks in the middle come from the plate and the mobile phone respectively. As the mobile phone overlaps with the plate, the Hi value of the mobile phone is larger. The rightmost peak with the largest Hi values come from the guns and the keys, which have the minimum peak value. The smaller the value of m, the smaller the difference between the different substances. Therefore, the holes are reduced, and the adhesion becomes stronger. The larger the value of m, the closer to the H component, the more holes will be formed, and the less adhesion will occur. m is an adjustable coefficient that can be set according to different X-ray images in practical applications.

Histogram of the Hi component of the whole X-ray image.
In this paper, a Hi color space segmentation algorithm is proposed according to the pseudo-color characteristics of X-ray images. The flowchart of X-ray image Hi color space segmentation is shown in Fig. 13. X-ray images need to be denoised. Since X-ray images are stored in RGB color space, the denoised images are converted to HSI color space. Then the new color space component Hi proposed in this paper is constructed by Equation (13). The improved K-means clustering is applied to the Hi component. After graying, binarization and morphological operations which are used to separate the overlap and adhesion, objects can be extracted. If the evaluation index Dice is not less than 0.9, segmented images are output. If not, m is increased by 1 and Hi is reconstructed until the Dice requirement is met.

Flowchart of X-ray image Hi color space segmentation.
The above image is taken as an example. The denoised X-ray image is shown in Fig. 14(a). When m is 1 and 2, Dice is 0.5509 and 0.5681 that cannot meet the requirement. When m is 3, the Hi component is reconstructed, Dice is 0.9259 and satisfies the requirement. The results obtained by applying the K-means clustering method to the reconstructed Hi component is shown in Fig. 14(b), and Fig. 14(c) is obtained after graying and binarization. It shows that the clustering effect is favorable, but there are still adhesions.

The gun segmentation process.
In this paper, the square structural element is used for corrosion, and the connected domains are obtained and then expanded. As shown in Fig. 14(d), all the objects can be separated without adhesion after corrosion, but there are still many meaningless small areas that need to be deleted. The connected area is separated to obtain the corrosion image of the gun shown in Fig. 14(e). Due to the corrosion process, the gun image needs to be expanded, and the expansion image is shown in Fig. 14(f). Then, the Canny operator is used to extract the edges as shown in Fig. 14(g). The results show that the object and the edge can be well extracted from a complex background by the Hi color space segmentation method based on clustering and morphology.
X-ray image detection method based on Hi color space segmentation is proposed in this paper. The algorithm flowchart is shown in Fig. 15. The main steps of the algorithm in this paper are as follows. In the training phase, X-ray image training sets need to be denoised. Second, the denoised image is converted from RGB color space to HSI color space. Third, the new color space component Hi proposed in this paper is constructed. Fourth, the improved K-means clustering is applied to the Hi component. After graying, binarization and morphological operations which are used to separate the overlap and adhesion, target objects can be obtained. Then, the features of the target objects are extracted and fused. Finally, the processed features are fed into the support vector machine to obtain the detection model. In the detection phase, X-ray images also need to be deniosed and segmented based on Hi color space. Then the features are extracted and fused. The processed features are fed into the detection model. If it is classified as a certain class, the output result is positive. If not, the output result is negative.

Flowchart of X-ray image detection algorithm based on the Hi color space segmentation.
X-ray image segmentation experiments and evaluation
Different segmentation methods are applied to various pseudo-color X-ray images, and the segmentation results are shown in Fig. 16. Accuracy, precision, MCC, Dice, Jaccard and time are used to evaluate the image segmentation quality, which are shown in Table 1. The evaluation indexes in bold represent the better segmentation results in Table 1.

Results from different segmentation methods.
Evaluation indexes of different segmentation methods on X-ray images
In Fig. 16(1), the backgrounds are complex due to overlapping and adhesion in the images. The guns, knives and bottles need to be segmented from complex backgrounds. Figure 16(2) are the experimental results obtained by K-means clustering on the H component of HSI color space, which show that there are many holes in guns and bottle. This situation seriously affects the quality of segmentation and subsequent processing. The adhesion is serious when K-means clustering on the S component clustering, I component clustering and fast fuzzy c-means clustering are applied to these X-ray images in Fig. 16(3)-(5), the quality of segmentation is poor. Genetic clustering experimental results are shown in Fig. 16(6), this method requires long computation time and cannot guarantee real-time performance, which is not suitable for security inspection field applications.
From the experimental results in Fig. 16 and Table 1, the results of cases (a), (d), (e) and (f) show that the proposed method of this paper is obviously better than other methods. In case (b), the accuracy, MCC, Dice and Jaccard of the genetic clustering and this paper method are comparable, the precision of this paper method is better than the genetic clustering method. And the time of the genetic clustering method is 189 times longer than this paper method which cannot meet the time requirement. Therefore, the genetic clustering method cannot be used in actual security inspection. In case (c), the evaluation indexes of the H component clustering method and this paper method are comparable. The knife segmented image of the application of H component clustering method has no holes and complete shape, so H component plays a dominant role, and I component is supporting role. Therefore, the evaluation indexes of this paper method is only a little higher than those of the H component clustering method.
The segmentation method proposed in this paper can achieve the best effect. A new Hi component is constructed, and clustering is applied to this component. It can be seen that the holes are significantly reduced, and the overall shape of the objects can be better achieved. The segmented objects can better reflect its shape characteristics. The segmentation method in this paper is verified to be effective for various pseudo-color X-ray images with overlap and adhesion.
Support vector machine (SVM) training
For small sample gun detection, the number of positive samples in the training set is 12, the number of negative samples is 16. Then the detection model of SVM is trained.
(
Four kernel functions are used to map low-dimensional data to high-dimensional data.
1) Linearity:
2) Polynomial:
3) Sigmoid:
4) Radial basis:
where r = ||
Table 2 shows the accuracies, recalls and false positives obtained by detecting the test set after training the SVM with four kernel functions.
Detection indexes corresponding to different kernel functions
As can be seen from Table 2, the radial basis kernel function has the highest accuracy and recall. Since no sample is determined to be a gun, the sigmoid kernel function has no false positives, so the radial basis kernel function has the lowest false positive. The radial basis function has the highest accuracy and recall, and the lowest false positive, so the radial basis function has the best detection effect.
(2) Standardization
Sample standardization is to map a one-dimensional value of the sample to a certain range. Column mean value and standard deviation are used to apply the standardization transformation to each variable of the sample, so that the mean value of the sample can be transformed to 0, and the variance after standardization is 1.
After the training set samples are standardized and input into the SVM with the four kernel functions, the accuracies, recalls, and false positives corresponding to the four kernel functions are obtained in Table 3.
Detection indexes corresponding to different kernel functions after standardization
It can be seen from Table 3 that the accuracies of the four SVM kernel functions have been greatly improved after standardization. The accuracy of polynomial kernel function has the highest increase, and the accuracy of radial basis kernel function with the best detection effect has increased from 0.8056 to 0.9444. Radial basis kernel function also has the highest recall and the lowest false positive. SVM classifies samples according to the sample distance. After standardization, samples can be assigned to a certain range to reduce misclassification caused by large numerical distance. The detection effect can also be clearly seen from the obtained detection indexes. Therefore, the standardization of sample features is an essential step in recognition.
(3) SVM parameter optimization
After standardized image features are input to SVM for training. SVM adopts the radial basis kernel function and grid search to optimize kernel parameter and penalty factor. The range of kernel parameter and penalty factor is set to [0.1, 100]. Due to the large amount of data, the penalty factor [0.1, 10] and the kernel parameter [0.1, 45] are intercepted here. The accuracies obtained from the experiments are shown in Fig. 17. For many groups of the penalty factor and the kernel parameter, the highest accuracy can be achieved. Since the smaller the penalty factor is, the stronger the generalization ability is, 1.0 is chosen as the minimum penalty factor. SVM detection model is the best with penalty factor 1.0 and kernel parameter 0.5.

Correspondence accuracies of SVM parameters.
The X-ray image detection method based on Hi color space segmentation proposed in this paper is applied to detect gun and knife X-ray images in this paper. Accuracy, recall and false positive rate are used to detect performance. The higher the accuracy and recall are and the lower the false positive is, the better the detection effect is. The detection results are shown in Table 4. The results demonstrated that the accuracy of gun detection is 0.9744, and the accuracy of knife detection is 1. The experimental results have good effect, which verifies the effectiveness of the detection method proposed in this paper. It can meet the requirements of actual safety inspection and has practical application value.
Detection evaluation indexes
Detection evaluation indexes
In this paper, the influence of eight color spaces on segmentation and their internal mechanisms are studied in detail. Mapping RGB to HSI and HSV color spaces can better improve the clustering results. Then, due to the pseudo-color characteristics of X-ray images, the Hi color space component is proposed, which can effectively improve the quality of clustering results. The corrosion and expansion methods of morphology are applied to remove adhesion. In addition, the Hi color space segmentation algorithm is proposed, which can efficiently solve the overlapping and adhesion problems for objects with complex backgrounds. Finally, an X-ray image detection method based on Hi color space segmentation is proposed. The experiment and evaluation are carried out on real X-ray images and satisfactory results are achieved. The X-ray image detection method based on the Hi color space segmentation can better solve the segmentation and detection problem and meet the requirements of actual security inspection.
Footnotes
Acknowledgments
This paper is supported by Qinhuangdao Science and Technology Research and Development Project (Grant No.202005A002).
