In the edge detection algorithm, being able to accurately detect the edge of the target object is the premise of extracting the target object. For the scratch detection of high-speed train axles, accurate edge detection can improve the basis for subsequent 3D reconstruction and size measurement of scratches. In this paper, an edge detection template based on gray correlation is designed for the axles of high-speed trains, which can accurately locate the edges of scratches; for scratches at different angles, filters in different directions are added. By comparing the filtering results of different rotation angles, the angle with the best result is selected as the rotation angle of the pixel. This method not only has excellent edge positioning performance, but also can eliminate most of the noise in the image and improve the effect of edge extraction.