In industrial microscopic detection, learning-based autofocus methods have empowered operators to acquire high-quality images quickly. Learning-based methods consist of two parts: network model and prior dataset. The network model, which approximates the relationship between input and output, exists fitting error. The prior dataset is made by sharpness metric and used for model training, while the limitations of the metric itself will affect the accuracy of the dataset. Both the model and dataset are prone to errors, thereby limiting the potential for further improvements in focusing accuracy. In this paper, a high-precision autofocus pipeline was introduced, which predicts the defocus distance from a single natural image. A new method for making datasets was proposed, which overcomes the limitations of the sharpness metric itself and improves the overall accuracy of the dataset. Furthermore, a lightweight regression network was built, namely Natural-image Defocus Prediction Model (NDPM), to improve the focusing accuracy. A realistic dataset of sufficient size was made to train all models. The experiment shows NDPM has better focusing performance compared with other models, with a mean focusing error of 0.422μm.
The dataset contains a total of 240 focal stacks, each focal stack corresponds to a folder. In each focal stack, 161 images from near-focus to far-focus are collected continuously with a step size of 0.5um.The 81st image is the in-focus image obtained by the split-image method, that is, the defocus distance is 0um. According to the given step size, the theoretical defocus distance of each image can be calculated.