The pit on the bottom metal surface is one of the important indicators of cylindrical lithium battery surface defect detection. There are many complex factors in the detection of pit: non-uniform illumination of images, uneven reflection of the metal surface, low surface finishing, stains, rust and scratches. To solve these problems, a method for pit detection based on machine vision is proposed. Firstly, the grayscale distribution curve is extracted along the vertical direction of the bottom metal surface. Secondly, the grayscale difference model which is not sensitive to illumination distribution and noises is used to extract gray discontinuous points in a grayscale distribution curve. According to the reflective feature of the metal surface, the adaptive threshold of discontinuous points extraction is determined based on mean background subtraction. Finally, three feature parameters including gray value features and region features are used as the input of support vector machine (SVM) classifier to train and extract the pit region. The algorithm is evaluated on the self-built image database. The experimental results indicate the non-uniform illumination and uneven reflection have no effect on pit detection. Compared with the related well-established methods, our proposed algorithm can provide a better detection effect-the Recall, Precision and FNR are 0.982, 0.991 and 0.018 respectively.INDEX TERMS Machine vision, grayscale difference model, cylindrical lithium battery, defect detection, mean background subtraction.