Autofocus method, apparatus and computer device
By collecting and analyzing the blur and sharpness features of reference images in a microscope, and combining them with a machine learning model to quickly locate the focal plane, the problem of low focusing efficiency and high computational load in microscope autofocus technology is solved, achieving a highly efficient and accurate focusing process.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- NINGBO SUNNY INSTR
- Filing Date
- 2025-12-22
- Publication Date
- 2026-05-12
AI Technical Summary
Existing microscope autofocus technology suffers from low focusing efficiency and high computational load, making it difficult to meet the needs of high-speed scanning and real-time detection.
By controlling the movement of the microscope objective lens, reference images are acquired at different objective lens positions. The position of the target focal plane is determined using blur and sharpness features. Combined with a machine learning model, the focal plane is quickly located, reducing the amount of image acquisition and computational burden.
While maintaining focusing accuracy, it significantly improves focusing efficiency and reduces computational load, making it suitable for high-speed scanning and real-time detection scenarios.
Smart Images

Figure CN121364556B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of microscope technology, and in particular to an autofocusing method, apparatus, and computer device. Background Technology
[0002] In the field of microscopic observation, autofocus technology is crucial for ensuring image quality and observation efficiency. With the improvement of image sensor performance, higher demands are being placed on the speed and accuracy of autofocus technology.
[0003] Traditional autofocus uses the depth-of-focus method, which requires the acquisition of a large amount of image data in different focus states. This results in a huge number of images being acquired. Although it can ensure accuracy to a certain extent, the large amount of data processing and the long focusing time make it difficult to meet the needs of high-speed scanning, real-time detection and other scenarios.
[0004] It is evident that existing technologies in the field of microscope autofocus still suffer from low focusing efficiency and high computational load. Summary of the Invention
[0005] Therefore, it is necessary to provide an automatic focusing method, apparatus, and computer device that can improve focusing efficiency and reduce computational load while ensuring focusing accuracy, in order to address the aforementioned technical problems.
[0006] In a first aspect, this application provides an autofocusing method for use in a microscope, the autofocusing method comprising:
[0007] In response to the autofocus command, the objective lens is moved according to the first step value corresponding to the imaging parameters of the microscope, and at least two first reference images with different objective lens positions are acquired.
[0008] The position of the first objective lens is determined based on the objective lens position and blur characteristics corresponding to the first reference image;
[0009] The objective lens is moved according to the first objective lens position and a preset second step value, and at least two second reference images with different objective lens positions are acquired.
[0010] Based on the objective lens position and sharpness characteristics corresponding to the second reference image, the target focal plane position is determined and focusing is completed.
[0011] In one embodiment, the imaging parameters include depth-of-field parameters; the first reference image includes a first current reference image and a first step reference image; the step of controlling the objective lens movement according to the first step value corresponding to the imaging parameters of the microscope in response to an autofocus command, and acquiring at least two first reference images at different objective lens positions, includes:
[0012] Acquire the first current reference image at the current objective lens position;
[0013] Based on the first step value corresponding to the depth of field parameter, the objective lens is controlled to move at least once to acquire at least one first step reference image.
[0014] In one embodiment, determining the position of the first objective lens based on the objective lens position and blur characteristics corresponding to the first reference image includes:
[0015] According to the preset blur algorithm, the blur features of each of the first reference images are calculated;
[0016] The ratio of the blur features of every two first reference images and the difference in the corresponding objective lens positions are calculated sequentially to obtain the relative blur change features of the first reference images.
[0017] The position of the first objective lens is determined based on the relative change characteristics of the blurriness.
[0018] In one embodiment, determining the position of the first objective lens based on the relative change in blurriness includes:
[0019] The relative blurring change features are input into a pre-trained objective lens position prediction model to obtain the first objective lens position.
[0020] In one embodiment, the training process of the objective lens position prediction model includes:
[0021] Within the movable range of the objective lens of the microscope, the objective lens is moved according to a preset step interval to obtain sample images of the target sample at each objective lens position;
[0022] The blurring features of each sample image are calculated according to a preset blurring algorithm.
[0023] The ratio of the blur features of every two sample images and the difference in objective lens position are calculated sequentially to obtain the relative change features of blur. The subtrahend or minuend corresponding to the difference in objective lens position is taken as the true objective lens position of the relative change features of blur.
[0024] Based on the multiple relative blurring characteristics and the actual objective lens position, a preset machine learning model is trained to obtain the objective lens position prediction model.
[0025] In one embodiment, calculating the blur characteristics of each image according to a preset blur algorithm includes:
[0026] Image features are extracted from the image according to a preset gradient operator to obtain gradient information; the gradient information includes horizontal gradient and vertical gradient.
[0027] The sum of the absolute values of the horizontal gradient and the vertical gradient is used as the blur feature of the image.
[0028] In one embodiment, controlling the objective lens movement based on the first objective lens position and a preset second step value to acquire at least two second reference images with different objective lens positions includes:
[0029] The objective lens is moved to the target position according to the first objective lens position and the second step value to obtain at least two images with different objective lens positions; the target position includes at least two of the following: the first objective lens position, the difference between the first objective lens position and the second step value, and the sum of the first objective lens position and the second step value.
[0030] In one embodiment, determining the target focal plane position and completing focusing based on the objective lens position and sharpness features corresponding to the second reference image includes:
[0031] Based on the preset sharpness algorithm, the sharpness features of each second reference image are calculated respectively;
[0032] Based on the sharpness characteristics of each second reference image, target reference images are selected, and the objective lens position corresponding to the target reference image is taken as the target focal plane position;
[0033] Control the objective lens to move to the target focal plane position.
[0034] Secondly, this application provides an autofocusing device for use in a microscope, the autofocusing device comprising:
[0035] The first moving module is used to respond to the autofocus command and control the objective lens to move according to the first step value corresponding to the imaging parameters of the microscope, so as to acquire at least two first reference images with different objective lens positions.
[0036] The position analysis module is used to determine the position of the first objective lens based on the objective lens position and blur characteristics corresponding to the first reference image;
[0037] The second moving module is used to control the movement of the objective lens according to the position of the first objective lens and a preset second step value, and to acquire at least two second reference images with different objective lens positions.
[0038] The focal plane analysis module is used to determine the target focal plane position and complete focusing based on the objective lens position and sharpness characteristics corresponding to the second reference image.
[0039] Thirdly, this application provides a computer device including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the method described above.
[0040] The aforementioned autofocus method, apparatus, and computer equipment, in response to an autofocus command, control the movement of the objective lens according to the first step value corresponding to the microscope's imaging parameters, acquire at least two first reference images at different objective lens positions, determine the first objective lens position based on the objective lens position and blur characteristics corresponding to the first reference images, control the objective lens movement based on the first objective lens position and a preset second step value, acquire at least two second reference images at different objective lens positions, determine the target focal plane position and complete focusing based on the objective lens position and sharpness characteristics corresponding to the second reference images, determine the first reference image acquisition by using imaging parameters, making the coarse adjustment process more compatible with the microscope, thereby calculating blur characteristics to drive the rapid determination of the first objective lens position, acquiring sharpness characteristics through the second step value, and finally locking the target focal plane position. This significantly reduces the amount of image acquisition and computational burden while maintaining focusing accuracy, achieving the technical effect of improving focusing efficiency and reducing computational load while ensuring focusing accuracy. Attached Figure Description
[0041] Figure 1 This is a diagram illustrating the application environment of an autofocus method in one embodiment.
[0042] Figure 2 This is a flowchart illustrating an autofocus method in one embodiment;
[0043] Figure 3 This is a flowchart illustrating the autofocus method in another embodiment;
[0044] Figure 4 This is a flowchart illustrating the autofocus method in another embodiment;
[0045] Figure 5 This is a structural block diagram of an autofocus device in one embodiment;
[0046] Figure 6 This is an internal structural diagram of a computer device in one embodiment. Detailed Implementation
[0047] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0048] The autofocus method provided in this application embodiment can be applied to, for example... Figure 1In the application environment shown, terminal 102 communicates with image acquisition device 106 mounted on microscope 104 via a wired network. Responding to an autofocus command, terminal 102 controls the objective lens movement according to a first step value corresponding to the microscope's imaging parameters, and acquires at least two first reference images at different objective lens positions via image acquisition device 106. Based on the objective lens position and blur characteristics corresponding to the first reference images, the first objective lens position is determined. Based on the first objective lens position and a preset second step value, the objective lens movement is controlled to acquire at least two second reference images at different objective lens positions. Based on the objective lens position and sharpness characteristics corresponding to the second reference images, the target focal plane position is determined and focusing is completed. Terminal 102 can be, but is not limited to, various personal computers, laptops, smartphones, and tablets.
[0049] In one embodiment, such as Figure 2 As shown, an autofocus method is provided, which is applied to... Figure 1 Taking terminal 102 as an example, the explanation includes the following steps:
[0050] In step S100, in response to the autofocus command, the objective lens is moved according to the first step value corresponding to the imaging parameters of the microscope, and at least two first reference images with different objective lens positions are acquired.
[0051] Among them, the autofocus command can be a control signal that triggers the autofocus process. Furthermore, the autofocus command can be used to start the microscope autofocus process, so that the system switches from the standby state to the focus calculation and execution mode.
[0052] Imaging parameters can be a set of optical and electronic parameters that affect the quality of microscope image acquisition, and can be used to determine the resolution and contrast characteristics of image acquisition. For example, imaging parameters may include, but are not limited to, one or more of the following: depth of field, magnification, light source wavelength, and sensor resolution.
[0053] The first step value can be the unit of measurement for the objective lens's movement along the optical axis during the coarse focusing stage. The first step value can be used to achieve rapid scanning of a large focal plane area, reducing the number of image acquisitions. The first step value can include, but is not limited to, a step ratio based on magnification, a step interval based on depth-of-field estimation, or a compensation step size based on system response delay. Correspondingly, the first reference image can be a set of images acquired at different objective lens positions during the coarse focusing stage. For example, the first reference image can be used to provide low-density sampling data over a large focal plane area for preliminary assessment of blur trends.
[0054] Furthermore, controlling the objective lens movement based on the first step value corresponding to the microscope's imaging parameters can be achieved by receiving an autofocus command, calculating or calling a preset first step value based on the imaging parameters, and driving a stepper motor to adjust the objective lens position along the optical axis. In an exemplary embodiment, a standard first step value can be obtained by looking up a table based on the mapping relationship between depth of field, objective lens numerical aperture, and the first step value, and then driving the actuator. This allows for the establishment of a coarse initial motion reference, ensuring that the objective lens moves at preset intervals.
[0055] Step S200: Determine the position of the first objective lens based on the objective lens position and blur characteristics corresponding to the first reference image.
[0056] The blurriness feature can be a quantitative indicator reflecting the degree of image detail loss. It can be used to quickly assess the blurriness trend of an image under large step conditions, thereby achieving coarse localization with low computational overhead. For example, depending on the calculation method, the blurriness feature can be any one or more of the following: the sum of gradient magnitudes, the low-frequency energy ratio in the frequency domain, and the mean of local variance.
[0057] The position of the first objective lens can be a rough focal plane coordinate calculated based on the first reference image and blur characteristics. Correspondingly, the position of the first objective lens is determined according to the objective lens position and blur characteristics corresponding to the first reference image. This can be achieved by calculating the blur characteristics for each first reference image, constructing a curve showing how blur changes with the objective lens position, and then determining the location of the extreme point through fitting. In an exemplary embodiment, determining the position of the first objective lens based on the objective lens position and blur characteristics corresponding to the first reference image can be done by using cubic spline interpolation to fit the blur curve and finding the maximum point as the position of the first objective lens. This allows for rapid coarse localization of a large focal plane, significantly reducing the subsequent search space and computational resource consumption.
[0058] In step S300, the objective lens is moved according to the position of the first objective lens and the preset second step value, and at least two second reference images with different objective lens positions are acquired.
[0059] The second step value can be the step size unit in which the objective lens moves along the optical axis during the fine focusing stage.
[0060] The second reference image can be a set of images acquired at different objective lens positions during the fine focusing stage, used to provide high-density sampling data near the target focal plane to achieve accurate sharpness distribution assessment.
[0061] In this embodiment, the objective lens can be driven forward or backward according to a preset second step value, based on the position of the first objective lens, to form a local search range. Furthermore, by controlling the movement of the objective lens according to the position of the first objective lens and the preset second step value, one or more step points can be selected on one or both sides of the position of the first objective lens to limit the fine search range to the vicinity of the coarse focal plane and avoid repeated sampling of invalid areas.
[0062] Step S400: Determine the target focal plane position and complete focusing based on the objective lens position and sharpness characteristics corresponding to the second reference image.
[0063] Sharpness features can be quantitative indicators reflecting the richness of image details, thereby accurately evaluating image quality under small step conditions and supporting high-precision focal plane positioning. For example, sharpness features can be calculated using methods including, but not limited to, Laplacian variance, Tenengrad gradient energy, and Brenner gradient.
[0064] The target focal plane position can be the optimal imaging focal plane coordinates determined after a fine search. The target focal plane position can be used as the final focusing output, controlling the objective lens to remain at the best imaging position. The target focal plane position can include, but is not limited to, the position corresponding to the maximum sharpness, the zero gradient point, and the peak variance.
[0065] Based on the objective lens position and sharpness features corresponding to the second reference image, one can calculate the sharpness features for each second reference image, construct a curve of sharpness changing with the objective lens position, locate the peak point and control the objective lens to move to that position, or one can find the objective lens position with the highest sharpness among multiple sharpness features as the target focal plane.
[0066] This embodiment provides an autofocus method that, in response to an autofocus command, controls the movement of the objective lens according to a first step value corresponding to the microscope's imaging parameters, acquiring at least two first reference images at different objective lens positions. Based on the objective lens position and blur characteristics corresponding to the first reference images, the first objective lens position is determined. Then, based on the first objective lens position and a preset second step value, the objective lens movement is controlled, acquiring at least two second reference images at different objective lens positions. Finally, based on the objective lens position and sharpness characteristics corresponding to the second reference images, the target focal plane position is determined and focusing is completed. The first step value, determined by imaging parameters, guides the acquisition of the first reference images, making the coarse adjustment process more compatible with the microscope. This allows for the rapid determination of the first objective lens position by calculating blur characteristics. The second step value is used to acquire and obtain sharpness characteristics, ultimately locking the target focal plane position. This significantly reduces image acquisition and computational burden while maintaining focusing accuracy, achieving the technical effect of improving focusing efficiency and reducing computational load while ensuring focusing accuracy.
[0067] In one embodiment, the imaging parameters include depth-of-field parameters; the first reference image includes a first current reference image and a first step reference image; in response to an autofocus command, the objective lens is moved according to the first step value corresponding to the microscope's imaging parameters, and at least two first reference images at different objective lens positions are acquired, including:
[0068] Acquire the first current reference image at the current objective lens position;
[0069] Based on the first step value corresponding to the depth of field parameter, control the objective lens to move at least once and acquire at least one first step reference image.
[0070] The depth-of-field parameter can be the range of axial object distance variation allowed by the objective lens in a microscope while maintaining acceptable image sharpness. This ensures that the step spacing matches the resolution characteristics of the optical system and avoids exceeding the necessary sampling density. For example, the depth-of-field parameter can be calculated from the numerical aperture and working wavelength of the objective lens using optical formulas, or it can be obtained by calling pre-stored objective lens calibration data in the system.
[0071] The first current reference image can be a reference image acquired when the objective lens is at its current preset position at the start of the autofocus process, and can be used to provide a sharpness reference for the focus starting point. In an exemplary embodiment, the first current reference image can be acquired immediately after responding to the autofocus command by triggering the imaging sensor to acquire an image of the current objective lens position without any displacement, thereby establishing a physical starting reference for the focusing process, avoiding searching from a random position, and improving the reliability of trend judgment.
[0072] The first step reference image can be an auxiliary image acquired after moving the objective lens based on the step value calculated according to the depth parameters based on the first current reference image. It can be used to provide a small number of physically meaningful comparison samples to quickly determine the blur change trend and support the preliminary inference of the position of the first objective lens. In this embodiment, the first step reference image can be obtained by moving along the optical axis once or multiple times after acquiring the first current reference image and acquiring the corresponding image. Furthermore, one or more first step reference images can be acquired by moving once along the expected blur decrease direction, or two or more first step reference images can be acquired by moving once in each of the positive and negative directions to construct the blur change gradient. This allows for minimum necessary sampling under physical optical constraints, compressing the number of images acquired in the coarse search stage to one to three, significantly reducing the data volume and computational load.
[0073] This embodiment provides an autofocus method that acquires a first current reference image at the current objective lens position and controls the objective lens to move at least once based on the first step value corresponding to the depth of field parameter to acquire at least one first step reference image. This establishes a sharpness benchmark for the focusing starting point and provides the minimum necessary sampling under physical optical constraints. It transforms the traditional blind search that relies on fixed steps or statistical models into directional sampling based on the inherent characteristics of the optical system. As a result, the number of images acquired in the coarse focusing stage is reduced from five to ten in the traditional method to two to three, significantly reducing the computational burden. This achieves the technical effect of improving focusing efficiency and reducing computational load while ensuring focusing accuracy.
[0074] In one embodiment, determining the position of the first objective lens based on the objective lens position and blur characteristics corresponding to the first reference image includes:
[0075] Based on the preset blur algorithm, the blur features of each first reference image are calculated;
[0076] The ratio of the blur characteristics of each pair of first reference images and the difference in the corresponding objective lens positions are calculated sequentially to obtain the relative blur change characteristics of the first reference image.
[0077] The position of the first objective lens is determined based on the relative change characteristics of the blur.
[0078] The preset ambiguity algorithm can be a set of mathematical calculation rules for quantifying the degree of image blur, providing a reproducible and comparable ambiguity value output for the first reference image. For example, the preset ambiguity algorithm can employ any one or more of the following ambiguity algorithms, including but not limited to Laplacian variance, Tenengrad gradient energy, and Brenner gradient. For instance, ambiguity features can be obtained by calculating the variance after performing Laplacian convolution on a local region of the image, or by summing and normalizing the squared gradient magnitudes of the image, or by using other ambiguity feature calculations implemented using existing ambiguity algorithms to generate a ambiguity sequence of discrete sampling points. This embodiment does not limit this approach.
[0079] The ratio of ambiguity features can be the quotient between the ambiguity features of two adjacent first reference images, which can reflect the relative change of ambiguity features. It can be understood that the relative value can effectively eliminate the influence of system gain, illumination intensity drift, etc. on the absolute ambiguity value, thereby improving the stability of the trend judgment.
[0080] The ratio of blur features between every two first reference images is calculated sequentially. This can be achieved by dividing the blur feature values of two adjacent first reference images to obtain a ratio index, or by calculating the ratio of blur features between any two first reference images through permutations and combinations, which can include forward blur feature ratios and backward blur feature ratios. Furthermore, the relative change characteristic of blur is obtained by calculating the logarithm of this ratio, which enhances linear response, eliminates interference from system gain and illumination fluctuations on the absolute value of blur, and makes the stability and comparability of the change trend higher.
[0081] The difference in objective lens position can be the spatial displacement of the objective lens along the optical axis when the two first reference images are acquired. This can be used to provide the physical spatial scale corresponding to the blurring change, to normalize the blurring ratio, and to construct relative change features. In some embodiments, the difference in objective lens position between each pair of first reference images can be calculated by multiplying a fixed step value by the image sequence difference, or by reading the actual position and calculating the difference using a stepper motor encoder.
[0082] The relative ambiguity change feature can be an indicator reflecting the relative rate of change of ambiguity between adjacent first reference images. It can be used to enhance the robustness of focus plane positioning to illumination fluctuations, sample inhomogeneity, and sensor noise, and avoid misjudgment based on absolute value thresholds. In an exemplary embodiment, the relative ambiguity change feature can be calculated by dividing the ratio of the ambiguity features of the image pair by the difference in the corresponding objective lens positions, to characterize the slope of the local change of ambiguity with spatial displacement, constructing a local change index robust to noise and system drift, which has higher coarse positioning reliability compared to the traditional absolute ambiguity curve.
[0083] The position of the first objective lens can be determined based on the relative change characteristics of ambiguity. This can be based on prior knowledge or by querying a mapping table, mathematical model, neural network, etc., which allows the coarse focal plane to be determined based on local derivative features rather than global fitting, avoiding model generalization bias and improving positioning stability and computational efficiency.
[0084] This embodiment provides an autofocus method that calculates the blur characteristics of each first reference image according to a preset blur algorithm. It then calculates the ratio of the blur characteristics of every two first reference images and the difference between their corresponding objective lens positions to obtain the relative blur change characteristics. The position of the first objective lens is determined based on these relative blur change characteristics. By calculating the blur characteristics of each first reference image to determine the relative blur change characteristics, the interference of system gain and illumination fluctuations on the absolute value of blur can be eliminated, making the change trend more stable and comparable. This transforms the coarse positioning mechanism from a single model prediction relying on absolute blur values to differential detection based on the relative change rate between image pairs, accurately locating the position of the first objective lens. This avoids the reliance on absolute threshold calculations in traditional methods and ensures consistent coarse positioning results even when conditions such as sample reflectance, background brightness, and imaging noise change. This achieves the technical effect of improving focusing efficiency and reducing computational load while ensuring focusing accuracy.
[0085] In one embodiment, determining the position of the first objective lens based on the relative change characteristics of ambiguity includes:
[0086] The relative change features of blurriness are input into a pre-trained objective lens position prediction model to obtain the position of the first objective lens.
[0087] The pre-trained objective lens position prediction model can be a mapping function trained through supervised or unsupervised learning, used to map the relative blurring change features to the predicted value of the first objective lens position. In an exemplary embodiment, the pre-trained objective lens position prediction model can be trained using a large labeled dataset, with multiple sets of relative blurring change feature vectors as input and the corresponding real objective lens position labels as output. Exemplarily, the model structure can employ linear regression, support vector machines, lightweight neural networks, multilayer perceptrons, etc.
[0088] By inputting the relative change features of blur into a pre-trained objective lens position prediction model, the position of the first objective lens is obtained. By using the relative change features of blur as a robust input and combining it with a data-driven prediction model to achieve nonlinear mapping, the coarse positioning accuracy is effectively improved and the subsequent search range is reduced. Thus, while preserving the anti-interference ability of features, the amount of image acquisition and computational burden are reduced, achieving the technical effect of improving focusing efficiency and computational efficiency.
[0089] In one embodiment, the training process of the objective lens position prediction model includes:
[0090] Within the movable range of the microscope objective lens, the objective lens is moved according to a preset step interval to obtain sample images of the target sample at each objective lens position;
[0091] Based on the preset fuzziness algorithm, calculate the fuzziness features of each sample image;
[0092] The ratio of blur features of every two sample images and the difference in objective position are calculated sequentially to obtain the relative change features of blur. The subtrahend or minuend corresponding to the difference in objective position is taken as the true objective position of the relative change features of blur.
[0093] Based on multiple relative blurring characteristics and the actual objective lens position, a preset machine learning model is trained to obtain an objective lens position prediction model.
[0094] The target sample can be a representative biological or industrial sample used to train the objective lens position prediction model. For example, the target sample can be a single or multiple samples such as fluorescently labeled tissue sections, unstained cell suspensions, and metal-coated microstructures.
[0095] The sample images can be imaging data acquired at each preset position within the movable range of the objective lens, used for training, to calculate blur features and construct supervisory labels. The preset step interval can be a fixed step size unit for the objective lens to move along the optical axis during the model training phase. It can be used to ensure that the training data covers dense sampling of the focal plane area, providing spatial resolution support for establishing accurate mapping relationships. For example, the preset step interval can be the minimum step determined according to the optical diffraction limit, an equivalent step determined based on the sensor pixel size, or a uniform step determined based on the depth of field; this embodiment does not limit this.
[0096] Within the movable range of the microscope objective, the objective is moved according to a preset step interval to obtain a sample image of the target sample at each objective position. This can be achieved by moving the objective point by point within its entire movable range according to a preset step interval, and triggering the imaging sensor to acquire an image at each position.
[0097] The calculation of blur features for each sample image, the ratio of blur features, and the difference in objective lens position can be performed by referring to the calculation methods in any of the above embodiments, and will not be repeated here.
[0098] The true objective lens position can be used to label the true focal plane coordinates corresponding to the relative change features of blur, and can be used to provide accurate training targets for machine learning models and establish a mapping relationship between the relative change features of blur and the focal plane position.
[0099] The pre-defined machine learning model can be an algorithmic framework used to learn the mapping relationship between relative blur changes and the true objective lens position. Examples include, but are not limited to, one or more of support vector regression, random forest regression, and multilayer perceptron models. The objective lens position prediction model can be a deployable model instance trained for online prediction of the first objective lens position. It can be used to receive a small amount of relative blur changes in the actual focusing process and quickly output coarse positioning results, replacing traditional fitting methods.
[0100] This embodiment provides an autofocus method that, within the movable range of a microscope objective lens, controls the objective lens movement according to a preset step interval to obtain sample images of the target sample at each objective lens position. Based on a preset blurring algorithm, the blurring features of each sample image are calculated. The ratio of the blurring features between any two sample images, along with the objective lens position difference, is calculated to obtain the relative blurring change features. The subtrahend or minuend corresponding to the objective lens position difference is used as the true objective lens position for the relative blurring change features. Based on multiple relative blurring change features and the true objective lens position, a preset machine learning model is trained to obtain an objective lens position prediction model. This model is then used to construct a fully covered... A high-density sample image set of the focal plane region generates a sequence of blurry feature values for discrete sampling points, providing high-quality input features for machine learning. By assigning precise physical location labels to each relative change feature of blurriness, the input-output pairing data required for end-to-end supervised training is constructed, generating a deployable predictive model. This enables an efficient nonlinear mapping from low-dimensional relative change features to focal plane position. Compared to traditional fitting methods, this transfers the computationally expensive modeling process to the offline stage, significantly reducing the amount of real-time image acquisition and processing burden. While ensuring focusing accuracy, it simultaneously achieves the dual goals of improving focusing efficiency and reducing computational load.
[0101] In one embodiment, calculating the blur characteristics of each image according to a preset blur algorithm includes:
[0102] Image features are extracted from the image based on a preset gradient operator to obtain gradient information, which includes horizontal and vertical gradients.
[0103] The sum of the absolute values of the horizontal and vertical gradients is used as the blur feature of the image.
[0104] The preset gradient operator can be a fixed convolution kernel template used to extract local gradient responses in an image. It can be used to efficiently extract horizontal and vertical variation information of edges and texture structures in an image, serving as the basis for calculating fuzziness features. For example, the preset gradient operator can be a standard difference operator, such as the Sobel operator, Prewitt operator, or Scharr operator, which performs convolution operations with local regions of the image through a sliding window.
[0105] The horizontal gradient can be the rate of change of pixel intensity in an image along the horizontal direction, reflecting the intensity distribution of horizontal edges in the image. Furthermore, the horizontal gradient can be obtained by performing a convolution operation on the image using a predefined gradient operator with a convolution kernel in the horizontal direction, resulting in a gradient response matrix. Similarly, the vertical gradient can be the rate of change of pixel intensity in an image along the vertical direction, reflecting the intensity distribution of vertical edges in the image. Furthermore, the vertical gradient can be obtained by performing a convolution operation on the image using a predefined gradient operator with a convolution kernel in the vertical direction, resulting in a gradient response matrix.
[0106] The sum of the absolute values of the horizontal and vertical gradients can be used as a lightweight blur metric. For example, its value can decrease as the image blur increases, thus quickly assessing the focal plane state.
[0107] This embodiment provides an autofocus method that extracts image features from an image using a preset gradient operator to obtain gradient information. The sum of the absolute values of the horizontal and vertical gradients is used as the blur feature of the image. By extracting the horizontal and vertical gradient components using the gradient operator and using the sum of their absolute values as the blur feature, a low-complexity and high-efficiency image sharpness evaluation mechanism can be constructed. This significantly reduces the processing time and computational power requirements for a single image. Furthermore, the gradient operator is sensitive to edge structures and is strongly correlated with the sharpness of the focal plane. The sum of absolute values retains directional information and is more robust than single-channel gradients. Thus, while maintaining positioning accuracy comparable to traditional methods, the computational burden of each image is effectively reduced.
[0108] In one embodiment, controlling the objective lens movement based on the first objective lens position and a preset second step value, and acquiring at least two second reference images with different objective lens positions includes:
[0109] The objective lens is moved to the target position based on the first objective lens position and the second step value, and at least two images with different objective lens positions are obtained; the target position includes at least two of the following: the first objective lens position, the difference between the first objective lens position and the second step value, and the sum of the first objective lens position and the second step value.
[0110] The first objective lens position can be a coarse focal plane coordinate calculated based on the first reference image and blur features. This coordinate can be used as a starting reference point for fine-grained searching to limit the spatial range of subsequent high-precision searches. Furthermore, the position of the first objective lens is determined by fitting the curve of the blur features of the first reference image as a function of the objective lens position, thus identifying the location of the blur extremum point.
[0111] The objective lens is moved to the target position based on the first objective lens position and the second step value to obtain at least two images at different objective lens positions. This can be achieved by using the first objective lens position as a reference, calculating the second step value, moving the objective lens to the specified target position, and then triggering image acquisition. Furthermore, this can be achieved by acquiring images at two or three discrete points: the first objective lens position, the first objective lens position minus the second step value, and the first objective lens position plus the second step value. This minimizes the number of images acquired while maintaining the focal plane capture probability, significantly reducing the data generation and processing load.
[0112] This embodiment provides an autofocus method that controls the objective lens to move to the target position based on the position of the first objective lens and the second step value, and acquires at least two images with different objective lens positions. By using the coarse positioning result as an anchor point, it acquires the minimum number of images in the neighborhood most likely to contain the true focal plane. The position of the first objective lens serves as the sampling center to ensure that the true focal plane is within the sampling interval, and the second step value serves as the interval unit to ensure the resolution of the sampling points. This method can fully capture the trend of sharpness changes, thereby compressing the number of images acquired from multiple images in traditional methods to two or three images. This achieves the effect of optimizing the number of images acquired and the amount of computation without sacrificing focusing accuracy.
[0113] In one embodiment, determining the target focal plane position and completing focusing based on the objective lens position and sharpness features corresponding to the second reference image includes:
[0114] Based on the preset sharpness algorithm, the sharpness features of each second reference image are calculated respectively;
[0115] Based on the sharpness characteristics of each second reference image, a target reference image is selected, and the objective lens position corresponding to the target reference image is taken as the target focal plane position.
[0116] Control the objective lens to move to the target focal plane position.
[0117] Among them, sharpness features can be a quantitative indicator that reflects the richness of image details, and are used to filter the best image and determine the target focal plane position.
[0118] Based on the preset sharpness algorithm, the sharpness features of each second reference image are calculated. This can be achieved by applying the preset sharpness algorithm to each second reference image, calculating its sharpness value pixel by pixel or local area, and generating a corresponding sharpness feature vector. This enables high-resolution quantitative evaluation of the image quality of local areas, providing a comparable numerical basis for subsequent screening.
[0119] Based on the sharpness characteristics of each second reference image, a target reference image is selected, and the objective lens position corresponding to the target reference image is taken as the target focal plane position. This can be achieved by comparing the sharpness feature values of all second reference images, selecting the image with the highest value as the target reference image, and extracting its objective lens position as the target focal plane position. By directly selecting the image with the highest sharpness feature value as the target, accurate determination of the target focal plane can be achieved, avoiding misjudgments caused by local noise interference, and improving the reliability and stability of positioning.
[0120] This embodiment provides an autofocus method that calculates the sharpness features of each second reference image, selects the target reference image and uses its corresponding objective lens position as the target focal plane position, and controls the objective lens to move to the target focal plane position. It achieves high-resolution quantitative evaluation through a preset sharpness algorithm and achieves accurate target determination through sharpness feature comparison. This method can improve positioning robustness in dynamic or low signal-to-noise ratio scenarios, and achieves the technical effects of reducing computational complexity and avoiding curve fitting risks.
[0121] To more clearly illustrate the technical solution of this application, a detailed embodiment is also provided.
[0122] In the field of microscopic observation, autofocus technology is crucial for ensuring image quality and observation efficiency. Traditional focus depth methods require acquiring a large amount of image data at different focus states, resulting in large data processing volumes and long focusing times, making it difficult to meet the needs of high-speed scanning and real-time detection scenarios. With the improvement of image sensor performance and the development of machine learning technology, higher demands are placed on the speed and accuracy of autofocus technology. Although some existing autofocus methods attempt to reduce the number of images acquired, they are insufficient in the accuracy of mapping the relationship between blur and depth, leading to poor focusing accuracy or the need for multiple adjustments, affecting the observation experience and detection efficiency. In one embodiment, to solve the problems of large data volume, slow focusing, and insufficient accuracy of traditional methods, an autofocus method based on defocus depth estimation is provided, which can achieve fast and accurate focusing with only a small number of images. The method includes a mathematical modeling stage and a focusing execution stage.
[0123] I. Mathematical Modeling Stage.
[0124] Mathematical modeling is used to establish a mapping relationship between blur and relative depth, providing a calculation basis for subsequent focusing, such as... Figure 3As shown, the process includes focusing on the object, acquiring one image at a depth-of-field interval from the lower defocus position to the upper defocus position; extracting image features using machine learning methods; and establishing a mathematical model based on the image features and relative positional relationships. The specific steps are as follows:
[0125] 1. Image Acquisition: For different samples or different areas of the same sample, acquire multiple sets of images at different heights to ensure that the images cover different defocus levels and sample features.
[0126] 2. Feature Extraction: The acquired image is processed using an image feature extraction algorithm to calculate and extract the ratio of image features, thereby characterizing the degree of blur in the image.
[0127] 3. Model Construction: The extracted image feature ratios (blurry index) and the corresponding Z-axis heights (relative depths) are used as datasets. The datasets are fitted and trained to establish a mathematical model of the mapping relationship between blurryness and relative depth.
[0128] II. Focusing Execution Phase.
[0129] Based on the established mathematical model, the focus position is calculated and the lens is driven to focus by acquiring a small number of real-time images, such as... Figure 4 The process may include: acquiring the image and coordinates of the current position (e.g., image A and its corresponding position A); moving upwards by 5 depths of field; acquiring the current image and coordinates (e.g., image B and its corresponding position B); continuing to move upwards by 5 depths of field; acquiring the image and coordinates of the current position (e.g., image C and its corresponding position C); calculating multimodal feature information based on the image, and predicting the focal plane coordinates based on the feature and coordinate information; moving to a position one depth of field less than the focal plane; starting to move upwards by two depths of field; calculating the image sharpness value; and moving to the position with the best sharpness. The specific process is as follows:
[0130] 1. Initial image acquisition: Slightly move the microscope's Z-axis during the movement, acquiring two images at different focus states and recording the corresponding Z-axis position coordinates of the two images.
[0131] 2. Real-time feature extraction: Using the same image feature extraction algorithm as in the mathematical modeling stage, feature processing is performed on the two acquired real-time images to calculate the corresponding image feature ratio.
[0132] 3. Focal plane position prediction: Substitute the extracted real-time image feature ratios and their corresponding Z-axis positions into the established mathematical model, and predict the Z-axis position corresponding to the focal plane through model calculation.
[0133] 4. Accurate Focal Plane Verification: Control the Z-axis movement to the predicted focal plane position, then move it up and down by N depth of field distances at that position, and collect images within that range. Calculate the sharpness values of the three images, and select the Z-axis position corresponding to the image with the highest sharpness as the final focal plane position.
[0134] 5. Final focusing: Drive the microscope's Z-axis to move to the determined final focal plane position to complete the autofocus process.
[0135] In one specific embodiment, taking a microscope with a numerical aperture of 0.33 as an example, applied to the observation of semiconductor adhesive samples, the specific implementation steps are as follows:
[0136] I. Mathematical Modeling Stage.
[0137] 1. Image acquisition: Three different types of semiconductor adhesive samples were selected. Images were acquired at 100µm intervals within the Z-axis height range of 10-20mm under the microscope. 100 images were acquired for each sample, for a total of 300 images and corresponding Z-axis position data.
[0138] 2. Feature Extraction: The preset ambiguity algorithm used in this embodiment is the Sobel gradient operator as the image feature extraction algorithm. It calculates the horizontal gradient and vertical gradient of each image and uses the ratio of the sum of the absolute values of the gradients as the image feature ratio (ambiguity index).
[0139] 3. Model Construction: A nonlinear regression algorithm is used to fit the "ambiguity-relative depth" data to establish a nonlinear mapping model: y=f(x), where y is the relative depth (Z-axis height, unit: mm) and x is the ambiguity index.
[0140] II. Focusing Execution Phase.
[0141] 1. Initial image acquisition: Control the Z-axis to move slightly upward by 500um from the current position (assuming it is 12mm), and acquire two images (i.e., the first reference image) at the positions of 12.5mm and 13mm respectively, and record the corresponding Z-axis coordinates.
[0142] 2. Real-time feature extraction: The Sobel gradient operator is used to calculate the blur features (i.e., the absolute values of the horizontal and vertical gradients) of the two images respectively, and then the ratio of the blur features of the two images is calculated to obtain the blur index (i.e., the relative change feature of blur), which are 28.5 and 30.2 respectively.
[0143] 3. Focal plane position prediction: Substituting the blur index and the corresponding Z-axis position into the linear model, the predicted focal plane Z-axis position is calculated to be 64.2mm, which is the position of the first objective lens.
[0144] 4. Focal plane accuracy verification: Given that the depth of field of the microscope is 0.5mm, the Z-axis was moved to 64.2mm, and then images were acquired at three positions: 64.0mm, 64.2mm, and 64.4mm. The sharpness values were calculated using the gray-scale variance method and were 125, 189, and 132, respectively. The position with the highest sharpness, 64.2mm, was selected as the final focal plane position.
[0145] 5. Final focusing: Drive the Z-axis to move to 64.2mm to complete focusing. The whole process takes about 0.8 seconds.
[0146] In another specific embodiment, taking a microscope objective lens with a numerical aperture of 0.9 as an example, applied to the observation of biological slide samples, the specific implementation steps are as follows:
[0147] I. Mathematical Modeling Stage.
[0148] 1. Image acquisition: Four different types of biological slice samples were selected, and images were acquired at 0.01 mm intervals at a Z-axis height of 2 mm. 100 images were acquired for each sample, for a total of 400 images and corresponding Z-axis position data.
[0149] 2. Feature Extraction: The preset blurring algorithm used in this embodiment is the Laplacian operator as the image feature extraction algorithm. It calculates the absolute value of the second derivative of each image and selects the clearest image among multiple images as the standard clear image.
[0150] 3. Model Construction: A nonlinear mapping model was established by training on 400 sets of data using the support vector machine algorithm. The model's goodness of fit R0 was [value missing]. 2 It is 0.96.
[0151] II. Focusing Execution Phase.
[0152] 1. Initial image acquisition: Control the Z-axis to move downwards by 0.16mm from 49mm, and acquire two images at positions of 48.84mm and 49.16mm respectively.
[0153] 2. Real-time feature extraction: The blur features of the two images were calculated using the Laplacian operator, and the blur indices were 42.1 and 45.3, respectively.
[0154] 3. Focal plane position prediction: Substituting into the support vector machine model, the predicted focal plane Z-axis position is 48.8mm.
[0155] 4. Accurate focal plane verification: Images were acquired at 48.7mm, 48.8mm, and 48.9mm, and the sharpness values were calculated to be 98, 176, and 105, respectively, confirming 48.8mm as the final focal plane.
[0156] 5. Final focus: Drive the Z-axis to move to 48.8mm to complete focusing, which takes about 1.0 second.
[0157] As can be seen from the results of the above embodiments, the autofocus method of this embodiment can achieve fast focusing with a time of less than 1 second and has a high focusing progress, so that the final image sharpness of the focal plane reaches the optimal level, thus effectively adapting to different microscopic observation scenarios.
[0158] The autofocus method provided in this embodiment can achieve the following technical effects: (1) Fast focusing speed: Only 2 to 3 images with different focusing conditions need to be processed to complete the core calculation, which greatly reduces the amount of data acquisition and processing compared with the traditional focusing depth method, and significantly improves focusing efficiency; (2) High focusing accuracy: A precise mapping model between blur and relative depth is established by machine learning algorithm, and the sharpness verification within the depth of field is combined to ensure the accuracy of the focusing position; (3) Strong adaptability: By collecting images of different samples and different heights for modeling, it can be adapted to a variety of microscopic observation scenarios and sample types; (4) Simple operation: The focusing process is highly automated and can complete the entire process from image acquisition to lens positioning without manual intervention.
[0159] It should be understood that although the steps in the flowcharts of the embodiments described above are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the embodiments described above may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages of other steps.
[0160] Based on the same inventive concept, this application also provides an apparatus for implementing the method described above. The solution provided by this apparatus is similar to the solution described in the above method; therefore, specific limitations in one or more apparatus embodiments provided below can be found in the limitations of the method described above, and will not be repeated here.
[0161] In one embodiment, such as Figure 5 As shown, this application provides an autofocus device for use in a microscope. The autofocus device includes:
[0162] The first moving module 100 is used to respond to the autofocus command, control the objective lens to move according to the first step value corresponding to the imaging parameters of the microscope, and acquire at least two first reference images with different objective lens positions.
[0163] The position analysis module 200 is used to determine the position of the first objective lens based on the objective lens position and blur characteristics corresponding to the first reference image.
[0164] The second moving module 300 is used to control the movement of the objective lens according to the position of the first objective lens and a preset second step value, and to acquire at least two second reference images with different objective lens positions.
[0165] The focal plane analysis module 400 is used to determine the target focal plane position and complete focusing based on the objective lens position and sharpness characteristics corresponding to the second reference image.
[0166] In one embodiment, the imaging parameters include depth parameters; the first reference image includes a first current reference image and a first forward reference image; the first moving module 100 is further configured to:
[0167] Acquire the first current reference image at the current objective lens position;
[0168] Based on the first step value corresponding to the depth of field parameter, the objective lens is controlled to move at least once to acquire at least one first step reference image.
[0169] In one embodiment, the location analysis module 200 is further configured to:
[0170] According to the preset blur algorithm, the blur features of each of the first reference images are calculated;
[0171] The ratio of the blur features of every two first reference images and the difference in the corresponding objective lens positions are calculated sequentially to obtain the relative blur change features of the first reference images.
[0172] The position of the first objective lens is determined based on the relative change characteristics of the blurriness.
[0173] In one embodiment, the location analysis module 200 is further configured to:
[0174] The relative blurring change features are input into a pre-trained objective lens position prediction model to obtain the first objective lens position.
[0175] In one embodiment, the training process of the objective lens position prediction model includes:
[0176] Within the movable range of the objective lens of the microscope, the objective lens is moved according to a preset step interval to obtain sample images of the target sample at each objective lens position;
[0177] The blurring features of each sample image are calculated according to a preset blurring algorithm.
[0178] The ratio of the blur features of every two sample images and the difference in objective lens position are calculated sequentially to obtain the relative change features of blur. The subtrahend or minuend corresponding to the difference in objective lens position is taken as the true objective lens position of the relative change features of blur.
[0179] Based on the multiple relative blurring characteristics and the actual objective lens position, a preset machine learning model is trained to obtain the objective lens position prediction model.
[0180] In one embodiment, calculating the blur characteristics of each image according to a preset blur algorithm includes:
[0181] Image features are extracted from the image according to a preset gradient operator to obtain gradient information; the gradient information includes horizontal gradient and vertical gradient.
[0182] The sum of the absolute values of the horizontal gradient and the vertical gradient is used as the blur feature of the image.
[0183] In one embodiment, the second moving module 300 is further configured to:
[0184] The objective lens is moved to the target position according to the first objective lens position and the second step value to obtain at least two images with different objective lens positions; the target position includes at least two of the following: the first objective lens position, the difference between the first objective lens position and the second step value, and the sum of the first objective lens position and the second step value.
[0185] In one embodiment, the focal plane analysis module 400 is further configured to:
[0186] Based on the preset sharpness algorithm, the sharpness features of each second reference image are calculated respectively;
[0187] Based on the sharpness characteristics of each second reference image, target reference images are selected, and the objective lens position corresponding to the target reference image is taken as the target focal plane position;
[0188] Control the objective lens to move to the target focal plane position.
[0189] The modules in the aforementioned autofocus device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in the processor of a computer device in hardware form or independent of it, or stored in the memory of a computer device in software form, so that the processor can call and execute the operations corresponding to each module.
[0190] In one embodiment, a computer device is provided, which may be a terminal, and its internal structure diagram may be as follows: Figure 6 As shown, the computer device includes a processor, memory, communication interface, display screen, and input devices connected via a system bus. The processor provides computing and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The communication interface is used for wired or wireless communication with external terminals; wireless communication can be achieved through Wi-Fi, mobile cellular networks, NFC (Near Field Communication), or other technologies. When executed by the processor, the computer program implements an autofocus method. The display screen can be an LCD screen or an e-ink screen. The input devices can be a touch layer covering the display screen, buttons, a trackball, or a touchpad on the computer device's casing, or an external keyboard, touchpad, or mouse.
[0191] Those skilled in the art will understand that Figure 6 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0192] In one embodiment, a computer device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the autofocus method of any of the above embodiments:
[0193] In response to the autofocus command, the objective lens is moved according to the first step value corresponding to the imaging parameters of the microscope, and at least two first reference images with different objective lens positions are acquired.
[0194] The position of the first objective lens is determined based on the objective lens position and blur characteristics corresponding to the first reference image;
[0195] The objective lens is moved according to the first objective lens position and a preset second step value, and at least two second reference images with different objective lens positions are acquired.
[0196] Based on the objective lens position and sharpness characteristics corresponding to the second reference image, the target focal plane position is determined and focusing is completed.
[0197] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed by a processor, implements the autofocus method of any of the above embodiments:
[0198] In response to the autofocus command, the objective lens is moved according to the first step value corresponding to the imaging parameters of the microscope, and at least two first reference images with different objective lens positions are acquired.
[0199] The position of the first objective lens is determined based on the objective lens position and blur characteristics corresponding to the first reference image;
[0200] The objective lens is moved according to the first objective lens position and a preset second step value, and at least two second reference images with different objective lens positions are acquired.
[0201] Based on the objective lens position and sharpness characteristics corresponding to the second reference image, the target focal plane position is determined and focusing is completed.
[0202] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties.
[0203] Those skilled in the art will understand that all or part of the processes in the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium. When executed, the computer program can include the processes of the embodiments described above. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, distributed databases based on blockchain. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, data processing logic devices based on quantum computing, etc., and are not limited to these.
[0204] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0205] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.
Claims
1. An autofocus method, characterized in that, When applied to a microscope, the autofocus method includes: In response to an autofocus command, the objective lens is moved according to the first step value corresponding to the imaging parameters of the microscope, and at least two first reference images with different objective lens positions are acquired; the imaging parameters include depth of field parameters; the depth of field parameters are calculated by optical formulas from the numerical aperture and working wavelength of the objective lens. The position of the first objective lens is determined based on the objective lens position and blur characteristics corresponding to the first reference image. This determination includes: calculating the blur characteristics of each first reference image using a preset blur algorithm; sequentially calculating the ratio of the blur characteristics of every two first reference images and the difference in their corresponding objective lens positions to obtain the relative blur change characteristics of the first reference images; and determining the position of the first objective lens based on these relative blur change characteristics. The determination also includes: inputting the relative blur change characteristics into a pre-trained objective lens position prediction model to obtain the position of the first objective lens. The objective lens is moved according to the first objective lens position and a preset second step value, and at least two second reference images with different objective lens positions are acquired. Based on the objective lens position and sharpness characteristics corresponding to the second reference image, the target focal plane position is determined and focusing is completed.
2. The autofocus method according to claim 1, characterized in that, The imaging parameters include depth-of-field parameters; the first reference image includes a first current reference image and a first step reference image; the step of controlling the objective lens movement according to the first step value corresponding to the imaging parameters of the microscope in response to the autofocus command, and acquiring at least two first reference images at different objective lens positions, includes: Acquire the first current reference image at the current objective lens position; Based on the first step value corresponding to the depth of field parameter, the objective lens is controlled to move at least once to acquire at least one first step reference image.
3. The autofocus method according to claim 1, characterized in that, The training process of the objective lens position prediction model includes: Within the movable range of the objective lens of the microscope, the objective lens is moved according to a preset step interval to obtain sample images of the target sample at each objective lens position; The blurring features of each sample image are calculated according to a preset blurring algorithm. The ratio of the blur features of every two sample images and the difference in objective lens position are calculated sequentially to obtain the relative change features of blur. The subtrahend or minuend corresponding to the difference in objective lens position is taken as the true objective lens position of the relative change features of blur. Based on the multiple relative blurring characteristics and the actual objective lens position, a preset machine learning model is trained to obtain the objective lens position prediction model.
4. The autofocus method according to claim 3, characterized in that, Based on the preset blurring algorithm, the blurring features of each image are calculated, including: Image features are extracted from the image according to a preset gradient operator to obtain gradient information; the gradient information includes horizontal gradient and vertical gradient. The sum of the absolute values of the horizontal gradient and the vertical gradient is used as the blur feature of the image.
5. The autofocus method according to claim 1, characterized in that, The step of controlling the objective lens movement based on the first objective lens position and a preset second step value, and acquiring at least two second reference images at different objective lens positions, includes: The objective lens is moved to the target position according to the first objective lens position and the second step value to obtain at least two images with different objective lens positions; the target position includes at least two of the following: the first objective lens position, the difference between the first objective lens position and the second step value, and the sum of the first objective lens position and the second step value.
6. The autofocus method according to claim 1, characterized in that, The step of determining the target focal plane position and completing focusing based on the objective lens position and sharpness features corresponding to the second reference image includes: Based on the preset sharpness algorithm, the sharpness features of each second reference image are calculated respectively; Based on the sharpness characteristics of each second reference image, target reference images are selected, and the objective lens position corresponding to the target reference image is taken as the target focal plane position; Control the objective lens to move to the target focal plane position.
7. An automatic focusing device, characterized in that, The autofocus device, used in microscopes, includes: The first moving module is used to respond to an autofocus command and control the movement of the objective lens according to the first step value corresponding to the imaging parameters of the microscope, so as to acquire at least two first reference images at different objective lens positions; the imaging parameters include depth of field parameters; the depth of field parameters are calculated by optical formulas from the numerical aperture and working wavelength of the objective lens. The position analysis module is used to determine the position of the first objective lens based on the objective lens position and blur characteristics corresponding to the first reference image. Determining the position of the first objective lens based on the objective lens position and blur characteristics corresponding to the first reference image includes: calculating the blur characteristics of each of the first reference images according to a preset blur algorithm; sequentially calculating the ratio of the blur characteristics of every two first reference images and the difference in the corresponding objective lens positions to obtain the relative blur change characteristics of the first reference images; and determining the position of the first objective lens based on the relative blur change characteristics. The determination of the position of the first objective lens based on the relative blur change characteristics includes: inputting the relative blur change characteristics into a pre-trained objective lens position prediction model to obtain the position of the first objective lens. The second moving module is used to control the movement of the objective lens according to the position of the first objective lens and a preset second step value, and to acquire at least two second reference images with different objective lens positions. The focal plane analysis module is used to determine the target focal plane position and complete focusing based on the objective lens position and sharpness characteristics corresponding to the second reference image.
8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the method of any one of claims 1 to 6.