摘要 |
A method and device for calculating a ridge distance. The method comprises: acquiring an original image and carrying out gray-scale processing to generate a gray-scale image (S1); generating a normal image and a tangential image according to the gray-scale image (S2); filtering the gray-scale image according to the tangential image to generate a smooth image, and converting the smooth image into a binary image (S3); partitioning the binary image, and determining a normal direction of a central point of each partition according to the normal image (S4); traversing pixels at the normal direction of the central point of each partition within each partition to calculate the number of times that pixel values of two adjacent pixels within each partition vary between a first pixel value and a second pixel value, and coordinates and a sub-pixel value of a corresponding boundary point at the variation, wherein the first pixel value is a pixel value of a pixel where a crest line is located and the second pixel value is a pixel value of a pixel where a valley line is located (S5); and generating a ridge distance according to the number of variation times, and the coordinates and the sub-pixel value of the corresponding boundary point at the variation (S6). According to the method, a boundary point of a crest line and a valley line is searched, and a ridge distance is calculated according to coordinates and a sub-pixel value of the boundary point, so that the accuracy is improved, the noise resisting ability is higher, and the application range is wider. |