A method for precise focusing of microscopic images of microorganisms
By employing spatial weighted feature enhancement, adaptive threshold denoising, and mask constraint methods, the signal-to-noise ratio of microbial microscopic images is optimized, solving the problem of interference-affected areas in existing autofocus algorithms for microbial microscopic images, and achieving efficient and accurate microbial detection.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- WEST CHINA HOSPITAL SICHUAN UNIV
- Filing Date
- 2026-03-04
- Publication Date
- 2026-05-26
Smart Images

Figure CN121763551B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of clinical microbiology microscopic image processing and computer vision technology, specifically to a method for precise focusing of microscopic images of microorganisms. Background Technology
[0002] In fields such as clinical microbiology testing and environmental microbiology monitoring, obtaining clear microscopic images of microorganisms is a core prerequisite for subsequent tasks such as microbial counting, species identification, and drug sensitivity analysis. Autofocus technology is a key support for achieving this. With the widespread adoption of automated microscopy equipment, traditional focusing methods relying on manual judgment have been gradually phased out due to their low efficiency and high subjectivity, while machine vision-based autofocus algorithms have become the mainstream.
[0003] Microbial microscopic images possess significant unique characteristics: they contain numerous interfering regions, such as impurity particles, detached cell fragments, and water ripples formed by liquid media. These interfering regions typically occupy more than 80% of the image area, while the actual microbial targets that need to be focused on are not only small in area—for example, a single microorganism often occupies less than 1% of the image—but also share certain similarities in grayscale features with some of the interfering regions. This characteristic of "numerous interference and small targets" places extremely high demands on the targeting and accuracy of autofocus algorithms.
[0004] Currently, automatic focusing of microbial microscopic images commonly employs traditional sharpness assessment algorithms, primarily including the Laplacian operator method, the Sobel gradient method, and the Tenengrad gradient method. The core principle of these methods is to evaluate sharpness by calculating the degree of grayscale change in image pixels—the more dramatic the grayscale change, the sharper the image edges, and the better the focusing effect. Among these, the Laplacian operator method is widely used; however, this existing technology has significant drawbacks: because the Laplacian operator evaluates grayscale changes across the entire image, when there are large areas of interference in the image, the algorithm will use the sharpness of these interference areas as the primary criterion. For example, when a water ripple area presents sharp edges due to accurate focusing, its grayscale change will be much more dramatic than that of an inaccurately focused microbial area. This causes the algorithm to mistakenly classify an image with "sharp interference and blurred microorganisms" as the best focused image, severely affecting the accuracy of subsequent microbial detection. Related studies have shown that when using this method to focus on bacterial samples, the success rate of achieving sharp microbial areas is less than 30%, greatly limiting the application value of automated microscopic equipment. Summary of the Invention
[0005] To address the aforementioned shortcomings in existing technologies, this invention provides a precise focusing method for microbial microscopic images. Based on spatial-frequency dual-domain enhancement and dynamic mask constraints, it solves the problem that existing focusing methods in microbial microscopic image focusing suffer from the issue that the area of interference regions such as impurities, cells, and water ripples in the image is much larger than the area of the target microorganism, leading to a bias in focusing evaluation towards interference regions and ultimately resulting in blurred microorganisms while the interference regions remain clear.
[0006] To achieve the above-mentioned objectives, the technical solution adopted by this invention is as follows:
[0007] A method for precise focusing of microscopic images of microorganisms includes the following steps:
[0008] S1. Acquire multiple microscopic images of microorganisms under different objective lens focal lengths;
[0009] S2. Using a gradient statistical method of spatial weighted feature enhancement and adaptive threshold denoising, the sharpness score of each microbial microscopic image is calculated, and sharpness selection is performed to obtain multiple candidate microbial microscopic images.
[0010] S3. Perform spatial-frequency dual-domain feature enhancement on each candidate microscopic image to obtain each candidate microscopic image with enhanced signal-to-noise ratio;
[0011] S4. Perform microbial region detection on each signal-to-noise ratio enhanced candidate microscopic image and generate a mask that only covers the microbial region;
[0012] S5. Use a mask to block out pixels outside the microbial region in each candidate microbial image, calculate the sharpness score, and use the candidate microbial image with the highest sharpness score as the microbial image with precise focus.
[0013] Further, step S1 includes the following sub-steps:
[0014] S11. Fix the microbial sample onto the microscope stage;
[0015] S12. Drive the objective lens of the microscope to move from the preset minimum focal length to the preset maximum focal length in preset steps, acquire microscopic images of microorganisms at each focal length, and record the corresponding objective lens focal length value.
[0016] Furthermore, step S2 includes the following sub-steps:
[0017] S21. Calculate the original gradient feature map of each microbial microscopic image;
[0018] S22. Calculate the global grayscale mean of each microbial microscopic image and obtain each dynamic suppression threshold through nonlinear mapping function.
[0019] S23. Using various dynamic suppression thresholds, and according to the following formula, perform nonlinear mapping processing on the original gradient feature maps of the corresponding microbial microscopic images to obtain the gradient feature maps for each adaptive noise reduction: ,
[0020] Where x is the row number and y is the column number. For the pixel value in the x-th row and y-th column of the gradient feature map for adaptive noise reduction, The pixel value in the x-th row and y-th column of the original gradient feature map. This is the dynamic suppression threshold;
[0021] S24. Introduce a Gaussian space weight matrix to weight the gradient feature map of adaptive noise reduction, and calculate the sharpness score of each microbial microscopic image.
[0022] S25. Based on the sharpness score of each microbial microscopic image, a sharpness selection is performed to obtain multiple candidate microbial microscopic images.
[0023] Furthermore, the method in S21 is as follows:
[0024] Using a discrete second-derivative Laplacian operator convolution kernel, the contours of each microbial microscopic image are captured through convolution operations according to the following formula, resulting in original gradient feature maps: ,
[0025] ,
[0026] Where L is the discrete second derivative Laplacian operator convolution kernel, * is the convolution operation, G is the original gradient feature map, and I is the microscopic image of microorganisms.
[0027] Furthermore, the expression for S24 is: , ,
[0028] in, The sharpness score of microscopic images of microorganisms is given, where N is the total number of pixels in the microscopic image of microorganisms, x is the row number, and y is the column number. For the pixel value in the x-th row and y-th column of the gradient feature map for adaptive noise reduction, The value in the x-th row and y-th column of the Gaussian space weight matrix is... The pixel mean after weighted gain of the gradient feature map for adaptive noise reduction. It is a natural exponential function. The standard deviation is Gaussian. The coordinates of the center of the gradient feature map for adaptive noise reduction.
[0029] Furthermore, step S3 includes the following sub-steps:
[0030] S31. Convert the candidate microscopic images of microorganisms from RGB space to LAB space;
[0031] S32. Use the CLAHE algorithm to equalize the local contrast in the spatial domain of candidate microscopic images of microorganisms.
[0032] S33. The high-frequency detail features of the LAB spatial brightness channel of the candidate microbial microscopic image are extracted and compensated by the difference of Gaussian operator to obtain a candidate microbial microscopic image with enhanced signal-to-noise ratio.
[0033] Further, the method in S32 is as follows: the LAB spatial brightness channel of the candidate microscopic image is reconstructed using the following transformation function: ,
[0034] Where r is the pixel gray level. For transformation function, The cumulative distribution function is... Maximum value of the LAB spatial brightness channel in candidate microscopic images of microorganisms Minimum value of LAB spatial brightness channel in candidate microscopic images of microorganisms.
[0035] Furthermore, the expression for S33 is: , ,
[0036] Where x is the row number and y is the column number. For the pixel value in the x-th row and y-th column of the candidate microbial microscopic image for signal-to-noise ratio enhancement, The value in the x-th row and y-th column of the LAB spatial brightness channel of the candidate microscopic image. The value at row x and column y represents the high-frequency detail feature of the LAB spatial brightness channel in the candidate microscopic image, where * denotes the convolution operation. The value of the x-th row and y-th column of the first-scale Gaussian operator. The value of the x-th row and y-th column of the second-scale Gaussian operator.
[0037] Furthermore, step S4 includes the following sub-steps:
[0038] S41. Detect the microbial regions in each signal-to-noise ratio enhanced candidate microscopic image of microorganisms using a target detection model, and record and count the effective detection boxes in each image; the effective detection boxes are detection boxes with a confidence level greater than or equal to 0.7.
[0039] S42. Select the candidate microbial microscopic image with the most effective detection boxes, the highest average confidence, and the enhanced signal-to-noise ratio as the baseline image.
[0040] S43. On a completely black background, fill the corresponding areas of all valid detection boxes in the reference image with white to obtain a mask;
[0041] S44. Perform a morphological expansion operation on the mask so that the mask only covers the microbial region, and the gradient change information of the outermost microorganism can be completely contained within the mask.
[0042] Furthermore, step S5 includes the following sub-steps:
[0043] S51. Using the following formula, a mask is used to block out pixels in each candidate microbial image except for the microbial region: ,
[0044] Where x is the row number and y is the column number. The pixel value in the x-th row and y-th column of the candidate microorganism image. To mask the pixel value in the x-th row and y-th column of the candidate microorganism image, excluding pixels from the microbial region. The value in the x-th row and y-th column of the mask;
[0045] S52. Calculate the sharpness score of the candidate microbial image with pixels other than the microbial region masked by the method in S24.
[0046] S53. Select the candidate microbial image with the highest sharpness score as the microbial image for precise focusing.
[0047] The beneficial effects of this invention are as follows: This invention employs a layered focusing strategy of spatial weighted coarse selection, dual-domain enhanced detection, and mask-based local fine evaluation. First, it rapidly locks the candidate focal length range using a gradient statistical method with spatial weighting and adaptive threshold noise reduction. Then, it optimizes the signal-to-noise ratio of microbial microscopic images through spatial-frequency dual-domain feature enhancement. Finally, it generates a precise mask through target detection. Under the constraints of the mask, it achieves accurate clarity evaluation of the microbial region, ensuring the acquisition of clear microscopic images of the microbial body and improving the accuracy and reliability of microbial detection. Attached Figure Description
[0048] Figure 1 This is a flowchart of a method for precise focusing of microbial microscopic images according to an embodiment of the present invention;
[0049] Figure 2 The image shown is a microscopic image of microorganisms, denoted as IMG_400μm.jpg, from an embodiment of the present invention.
[0050] Figure 3 The image shown is a microscopic image of microorganisms, denoted as IMG_450μm.jpg, from an embodiment of this invention.
[0051] Figure 4 The image shown is a microscopic image of microorganisms, denoted as IMG_550μm.jpg, from an embodiment of the present invention.
[0052] Figure 5The image shown is a microscopic image of microorganisms, denoted as IMG_600μm.jpg, from an embodiment of this invention.
[0053] Figure 6 The image shown is a microscopic image of microorganisms, denoted as IMG_650μm.jpg, from an embodiment of the present invention. Detailed Implementation
[0054] The specific embodiments of the present invention are described below to enable those skilled in the art to understand the present invention. However, it should be understood that the present invention is not limited to the scope of the specific embodiments. For those skilled in the art, various changes are obvious as long as they are within the spirit and scope of the present invention as defined and determined by the appended claims. All inventions utilizing the concept of the present invention are protected.
[0055] like Figure 1 As shown, a method for precise focusing of microscopic images of microorganisms includes the following steps:
[0056] S1. Collect multiple microscopic images of microorganisms under different objective lens focal lengths.
[0057] In this embodiment, the following parameter configurations are completed before the method is executed to ensure that all modules work together:
[0058] Focal length parameters: Based on the thickness characteristics of the Escherichia coli smear in this embodiment, the objective lens focal length scanning range is set to 0-1000μm and the scanning step size is 50μm. Therefore, the final number of image sequences acquired is 21, which meets the requirement of more than 5.
[0059] Focusing algorithm parameters: The Laplacian operator uses a 3×3 convolution kernel, and the sharpness evaluation threshold is set to 50. Images below this value are judged to be severely out of focus and are directly filtered out.
[0060] Target detection model parameters (YOLO model is used in this embodiment): Load the pre-trained microbial detection model (the training dataset contains 10,000 microscopic images of microorganisms under different backgrounds, with an annotation accuracy of 99.2%), set the confidence threshold to 0.7 (to filter false detection boxes with low confidence), and set the IOU threshold to 0.3 (to handle the problem of overlapping detection boxes).
[0061] S1 includes the following steps:
[0062] S11. Fix the microbial sample onto the microscope stage;
[0063] S12. Drive the objective lens of the microscope to move from the preset minimum focal length to the preset maximum focal length in preset steps, acquire microscopic images of microorganisms at each focal length, and record the corresponding objective lens focal length value.
[0064] In this embodiment, the E. coli smear sample is fixed on the microscope stage, and the automatic focusing process is initiated:
[0065] After receiving the command, the microscope control unit drives the objective lens to move from a focal length of 0 μm to 1000 μm in 50 μm increments. For each increment, the CMOS image sensor is triggered to capture a 1024×1024 pixel microscopic image, and a unique identifier is added to each image (named in the format "IMG_focal length value μm.jpg", such as IMG_50μm.jpg). At the same time, the focal length value of the objective lens corresponding to each image is recorded, forming a focusing sequence containing 21 images, which is then stored in the local cache directory.
[0066] S2. Using a gradient statistical method combining spatial weighted feature enhancement and adaptive threshold denoising, the sharpness score of each microbial microscopic image is calculated, and sharpness selection is performed to obtain multiple candidate microbial microscopic images.
[0067] S2 includes the following steps:
[0068] S21. Using the discrete second-derivative Laplacian operator convolution kernel, the contours of each microbial microscopic image are captured through the convolution operation of the following formula, resulting in the original gradient feature maps:
[0069] ,
[0070] ,
[0071] Where L is the discrete second derivative Laplacian operator convolution kernel, * is the convolution operation, G is the original gradient feature map, and I is the microscopic image of microorganisms;
[0072] S22. Calculate the global grayscale mean of each microbial microscopic image, and obtain the dynamic suppression threshold by constructing a nonlinear mapping function based on power-law transformation. The calculation expression is: ,
[0073] in, The global grayscale mean; The nonlinear adjustment coefficient (in this embodiment, it is taken as...) >1 (e.g., 1.2-1.5), used to accelerate the increase of the suppression threshold when the brightness is high, in order to deal with more obvious water ripple interference; The base gain factor (e.g., 0.1-0.2). The minimum cutoff threshold is determined by the sensor noise floor (e.g., 5-10).
[0074] S23. Using various dynamic suppression thresholds, and according to the following formula, perform nonlinear mapping processing on the original gradient feature maps of the corresponding microbial microscopic images to obtain the gradient feature maps for each adaptive noise reduction: ,
[0075] Where x is the row number and y is the column number. For the pixel value in the x-th row and y-th column of the gradient feature map for adaptive noise reduction, The pixel value in the x-th row and y-th column of the original gradient feature map. Dynamic inhibition threshold;
[0076] S24. Introduce a Gaussian spatial weight matrix to apply a weighted gain to the gradient feature map of adaptive noise reduction. Calculate the sharpness score for each microbial microscopic image using the following formula: , ,
[0077] in, The sharpness score of microscopic images of microorganisms is given, where N is the total number of pixels in the microscopic image of microorganisms, x is the row number, and y is the column number. For the pixel value in the x-th row and y-th column of the gradient feature map for adaptive noise reduction, The value in the x-th row and y-th column of the Gaussian space weight matrix is... The pixel mean after weighted gain of the gradient feature map for adaptive noise reduction. It is a natural exponential function. It is the Gaussian standard deviation (usually taken as 1 / 3 of the image diagonal length to cover the main field of view). The center coordinates of the gradient feature map for adaptive noise reduction;
[0078] S25. Based on the sharpness score of each microbial microscopic image, a sharpness selection is performed to obtain multiple candidate microbial microscopic images.
[0079] Based on the above steps, this embodiment constructs a gradient statistical model for spatial weighted feature enhancement and adaptive threshold denoising, and performs mathematical optimization on the characteristics of high noise and complex background in microbial microscopic imaging.
[0080] To eliminate common water ripples and background electronic noise interference in microbial images, the model introduces a dynamic suppression threshold. This threshold is determined by a nonlinear mapping function based on the global grayscale mean of the image. The gradient feature map is then subjected to nonlinear mapping to obtain a denoised gradient distribution map. This step ensures that the sharpness evaluation only responds to the true microbial edge information, effectively shielding weak background clutter and thus improving the signal-to-noise ratio for focusing at the underlying computational logic.
[0081] To address the optical characteristic that the center field of view has higher sharpness than the edge field of view in microscope objective imaging, a Gaussian spatial weight matrix is introduced. This matrix assigns weights with the image center point as the origin, and the edge weights decrease Gaussianly with increasing radial distance.
[0082] The denoised gradient features are fused with the spatial weight matrix to calculate the sharpness score of the final microscopic image of the microorganism. This score is obtained by calculating the spatially weighted gradient variance. The larger the value, the more prominent the edge details of the microbial targets in the image, which serves as the basis for initially screening the clearest image sequences.
[0083] Comparing the sharpness scores of 21 images, assuming the image with the highest score is IMG_500μm.jpg (focal length 500μm), then this image and the two images before and after it in the focus sequence are selected to form the following... Figure 2 , Figure 3 , Figure 4 , Figure 5 and Figure 6 The candidate sequences shown are: IMG_400μm.jpg, IMG_450μm.jpg, IMG_500μm.jpg, IMG_550μm.jpg, and IMG_600μm.jpg. The purpose of this step is to quickly identify focal length ranges that may contain clear bacterial regions through overall scoring, thereby reducing the computational load of subsequent target detection.
[0084] S3. Perform spatial-frequency dual-domain feature enhancement on each candidate microscopic image to obtain each candidate microscopic image with enhanced signal-to-noise ratio.
[0085] S3 includes the following steps:
[0086] S31. Convert the candidate microscopic images of microorganisms from RGB space to LAB space;
[0087] S32. The CLAHE algorithm is used to equalize the local contrast in the spatial domain of candidate microbial microscopic images. Specifically, the LAB spatial brightness channel of the candidate microbial microscopic images is reconstructed using the following transformation function: ,
[0088] Where r is the pixel gray level. For transformation function, The cumulative distribution function is... Maximum value of the LAB spatial brightness channel in candidate microscopic images of microorganisms Minimum value of LAB spatial brightness channel in candidate microscopic images of microorganisms;
[0089] Cumulative distribution function In a candidate microscopic image of microorganisms, a pixel with a gray value less than or equal to r is... The function has a range of [0, 1] and is used to non-linearly map the non-uniformly distributed gray levels of the original image to [0, 1]. This allows for adaptive enhancement of local contrast within a specific range.
[0090] S33. Using the following formula, the high-frequency detail features of the LAB spatial brightness channel of the candidate microbial microscopic image are extracted and compensated, resulting in a candidate microbial microscopic image with enhanced signal-to-noise ratio: , ,
[0091] Where x is the row number and y is the column number. For the pixel value in the x-th row and y-th column of the candidate microbial microscopic image for signal-to-noise ratio enhancement, The value in the x-th row and y-th column of the LAB spatial brightness channel of the candidate microscopic image. The value at row x and column y represents the high-frequency detail feature of the LAB spatial brightness channel in the candidate microscopic image, where * denotes the convolution operation. The value of the x-th row and y-th column of the first-scale Gaussian operator. This is the value in the x-th row and y-th column of the second-scale Gaussian operator.
[0092] S4. Perform microbial region detection on each signal-to-noise ratio enhanced candidate microscopic image and generate a mask that only covers the microbial region.
[0093] S4 includes the following steps:
[0094] S41. Detect the microbial regions in each signal-to-noise ratio enhanced candidate microscopic image of microorganisms using a target detection model, and record and count the effective detection boxes in each image; the effective detection boxes are detection boxes with a confidence level greater than or equal to 0.7.
[0095] S42. Select the candidate microbial microscopic image with the most effective detection boxes, the highest average confidence, and the enhanced signal-to-noise ratio as the baseline image.
[0096] S43. On a completely black background, fill the corresponding areas of all valid detection boxes in the reference image with white to obtain a mask;
[0097] S44. Perform a morphological expansion operation on the mask so that the mask only covers the microbial region, and the gradient change information of the outermost microorganism can be completely contained within the mask.
[0098] In this embodiment, an image preprocessing operator based on space-frequency dual-domain feature enhancement is constructed to optimize feature extraction of candidate sequence images. Subsequently, the YOLOv11-nano(OBB) model is used to achieve accurate extraction of microbial targets.
[0099] Before inputting candidate sequence images into the model, this invention implements a dual enhancement strategy for microbial sample imaging design to offset optical differences between different devices.
[0100] To address the background halo effect caused by uneven light source in microscopic images of microorganisms, the image was first converted from RGB space to LAB space, and the brightness channel was adjusted. Local histogram reconstruction is performed. Its core principle is to suppress noise by limiting contrast gain. Through this process, the image maintains global brightness balance while enhancing the local edge contrast between small targets (bacteria) and complex backgrounds (such as cell debris).
[0101] The blurring caused by varying microscope focusing distances is addressed by using the difference of Gaussian operator to extract and compensate for high-frequency features in the image. First, two spatial Gaussian operators of different scales are constructed. and Convolution is performed on the image brightness channel. For finer scales (e.g., 0.5). A slightly coarser scale (e.g., 1.0) is then used. The difference plots of the two are then calculated. The detailed components of the target edges are then obtained. Finally, these detailed components are compensated back to the original image using a gain coefficient λ to obtain the enhanced image. This frequency domain enhancement operator can significantly enhance key morphological features such as bacterial edges and hyphal branches, effectively compensating for the lack of ability to capture high-frequency details and providing input data with a higher signal-to-noise ratio for subsequent model inference.
[0102] The preprocessed enhanced image is then input into the YOLOv11-nano (OBB) model for inference. The model uses OBB (Rotated Bounding Box) output, which can more accurately fit the natural morphology of microorganisms and reduce redundant background pixels.
[0103] The model counts microbial targets with a confidence level ≥ 0.7 in each image.
[0104] The image with the most bounding boxes is selected as the "baseline image". If the number of bounding boxes is the same, the image with the higher average confidence score is selected to ensure that the generated mask is based on the most reliable recognition result.
[0105] In this embodiment, based on the coordinates of all valid OBB detection boxes in the reference image, the areas corresponding to all valid detection boxes in the reference image are filled with white (pixel value 255) on a completely black background, resulting in a mask that only contains microbial regions.
[0106] Then, a morphological dilation operation is performed on the generated mask. Let the initial mask be A, and the structuring element be B (such as a 3×3 elliptic operator). The dilation operation is expressed as: ,
[0107] This step aims to slightly expand the mask area outwards from the target. Since the Laplacian focusing algorithm relies on grayscale jumps at the target edges, the dilation process ensures that the gradient change information of the outermost edge of the bacteria is fully contained within the mask evaluation area. This effectively prevents the loss of crucial edge focusing information due to an overly tight detection box, thereby significantly improving the sensitivity of subsequent precise focus scores.
[0108] S5. Use a mask to block out pixels outside the microbial region in each candidate microbial image, calculate the sharpness score, and use the candidate microbial image with the highest sharpness score as the microbial image with precise focus.
[0109] S5 includes the following steps:
[0110] S51. Using the following formula, a mask is used to block out pixels in each candidate microbial image except for the microbial region: ,
[0111] Where x is the row number and y is the column number. The pixel value in the x-th row and y-th column of the candidate microorganism image. y is the value in the x-th row and y-th column of the candidate microbial image, after filtering out pixels other than the microbial region;
[0112] In this embodiment, the white pixel value is 255;
[0113] S52. Calculate the sharpness score of the candidate microbial image with pixels other than the microbial region masked by the method in S24.
[0114] S53. Select the candidate microbial image with the highest sharpness score as the microbial image for precise focusing.
[0115] In this embodiment, the generated mask is used to perform region segmentation on the five images in the candidate sequence, retaining only the image content corresponding to the white areas in the mask, and then the sharpness of the segmented local images is evaluated.
[0116] This embodiment uses a pixel-by-pixel logical AND algorithm to perform background masking on the image. The specific steps are: traversing candidate images. For each pixel in the image, read the mask. Corresponding coordinates The pixel value. If If the value is valid (i.e., the white area represents the microbial target), then retain it. The original grayscale value is used as the output; if If the value is invalid (i.e., a black area representing background interference), the pixel value at that coordinate is forcibly set to 0 (black). This data filtering operation generates a local image that retains only the texture features of the microbial target. From a mathematical perspective, the image data corresponding to the black areas of the mask is "reset to zero," thereby completely blocking impurities and background interference.
[0117] Then, in this embodiment, the same method as in step S24 is used to calculate the sharpness score for each local image, but at this time the calculation range is only the microbial area, avoiding the influence of the interference area.
[0118] For example, the local sharpness score of IMG_450μm.jpg is 89.2, that of IMG_500μm.jpg is 78.5, and that of IMG_550μm.jpg is 92.1.
[0119] Final focus image determination: Compare the sharpness scores of 5 local images, and select the image with the highest score (IMG_550μm.jpg in this example, with a score of 92.1) as the final best focus image.
[0120] Some technical solutions of the embodiments of the present invention also have the following alternative solutions:
[0121] For example, the Laplace operator variance method used as the algorithm for sharpness scoring can be replaced by the following two schemes, which have the same implementation principle but slightly different applicable scenarios:
[0122] Tenengrad gradient method: This method uses the Sobel operator to calculate the gradient of the image in the x and y directions, and uses the sum of the squared gradients in the two directions as the sharpness score. This method is more sensitive to low-contrast microbial images and is suitable for scenes where the gray-level difference between microorganisms and the background is small.
[0123] Brenner gradient method: calculates the sum of squares of the gray level differences between two adjacent pixels in an image. This method is more than 30% faster than the Laplacian operator and is suitable for automated detection equipment with higher real-time requirements.
[0124] The YOLOv11-nano (OBB) model used can be replaced by the following models, all of which have the core function of achieving accurate detection of microbial targets:
[0125] YOLOv5s model: Compared with YOLOv11-nano, the detection accuracy is improved by about 5%, but the model size is larger and the calculation speed is slightly slower. It is suitable for scenarios with extremely high detection accuracy requirements and moderate speed requirements.
[0126] Faster R-CNN model: Based on a two-stage detection framework, it has a recall rate of 8%-10% higher than the YOLO series for detecting small target microorganisms, but its inference speed is slower. It is suitable for offline focusing or scenarios with a small sample size.
[0127] The lightweight model MobileNet-SSD has a model size that is only 1 / 3 that of YOLOv8-nano. It is fast and suitable for scenarios with limited hardware resources, such as embedded microscopy devices. Although the detection accuracy is slightly reduced, it can be compensated for by increasing the amount of training samples.
[0128] The rule for selecting candidate microscopic images of microorganisms in this embodiment, "two images before and two after the clearest overall image", can be replaced with "selecting the top 5 images in terms of overall clarity score". This approach does not need to consider the position of the image in the sequence and is suitable for scenarios where the focal length and clarity do not change monotonically (such as multiple clear peaks caused by uneven sample thickness), and can more comprehensively cover the potential best focus area.
[0129] In summary, this invention employs a layered focusing strategy of "spatial weighted coarse selection—dual-domain enhanced detection—mask local fine evaluation." First, it utilizes a gradient statistical model that combines spatial weighting and adaptive threshold denoising to quickly lock the candidate focal length range. Then, it introduces a spatial-frequency dual-domain feature enhancement operator to optimize image features and combines it with YOLOv11-n rotational target detection to generate a precise dynamic morphological mask. Finally, under the constraints of the mask, it achieves accurate clarity evaluation of the microbial region, ensuring the acquisition of clear microscopic images of the microorganisms and improving the accuracy and reliability of microbial detection.
[0130] Compared to existing technologies:
[0131] More targeted focusing: Existing technologies evaluate the entire image, which is easily affected by large areas of interference; This invention uses the YOLO model to accurately locate microbial areas and only evaluates the sharpness of the target area, ensuring that the focusing result is biased towards microorganisms rather than interference. Experimental verification shows that the success rate of sharpening microbial areas has been increased from less than 30% in existing technologies to more than 92%.
[0132] Wider adaptability: The focusing effect of existing technologies depends on the gray-scale features of the interference area in the image, which has poor adaptability to different sample backgrounds; the YOLO model of the present invention can be finely adjusted to adapt to different types of microorganisms (such as Escherichia coli and Staphylococcus aureus) and different sample types (smears, petri dishes) without modifying the core algorithm logic.
[0133] Better balance between efficiency and accuracy: Existing technologies require increasing the number of images to improve accuracy, which leads to reduced efficiency; This invention reduces the number of images for target detection through "overall coarse selection" and ensures focusing accuracy through "local fine evaluation". Under the same hardware conditions, the focusing time is shortened by 40% compared with existing technologies, while the accuracy is significantly improved.
[0134] The above are merely preferred embodiments of the present invention and are not intended to limit the present invention. Various modifications and variations can be made to the present invention by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. A method for precise focusing of microscopic images of microorganisms, characterized in that, Includes the following steps: S1. Acquire multiple microscopic images of microorganisms under different objective lens focal lengths; S2. Using a gradient statistical method of spatial weighted feature enhancement and adaptive threshold denoising, the sharpness score of each microbial microscopic image is calculated, and sharpness selection is performed to obtain multiple candidate microbial microscopic images. S3. Perform spatial-frequency dual-domain feature enhancement on each candidate microscopic image to obtain each candidate microscopic image with enhanced signal-to-noise ratio; S4. Perform microbial region detection on each signal-to-noise ratio enhanced candidate microscopic image and generate a mask that only covers the microbial region; S5. Use a mask to block out pixels in each candidate microbial image except for the microbial region, calculate the sharpness score, and take the candidate microbial image with the highest sharpness score as the microbial image with precise focus. S3 includes the following steps: S31. Convert the candidate microscopic images of microorganisms from RGB space to LAB space; S32. Use the CLAHE algorithm to equalize the local contrast in the spatial domain of candidate microscopic images of microorganisms. S33. The high-frequency detail features of the LAB spatial brightness channel of the candidate microbial microscopic image are extracted and compensated by the difference of Gaussian operator to obtain a candidate microbial microscopic image with enhanced signal-to-noise ratio. S4 includes the following steps: S41. Detect the microbial regions in each signal-to-noise ratio enhanced candidate microscopic image using the target detection model, and record and count the effective detection boxes in each image. S42. Select the candidate microbial microscopic image with the most effective detection boxes, the highest average confidence, and the enhanced signal-to-noise ratio as the baseline image. S43. On a completely black background, fill the corresponding areas of all valid detection boxes in the reference image with white to obtain a mask; S44. Perform a morphological expansion operation on the mask so that the mask only covers the microbial region, and the gradient change information of the outermost microorganism can be completely contained within the mask.
2. The method for precise focusing of microbial microscopic images according to claim 1, characterized in that, S1 includes the following steps: S11. Fix the microbial sample onto the microscope stage; S12. Drive the objective lens of the microscope to move from the preset minimum focal length to the preset maximum focal length in preset steps, acquire microscopic images of microorganisms at each focal length, and record the corresponding objective lens focal length value.
3. The method for precise focusing of microbial microscopic images according to claim 1, characterized in that, S2 includes the following steps: S21. Calculate the original gradient feature map of each microbial microscopic image; S22. Calculate the global grayscale mean of each microbial microscopic image and obtain each dynamic suppression threshold through nonlinear mapping function. S23. Using various dynamic suppression thresholds, and according to the following formula, perform nonlinear mapping processing on the original gradient feature maps of the corresponding microbial microscopic images to obtain the gradient feature maps for each adaptive noise reduction: , in, For row number, For column numbers, The gradient feature map for adaptive noise reduction OK Column pixel values, The first one in the original gradient feature map OK Column pixel values, This is the dynamic suppression threshold; S24. Introduce a Gaussian space weight matrix to weight the gradient feature map of adaptive noise reduction, and calculate the sharpness score of each microbial microscopic image. S25. Based on the sharpness score of each microbial microscopic image, a sharpness selection is performed to obtain multiple candidate microbial microscopic images.
4. The method for precise focusing of microbial microscopic images according to claim 3, characterized in that, The method in S21 is as follows: Using a discrete second-derivative Laplacian operator convolution kernel, the contours of each microbial microscopic image are captured through convolution operations according to the following formula, resulting in original gradient feature maps: , , in, For the convolution kernel of the discrete second derivative Laplace operator, For convolution operations, This is the original gradient feature map. Microscopic images of microorganisms.
5. The method for precise focusing of microbial microscopic images according to claim 4, characterized in that, The expression for S24 is: , , in, Scoring the sharpness of microscopic images of microorganisms. This represents the total number of pixels in a microscopic image of a microorganism. For row number, For column numbers, The gradient feature map for adaptive noise reduction OK Column pixel values, The Gaussian space weight matrix is the first... OK Column values, The pixel mean after weighted gain of the gradient feature map for adaptive noise reduction. It is a natural exponential function. The standard deviation is Gaussian. The coordinates of the center of the gradient feature map for adaptive noise reduction.
6. The method for precise focusing of microbial microscopic images according to claim 1, characterized in that, The method in S32 is as follows: the LAB spatial brightness channel of the candidate microbial microscopic image is reconstructed using the following transformation function: , in, For pixel grayscale, For transformation function, The cumulative distribution function is... Maximum value of the LAB spatial brightness channel in candidate microscopic images of microorganisms Minimum value of LAB spatial brightness channel in candidate microscopic images of microorganisms.
7. The method for precise focusing of microbial microscopic images according to claim 6, characterized in that, The expression for S33 is: , , in, For row number, For column numbers, For signal-to-noise ratio enhanced candidate microscopic images of microorganisms OK Column pixel values, For candidate microbial microscopic images, the LAB spatial brightness channel is the first... OK Column values, High-frequency detail features of the LAB spatial brightness channel in candidate microscopic images of microorganisms OK Column values, * indicates convolution operation. The first-scale Gaussian operator OK Column values, For the second-scale Gaussian operator OK Column values.
8. The method for precise focusing of microbial microscopic images according to claim 5, characterized in that, S5 includes the following steps: S51. Using the following formula, a mask is used to block out pixels in each candidate microbial image except for the microbial region: , in, For row number, For column numbers, For candidate microbial images OK Column pixel values, To mask the candidate microbial image of pixels other than the microbial region. OK Column pixel values, For the mask OK Column values; S52. Calculate the sharpness score of the candidate microbial image with pixels other than the microbial region masked by the method in S24. S53. Select the candidate microbial image with the highest sharpness score as the microbial image for precise focusing.
Citation Information
Patent Citations
High-precision rapid focus detection method based on push-broom underwater hyperspectral original image
CN113989143A
Multi-focus image fusion microscope imaging method based on sputum slide
CN118688950A