Automatic focusing method and system for cell microscopic examination
By acquiring and processing the initial images of cell microscopy, a matrix is constructed to adjust the focus position, which solves the focusing errors caused by bubbles or impurities and ensures the accuracy and clarity of autofocus in cell microscopy.
Patent Information
- Application Number
- CN202511153105.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-18
- Publication Date
- 2025-11-14
AI Technical Summary
During blood cell microscopy, air bubbles or impurities can cause autofocus errors, affecting the accuracy of cell counting.
The system acquires an initial image using an action camera, obtains a target image based on its sharpness score, performs preprocessing to obtain pixels, constructs first and second matrices, iterates through the matrices to obtain the optimal value, and adjusts the focus position.
It achieves automatic focusing, avoiding focusing errors caused by bubbles or impurities, and ensuring the clarity of cell images and the accuracy of cell counting.
Smart Images

Figure CN120949432A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of cell microscopy technology, and in particular to an automatic focusing method and system for cell microscopy. Background Technology
[0002] In the process of blood cell microscopy, autofocus is required to capture clear cell images. Autofocus methods generally involve acquiring images from multiple positions along the vertical direction of the cell counting chamber and calculating the sharpness of each image, such as the gradient method, variance method, and Laplacian operator. However, regardless of the sharpness evaluation method, it may be affected by air bubbles or impurities. Furthermore, because air bubbles and cells have a large density difference, they are often not on the same plane, causing a deviation in the focus plane found during the autofocus process, thus failing to capture cells and resulting in counting errors.
[0003] Therefore, providing an automatic focusing method and system for cell microscopy that avoids focusing errors caused by air bubbles or impurities is a technical problem that urgently needs to be solved by those skilled in the art. Summary of the Invention
[0004] To address the aforementioned technical problems, the present invention aims to provide an automatic focusing method and system for cell microscopy, which can achieve automatic focusing while avoiding focusing errors caused by air bubbles or impurities.
[0005] The first objective of this invention is to provide an automatic focusing method for cell microscopy. The technical solution provided by this invention is as follows: An automated focusing method for cell microscopy includes the following steps: Acquire initial images using an action camera; The initial image is scored based on its clarity to obtain the target image; The target image is preprocessed to obtain the pixels of the target image; Construct a first matrix and a second matrix based on the pixels; The optimal value is obtained by traversing the first matrix and the second matrix; The focus position is adjusted by determining the optimal value.
[0006] Preferably, acquiring the initial image using an action camera specifically includes: Control the movement of the lens barrel and camera to the pre-focus position; The lens barrel is controlled to move upward to half of the preset range S. When the lens barrel moves T steps, the initial image is acquired through the camera.
[0007] Preferably, the step of scoring the initial image based on its clarity to obtain the target image specifically includes: Calculate the sharpness of the initial image; The initial image is scored based on its clarity, and the image with the highest score is selected as the target image.
[0008] Preferably, the preprocessing of the target image to obtain the pixels of the target image specifically includes: Convert the target image into a grayscale image; The grayscale image is binarized to obtain the pixels of the grayscale image.
[0009] Preferably, constructing the first matrix and the second matrix based on the pixels specifically includes: Get the pixels with a value of 1 in the row direction; Iterate through all rows to construct the first matrix.
[0010] Preferably, constructing the first matrix and the second matrix based on the pixels specifically includes: Get the pixels with a value of 1 in the row and column directions; Iterate through all columns to construct the second matrix.
[0011] Preferably, the step of traversing the first matrix and the second matrix to obtain the optimal value specifically includes: The optimal value of all values in the first matrix and the second matrix is obtained by traversing the first matrix and the second matrix.
[0012] Preferably, the step of adjusting the focus position by judging the optimal value specifically includes: If the optimal value is not less than the judgment threshold, then adjust the focus position of the counting plate; If the optimal value is less than the determination threshold, then a cell image is acquired at the current location.
[0013] The second objective of this invention is to provide an automated focusing system for cell microscopy. The technical solution provided by this invention is as follows: An automated focusing system for cell microscopy includes: a first acquisition module, a scoring module, a second acquisition module, a construction module, a traversal module, and a judgment module; The first acquisition module is used to acquire an initial image using a motion camera; The scoring module is used to score the initial image based on its clarity in order to obtain the target image; The second acquisition module is used to preprocess the target image to obtain the pixels of the target image; The construction module is used to construct a first matrix and a second matrix based on the pixels; The traversal module is used to obtain the optimal value by traversing the first matrix and the second matrix; The judgment module is used to adjust the focus position by judging the optimal value.
[0014] This invention provides an automatic focusing method for cell microscopy, which involves acquiring an initial image using a motion camera; scoring the initial image based on its clarity to obtain a target image; preprocessing the target image to obtain its pixels; constructing a first matrix and a second matrix based on the pixels; obtaining an optimal value by traversing the first matrix and the second matrix; and adjusting the focus position by judging the optimal value. This method achieves automatic focusing by processing the initial image, while avoiding focusing errors caused by air bubbles or impurities.
[0015] The present invention also provides an automatic focusing system for cell microscopy. Since this system and the automatic focusing method for cell microscopy solve the same technical problem and belong to the same technical concept, they should have the same beneficial effects, and will not be described in detail here. Attached Figure Description
[0016] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0017] Figure 1 This is a flowchart illustrating an automatic focusing method for cell microscopy in an embodiment of the present invention. Figure 2 This is a schematic diagram of an automated focusing system for cell microscopy in an embodiment of the present invention; Figure 3 This is a schematic diagram of the structure of an electronic device according to an embodiment of the present invention. Detailed Implementation
[0018] To enable those skilled in the art to better understand the technical solutions in this application, the technical solutions in the embodiments of this application will be clearly and completely described below. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0019] like Figure 1 As shown, this embodiment of the invention provides an automatic focusing method for cell microscopy, comprising the following steps: S1. Acquire the initial image using an action camera; S2. Score the initial image based on its clarity to obtain the target image; S3. Preprocess the target image to obtain the pixels of the target image; S4. Construct a first matrix and a second matrix based on the pixels; S5. Obtain the optimal value by traversing the first matrix and the second matrix; S6. Adjust the focus position by judging the optimal value.
[0020] In steps S1 to S6, an initial cell image is captured using a motion camera. The sharpness of this initial cell image is then calculated, and a score is given based on the sharpness to obtain a target image. The target image is then preprocessed to obtain its pixel count. Two matrices, a first matrix and a second matrix, are constructed based on the obtained pixel count. The first and second matrices are iterated through to obtain their optimal values. Finally, the optimal values are used to adjust the focus position, thereby achieving automatic focusing while avoiding focusing errors caused by bubbles or impurities.
[0021] Preferably, acquiring the initial image using an action camera specifically includes: Control the movement of the lens barrel and camera to the pre-focus position; The lens barrel is controlled to move upward to half of the preset range S. When the lens barrel moves T steps, the initial image is acquired through the camera.
[0022] In practical application, the stage system drives the counting plate to move to the starting position of the image capture, the Z-axis system drives and controls the lens barrel and camera to move to the pre-focus position, and the Z-axis drive system controls the lens barrel to move upward by half of the preset range S. Then, the camera acquires one initial image for every T steps the lens barrel moves, for a total of S / T initial images, each initial image having a pixel value of M x N.
[0023] Preferably, the step of scoring the initial image based on its clarity to obtain the target image specifically includes: Calculate the sharpness of the initial image; The initial image is scored based on its clarity, and the image with the highest score is selected as the target image.
[0024] In practical applications, the sharpness of S / T initial images is calculated, and then the initial images are scored based on their sharpness. The image with the highest score is selected as the target image, and the target image is assigned the number L.
[0025] Preferably, the preprocessing of the target image to obtain the pixels of the target image specifically includes: Convert the target image into a grayscale image; The grayscale image is binarized to obtain the pixels of the grayscale image.
[0026] In practical applications, the Lth target image is preprocessed. The first step is to convert the Lth target image into a grayscale image. The second step is to perform binarization on the grayscale image, that is, to assign a value of 1 to pixels with a grayscale value greater than a certain grayscale threshold (preferably 110), and to assign a value of 0 to pixels with a grayscale value less than or equal to the grayscale threshold.
[0027] Preferably, constructing the first matrix and the second matrix based on the pixels specifically includes: Get the pixels with a value of 1 in the row direction; Iterate through all rows to construct the first matrix.
[0028] In practical application, the number of pixels with a value of 1 in the row direction after binarization of the image is counted as follows: If a pixel with a value of 0 is encountered for the first time in the i-th row, the first statistical value Ki1 of that row is temporarily set to 1. If the next pixel is also 0, Ki1 is recorded as 2. If the next pixel is 1, the final value of Ki1 is 2. Continue to traverse the next pixel. If it is 0, Ki2 is temporarily set to 1. Continue to traverse the next pixel. If it is 0, Ki2 is temporarily set to 2. If there are C consecutive pixels with a value of 0, the final value of Ki2 is C. Then start traversing the next pixel. The initial value of Ki3 is 0. If a pixel with a value of 0 is encountered, Ki3 is incremented by 1. This process is repeated until the i-th row is completed. The number of statistical values Kij in the i-th row is indefinite, that is, the value of j is not a constant. After traversing all M rows, this will form a first matrix RM with M rows, but each row has a different number of rows.
[0029] Preferably, constructing the first matrix and the second matrix based on the pixels specifically includes: Get the pixels with a value of 1 in the row and column directions; Iterate through all columns to construct the second matrix.
[0030] In practical application, the pixels with a value of 1 in the row and column directions of the binarized image are counted as follows: When a pixel with a value of 0 is encountered for the first time in the j-th column, the first statistical value K1j of that row is temporarily set to 1. If the next pixel is also 0, K1j is recorded as 2. If the next pixel is 1, the final value of K1j is 2. Continue to traverse the next pixel. If it is 0, K2j is temporarily set to 1. Continue to traverse the next pixel. If it is 0, K2j is temporarily set to 2. If there are C consecutive pixels with a value of 0, the final value of K2j is C. Then start traversing the next pixel. The initial value of K3j is 0. When a pixel with a value of 0 is encountered, K3j is incremented by 1. This process is repeated until the i-th row is completed. The number of statistical values Kij in the j-th column is indefinite, that is, the value of i is not a constant. After traversing all N columns, this will form a second matrix RN with N rows, but with a different number of rows in each column; Preferably, the step of traversing the first matrix and the second matrix to obtain the optimal value specifically includes: The optimal value of all values in the first matrix and the second matrix is obtained by traversing the first matrix and the second matrix.
[0031] In practical applications, we traverse the first matrix RM and the second matrix RN, find the maximum value of all values in the two matrices, take the maximum value as the optimal value, and denote the optimal value as MAX.
[0032] Preferably, the step of adjusting the focus position by judging the optimal value specifically includes: If the optimal value is not less than the judgment threshold, then adjust the focus position of the counting plate; If the optimal value is less than the determination threshold, then a cell image is acquired at the current location.
[0033] In practical application, the optimal value MAX is compared with the judgment threshold A. If the optimal value MAX is not less than the judgment threshold A, the stage moves the counting plate a certain distance along the Y or X direction and enters the Z-axis drive system to control the microscope tube to move upward by half of the preset range S. Then, the camera acquires one image for every T steps the microscope tube moves, for a total of S / T images, each image having M x N pixels. If the optimal value MAX is less than the judgment threshold A, a cell image is acquired at the current position.
[0034] like Figure 2As shown, this embodiment of the invention provides an automatic focusing system for cell microscopy, comprising: a first acquisition module, a scoring module, a second acquisition module, a construction module, a traversal module, and a judgment module; The first acquisition module is used to acquire an initial image using a motion camera; The scoring module is used to score the initial image based on its clarity in order to obtain the target image; The second acquisition module is used to preprocess the target image to obtain the pixels of the target image; The construction module is used to construct a first matrix and a second matrix based on the pixels; The traversal module is used to obtain the optimal value by traversing the first matrix and the second matrix; The judgment module is used to adjust the focus position by judging the optimal value.
[0035] In practical application, the automatic focusing system for cell microscopy includes a first acquisition module, a scoring module, a second acquisition module, a construction module, a traversal module, and a judgment module. The scoring module is connected to both the first and second acquisition modules; the construction module is connected to both the second acquisition module and the traversal module; and the judgment module is connected to the traversal module. After acquiring an initial image using a motion camera through the first acquisition module, the initial image is transmitted to the scoring module. The scoring module scores the initial image based on its clarity to obtain a target image, which is then transmitted to the second acquisition module. The second acquisition module preprocesses the target image to obtain its pixels and transmits these pixels to the construction module. The construction module constructs two matrices based on these pixels, namely a first matrix and a second matrix, and then transmits both matrices to the traversal module. The traversal module traverses these two matrices to obtain the optimal value for all matrix values and then transmits this optimal value to the judgment module. The judgment module judges this optimal value and adjusts the focus position based on the judgment result.
[0036] Furthermore, embodiments of this application also disclose an electronic device, Figure 3 This is a structural diagram of an electronic device according to an exemplary embodiment. The content of the diagram should not be construed as limiting the scope of this application.
[0037] Figure 3This is a schematic diagram of an electronic device provided in an embodiment of this application. The electronic device 20 specifically includes: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. The memory 22 stores a computer program, which is loaded and executed by the processor 21 to implement the relevant steps in the cell microscopy autofocus method disclosed in any of the foregoing embodiments. Alternatively, the electronic device 20 in this embodiment can specifically be an electronic computer.
[0038] In this embodiment, the power supply 23 is used to provide operating voltage for each hardware device on the electronic device 20; the communication interface 24 can create an automatic focusing channel for cell microscopy between the electronic device 20 and external devices, and the communication protocol it follows can be any communication protocol applicable to the technical solution of this application, and is not specifically limited here; the input / output interface 25 is used to acquire external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs, and is not specifically limited here.
[0039] In addition, the memory 22, as a carrier for resource storage, can be a read-only memory, random access memory, disk or optical disk, etc. The resources stored thereon can include operating system 221, computer program 222 and data 223, etc., and the storage method can be temporary storage or permanent storage.
[0040] The operating system 221 manages and controls the various hardware devices and computer programs 222 on the electronic device 20 to enable the processor 21 to perform calculations and processing on the data 223 in the memory 22. It can be Windows Server, Netware, Unix, Linux, etc. The computer program 222, in addition to including a computer program capable of performing the cell microscopy autofocus method executed by the electronic device 20 as disclosed in any of the foregoing embodiments, may further include computer programs capable of performing other specific tasks. The data 223 may include data received by the cell microscopy autofocus device from external devices, as well as data collected by its own input / output interface 25.
[0041] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein can be implemented directly by hardware, a software module executed by a processor, or a combination of both. The software module can be located in random access memory (RAM), main memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the art.
[0042] Furthermore, this application also discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, it implements the aforementioned autofocusing method for cell microscopy. Specific steps of this method can be found in the corresponding content disclosed in the foregoing embodiments, and will not be repeated here.
[0043] In the embodiments provided in this application, it should be understood that the disclosed methods and systems can be implemented in other ways. The apparatus embodiments described above are merely illustrative. For example, the division of modules is only a logical functional division, and in actual implementation, there may be other division methods, such as: multiple modules or components can be combined, or integrated into another system, or some features can be ignored or not executed. In addition, the coupling, direct coupling, or communication connection between the various components shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or modules, and can be electrical, mechanical, or other forms.
[0044] Furthermore, in the various embodiments of the present invention, each functional module can be fully integrated into a processor, or each module can be a separate device, or two or more modules can be integrated into a device; each functional module in the various embodiments of the present invention can be implemented in hardware or in the form of hardware plus software functional units.
[0045] Those skilled in the art will understand that all or part of the steps of the above method embodiments can be implemented by program instructions and related hardware. The aforementioned program instructions can be stored in a computer-readable storage medium. When the program instructions are executed, they perform the steps of the above method embodiments. The aforementioned storage medium includes various media that can store program code, such as mobile storage devices, read-only memory (ROM), magnetic disks, or optical disks.
[0046] It should be understood that the use of terms such as "system," "device," "unit," and / or "module" in this application is merely one method of distinguishing different components, elements, parts, sections, or assemblies at different levels. However, if other terms can achieve the same purpose, they may be replaced by other expressions.
[0047] As indicated in this application and claims, unless the context clearly indicates otherwise, the words "a," "an," "a," and / or "the" are not specifically singular and may include the plural. Generally, the terms "comprising" and "including" only indicate the inclusion of expressly identified steps and elements, which do not constitute an exclusive list, and the method or apparatus may also include other steps or elements. An element defined by the phrase "comprising an..." does not exclude the presence of other identical elements in the process, method, product, or apparatus that includes the element.
[0048] Hereinafter, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature.
[0049] If a flowchart is used in this application, it is used to illustrate the operations performed by the system according to embodiments of this application. It should be understood that the preceding or following operations are not necessarily performed in exact order. Instead, the steps can be processed in reverse order or simultaneously. Furthermore, other operations can be added to these processes, or one or more steps can be removed from them.
[0050] The above description of the disclosed embodiments enables those skilled in the art to make or use the invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the invention. Therefore, the invention is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. An automatic focusing method for cell microscopy, characterized in that, Includes the following steps: Acquire initial images using an action camera; The initial image is scored based on its clarity to obtain the target image; The target image is preprocessed to obtain the pixels of the target image; Construct a first matrix and a second matrix based on the pixels; The optimal value is obtained by traversing the first matrix and the second matrix; The focus position is adjusted by determining the optimal value.
2. The automatic focusing method for cell microscopy according to claim 1, characterized in that, The acquisition of the initial image via a motion camera specifically includes: Control the movement of the lens barrel and camera to the pre-focus position; The lens barrel is controlled to move upward to half of the preset range S. When the lens barrel moves T steps, the initial image is acquired through the camera.
3. The automatic focusing method for cell microscopy according to claim 1, characterized in that, The step of scoring the initial image based on its clarity to obtain the target image specifically includes: Calculate the sharpness of the initial image; The initial image is scored based on its clarity, and the image with the highest score is selected as the target image.
4. The automatic focusing method for cell microscopy according to claim 1, characterized in that, The preprocessing of the target image to obtain the pixels of the target image specifically includes: Convert the target image into a grayscale image; The grayscale image is binarized to obtain the pixels of the grayscale image.
5. The automatic focusing method for cell microscopy according to claim 1, characterized in that, The construction of the first matrix and the second matrix based on the pixels specifically includes: Get the pixels with a value of 1 in the row direction; Iterate through all rows to construct the first matrix.
6. The automatic focusing method for cell microscopy according to claim 1, characterized in that, The construction of the first matrix and the second matrix based on the pixels specifically includes: Get the pixels with a value of 1 in the row and column directions; Iterate through all columns to construct the second matrix.
7. The automatic focusing method for cell microscopy according to claim 1, characterized in that, The step of traversing the first matrix and the second matrix to obtain the optimal value specifically includes: The optimal value of all values in the first matrix and the second matrix is obtained by traversing the first matrix and the second matrix.
8. The automatic focusing method for cell microscopy according to claim 1, characterized in that, The step of adjusting the focus position by judging the optimal value specifically includes: If the optimal value is not less than the judgment threshold, then adjust the focus position of the counting plate; If the optimal value is less than the determination threshold, then a cell image is acquired at the current location.
9. An automatic focusing system for cell microscopy, characterized in that, include: The module consists of a first acquisition module, a scoring module, a second acquisition module, a construction module, a traversal module, and a judgment module. The first acquisition module is used to acquire an initial image using a motion camera; The scoring module is used to score the initial image based on its clarity in order to obtain the target image; The second acquisition module is used to preprocess the target image to obtain the pixels of the target image; The construction module is used to construct a first matrix and a second matrix based on the pixels; The traversal module is used to obtain the optimal value by traversing the first matrix and the second matrix; The judgment module is used to adjust the focus position by judging the optimal value.