## 5 X-ray Image Key Target Tracking and Extraction
### Extraction of Key Targets in X-ray Images  
The detection and tracking algorithm can accurately locate the location of each package in each frame image. To intercept each package completely and without repeating, it is necessary to extract the key target of the video [37; 38; 39]. That is, in the process of a package from entering the picture to leaving the picture, a frame is selected in which the package is completely displayed as the key target of the package, and the package area of the frame is cut out as the image of the package. Since the X-ray machine usually moves the package in a fixed direction, assuming that the package moves from right to left, the extraction method is as described below.  
A trigger line is set at a distance to the right of the image. For any package B and frame \(F_{k}\) containing package B, \(Flag\big{(}F_{k}^{\ B}\big{)}\) represents the position relationship between the right edge of the package frame and the trigger line. \(Flag\big{(}F_{k}^{\ B}\big{)}\ =\ 0\) is when the right edge of the package frame is on the right side of the trigger line; otherwise, \(Flag\big{(}F_{k}^{\ B}\big{)}\ =\ 1\).  
We let \(F_{0},F_{1},\dots,F_{n}\) be all the video frames of a package appearing in the picture, and sort them in chronological order, that is, the next frame of \(F_{i}\) is \(F_{i+1}\).  
Since the package enters from the right at the beginning, before the package passes through the trigger line, as shown in Figure 21a, the right boundary of the package frame must be on the right side of the trigger line at the beginning, and obviously there is \(0<i<n\) that makes  
\[Flag\big{(}F_{k}^{\ B}\big{)}\ =\ 0,\ \ k<i. \tag{15}\]  
As the package moves to the left, as shown in Figure 21b, after the package passes through the trigger line, there must be \(i<j<n\) that makes  
\[Flag\big{(}F_{k}^{\ B}\big{)}\ =\ 0,\ \ k<j, \tag{16}\]  
\[Flag\Big{(}F_{j}^{\ B}\Big{)}\ =\ 1, \tag{17}\]  
where \(F_{j}\) is the frame that passes through the trigger line for the first time on the right side of the package frame, and \(F_{j}\) is the key frame of the package used to obtain the complete image of the package.  
X-ray package detection tracks the extraction process, as shown in Figure 22.  
Step 1: The ES-MBD method is used to process the input video frame, calculate its multi-channel background difference, and use the Sobel operator to process the gray image. The two are binarized and denoised respectively, and then merged. The combined results are expanded by morphology to obtain the binarized image.  
Step 2: The Suzuki algorithm is used to detect the contour of the binary image. The outer boundary whose parent boundary is the frame in the result is selected as the detected package box area.  
Step 3: The package box region obtained in Step 2 is matched with the package in the cache, and the cache is updated. At the same time, the key frame judgment is carried out for the successfully matched package.  
Step 4: If there is a package with successful key frame judgment in Step 3, the package box area is intercepted as the image output of the package.  
Figure 21: (**a**) Before the package crosses the red trigger line; (**b**) after the package crosses the red trigger line.