Abstract:Objective To address problems in X-ray-based foreign object detection in packaged foods, including low accuracy caused by the high proportion of low-frequency features in images and small grayscale differences between foreign objects and the background, as well as the loss of micro foreign object features, an improved intelligent detection scheme is proposed to overcome the inability of traditional detection methods to meet the real-time and reliability requirements of automated production lines.Methods Based on the intelligent detection system for foreign objects in packaged foods, this study proposes an intelligent detection method for foreign objects in packaged foods integrating an improved YOLOv13 model and X-ray. The core feature extraction module, DC-A2C2F, is redesigned to precisely focus on regions with sharp gray-level variations along foreign object boundaries, thus enhancing the discriminability between foreign object features and the background. A multi-order feature aggregation module (MFAM) is introduced into the backbone network to mitigate the dilution of micro foreign object features and retain critical detail information. A dual-path fusion pyramid network (DFPN) is designed to optimize the neck structure, achieving balanced matching between semantic and detailed information to accommodate the detection requirements of foreign objects of different sizes.Results The proposed method achieves a mean average precision of over 98.50% for multiple types of foreign objects, including metal, glass, and plastic. Compared with the YOLOv13 model, the proposed method reduces the missed detection rate from 2.2% to 0.4% while maintaining an inference speed of over 50 frames per second.Conclusion The improved YOLOv13 model accurately adapts to the feature characteristics of X-ray images. The proposed detection method combines high detection accuracy, a low missed detection rate, and real-time performance, fully meeting the real-time detection requirements of automated production lines.