## 5 X-ray Image Key Target Tracking and Extraction
### X-ray Image Key Target Tracking  
(1) Target tracking algorithm  
The binarization method can extract the target in each frame picture. In order to find out the corresponding relationship between each target in the adjacent frame, it is necessary to use the target tracking algorithm to track the package box extracted based on the object as input. The steps are as follows:  
Step 1: The frame in which packages appear for the first time is taken as the initial frame. Each package \(B_{k}\) detected in this frame is assigned a unique number \(f(B_{k})\) and stored in the cache;  
Step 2: A new frame is detected. Each package \(B_{i}\) detected by a new frame with all the packages in the cache is compared, the most matched cache package \(B^{-1}_{j}\) is selected, they are considered to be the same package, \(f(B_{i})\ =\ f\big{(}B^{-1}_{j}\big{)}\) is set, and the cache of the package is updated;  
Figure 18: Binarization results of different methods: (**a**) Background difference binarization; (**b**) binarization of Sobel operator edge detection; (**c**) ES-MBD binarization. Step 3: If package \(B_{m}\) is detected in the new frame of Step 2 and does not match the cache, it is considered as a new package, and a new unique number \(f(B_{m})\) is assigned to it, and it is included in the cache; Step 4: If the cache package \(B^{-1}{}_{n}\) in Step 2 does not match the cache package of the new frame, the cache of the package is deleted. (2) The selection of loss function  
The function used to evaluate the degree of package matching is called the loss function used by the tracking algorithm. The overlapping degree of package boxes is used as the loss function to evaluate the degree of match, and the intersection ratio (IoU) and its variants are adopted. IoU is the most commonly used index in target detection, and its definition is shown in Formula (10):  
\[\text{IoU}\ =\ \frac{|A\cap B|}{|A\cup B|}. \tag{10}\]  
Figure 19: Example diagram of [PERSON]’s algorithm: The circled pixel points in (**a**–**e**) correspond to the border descriptions for each link on the right. IoU can reflect the overlap degree of two targets, and it has scaled invariance. However, there are some disadvantages of IoU. If two objects do not intersect, according to definition, IoU = 0. Then, IoU cannot accurately reflect the degree of overlap. As shown in Figure 20, IoUs are equal in all three cases, but the degree of coincidence is not the same. The graph on the right has the best regression and the graph on the left has the worst regression. GIoU's thought is put forward by [PERSON] et al. in CVPR2019 Rezatofighi (2019). Its definition is shown in Formula (11):  
\[\text{GIoU = IoU}-\frac{|\text{A}_{\text{c}}-\text{U}|}{|\text{A}_{\text{c}}|}. \tag{11}\]  
First, the minimum closure area of the two boxes is calculated to determine the IoU; then, the proportion of the closure area that does not belong to the two boxes to the closure area is computed, and finally this proportion is subtracted from IoU to obtain GIoU. Like IoU, GIoU is a distance measure, and it is insensitive to scale. At the same time, GIoU is the lower bound of IoU; in the case that the two boxes coincide infinitely, IoU = GIoU. On the other hand, IoU takes the value of [0, 1], but GIoU has a symmetric interval, taking the value range of [-1, 1]. The maximum value 1 is taken when the two coincide, and the minimum value \(-1\) is taken when they have no intersection and are infinitely far away, so GIoU is a very good distance measure. Different from IoU, which only focuses on the overlap area, GIoU focuses on not only the overlap area, but also other non-overlap areas, which can better reflect the overlap degree of the two. In order to make the target frame regression more stable, for the scene of target frame regression, the distance, overlap rate and scale between the target and anchor are taken into account to obtain DIoU (2019), which does not have the divergence problem in the training process like IoU and GIoU.