CN117850017B - Microscope automatic focusing method, device, computer equipment and storage medium - Google Patents

Microscope automatic focusing method, device, computer equipment and storage medium Download PDF

Info

Publication number
CN117850017B
CN117850017B CN202410259113.7A CN202410259113A CN117850017B CN 117850017 B CN117850017 B CN 117850017B CN 202410259113 A CN202410259113 A CN 202410259113A CN 117850017 B CN117850017 B CN 117850017B
Authority
CN
China
Prior art keywords
focusing
image
images
lens
turning
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202410259113.7A
Other languages
Chinese (zh)
Other versions
CN117850017A (en
Inventor
沈艺
李阳
江浩
黄迪锋
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Suzhou Basecare Medical Device Co ltd
Original Assignee
Suzhou Basecare Medical Device Co ltd
Filing date
Publication date
Application filed by Suzhou Basecare Medical Device Co ltd filed Critical Suzhou Basecare Medical Device Co ltd
Priority to CN202410259113.7A priority Critical patent/CN117850017B/en
Publication of CN117850017A publication Critical patent/CN117850017A/en
Application granted granted Critical
Publication of CN117850017B publication Critical patent/CN117850017B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Abstract

The application relates to an automatic focusing method and device for a microscope, computer equipment and a storage medium. And controlling the lens to move based on preset focusing process parameters, acquiring focusing images and the quantity of focusing images acquired when each focusing process moves at a corresponding moving speed, controlling the lens to turn around when the corresponding focusing process turning-around condition is met according to the focusing images and the quantity of focusing images, and moving according to the moving speed of the focusing process after turning around until the turning-around times are reached, and controlling the lens to stop moving when the termination condition is met, so as to finish focusing on the microscope. The method has the advantages that the parameter of the focusing process is set in advance, the next focusing process is continuously shortened, the moving speed is reduced, the problem of inaccurate positioning caused by continuous movement of inertia of the microscope lens after high-speed stop is solved, the clearest visual field is positioned more accurately and precisely, the focusing time is reduced, and the focusing efficiency and the focusing precision are improved.

Description

Microscope automatic focusing method, device, computer equipment and storage medium
Technical Field
The present application relates to the field of instrument focusing technology, and in particular, to a method, an apparatus, a computer device, a storage medium and a computer program product for automatic focusing of a microscope.
Background
Microscopes are an indispensable important instrument in many scientific fields, such as biology, medicine, material science, etc. Focusing is a crucial step during operation of the microscope. The conventional manual focusing method not only requires time and effort for an operator to adjust the lens position, but also is prone to errors. In order to improve the use efficiency and precision of the microscope, an automatic focusing algorithm has been developed. Such an algorithm may automatically identify the sharpest focus of the sample or target, thereby making the focusing process faster and more accurate. This is of great significance for scientific research and experimental work.
However, the definition requirements are also extremely high for sample (e.g., sperm) images that appear as a single tone under a microscope with insignificant changes. However, most microscopes on the market have unacceptable factory stride errors in terms of definition of such samples, so even if a focusing algorithm finds a clear focusing position, focusing is unclear due to the error of the microscope. Thus, there is a need for an auto-focus method that can meet the sharpness requirements for such samples.
Disclosure of Invention
In view of the foregoing, it is desirable to provide a method, apparatus, computer device, computer readable storage medium, and computer program product for auto-focusing a microscope that can meet the requirements of sharpness accuracy.
In a first aspect, the present application provides a method for auto-focusing a microscope, comprising:
Controlling lens movement based on preset focusing process parameters, wherein the focusing process parameters comprise turning times, termination conditions, movement speed corresponding to each focusing process and turning conditions;
Acquiring focusing images acquired during movement at corresponding movement speeds in each focusing process and the quantity of the focusing images, controlling the lens to turn around when a turning-around condition corresponding to the focusing process is met according to the focusing images and the quantity of the focusing images, and moving according to the movement speed of the focusing process after turning around until the turning-around times are reached, and controlling the lens to stop moving when a termination condition is met, so that focusing on the microscope is completed.
In one embodiment, the number of turning around is three, and the turning around conditions include a first turning around condition, a second turning around condition and a third turning around condition; the method for acquiring the focusing images and the quantity of the focusing images acquired when moving at the corresponding moving speed in each focusing process, when the turning condition of the corresponding focusing process is met according to the focusing images and the quantity of the focusing images, controlling the lens to turn around, and moving at the moving speed of the focusing process after turning around until the turning around times are reached, and when the termination condition is met, controlling the lens to stop moving comprises the following steps:
Acquiring a first focusing image and the number of the first focusing images acquired when the lens moves at an initial speed in a first focusing process, converting the moving direction of the lens when the first turning condition is met according to the first focusing image and the number of the first focusing images, and determining the first moving speed of a second focusing process after turning around based on a preset speed descending trend;
Acquiring second focusing images and the number of the second focusing images acquired when the lens moves at a first moving speed in a second focusing process, converting the moving direction of the lens when the second turning condition is met according to the second focusing images and the number of the second focusing images, and determining the second moving speed of a third focusing process after turning around based on a preset speed descending trend;
acquiring a third focusing image and the number of the third focusing images acquired when the lens moves at a second moving speed in a third focusing process, converting the moving direction of the lens when the third turning condition is met according to the third focusing image and the number of the third focusing image, and determining the third moving speed of a fourth focusing process after turning around based on a preset speed descending trend;
and acquiring a fourth focusing image and the number of the fourth focusing images acquired when the lens moves at a third moving speed in a fourth focusing process, and controlling the lens to stop moving when the termination condition is determined to be met according to the fourth focusing image and the number of the fourth focusing images.
In one embodiment, the acquiring the first focusing image and the number of first focusing images acquired when the lens moves at the initial speed in the first focusing process, and when determining that the first turning condition is met according to the first focusing image and the number of first focusing images, converting the moving direction of the lens includes:
Acquiring a first focusing image acquired when the lens moves at an initial speed in a first focusing process;
performing target detection on the first focusing image, determining that the first focusing image is a first target focusing image when a target object is detected, acquiring a first position of the first target focusing image in the first focusing process, determining that a first turning-around condition is met if the interval between the second position of the first focusing image which is currently acquired and the first position of the first target focusing image reaches a set value, and converting the moving direction of the lens; or alternatively
And if no target object is detected in the first focusing images and the number of the first focusing images reaches a first number threshold, determining that a first turning condition is met, and converting the moving direction of the lens.
In one embodiment, the acquiring the second focusing image and the number of the second focusing images acquired when the lens moves at the first moving speed in the second focusing process, and when determining that the second turning condition is met according to the second focusing image and the number of the second focusing images, converting the moving direction of the lens includes:
Acquiring a second focusing image acquired when the lens moves at a first moving speed in a second focusing process;
performing target detection on the second focusing image, and acquiring definition of the second focusing image when a target object is detected;
When the second focusing image is identified as a second target focusing image based on the category of the target object, determining the second focusing image with the largest definition acquired in the second focusing process, if the first set number of second focusing images with the definition are continuously acquired after the second focusing image with the largest definition, determining that a second turning condition is met, and converting the moving direction of the lens; or alternatively
If the second target focusing image is not recognized in the second focusing images and the number of the second focusing images reaches a second number threshold, determining that a second turning condition is met, and converting the moving direction of the lens; or alternatively
If the second target focusing image is identified in the second focusing images, but after the second focusing image with the largest definition, the first set number of second focusing images with the definition are not continuously acquired, and the number of the second focusing images reaches a second number threshold, determining that a second turning condition is met, and converting the moving direction of the lens.
In one embodiment, the acquiring the third focusing image and the number of the third focusing images acquired when the lens moves at the second moving speed in the third focusing process, and when determining that the third turning condition is met according to the third focusing image and the number of the third focusing images, converting the moving direction of the lens includes:
Acquiring a third focusing image acquired when the lens moves at a second moving speed in a third focusing process;
Performing target detection on the third focusing image, and acquiring definition of the third focusing image when a target object is detected;
When the third focusing image is identified as a third target focusing image based on the category of the target object, determining the last third focusing image with definition acquired in the third focusing process, if a second set number of third focusing images without definition are continuously acquired after the last third focusing image with definition, determining that a third turning condition is met, and converting the moving direction of the lens; or alternatively
If the third target focusing image is not recognized in the third focusing images and the number of the third focusing images reaches a third number threshold, determining that a third turning condition is met, and converting the moving direction of the lens; or alternatively
If the third target focusing image is identified in the third focusing images, but after the last third focusing image with definition, a second set number of third focusing images without definition are not continuously acquired, and the number of the third focusing images reaches a third number threshold, determining that a third turning condition is met, and converting the moving direction of the lens.
In one embodiment, the acquiring the fourth focusing image and the number of fourth focusing images acquired when the lens moves at the third moving speed in the fourth focusing process, and controlling the lens to stop moving when it is determined that the termination condition is satisfied according to the number of fourth focusing images and the number of fourth focusing images, includes:
Acquiring a fourth focusing image acquired when the lens moves at a third moving speed in a fourth focusing process;
Performing target detection on the fourth focusing image, and acquiring definition of the fourth focusing image when a target object is detected;
When the fourth focusing image is identified as a fourth target focusing image based on the category of the target object, determining the fourth focusing image with the largest definition acquired in the fourth focusing process and determining the target focusing image with the largest definition acquired in the second focusing process and the third focusing process, and when the difference between the definition of the fourth focusing image with the largest definition and the definition of the target focusing image is larger than a set threshold value, determining that a termination condition is met, and controlling the lens to stop moving; or alternatively
If the fourth target focusing image is not recognized in the fourth focusing images and the number of the fourth focusing images reaches a fourth number threshold, determining that a termination condition is met, and controlling the lens to stop moving; or alternatively
And if the fourth target focusing image is identified in the fourth focusing images, but the difference between the definition of the fourth focusing image with the largest definition and the definition of the target focusing image is smaller than or equal to a set threshold value, and the number of the fourth focusing images reaches a fourth number threshold value, determining that a termination condition is met, and controlling the lens to stop moving.
In one embodiment, the method for acquiring the definition of the focusing image includes:
Identifying the category and the number under each category of the target object in the focusing image, and acquiring a first definition corresponding to the category according to the preset category weight and the number under each category, wherein the focusing image comprises any one of a second focusing image, a third focusing image and a fourth focusing image;
identifying a target area of the target object in the focusing image, and determining a second definition of the target object according to the gradient of each pixel point in the target area;
And determining the definition of the focusing image according to the first definition and the second definition.
In one embodiment, the first movement speed is less than the initial speed, the second movement speed is less than the first movement speed, and the third movement speed is less than the second movement speed.
In a second aspect, the present application provides an autofocus device for a microscope, the device comprising:
the control module is used for controlling the lens to move based on preset focusing process parameters, wherein the focusing process parameters comprise turning frequency, termination conditions, moving speed corresponding to each focusing process and turning conditions;
The focusing module is used for acquiring focusing images acquired when each focusing process moves at a corresponding moving speed and the quantity of the focusing images, controlling the lens to turn around when a turning-around condition corresponding to the focusing process is met according to the focusing images and the quantity of the focusing images, moving according to the moving speed of the focusing process after turning around until the turning-around times are reached, and controlling the lens to stop moving when a termination condition is met, so that focusing on the microscope is completed.
In a third aspect, the present application provides a computer device comprising a memory storing a computer program and a processor implementing the steps of the method described above when the processor executes the computer program.
In a fourth aspect, the present application provides a computer readable storage medium having stored thereon a computer program which when executed by a processor performs the steps of the method described above.
In a fifth aspect, the application provides a computer program product comprising a computer program which, when executed by a processor, implements the steps of the method described above.
According to the automatic focusing method, device, computer equipment, storage medium and computer program product of the microscope, the computer equipment controls the lens to move based on preset focusing process parameters, acquires focusing images acquired during movement at corresponding movement speeds in each focusing process and the quantity of the focusing images, controls the lens to turn around when the turning-around condition of the corresponding focusing process is met according to the focusing images and the quantity of the focusing images, and moves according to the movement speed of the focusing process after turning around until the turning-around times are reached and the termination condition is met, controls the lens to stop moving, and completes focusing of the microscope. The method has the advantages that the parameter of the focusing process is set in advance, the next focusing process is continuously shortened, the moving speed is reduced, the problem of inaccurate positioning caused by continuous movement of inertia of the microscope lens after high-speed stop is solved, the clearest visual field is positioned more accurately and precisely, the focusing time is reduced, and the focusing efficiency and the focusing precision are improved.
Drawings
In order to more clearly illustrate the embodiments of the present application or the technical solutions in the related art, the drawings that are required to be used in the embodiments or the related technical descriptions will be briefly described, and it is apparent that the drawings in the following description are only some embodiments of the present application, and other drawings may be obtained according to the drawings without inventive effort for those skilled in the art.
FIG. 1 is a flow chart of an auto-focus method of a microscope according to one embodiment;
FIG. 2 is a flow chart illustrating a focusing step in one embodiment;
FIG. 3 is a schematic diagram of a focusing process in one embodiment;
FIG. 4 is a flow chart of a step of obtaining sharpness in one embodiment;
FIG. 5A is a schematic diagram of a target object state class of 0 in one embodiment;
FIG. 5B is a schematic diagram of a target object state class 1 in one embodiment;
FIG. 5C is a schematic diagram of a target object state class 2 in one embodiment;
FIG. 5D is a schematic diagram of a target object state class 3 in one embodiment;
FIG. 6 is a block diagram of an auto-focus device of a microscope in one embodiment;
fig. 7 is an internal structural diagram of a computer device in one embodiment.
Detailed Description
The present application will be described in further detail with reference to the drawings and examples, in order to make the objects, technical solutions and advantages of the present application more apparent. It should be understood that the specific embodiments described herein are for purposes of illustration only and are not intended to limit the scope of the application.
The automatic focusing method of the microscope provided by the application can be applied to computer equipment. The computer device may be a terminal, or a server, or a system of a terminal and a server. The terminal can be, but not limited to, various personal computers, notebook computers, smart phones, tablet computers, internet of things equipment and portable wearable equipment, and the internet of things equipment can be smart speakers, smart televisions, smart air conditioners, smart vehicle-mounted equipment and the like. The portable wearable device may be a smart watch, smart bracelet, headset, or the like. The server may be implemented as a stand-alone server or as a server cluster composed of a plurality of servers.
In one embodiment, as shown in fig. 1, a microscope auto-focusing method is provided, and this embodiment is illustrated by applying the method to a terminal, it will be understood that the method may also be applied to a server, and may also be applied to a system including a terminal and a server, and implemented through interaction between the terminal and the server. In this embodiment, the method includes the steps of:
step 102, controlling lens movement based on preset focusing process parameters.
The focusing process parameters comprise the turning times, the termination condition, the corresponding moving speed of each focusing process and the turning condition. The turning times refer to the times of turning the lens, which is required to be executed when focusing is completed, and the turning conditions refer to the conditions which are required to be achieved when turning the lens, namely the conditions for triggering turning the lens. The termination condition is a condition for terminating the focusing process, that is, a condition for completing focusing. The moving speed refers to the speed at which the computer device controls the movement of the microscope during focusing. In this embodiment, different focusing processes before and after each turn are defined, and each focusing process has its own moving speed and turn-around condition, that is, the moving speed and turn-around condition of each focusing process are different from those of other focusing processes. Specifically, the moving speed of each focusing process gradually decreases based on a preset speed decreasing trend.
In this embodiment, when the computer device automatically focuses on the microscope, the computer device first needs to acquire a preset focusing process parameter, and then can control the lens (i.e. the microscope lens) to move based on the preset focusing process parameter.
Step 104, acquiring focusing images and the quantity of focusing images acquired when moving at a corresponding moving speed in each focusing process, and completing focusing of the microscope according to the focusing images and the quantity of focusing images.
In this embodiment, the computer device controls the lens to turn around when the turning around condition corresponding to the focusing process is met according to the focusing images and the number of focusing images acquired during movement at the corresponding movement speed in each focusing process, and controls the lens to stop moving until the turning around times are reached and the termination condition is met when the turning around condition is met after the lens turns around is determined to meet the turning around condition corresponding to the focusing process according to the focusing images and the number of focusing images.
The focusing image is a group of pictures from blurring to clear to blurring, which are obtained by shooting by an image acquisition device (such as a digital camera, an analog camera and the like) carried on the microscope. The number of the focusing images refers to the number of the focusing images acquired in the current focusing process.
In the automatic focusing method of the microscope, the computer equipment controls the lens to move based on preset focusing process parameters, acquires focusing images acquired during movement at corresponding movement speeds in each focusing process and the quantity of the focusing images, controls the lens to turn around when the turning-around condition corresponding to the focusing process is met according to the focusing images and the quantity of the focusing images, and moves according to the movement speeds of the focusing processes after turning around until the turning-around times are reached, and controls the lens to stop moving when the termination condition is met, so that focusing on the microscope is completed. The method has the advantages that the parameter of the focusing process is set in advance, the next focusing process is continuously shortened, the moving speed is reduced, the problem of inaccurate positioning caused by continuous movement of inertia of the microscope lens after high-speed stop is solved, the clearest visual field is positioned more accurately and precisely, the focusing time is reduced, and the focusing efficiency and the focusing precision are improved.
In an exemplary embodiment, the number of times of turning around is three, and the turning around conditions include a first turning around condition, a second turning around condition, and a third turning around condition, as shown in fig. 2, step 104 may specifically further include:
Step 202, acquiring a first focusing image and the number of the first focusing images acquired when the lens moves at an initial speed in a first focusing process, converting the moving direction of the lens when the first turning condition is met according to the first focusing image and the number of the first focusing images, and determining the first moving speed of a second focusing process after turning based on a preset speed descending trend.
The initial speed may be a movement speed of the lens in the first focusing process preset in the focusing process parameter. The first focusing image is a focusing image collected in the first focusing process, and the first turning-around condition is a condition for triggering turning around in the first focusing process. The second focusing process is the next focusing process adjacent to the first focusing process, and the first moving speed is the moving speed of the lens in the second focusing process.
In this embodiment, at the beginning of focusing, the computer device controls the lens to enter the first focusing process and move at an initial speed while collecting the first focusing image and the number of first focusing images in the first focusing process. When the first turning-around condition is met according to the first focusing images and the quantity of the first focusing images, the moving direction of the lens is converted, namely the lens is controlled to turn around and enter a second focusing process, and meanwhile, the first moving speed of the second focusing process after turning around is determined based on a preset speed descending trend.
Specifically, the computer equipment acquires a first focusing image acquired when the lens moves at an initial speed in a first focusing process, performs target detection on the first focusing image, determines that the first focusing image is the first target focusing image when a target object is detected, further acquires a first position of the first target focusing image in the first focusing process, and determines that a first turning-around condition is met and converts the moving direction of the lens if the interval between a second position of the first focusing image acquired currently and the first position of the first target focusing image reaches a set value; or if no target object is detected in the first focusing images and the number of the first focusing images reaches a first number threshold, determining that the first turning condition is met, and converting the moving direction of the lens.
The target detection is to perform visual detection on the first focusing image so as to find out a target object of interest in the image. In this embodiment, the target object may be sperm. Specifically, a trained target detection model may be pre-deployed in the computer device, and the target detection model may be pre-trained using the terminal or other computer devices outside the terminal.
The first target focus image is a first focus image from which the target object is detected, and it can be understood that when the target object, i.e., sperm, can be detected from the first focus image, it means that the sharpness of the first focus image can be calculated, and therefore, the first focus image can be determined to be the first target focus image. That is, the first target focus image is a first focus image having sharpness.
The first position may be a position where the first target focusing image is located, that is, a position where the first focusing image corresponding to the first target focusing image is located in the first focusing process, for example, may be an image number where the first target focusing image is located in the first focusing process. The second position may be a position where the currently collected first focusing image is located, that is, an image number where the currently collected first focusing image is located in the first focusing process. Specifically, for each first focusing image collected in the first focusing process, numbering can be performed based on the time sequence of collection of the first focusing images, and then each first focusing image has a corresponding image number. The set value may be a preset interval size of image numbers. The first number threshold may be a maximum number of first in-focus images acquired during the first in-focus process set in the first u-turn condition.
In this embodiment, as shown in fig. 3, the initial speed is V0, the set value is 2, and the first number threshold is 40, for example. It should be noted that, the initial speed is the maximum speed in the whole focusing, the step is also large, the interval between the collected images is large, so the continuity is low, and the sharpness between the collected images changes rapidly. Specifically, the computer device acquires first focusing images sequentially acquired when the lens moves at an initial speed V0 in a first focusing process (for example, a first process in the figure), sequentially performs target detection on the first focusing images, when a target object is detected, determines that the first focusing image is a first target focusing image, acquires a first position (which may be an image number corresponding to the first target focusing image) of the first target focusing image in the first focusing process, continuously acquires the first focusing image (i.e., a first focusing image currently acquired) to perform target detection, and acquires a second position (which may be an image number corresponding to the first focusing image currently acquired) of the first focusing image when the target object is not detected, determines that a first turning condition is met when an interval between the second position and the first position is greater than or equal to a set value 2, and turns around to switch a moving direction of the lens, thereby shortening the focusing process.
When the target object is detected by detecting the target object by continuously collecting the first focusing image (i.e., the first focusing image collected currently), the first focusing image collected currently can be determined as the first target focusing image, and then the first position of the first target focusing image can be obtained as the subsequent reference. It is understood that the first target focusing image may be the last focusing image with sharpness acquired during the first focusing process, that is, the last focusing image in which the target object is detected.
In one scenario, if no target object is detected in the first focusing images, and the number of the first focusing images reaches the first number threshold 40 (i.e., when the lens moves to the bottom), it may be determined that the first u-turn condition is satisfied, and the lens may be turned around to switch the moving direction of the lens, thereby shortening the focusing process.
Step 204, acquiring the second focusing image and the number of the second focusing images acquired when the lens moves at the first moving speed in the second focusing process, converting the moving direction of the lens when the second turning condition is met according to the second focusing image and the number of the second focusing images, and determining the second moving speed of the third focusing process after turning based on the preset speed descending trend.
The first movement speed may be a movement speed of the lens in the second focusing process preset in the focusing process parameter. The second focusing image is a focusing image collected in the second focusing process, and the second turning-around condition is a condition for triggering turning around in the second focusing process. The third focusing process is the next focusing process adjacent to the second focusing process, and the second moving speed is the moving speed of the lens in the third focusing process.
In this embodiment, after the computer device controls the lens to turn around to enter the second focusing process based on the above steps, the second focusing image and the number of second focusing images in the second focusing process may also be obtained. When the second turning condition is met according to the second focusing images and the number of the second focusing images, the moving direction of the lens is converted, namely the lens is controlled to turn around and enter a third focusing process, and meanwhile, the second moving speed of the third focusing process after turning around is determined based on a preset speed descending trend.
Specifically, the computer device acquires a second focusing image acquired when the lens moves at a first moving speed in a second focusing process, performs target detection on the second focusing image, acquires definition of the second focusing image when a target object is detected, determines a second focusing image with the largest definition acquired in the second focusing process when the second focusing image is identified as the second target focusing image based on the category of the target object, and if a first set number of second focusing images with definition are continuously acquired after the second focusing image with the largest definition, determines that a second turning-around condition is met, and converts the moving direction of the lens. Or if the second target focusing image is not recognized in the second focusing images and the number of the second focusing images reaches a second number threshold, determining that the second turning condition is met, and converting the moving direction of the lens. Or if the second target focusing image is identified in the second focusing images, but after the second focusing image with the largest definition, the first set number of second focusing images with the definition are not continuously acquired, and the number of the second focusing images reaches a second number threshold, determining that the second turning condition is met, and converting the moving direction of the lens.
The category of the target object may be a determined category of the detected target object when target detection is performed, and specifically, detection and recognition are performed by a target detection model pre-deployed in the computer device. The first set number may then be a preset number value. The second number threshold may be a maximum number of second in-focus images acquired during the second in-focus process set in the second u-turn condition.
In this embodiment, as shown in fig. 3, the first moving speed is V1, the first set number is 2, and the second number threshold is 45, for example. The first moving speed V1 is smaller than the initial speed V0, and the interval between the collected images is moderate (smaller than the interval between the collected images in the first focusing process), so that images with the definition being calculated can be continuously collected. Specifically, the computer device sequentially acquires second focusing images when the lens moves at a first moving speed V1 in a second focusing process (such as a second process in the figure), sequentially detects targets of the second focusing images, further acquires definition of the second focusing images when a target object is detected, identifies whether the second focusing images are second target focusing images according to the category of the detected target object, determines a second focusing image with the largest definition acquired in the second focusing process when the second focusing images are identified as the second target focusing images, and continuously acquires a first set number of second focusing images with definition such as 2 after the second focusing images with the largest definition, determines that a second turning condition is met, and can turn around to switch the moving direction of the lens so as to shorten the focusing process.
It is to be understood that the second focusing image with the greatest sharpness may be the same focusing image as the second target focusing image, or may be a different focusing image, which is not limited in this embodiment, and the determination is made based on the actual measured value. Specifically, the second target focus image refers to a second focus image in which the number of target objects of a target class in the image is greater than or equal to 50%, that is, the ratio of the number of target objects of a target class in the image to the total number of target objects of all classes in the image is greater than or equal to 50%. Specifically, the category refers to a category corresponding to different states when a target object in an image changes from near blur to clear and then to far blur in a focusing process, for example, a category of a state with extremely high exposure under near blur, a category of a state with relatively high exposure under near blur, a category of a clear state, and a category of a state under far blur. The target class may then be a clear state class. That is, the second target focused image refers to a second focused image in which the number of state categories in which sperm are clear in the image is 50% or more. It should be noted that, the category of the target object may be detected and identified by a target detection model pre-deployed in the computer device.
In one scenario, if no second target focus image is identified in the second focus images, and the number of the second focus images reaches a second number threshold, for example, 45 (i.e., when the top u-turn condition is satisfied), it may be determined that the second u-turn condition is satisfied, and the lens may be turned around to change the moving direction of the lens, thereby shortening the focusing process.
In one scenario, if the second target focusing image is identified in the second focusing images, but after the second focusing image with the largest definition, the first set number of second focusing images with the definition, for example, 2 second focusing images with the definition, are not continuously collected, and when the number of the second focusing images reaches the second number threshold value, for example, 45, it can be determined that the second turning condition is met, and the moving direction of the lens is converted, so that the focusing process is shortened.
Step 206, acquiring the third focusing image and the number of the third focusing images acquired when the lens moves at the second moving speed in the third focusing process, converting the moving direction of the lens when the third turning condition is met according to the third focusing image and the number of the third focusing images, and determining the third moving speed of the fourth focusing process after turning based on the preset speed descending trend.
The second movement speed may be a movement speed of the lens in the third focusing process preset in the focusing process parameter. The third focusing image is a focusing image collected in the third focusing process, and the third turning-around condition is a condition for triggering turning around in the third focusing process. The fourth focusing process is the next focusing process adjacent to the third focusing process, and the third moving speed is the moving speed of the lens in the fourth focusing process.
In this embodiment, when the computer device controls the lens to turn around to enter the third focusing process based on the above steps, the computer device may further obtain the collected third focusing image and the number of the third focusing image when the lens moves at the second moving speed in the third focusing process, and when the third focusing image and the number of the third focusing image are determined to meet the third turning around condition, the moving direction of the lens is converted, that is, the lens is controlled to turn around and enter the fourth focusing process, and meanwhile, the third moving speed of the fourth focusing process after turning around is determined based on the preset speed decreasing trend.
Specifically, the computer equipment acquires a third focusing image acquired when the lens moves at a second moving speed in a third focusing process, performs target detection on the third focusing image, and acquires the definition of the third focusing image when a target object is detected; when the third focusing image is identified as the third target focusing image based on the category of the target object, determining the last third focusing image with definition acquired in the third focusing process, if a second set number of third focusing images without definition are continuously acquired after the last third focusing image with definition, determining that the third turning condition is met, and converting the moving direction of the lens. Or if the third target focusing image is not recognized in the third focusing images and the number of the third focusing images reaches a third number threshold, determining that the third turning condition is met, and converting the moving direction of the lens. Or if the third target focusing image is identified in the third focusing images, but after the last third focusing image with definition, the second set number of third focusing images without definition are not continuously acquired, and the number of the third focusing images reaches a third number threshold, determining that a third turning condition is met, and converting the moving direction of the lens.
The second set number may be a preset number value. The third number threshold may be a maximum number of third in-focus images acquired during a third in-focus process set in a third u-turn condition.
In this embodiment, as shown in fig. 3, the second moving speed is V2, the second set number is 5, and the third number threshold is 90, for example. The second moving speed V2 is smaller than the first moving speed V1, and the interval between the collected images is smaller, so that the image definition gap near the image with the maximum definition becomes smaller. Based on this, the computer device further acquires the sharpness of the third focusing image by acquiring the third focusing image sequentially acquired when the lens moves at the second moving speed V2 in the third focusing process (such as the third process in the figure) and sequentially performing target detection on the third focusing image, when the target object is detected. And identifying whether the third focusing image is a third target focusing image according to the detected category of the target object, determining the last third focusing image with definition acquired in the third focusing process when the third focusing image is identified as the third target focusing image, and if a second set number of third focusing images without definition, such as 5 third focusing images without definition, are continuously acquired after the last third focusing image with definition, determining that a third turning condition is met, and turning around to change the moving direction of the lens, thereby shortening the focusing process.
Specifically, the third target focusing image refers to a third focusing image in which the number of target objects of the target class in the image is greater than or equal to 50%, that is, the ratio of the number of target objects of the target class in the image to the total number of target objects of all classes in the image is greater than or equal to 50%. The target class can be a clear state class, and the target object is sperms. That is, the third target focused image is a third focused image in which the number of the state categories in which the sperm are clear in the image is 50% or more. It should be noted that, the category of the target object may be detected and identified by a target detection model pre-deployed in the computer device.
In one scenario, if no third target focusing image is identified in the third focusing images, and the number of the third focusing images reaches a third number threshold, for example, 90 (i.e., when the bottom turning condition is met), it may be determined that the third turning condition is met, that is, the lens may be turned around to change the moving direction of the lens, so as to shorten the focusing process.
In one scenario, if the third target focusing image is identified in the third focusing images, but after the last third focusing image with definition, the second set number of third focusing images without definition are not continuously collected, and when the number of the third focusing images reaches a third number threshold, for example, 90, it may be determined that the third turning condition is met, and the moving direction of the lens is converted, so that the focusing process is shortened.
Step 208, acquiring the fourth focusing image and the number of the fourth focusing images acquired when the lens moves at the third moving speed in the fourth focusing process, and controlling the lens to stop moving when the termination condition is determined to be met according to the number of the fourth focusing images and the number of the fourth focusing images.
The third movement speed may be a movement speed of the lens in the fourth focusing process preset in the focusing process parameter. The fourth focusing image is a focusing image collected in the fourth focusing process, and the termination condition is a condition for terminating the focusing process, namely a triggering condition for completing focusing.
In this embodiment, after the computer device controls the lens to turn around to enter the fourth focusing process based on the above steps, the computer device may further obtain the fourth focusing image and the number of fourth focusing images collected when the lens moves at the third moving speed in the fourth focusing process, and when it is determined that the termination condition is met according to the fourth focusing image and the number of fourth focusing images, control the lens to stop moving, thereby completing the focusing process.
Specifically, the computer equipment acquires a fourth focusing image when the lens moves at a third moving speed in a fourth focusing process, performs target detection on the fourth focusing image, and acquires definition of the fourth focusing image when a target object is detected; when the fourth focusing image is identified as the fourth target focusing image based on the category of the target object, determining the fourth focusing image with the largest definition acquired in the fourth focusing process, determining the target focusing image with the largest definition acquired in the second focusing process and the third focusing process, and when the difference between the definition of the fourth focusing image with the largest definition and the definition of the target focusing image is larger than a set threshold value, determining that a termination condition is met, and controlling the lens to stop moving; or if the fourth target focusing image is not recognized in the fourth focusing images and the number of the fourth focusing images reaches a fourth number threshold, determining that a termination condition is met, and controlling the lens to stop moving; or if the fourth target focusing image is identified in the fourth focusing images, but the difference between the definition of the fourth focusing image with the largest definition and the definition of the target focusing image is smaller than or equal to a set threshold value, and the number of the fourth focusing images reaches a fourth number threshold value, determining that the termination condition is met, and controlling the lens to stop moving. Because the moving speed of the lens is very small at this moment, when the motor lens of the microscope is informed to stop moving, the microscope can only move forward at very slow speed due to inertia, so that the microscope finally stays in a clear range, the problem that the lens of the microscope is inaccurately positioned due to continuous movement of the inertia after the lens of the microscope stops at high speed is solved, and the focusing is more accurate.
The set threshold may be a preset sharpness threshold condition, and the fourth number threshold may be a maximum number of fourth focusing images acquired in a fourth focusing process, which are set in the focusing process parameters.
In the present embodiment, as shown in fig. 3, the third moving speed is V3, and the fourth number threshold is 180, for example. The third moving speed V3 is smaller than the second moving speed V2, the interval between the collected images is smaller, and the change of the definition of the adjacent images is tiny. Based on this, the computer device acquires the fourth focusing images sequentially acquired when the lens moves at the third moving speed V3 in the fourth focusing process (such as the fourth process in the figure), and sequentially performs target detection on the fourth focusing images, and further acquires the sharpness of the fourth focusing images when the target object is detected. And identifying whether the fourth focusing image is a fourth target focusing image according to the detected type of the target object, when the fourth focusing image is identified as the fourth target focusing image, determining the fourth focusing image with the largest definition acquired in the fourth focusing process, and determining the target focusing image with the largest definition acquired in the second focusing process and the third focusing process, namely determining one focusing image with the largest definition from all focusing images acquired in the second focusing process and the third focusing process as the target focusing image, and determining that a termination condition is met when the difference between the definition of the fourth focusing image with the largest definition and the definition of the target focusing image is larger than a set threshold value, and controlling the lens to stop moving so as to complete the focusing process.
Specifically, the set threshold may be determined based on the sharpness of the target in-focus image, for example, a negative of twenty percent of the sharpness of the target in-focus image may be taken as the set threshold. The fourth target focusing image is a fourth focusing image with the number of target objects in the target class in the image being greater than or equal to 50%, that is, the ratio of the number of target objects in the target class in the image to the total number of target objects in all classes in the image is greater than or equal to 50%. The target class can be a clear state class, and the target object is sperms. That is, the fourth target focused image is a fourth focused image in which the number of the state categories in which the sperm are clear in the image is 50% or more. It should be noted that, the category of the target object may be detected and identified by a target detection model pre-deployed in the computer device.
In one scenario, if none of the fourth target focus images is identified in the fourth focus images, and the number of the fourth focus images reaches a fourth number threshold, for example 180, it may be determined that a termination condition is satisfied, and the lens is controlled to stop moving, so as to complete focusing.
In one scenario, if the fourth target focus image is identified in the fourth focus images, but the difference between the sharpness of the fourth focus image with the largest sharpness and the sharpness of the target focus image is smaller than or equal to the set threshold, and the number of the fourth focus images reaches the fourth number threshold, for example, 180, it may be determined that the termination condition is satisfied, and the lens is controlled to stop moving, so as to complete focusing.
In an exemplary embodiment, in the above focusing process, the preset speed-down trend may be a speed-down coefficient preset based on a set speed, for example, a speed-down coefficient l= [1,0.5,0.333,0.0111], and if the set speed is V, a speed vi=v×l [ i ] of each focusing process, where L [ i ] is an i-th element in L. For example, the initial velocity v0=v×1, the first moving velocity v1=v×0.5, the second moving velocity v2=v×0.333, and the third moving velocity v3=v×0.0111. The first moving speed is less than the initial speed, the second moving speed is less than the first moving speed, and the third moving speed is less than the second moving speed in the whole focusing process. The speed in the focusing process is gradually reduced, the next focusing process and the moving speed are continuously shortened, the effective field of view of which definition needs to be calculated is reduced, the focusing time length is also reduced, and the focusing efficiency is improved.
In an exemplary embodiment, as shown in fig. 4, the method for acquiring the sharpness of the focusing image may include the steps of:
Step 402, identifying the category and the number under each category of the target object in the focusing image, and acquiring the first definition corresponding to the category according to the preset category weight and the number under each category.
Wherein the focus image includes any one of a second focus image, a third focus image, and a fourth focus image. That is, the sharpness of the focused image acquired in different focusing processes is the same in the calculation method. The target object is sperm. The category of the target object is a determined category of the detected target object when the focused image is subjected to target detection, and is specifically detected and identified by a target detection model which is deployed in advance in the computer equipment. Specifically, the category refers to a category corresponding to different states when a target object in an image changes from near blur to clear to far blur in a focusing process. The state type with extremely high exposure degree in near blur may be set to 0, the state type with relatively high exposure degree in near blur may be set to 1, the clear state type may be set to 2 (the state where the small sperm head is the most clear state), and the state type in far blur may be set to 3. The category weight is used to measure the importance of the corresponding category.
Specifically, taking a sperm image as an example, the definition of the sperm image has an important influence on the morphological evaluation of the sperm, and the sperm image with clear focusing can accurately distinguish whether the sperm is normal or not. According to the manual 6 of the laboratory for human semen inspection and treatment of the world health organization, the normal sperm head should be smooth in appearance, regular in outline, substantially elliptical, with the top body zone clearly distinguishable, accounting for 40% -70% of the head, without large vacuoles, and no more than two small vacuoles, and the top body rear zone free of any vacuoles. The outline of the abnormal sperm head is in a conical shape, a pear shape, an irregular shape and the like, and the abnormal sperm head structure also has the condition of excessive number of acrosome and vacuoles. Therefore, the sperm definition under different focal lengths in the microscope focusing process can be distinguished according to the shape, structure and color of the sperm head, so that the image can be classified into the state categories, and the method is as follows:
For the state class 0 with extremely high exposure degree under near blurring, as shown in fig. 5A, the state is mainly represented by overexposure of sperm head, the overexposure of obvious highlight area appears on the whole, the state is represented by pure white or nearly white, so that most of details are lost, the background is gray, and the whole small image presents gray tone.
For the state type 1 with higher exposure degree under near blurring, as shown in fig. 5B, the color of the whole head of the sperm is bright and light green, no obvious boundary exists between the acrosome region and the rear region of the acrosome, no obvious outline exists in the vacuole or the center of the vacuole is higher in exposure, so that the vacuole is highlighted, the head of the sperm is consistent with the background color, no obvious outline boundary exists, and the shape of the head of the sperm is not easy to be distinguished.
For the clear state category 2, as shown in fig. 5C, the sperm head has a clear and sharp outline head, and is clear and distinct from the edge of the background, and has no blurred or blurred area, so that the sperm head can accurately display the microstructure and color change of the sperm, the whole sperm head presents dark green, and the background is light grey green. If the sperm has acrosome and vacuole, the acrosome area (light white) and the rear area (dark green) of the sperm and the vacuole area (white) can be clearly distinguished.
For the state class 3 under far blurring, as shown in fig. 5D, the main appearance is that the edge contour is not clear, and lack of definition and sharpness, so that the whole image is blurred, and the colors may be mixed or graded, so that the whole image presents a turbid and blackish green tone. The outline of the head also has a circle of halation or blurry and blackish edge. And the outline of the head top body of the sperm and the outline of the vacuole cannot be distinguished.
In this embodiment, the computer device obtains the first definition corresponding to the category by identifying the category and the number under each category of the target object in the focused image, and according to the preset category weight and the number under each category. Specifically, in calculating the first sharpness, the calculation may be performed based on a sharp state class (including a class classified as 2) and a blurred state class (including a class classified as 0, 1, and 3). For example, if the class weight for the clear state class is 1.5 and the class weight for the blurred state class is 0.2, the class and the number under each class of sperm in the focused image are identified by the computer device, and the number a of sperm classified as 2 in the focused image and the number B of sperm classified as 0, 1 and 3 are counted, the first sharpness c1=a×1.5+b×0.2.
Step 404, identifying a target area of the target object in the focused image, and determining a second definition of the target object according to the gradient of each pixel point in the target area.
The target area refers to the head area of the sperm, and in this embodiment, the target area of the target object may be detected and identified by a target detection model deployed in advance in the computer device. The gradient of the pixel point can be calculated by using a Tenengrad gradient function (a function for calculating the image sharpness based on the gradient).
In this embodiment, the computer device may further identify a target area of the target object in the focused image, then determine a local sharpness, i.e., a second sharpness, of the corresponding target object according to a gradient of each pixel point in the target area, and then calculate the overall sharpness of the focused image by the following steps.
Specifically, the teningrad gradient function of a pixel point is defined as follows:
The preset matrix for calculating the gradient comprises the following steps:
,/>
where gx is the component of the sobel operator in the horizontal direction, and gy is the component of the sobel operator in the vertical direction. Gx is a first gradient value of the pixel point in the head region of the sperm in the horizontal direction, gy is a second gradient value of the pixel point in the head region of the sperm in the vertical direction. There is gx=gx×f (x, y), gy=gy×f (x, y), f (x, y) being the gray value of the pixel point (x, y) in the head region of the sperm. G (x, y) is the gray gradient value of the pixel point (x, y) in the head region of the sperm, i.e. the gradient of the pixel point in the target region.
And accumulating gradients of all pixel points in a head area of a certain sperm in the focusing image to obtain local definition of the corresponding sperm, namely obtaining second definition of a certain target object.
In step 406, the sharpness of the focused image is determined based on the first sharpness and the second sharpness.
Specifically, the computer device determines the overall definition of the focused image according to the acquired first definition and second definition.
Based on the steps, the local definition of each sperm in the corresponding image can be determined, namely, the second definition of each target object in the focusing image is obtained, the second definition of all the target objects in the focusing image is further averaged, the average definition of the target objects in the focusing image is obtained, and the sum of the average definition and the first definition is calculated, wherein the sum is the overall definition of the focusing image.
It can be understood that, based on the calculation of the definition, when the computer device detects and identifies the focused image through the pre-deployed target detection model, if any sperm of the above category is not identified, the definition of the focused image cannot be calculated, and only when the sperm of the above category is identified, the definition of the focused image can be calculated. That is, the in-focus image will have sharpness only if a specific class of sperm is identified.
In this embodiment, the definition of the sperm field of view can be accurately estimated by combining a deep learning algorithm (i.e., a pre-deployed target detection model), thereby meeting the high definition requirement of sperm morphology. In the whole asymptotic focusing process, definition is not required to be preset, the device is completely autonomous, the adaptability is strong, manual parameter adjustment is not required, the device has a good focusing effect on various fields of view of various semen, and the requirement of quick focusing can be met.
It should be understood that, although the steps in the flowcharts related to the embodiments described above are sequentially shown as indicated by arrows, these steps are not necessarily sequentially performed in the order indicated by the arrows. The steps are not strictly limited to the order of execution unless explicitly recited herein, and the steps may be executed in other orders. Moreover, at least some of the steps in the flowcharts described in the above embodiments may include a plurality of steps or a plurality of stages, which are not necessarily performed at the same time, but may be performed at different times, and the order of the steps or stages is not necessarily performed sequentially, but may be performed alternately or alternately with at least some of the other steps or stages.
Based on the same inventive concept, the embodiment of the application also provides a microscope automatic focusing device for realizing the microscope automatic focusing method. The implementation of the solution provided by the device is similar to that described in the above method, so specific limitations in one or more embodiments of the microscope auto-focusing device provided below can be found in the above limitations of the microscope auto-focusing method, and will not be repeated here.
In one exemplary embodiment, as shown in fig. 6, there is provided a microscope auto-focusing apparatus comprising: a control module 602 and a focus module 604, wherein:
the control module 602 is configured to control lens movement based on preset focusing process parameters, where the focusing process parameters include a turn-around number, a termination condition, a movement speed corresponding to each focusing process, and a turn-around condition;
The focusing module 604 is configured to obtain a focusing image collected when each focusing process moves at a corresponding moving speed and the number of focusing images, control the lens to turn around when a turning-around condition corresponding to the focusing process is met according to the focusing image and the number of focusing images, and move at the moving speed of the focusing process after turning around until the turning-around times are reached, and control the lens to stop moving when a termination condition is met, so as to complete focusing on the microscope.
In an exemplary embodiment, the number of turns is three, and the turning conditions include a first turning condition, a second turning condition, and a third turning condition; the focusing module is also used for: acquiring a first focusing image and the number of the first focusing images acquired when the lens moves at an initial speed in a first focusing process, converting the moving direction of the lens when the first turning condition is met according to the first focusing image and the number of the first focusing images, and determining the first moving speed of a second focusing process after turning around based on a preset speed descending trend; acquiring second focusing images and the number of the second focusing images acquired when the lens moves at a first moving speed in a second focusing process, converting the moving direction of the lens when the second turning condition is met according to the second focusing images and the number of the second focusing images, and determining the second moving speed of a third focusing process after turning around based on a preset speed descending trend; acquiring a third focusing image and the number of the third focusing images acquired when the lens moves at a second moving speed in a third focusing process, converting the moving direction of the lens when the third turning condition is met according to the third focusing image and the number of the third focusing image, and determining the third moving speed of a fourth focusing process after turning around based on a preset speed descending trend; and acquiring a fourth focusing image and the number of the fourth focusing images acquired when the lens moves at a third moving speed in a fourth focusing process, and controlling the lens to stop moving when the termination condition is determined to be met according to the fourth focusing image and the number of the fourth focusing images.
In an exemplary embodiment, the focusing module is further configured to: acquiring a first focusing image acquired when the lens moves at an initial speed in a first focusing process; performing target detection on the first focusing image, determining that the first focusing image is a first target focusing image when a target object is detected, acquiring a first position of the first target focusing image in the first focusing process, determining that a first turning-around condition is met if the interval between the second position of the first focusing image which is currently acquired and the first position of the first target focusing image reaches a set value, and converting the moving direction of the lens; or if no target object is detected in the first focusing images and the number of the first focusing images reaches a first number threshold, determining that a first turning condition is met, and converting the moving direction of the lens.
In an exemplary embodiment, the focusing module is further configured to: acquiring a second focusing image acquired when the lens moves at a first moving speed in a second focusing process; performing target detection on the second focusing image, and acquiring definition of the second focusing image when a target object is detected; when the second focusing image is identified as a second target focusing image based on the category of the target object, determining the second focusing image with the largest definition acquired in the second focusing process, if the first set number of second focusing images with the definition are continuously acquired after the second focusing image with the largest definition, determining that a second turning condition is met, and converting the moving direction of the lens; or if the second target focusing image is not recognized in the second focusing images and the number of the second focusing images reaches a second number threshold, determining that a second turning condition is met, and converting the moving direction of the lens; or if the second target focusing image is identified in the second focusing images, but after the second focusing image with the largest definition, the first set number of second focusing images with the definition are not continuously acquired, and the number of the second focusing images reaches a second number threshold, determining that a second turning condition is met, and converting the moving direction of the lens.
In an exemplary embodiment, the focusing module is further configured to: acquiring a third focusing image acquired when the lens moves at a second moving speed in a third focusing process; performing target detection on the third focusing image, and acquiring definition of the third focusing image when a target object is detected; when the third focusing image is identified as a third target focusing image based on the category of the target object, determining the last third focusing image with definition acquired in the third focusing process, if a second set number of third focusing images without definition are continuously acquired after the last third focusing image with definition, determining that a third turning condition is met, and converting the moving direction of the lens; or if the third target focusing image is not recognized in the third focusing images and the number of the third focusing images reaches a third number threshold, determining that a third turning condition is met, and converting the moving direction of the lens; or if the third target focusing image is identified in the third focusing images, but after the last third focusing image with definition, a second set number of third focusing images without definition are not continuously acquired, and the number of the third focusing images reaches a third number threshold, determining that a third turning condition is met, and converting the moving direction of the lens.
In an exemplary embodiment, the focusing module is further configured to: acquiring a fourth focusing image acquired when the lens moves at a third moving speed in a fourth focusing process; performing target detection on the fourth focusing image, and acquiring definition of the fourth focusing image when a target object is detected; when the fourth focusing image is identified as a fourth target focusing image based on the category of the target object, determining the fourth focusing image with the largest definition acquired in the fourth focusing process and determining the target focusing image with the largest definition acquired in the second focusing process and the third focusing process, and when the difference between the definition of the fourth focusing image with the largest definition and the definition of the target focusing image is larger than a set threshold value, determining that a termination condition is met, and controlling the lens to stop moving; or if the fourth target focusing image is not recognized in the fourth focusing images and the number of the fourth focusing images reaches a fourth number threshold, determining that a termination condition is met, and controlling the lens to stop moving; or if the fourth target focusing image is identified in the fourth focusing images, but the difference between the definition of the fourth focusing image with the largest definition and the definition of the target focusing image is smaller than or equal to a set threshold value, and the number of the fourth focusing images reaches a fourth number threshold value, determining that a termination condition is met, and controlling the lens to stop moving.
In an exemplary embodiment, the apparatus further includes a sharpness acquisition module for: identifying the category and the number under each category of the target object in the focusing image, and acquiring a first definition corresponding to the category according to the preset category weight and the number under each category, wherein the focusing image comprises any one of a second focusing image, a third focusing image and a fourth focusing image; identifying a target area of the target object in the focusing image, and determining a second definition of the target object according to the gradient of each pixel point in the target area; and determining the definition of the focusing image according to the first definition and the second definition.
In an exemplary embodiment, the first movement speed is less than the initial speed, the second movement speed is less than the first movement speed, and the third movement speed is less than the second movement speed.
The above-described modules in the microscope auto-focusing device may be implemented in whole or in part by software, hardware, and combinations thereof. The above modules may be embedded in hardware or may be independent of a processor in the computer device, or may be stored in software in a memory in the computer device, so that the processor may call and execute operations corresponding to the above modules.
In an exemplary embodiment, a computer device is provided, which may be a server or a terminal, and an internal structure diagram thereof may be as shown in fig. 7. The computer device includes a processor, a memory, an Input/Output interface (I/O) and a communication interface. The processor, the memory and the input/output interface are connected through a system bus, and the communication interface is connected to the system bus through the input/output interface. Wherein the processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, computer programs, and a database. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage media. The database of the computer device is used to store focusing process parameter data. The input/output interface of the computer device is used to exchange information between the processor and the external device. The communication interface of the computer device is used for communicating with an external terminal through a network connection. The computer program is executed by a processor to implement a microscope auto-focus method.
It will be appreciated by those skilled in the art that the structure shown in FIG. 7 is merely a block diagram of some of the structures associated with the present inventive arrangements and is not limiting of the computer device to which the present inventive arrangements may be applied, and that a particular computer device may include more or fewer components than shown, or may combine some of the components, or have a different arrangement of components.
In an exemplary embodiment, a computer device is provided comprising a memory and a processor, the memory having stored therein a computer program, the processor implementing the steps of the method as above when executing the computer program.
In one embodiment, a computer readable storage medium is provided, having stored thereon a computer program which, when executed by a processor, implements the steps of the method as above.
In one embodiment, a computer program product is provided comprising a computer program which, when executed by a processor, implements the steps of the method as above.
It should be noted that, the user information (including but not limited to user equipment information, user personal information, etc.) and the data (including but not limited to data for analysis, stored data, presented data, etc.) related to the present application are both information and data authorized by the user or sufficiently authorized by each party, and the collection, use and processing of the related data are required to meet the related regulations.
Those skilled in the art will appreciate that implementing all or part of the above described methods may be accomplished by way of a computer program stored on a non-transitory computer readable storage medium, which when executed, may comprise the steps of the embodiments of the methods described above. Any reference to memory, database, or other medium used in embodiments provided herein may include at least one of non-volatile and volatile memory. The nonvolatile Memory may include Read-Only Memory (ROM), magnetic tape, floppy disk, flash Memory, optical Memory, high density embedded nonvolatile Memory, resistive random access Memory (ReRAM), magneto-resistive random access Memory (Magnetoresistive Random Access Memory, MRAM), ferroelectric Memory (Ferroelectric Random Access Memory, FRAM), phase change Memory (PHASE CHANGE Memory, PCM), graphene Memory, and the like. Volatile memory can include random access memory (Random Access Memory, RAM) or external cache memory, and the like. By way of illustration, and not limitation, RAM can be in various forms such as static random access memory (Static Random Access Memory, SRAM) or dynamic random access memory (Dynamic Random Access Memory, DRAM), etc. The databases referred to in the embodiments provided herein may include at least one of a relational database and a non-relational database. The non-relational database may include, but is not limited to, a blockchain-based distributed database, and the like. The processor referred to in the embodiments provided in the present application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic unit, a data processing logic unit based on quantum computing, or the like, but is not limited thereto.
The technical features of the above embodiments may be arbitrarily combined, and all possible combinations of the technical features in the above embodiments are not described for brevity of description, however, as long as there is no contradiction between the combinations of the technical features, they should be considered as the scope of the description.
The foregoing examples illustrate only a few embodiments of the application and are described in detail herein without thereby limiting the scope of the application. It should be noted that it will be apparent to those skilled in the art that several variations and modifications can be made without departing from the spirit of the application, which are all within the scope of the application. Accordingly, the scope of the application should be assessed as that of the appended claims.

Claims (11)

1. A method for automatically focusing a microscope, the method comprising:
Controlling lens movement based on preset focusing process parameters, wherein the focusing process parameters comprise turning times, termination conditions, movement speed corresponding to each focusing process and turning conditions;
Acquiring focusing images acquired when moving at a corresponding moving speed in each focusing process and the quantity of the focusing images, controlling the lens to turn around when a turning-around condition corresponding to the focusing process is met according to the focusing images and the quantity of the focusing images, and moving at the moving speed of the focusing process after turning around until the turning-around times are reached and the termination condition is met, and controlling the lens to stop moving to finish focusing on the microscope;
The turning times are three times, and the turning conditions comprise a first turning condition, a second turning condition and a third turning condition; the method for acquiring the focusing images and the quantity of the focusing images acquired when moving at the corresponding moving speed in each focusing process, when the turning condition of the corresponding focusing process is met according to the focusing images and the quantity of the focusing images, controlling the lens to turn around, and moving at the moving speed of the focusing process after turning around until the turning around times are reached, and when the termination condition is met, controlling the lens to stop moving comprises the following steps:
Acquiring a first focusing image and the number of the first focusing images acquired when the lens moves at an initial speed in a first focusing process, converting the moving direction of the lens when the first turning condition is met according to the first focusing image and the number of the first focusing images, and determining the first moving speed of a second focusing process after turning around based on a preset speed descending trend;
Acquiring second focusing images and the number of the second focusing images acquired when the lens moves at a first moving speed in a second focusing process, converting the moving direction of the lens when the second turning condition is met according to the second focusing images and the number of the second focusing images, and determining the second moving speed of a third focusing process after turning around based on a preset speed descending trend;
acquiring a third focusing image and the number of the third focusing images acquired when the lens moves at a second moving speed in a third focusing process, converting the moving direction of the lens when the third turning condition is met according to the third focusing image and the number of the third focusing image, and determining the third moving speed of a fourth focusing process after turning around based on a preset speed descending trend;
and acquiring a fourth focusing image and the number of the fourth focusing images acquired when the lens moves at a third moving speed in a fourth focusing process, and controlling the lens to stop moving when the termination condition is determined to be met according to the fourth focusing image and the number of the fourth focusing images.
2. The method of claim 1, wherein the acquiring the first focus image and the number of first focus images acquired when the lens moves at an initial speed in a first focusing process, and when it is determined that a first u-turn condition is satisfied according to the first focus image and the number of first focus images, switching the moving direction of the lens comprises:
Acquiring a first focusing image acquired when the lens moves at an initial speed in a first focusing process;
performing target detection on the first focusing image, determining that the first focusing image is a first target focusing image when a target object is detected, acquiring a first position of the first target focusing image in the first focusing process, determining that a first turning-around condition is met if the interval between the second position of the first focusing image which is currently acquired and the first position of the first target focusing image reaches a set value, and converting the moving direction of the lens; or alternatively
And if no target object is detected in the first focusing images and the number of the first focusing images reaches a first number threshold, determining that a first turning condition is met, and converting the moving direction of the lens.
3. The method of claim 1, wherein the acquiring the second focus image and the number of second focus images acquired when the lens moves at the first moving speed in the second focusing process, and when it is determined that the second turning condition is satisfied according to the second focus image and the number of second focus images, switching the moving direction of the lens includes:
Acquiring a second focusing image acquired when the lens moves at a first moving speed in a second focusing process;
performing target detection on the second focusing image, and acquiring definition of the second focusing image when a target object is detected;
When the second focusing image is identified as a second target focusing image based on the category of the target object, determining the second focusing image with the largest definition acquired in the second focusing process, if the first set number of second focusing images with the definition are continuously acquired after the second focusing image with the largest definition, determining that a second turning condition is met, and converting the moving direction of the lens; or alternatively
If the second target focusing image is not recognized in the second focusing images and the number of the second focusing images reaches a second number threshold, determining that a second turning condition is met, and converting the moving direction of the lens; or alternatively
If the second target focusing image is identified in the second focusing images, but after the second focusing image with the largest definition, the first set number of second focusing images with the definition are not continuously acquired, and the number of the second focusing images reaches a second number threshold, determining that a second turning condition is met, and converting the moving direction of the lens.
4. The method of claim 1, wherein the acquiring the third focus image and the number of third focus images acquired when the lens moves at the second moving speed in the third focusing process, and when it is determined that the third turning condition is satisfied according to the third focus image and the number of third focus images, switching the moving direction of the lens includes:
Acquiring a third focusing image acquired when the lens moves at a second moving speed in a third focusing process;
Performing target detection on the third focusing image, and acquiring definition of the third focusing image when a target object is detected;
When the third focusing image is identified as a third target focusing image based on the category of the target object, determining the last third focusing image with definition acquired in the third focusing process, if a second set number of third focusing images without definition are continuously acquired after the last third focusing image with definition, determining that a third turning condition is met, and converting the moving direction of the lens; or alternatively
If the third target focusing image is not recognized in the third focusing images and the number of the third focusing images reaches a third number threshold, determining that a third turning condition is met, and converting the moving direction of the lens; or alternatively
If the third target focusing image is identified in the third focusing images, but after the last third focusing image with definition, a second set number of third focusing images without definition are not continuously acquired, and the number of the third focusing images reaches a third number threshold, determining that a third turning condition is met, and converting the moving direction of the lens.
5. The method of claim 1, wherein the acquiring the fourth focus image and the number of fourth focus images acquired when the lens moves at the third movement speed during the fourth focusing, and controlling the lens to stop moving when it is determined that a termination condition is satisfied according to the fourth focus image and the number of fourth focus images, comprises:
Acquiring a fourth focusing image acquired when the lens moves at a third moving speed in a fourth focusing process;
Performing target detection on the fourth focusing image, and acquiring definition of the fourth focusing image when a target object is detected;
When the fourth focusing image is identified as a fourth target focusing image based on the category of the target object, determining the fourth focusing image with the largest definition acquired in the fourth focusing process and determining the target focusing image with the largest definition acquired in the second focusing process and the third focusing process, and when the difference between the definition of the fourth focusing image with the largest definition and the definition of the target focusing image is larger than a set threshold value, determining that a termination condition is met, and controlling the lens to stop moving; or alternatively
If the fourth target focusing image is not recognized in the fourth focusing images and the number of the fourth focusing images reaches a fourth number threshold, determining that a termination condition is met, and controlling the lens to stop moving; or alternatively
And if the fourth target focusing image is identified in the fourth focusing images, but the difference between the definition of the fourth focusing image with the largest definition and the definition of the target focusing image is smaller than or equal to a set threshold value, and the number of the fourth focusing images reaches a fourth number threshold value, determining that a termination condition is met, and controlling the lens to stop moving.
6. The method according to any one of claims 3 to 5, wherein the method for acquiring the sharpness of the focused image includes:
Identifying the category and the number under each category of the target object in the focusing image, and acquiring a first definition corresponding to the category according to the preset category weight and the number under each category, wherein the focusing image comprises any one of a second focusing image, a third focusing image and a fourth focusing image;
identifying a target area of the target object in the focusing image, and determining a second definition of the target object according to the gradient of each pixel point in the target area;
And determining the definition of the focusing image according to the first definition and the second definition.
7. The method of any one of claims 1 to 5, wherein the first movement speed is less than the initial speed, the second movement speed is less than the first movement speed, and the third movement speed is less than the second movement speed.
8. An autofocus device for a microscope, the device comprising:
the control module is used for controlling the lens to move based on preset focusing process parameters, wherein the focusing process parameters comprise turning frequency, termination conditions, moving speed corresponding to each focusing process and turning conditions;
The focusing module is used for acquiring focusing images acquired when moving at a corresponding moving speed in each focusing process and the quantity of the focusing images, controlling the lens to turn around when a turning-around condition corresponding to the focusing process is met according to the focusing images and the quantity of the focusing images, and moving at the moving speed of the focusing process after turning around until the turning-around times are reached and the termination condition is met, and controlling the lens to stop moving to finish focusing on the microscope;
The turning times are three times, and the turning conditions comprise a first turning condition, a second turning condition and a third turning condition; the focusing module is specifically used for:
Acquiring a first focusing image and the number of the first focusing images acquired when the lens moves at an initial speed in a first focusing process, converting the moving direction of the lens when the first turning condition is met according to the first focusing image and the number of the first focusing images, and determining the first moving speed of a second focusing process after turning around based on a preset speed descending trend;
Acquiring second focusing images and the number of the second focusing images acquired when the lens moves at a first moving speed in a second focusing process, converting the moving direction of the lens when the second turning condition is met according to the second focusing images and the number of the second focusing images, and determining the second moving speed of a third focusing process after turning around based on a preset speed descending trend;
acquiring a third focusing image and the number of the third focusing images acquired when the lens moves at a second moving speed in a third focusing process, converting the moving direction of the lens when the third turning condition is met according to the third focusing image and the number of the third focusing image, and determining the third moving speed of a fourth focusing process after turning around based on a preset speed descending trend;
and acquiring a fourth focusing image and the number of the fourth focusing images acquired when the lens moves at a third moving speed in a fourth focusing process, and controlling the lens to stop moving when the termination condition is determined to be met according to the fourth focusing image and the number of the fourth focusing images.
9. A computer device comprising a memory and a processor, the memory storing a computer program, characterized in that the processor implements the steps of the method of any of claims 1 to 7 when the computer program is executed.
10. A computer readable storage medium, on which a computer program is stored, characterized in that the computer program, when being executed by a processor, implements the steps of the method of any of claims 1 to 7.
11. A computer program product comprising a computer program, characterized in that the computer program, when being executed by a processor, implements the steps of the method of any of claims 1 to 7.
CN202410259113.7A 2024-03-07 Microscope automatic focusing method, device, computer equipment and storage medium Active CN117850017B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202410259113.7A CN117850017B (en) 2024-03-07 Microscope automatic focusing method, device, computer equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202410259113.7A CN117850017B (en) 2024-03-07 Microscope automatic focusing method, device, computer equipment and storage medium

Publications (2)

Publication Number Publication Date
CN117850017A CN117850017A (en) 2024-04-09
CN117850017B true CN117850017B (en) 2024-06-07

Family

ID=

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US4931630A (en) * 1989-04-04 1990-06-05 Wyko Corporation Apparatus and method for automatically focusing an interference microscope
CN103760663A (en) * 2014-01-14 2014-04-30 宁波基内生物技术有限公司 Self-adaptive microscope, and use method and self-adaptive focusing method thereof
CN106772983A (en) * 2015-11-23 2017-05-31 大连光耀辉科技有限公司 A kind of microscope of auto-focusing
CN106842534A (en) * 2017-03-22 2017-06-13 上海理工大学 Auto-focusing microscope and measuring method based on double CCD

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US4931630A (en) * 1989-04-04 1990-06-05 Wyko Corporation Apparatus and method for automatically focusing an interference microscope
CN103760663A (en) * 2014-01-14 2014-04-30 宁波基内生物技术有限公司 Self-adaptive microscope, and use method and self-adaptive focusing method thereof
CN106772983A (en) * 2015-11-23 2017-05-31 大连光耀辉科技有限公司 A kind of microscope of auto-focusing
CN106842534A (en) * 2017-03-22 2017-06-13 上海理工大学 Auto-focusing microscope and measuring method based on double CCD

Similar Documents

Publication Publication Date Title
CN111007661B (en) Microscopic image automatic focusing method and device based on deep learning
US10444486B2 (en) Systems and methods for detection of blank fields in digital microscopes
AU2011357735B2 (en) Fast auto-focus in microscopic imaging
CN111083365B (en) Method and device for rapidly detecting optimal focal plane position
CN109782414B (en) Automatic focusing method based on definition of non-reference structure
JP6000699B2 (en) Cell division process tracking device and cell division process tracking program
CN111462075B (en) Rapid refocusing method and system for full-slice digital pathological image fuzzy region
CN105407265B (en) Interchangeable lens device, image capture apparatus and control method
CN111462076A (en) Method and system for detecting fuzzy area of full-slice digital pathological image
CN111948784B (en) Iterative optimization automatic focusing method based on hill climbing method
CN106934804B (en) Image definition detection method and device
CN106031148A (en) Imaging device and method for automatic focus in an imaging device as well as a corresponding computer program
US20220012884A1 (en) Image analysis system and analysis method
CN111932542B (en) Image identification method and device based on multiple focal lengths and storage medium
DE102020108640A1 (en) Voice-controlled camera with AI scene detection for precise focusing
CN114760415B (en) Lens focusing method, system, equipment and medium
JP6045292B2 (en) Cell counting device and cell counting program
CN114785959B (en) Automatic focusing method and device for fluorescence microscope, storage medium and electronic equipment
CN113822877B (en) AOI equipment microscope defect detection picture quality evaluation method and system
CN113237881B (en) Detection method and device for specific cells and pathological section detection system
CN113538545A (en) Monocular depth estimation method based on electro-hydraulic adjustable-focus lens and corresponding camera and storage medium
CN117850017B (en) Microscope automatic focusing method, device, computer equipment and storage medium
CN117850017A (en) Microscope automatic focusing method, device, computer equipment and storage medium
CN114998980B (en) Iris detection method and device, electronic equipment and storage medium
WO2020010634A1 (en) Cell image processing system and method, automatic smear reading device, and storage medium

Legal Events

Date Code Title Description
PB01 Publication
SE01 Entry into force of request for substantive examination
GR01 Patent grant