During the pharmaceutical process, it is inevitable that various defects emerge in the medicine vials which may greatly affect the product quality and reduce the productive efficiency. To address these problems, a method based on feature extraction and machine learning is developed for vial defect inspection. On image preprocessing, we used threshold algorithm to acquire the region of interest (ROI) which is comprised of some small patches obtained through image blocking, exhibiting favorable performances compared to some existing image segmentation methods. In the following computational framework, the LBP descriptors are firstly extracted in the ROI followed by the generation of visual dictionaries through the application of k-means clustering. Since the visual dictionaries can essentially represent the image, we finally employ the support vector machine (SVM) classifier to inspect whether the vials are with flaws. In the procedure of feature extraction, experiments show that the LBP yields superior performances, with (maximum recognition efficiency is about 90%) compared to the others, owing to the extraction of exact texture features.