A processor receives an image of a syringe. After identifying a background and foreground of the image, where the foreground indicates pixels that may be associated with a defect, the processor subtracts the background to generate an updated image with an accentuated foreground. The processor applies a bounding box to a group of pixels in the foreground and inputs the bounding box into a classifier. The classifier outputs a label indicating whether the syringe is defective.