Gram staining blood culture sample microscopic image recognition method
By combining color space enhancement and adaptive histogram equalization with spatial mapping convolution and route-enhanced multi-head self-attention modules, the problems of microscopic bacterial feature loss and background noise interference in existing technologies are solved, achieving high-precision and real-time microscopic image recognition.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- SICHUAN UNIV
- Filing Date
- 2026-03-16
- Publication Date
- 2026-06-26
AI Technical Summary
Existing technologies suffer from low bacterial identification accuracy in Gram-stained blood culture sample microscopic image recognition, mainly due to the loss of tiny bacterial features caused by strided convolution and interference from background noise in complex backgrounds.
We employ color space enhancement and adaptive histogram equalization to strengthen the edge and texture features of bacteria, and retain the feature information of tiny bacteria through a spatial mapping convolution module. We also combine a routing-enhanced multi-head self-attention module to dynamically filter background noise, thus constructing an enhanced YOLOV11 target detection network.
It significantly improves the detection accuracy and recall rate of tiny bacteria, reduces the false positive rate, and meets the high precision and real-time requirements of clinical testing.
Smart Images

Figure CN122290106A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image processing technology, and specifically to a method for recognizing microscopic images of Gram-stained blood culture samples. Background Technology
[0002] Bloodstream infections (sepsis) are life-threatening illnesses, and rapid etiological diagnosis of positive blood cultures is crucial for the accurate use of antibiotics in clinical practice. Gram staining microscopy is currently the "gold standard" and the preferred rapid diagnostic method for confirming the type of pathogen causing a bloodstream infection.
[0003] Traditional clinical workflows rely on laboratory physicians manually operating microscopes to search smears field by field under high-power oil immersion. Due to the tiny size (usually 0.5-2 μm) and diverse morphology of bacteria, and the complex background of blood culture samples (containing a large number of erythrocyte lysate fragments, protein precipitation, and dye crystals), manual microscopic examination is labor-intensive, prone to fatigue, highly subjective, and prone to missing low-concentration samples.
[0004] With the development of digital pathology technology, deep learning-based target detection algorithms (such as YOLO series, Faster R-CNN, etc.) have begun to be applied to microbial morphology identification, aiming to achieve automated bacterial search and classification.
[0005] Current technology directly uses general single-stage object detection models (such as standard YOLOv8 or YOLOv11 models) to train and predict microscopic images.
[0006] The implementation steps of existing technologies (general YOLO models) are typically as follows: Image input and downsampling: High-resolution microscopic images are input into the backbone network. The backbone network mainly consists of a series of convolutional layers (Conv) and pooling layers. To expand the receptive field and reduce computation, general models commonly use strided convolution (typically with a stride of 2) or max pooling for downsampling, gradually reducing the size of the feature maps (typically by a factor of 8, 16, or 32). Feature fusion: A feature pyramid (FPN) structure is used to concatenate and fuse deep semantic features with shallow localization features. Detector head output: Finally, the target's bounding box and category are regressed on feature maps at different scales using the detector head.
[0007] However, for Gram-stained blood culture samples, the aforementioned existing technologies have the following significant technical problems, making it difficult to meet the high-precision requirements of clinical practice: Problem 1: Stride-based convolutions lead to the loss of features in tiny bacteria: Gram-negative bacilli or cocci account for a very small percentage of pixels in microscopic images (often only a few dozen pixels). Existing technologies (such as standard YOLOv11) heavily utilize stride-2 stride convolutions for downsampling in the backbone network. This downsampling method is essentially "lossy compression," which has little impact on large targets (such as vehicles and pedestrians), but for tiny bacteria, stride convolutions directly discard some pixel information. After multiple consecutive downsampling operations, the effective feature information of tiny bacteria often disappears completely in the deep feature map, causing the model to "not see" the bacteria, resulting in serious missed detections.
[0008] Problem 2: Lack of dynamic filtering capability for complex backgrounds. Blood culture samples have extremely "dirty" backgrounds, filled with irregularly shaped cell debris and impurities. These background noises are similar to bacteria in morphology and color. Existing general-purpose convolutional neural networks typically perform indiscriminate convolution calculations on all regions of an image (whether background or target), causing the model to be unable to distinguish between "critical bacterial regions" and "useless background impurity regions." This makes the model susceptible to interference from background noise when extracting features, misidentifying crystals or debris as bacteria, resulting in a high false detection rate and wasting a lot of computational resources on background processing.
[0009] Therefore, existing technologies suffer from low accuracy in bacterial identification. Summary of the Invention
[0010] To address the aforementioned shortcomings in existing technologies, this invention provides a method for identifying Gram-stained blood culture samples using microscopic images, which solves the problem of low bacterial identification accuracy in existing technologies.
[0011] To achieve the above-mentioned objectives, the technical solution adopted by this invention is as follows: a method for identifying microscopic images of Gram-stained blood culture samples, comprising the following steps: S1. Acquire Gram-stained blood culture smear images using an optical microscope and label the pathogenic bacteria with rectangular boxes; S2. Perform color space conversion on the labeled Gram-stained blood culture smear image to obtain the L-channel image and calculate the gradient magnitude of the pixels. S3. Divide the L-channel image into blocks, calculate the dynamic shearing threshold based on the average gradient magnitude in the sub-blocks, and shear the grayscale histogram of each sub-block to obtain histogram equalization sub-blocks. S4. Eliminate block artifacts in each histogram equalization sub-block, stitch them together with the A channel image and B channel image, and transform them back to the RGB color space to obtain a contrast-enhanced image. S5. After scaling the contrast-enhanced image, input it into the enhanced YOLOV11 target detection network to obtain the category of pathogenic bacteria.
[0012] Furthermore, S2 includes the following sub-steps: S21. Convert the labeled Gram-stained blood culture smear image from RGB color space to LAB color space, extract the L channel, and obtain the L channel image. S22. Use the Sobel operator to calculate the horizontal and vertical gradients of the L-channel plot; S23. Based on the horizontal and vertical gradients, obtain the gradient magnitude of each pixel in the L channel image.
[0013] Furthermore, the formula for calculating the horizontal gradient in S22 is: , in, The horizontal gradient of a pixel. This is an L-channel plot; The formula for calculating the vertical gradient in S22 is: , in, The vertical gradient of a pixel; The formula for calculating the gradient magnitude in S23 is: , in, The gradient magnitude of a pixel. The x-coordinate of the pixel is y is the ordinate of the pixel.
[0014] Furthermore, S3 includes the following sub-steps: S31. Divide the L channel image into 8×8 non-overlapping sub-blocks; S32. Take the average value of each gradient magnitude in the sub-block to obtain the average gradient intensity of the corresponding sub-block; S33. Calculate the dynamic shear threshold based on the average gradient intensity of the sub-blocks; S34. For each sub-block, calculate the gray-level histogram, and trim the gray-level histogram based on the dynamic shearing threshold to obtain the histogram-equalized sub-block.
[0015] Furthermore, the formula for calculating the dynamic shear threshold in S33 is as follows: , in, For the first Dynamic shearing threshold for each sub-block Based on the basic shear limit value, For the first The average gradient intensity of each sub-block For the maximum average gradient intensity, To minimize the average gradient intensity, To prevent parameters with a denominator of zero, For adjustment coefficients, This is the number of the sub-block.
[0016] Furthermore, S4 includes the following sub-steps: S41. Use bilinear interpolation to eliminate the block effect of each histogram equalization sub-block to obtain the L-enhanced channel map; S42. Merge the L enhancement channel image, A channel image, and B channel image, and transform them back to the RGB color space to obtain a contrast-enhanced image.
[0017] Furthermore, the construction process of the enhanced YOLOv11 object detection network in S5 includes: replacing the traditional strided convolutional layer with a spatial mapping convolutional module in the YOLOv11 network, and replacing the C2PSA module in the YOLOv11 network with a route-enhanced multi-head self-attention module to obtain the enhanced YOLOv11 object detection network.
[0018] Furthermore, the backbone network of the enhanced YOLOv11 object detection network includes, in sequence: a first spatial mapping convolutional module, a second spatial mapping convolutional module, a first C3k2 module, a third spatial mapping convolutional module, a second C3k2 module, a fourth spatial mapping convolutional module, a third C3k2 module, a fifth spatial mapping convolutional module, a fourth C3k2 module, an SPPF module, and a route-enhanced multi-head self-attention module.
[0019] Furthermore, the spatial mapping convolution module in S5 handles inputs of size... Feature map The processing steps include: A1. According to the scaling factor Feature map Slicing and sampling were performed to obtain four sub-feature maps, among which, For feature map Length or width, The number of channels in the feature map. The identifier of the feature map is used as input to the spatial mapping convolution module; A2. Concatenate the four sub-feature maps along the channel dimension to obtain the concatenated feature map; A3. Apply a standard convolution with a stride of 1 to the concatenated feature map to obtain... The fused feature map, where, This represents the number of channels in the fused feature map.
[0020] Furthermore, the route-enhanced multi-head self-attention module applies the input feature map The processing steps include: B1. Feature Map Divided into A number of non-overlapping regions, among which... The identifier of the input feature map is used for the routing-enhanced multi-head self-attention module. It is a positive integer; B2. Reshape each region to include The sequence of feature units Tokens is used to obtain the reconstructed feature map. ,in, The number of feature unit tokens, To reshape the feature map, For feature map The number of channels, It is the set of real numbers; B3. Calculate the reconstructed feature map for each region. The average value of each feature unit Token in the channel dimension is used to obtain the representative vector of the region; B4, will The representative vectors of each region are concatenated row by row to obtain the region-level feature matrix; B5. Perform linear transformations on the region-level feature matrices respectively to obtain the query matrix and the key matrix; B6. Calculate the adjacency matrix between regions based on the query matrix and the key matrix; B7. Based on the adjacency matrix, filter the regions with the highest scores and generate a routing index; B8. Based on the routing index, collect the key tensors and value tensors of the key regions; B9. Based on the key tensor and value tensor, the attention features are calculated through multi-head self-attention, and then the depthwise convolution enhancement term is superimposed to output the final feature tensor.
[0021] The beneficial effects of this invention are as follows: 1. This invention enhances the edge and texture features of bacteria under low contrast and low brightness by color space enhancement and adaptive histogram equalization, making bacteria stand out more in complex backgrounds, further improving the model's accuracy in locating and classifying bacteria, and making it more suitable for real-world identification scenarios of clinical Gram-stained blood culture samples.
[0022] 2. Significantly Improved Detection Capability for Extremely Small Targets (Solving the "Feature Loss" Problem): Unlike existing general-purpose YOLO models that use strided convolution for "lossy" downsampling, this invention utilizes spatial mapping convolution module technology to transfer spatial pixel information losslessly into the depth channel. This allows the model to retain complete feature information when processing Gram-negative bacilli or micrococci with extremely low pixel proportions (0.5-2μm), effectively avoiding the problem of feature loss for small targets in deep networks, significantly improving the recall rate for low-concentration, small pathogens, and reducing clinical missed detections.
[0023] 3. Enhanced Anti-interference Capability in Complex Backgrounds (Solving the "Background False Detection" Problem): Addressing the complex backgrounds of blood culture samples, which are often filled with red blood cell debris, protein deposits, and dye crystals, this invention introduces a route-enhanced multi-head self-attention module. Unlike existing technologies that perform indiscriminate calculations across the entire image, this invention dynamically assesses the importance of image regions, automatically filters out useless background noise areas, and concentrates computational resources on key areas where bacteria are present. This significantly reduces the false detection rate caused by similar background impurities and improves detection specificity.
[0024] 4. Achieving a balance between high accuracy and computational efficiency: Although an attention mechanism is introduced, the routing-enhanced multi-head self-attention module uses a sparse routing calculation method, avoiding the huge computational overhead of traditional global attention. This invention significantly improves the accuracy of microscopic image recognition while maintaining a relatively fast inference speed, meeting the real-time and high-throughput requirements of clinical testing. Attached Figure Description
[0025] Figure 1 A flowchart of a method for recognizing microscopic images of Gram-stained blood culture samples; Figure 2 A schematic diagram of the backbone network structure for the enhanced YOLOv11 target detection network; Figure 3 A schematic diagram of the neck network structure for the enhanced YOLOv11 target detection network. Detailed Implementation
[0026] 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.
[0027] like Figure 1 As shown, a method for identifying Gram-stained blood culture samples using microscopic images includes the following steps: S1. Acquire Gram-stained blood culture smear images using an optical microscope and label the pathogenic bacteria with rectangular boxes; S2. Perform color space conversion on the labeled Gram-stained blood culture smear image to obtain the L-channel image and calculate the gradient magnitude of the pixels. S3. Divide the L-channel image into blocks, calculate the dynamic shearing threshold based on the average gradient magnitude in the sub-blocks, and shear the grayscale histogram of each sub-block to obtain histogram equalization sub-blocks. S4. Eliminate block artifacts in each histogram equalization sub-block, stitch them together with the A channel image and B channel image, and transform them back to the RGB color space to obtain a contrast-enhanced image. S5. After scaling the contrast-enhanced image, input it into the enhanced YOLOV11 target detection network to obtain the category of pathogenic bacteria.
[0028] In this embodiment, in S1, Gram-stained blood culture smear images are acquired using an optical microscope. LabelMe and other annotation tools are used to label the pathogenic bacteria in the images with rectangular boxes (categories include Gram-positive cocci, Gram-negative bacilli, etc.).
[0029] To address the issue that blood culture samples contain a large amount of noise such as red blood cell fragments and protein deposits in the background, and that traditional histogram equalization tends to over-amplify background noise while enhancing bacterial contrast, this invention proposes an adaptive contrast enhancement method based on local gradient weighting, corresponding to S2, S3, and S4, which dynamically adjusts the enhancement intensity according to the texture richness of local regions.
[0030] In this embodiment, S2 includes the following sub-steps: S21. Convert the labeled Gram-stained blood culture smear image from RGB color space to LAB color space, extract the L channel, and obtain the L channel image. S22. Use the Sobel operator to calculate the horizontal and vertical gradients of the L-channel plot; S23. Based on the horizontal and vertical gradients, obtain the gradient magnitude of each pixel in the L channel image.
[0031] In S21, due to the high correlation between the three channels of the RGB color space, direct processing can easily lead to color distortion. First, the original image is converted to the LAB color space, the luminance channel L is extracted for subsequent processing, and the A and B chrominance channels are kept unchanged.
[0032] In S22, to distinguish between "bacterial regions" (high-frequency information) and "background impurity regions" (low-frequency or noise information) in the image, the gradient magnitude of the L channel is calculated. The Sobel operator is used to calculate the horizontal gradient separately. and vertical gradient .
[0033] In this embodiment, the formula for calculating the horizontal gradient in S22 is: , in, The horizontal gradient of a pixel. This is an L-channel plot; The formula for calculating the vertical gradient in S22 is: , in, The vertical gradient of a pixel; The formula for calculating the gradient magnitude in S23 is: , in, The gradient magnitude of a pixel. The x-coordinate of the pixel is y is the ordinate of the pixel.
[0034] In this embodiment, S3 includes the following sub-steps: S31. Divide the L channel image into 8×8 non-overlapping sub-blocks; S32. Take the average value of each gradient magnitude in the sub-block to obtain the average gradient intensity of the corresponding sub-block; S33. Calculate the dynamic shear threshold based on the average gradient intensity of the sub-blocks; S34. For each sub-block, calculate the gray-level histogram, and trim the gray-level histogram based on the dynamic shearing threshold to obtain the histogram-equalized sub-block.
[0035] In this embodiment, the image is divided into 8×8 non-overlapping sub-blocks. For the first... For each sub-block, calculate its average gradient intensity. This measures the likelihood that the region contains bacterial edges. A dynamic shearing threshold is defined to suppress background noise. Unlike traditional CLAHE which uses a fixed threshold, the formula for calculating the dynamic shear threshold is: , in, For the first Dynamic shearing threshold for each sub-block Based on the basic shear limit value, For the first The average gradient intensity of each sub-block For the maximum average gradient intensity, To minimize the average gradient intensity, To prevent parameters with a denominator of zero, For adjustment coefficients, This is the number of the sub-block.
[0036] In this embodiment, the basic shear limit value A constant, such as 2.0; adjustment coefficient. It can be set to 0.5 to control the weight of the gradient's influence. and These are the maximum and minimum values of the average gradient across all sub-blocks in the entire image, respectively. To prevent tiny quantities with a denominator of zero.
[0037] This invention focuses on sub-blocks with high gradient values (i.e., containing bacterial edges). Enlarging allows for stronger contrast enhancement, highlighting bacterial morphology; in sub-blocks with low gradient values (i.e., flat backgrounds), Approaching or lower than the baseline value limits the redistribution of the histogram, thereby suppressing noise amplification of background debris.
[0038] In this embodiment, the specific process of S34 includes: calculating the grayscale histogram within each sub-block. This is done using a dynamic threshold. Trim the histogram: remove excess data. The number of pixels is evenly distributed across the other gray levels of the histogram, and then the cumulative distribution function (CDF) is calculated for mapping to complete local equalization.
[0039] In this embodiment, S4 includes the following sub-steps: S41. Use bilinear interpolation to eliminate the block effect of each histogram equalization sub-block to obtain the L-enhanced channel map; S42. Merge the L enhancement channel image, A channel image, and B channel image, and transform them back to the RGB color space to obtain a contrast-enhanced image.
[0040] In this embodiment, the enhanced image is uniformly resized to 640×640 pixels and used as input to the enhanced YOLOV11 object detection network.
[0041] In this embodiment, the construction process of the enhanced YOLOv11 object detection network in S5 includes: replacing the traditional strided convolutional layer with a spatial mapping convolutional module in the YOLOv11 network, and then replacing the C2PSA module in the YOLOv11 network with a route-enhanced multi-head self-attention module to obtain the enhanced YOLOv11 object detection network.
[0042] like Figure 2 As shown, the backbone network of the enhanced YOLOv11 object detection network includes the following modules connected in sequence: a first spatial mapping convolutional module, a second spatial mapping convolutional module, a first C3k2 module, a third spatial mapping convolutional module, a second C3k2 module, a fourth spatial mapping convolutional module, a third C3k2 module, a fifth spatial mapping convolutional module, a fourth C3k2 module, an SPPF module, and a route-enhanced multi-head self-attention module.
[0043] To address the issue of feature information loss in traditional strided convolution downsampling for tiny targets such as bacteria, this invention introduces a spatial mapping convolution module. This module preserves all pixel information of tiny bacteria through spatial depth transformation, preventing feature loss during downsampling.
[0044] like Figure 3As shown, the neck network of the enhanced YOLOv11 target detection network includes: a first upsampling layer, a first Concat layer, a fifth C3k2 module, a second upsampling layer, a second Concat layer, a sixth C3k2 module, a first Conv layer, a third Concat layer, a seventh C3k2 module, a second Conv layer, a fourth Concat layer, and an eighth C3k2 module.
[0045] The neck network of the enhanced YOLOv11 object detection network has the same neck network structure as the original YOLOv11 network.
[0046] Figure 2 The first output terminal of the backbone network and Figure 3 The first input terminal of the middle neck network is connected, Figure 2 The second output terminal of the backbone network and Figure 3 The second input terminal of the middle neck network is connected, Figure 2 The third output terminal of the backbone network and Figure 3 The third input terminal of the middle neck network is connected.
[0047] The output of the first spatial mapping convolution module is: 320×320×(min(64,mc)×W), where 320×320 is the feature map size, (min(64,mc)×W) is the number of channels, min is the smaller of the two values, mc is the channel hyperparameter, and W is the spatial rearrangement factor.
[0048] The output of the second spatial mapping convolution module is: 160×160×(min(128,mc)×W), where 160×160 is the feature map size and (min(128,mc)×W) is the number of channels.
[0049] The parameters of the first C3k2 module are: False, n=2×d, e=0.25, and the output is: 160×160×(min(256,mc)×W), where False is the small convolution kernel for extracting fine features of bacteria, n is the number of residual blocks, d is the depth factor, e is the channel compression ratio, 160×160 is the feature map size, and (min(256,mc)×W) is the number of channels.
[0050] The output of the third spatial mapping convolution module is: 80×80×(min(256,mc)×W), where 80×80 is the feature map size and (min(256,mc)×W) is the number of channels.
[0051] The parameters of the second C3k2 module are: False, n=2×d, e=0.25, and the output is: 80×80×(min(512,mc)×W), where 80×80 is the feature map size and (min(512,mc)×W) is the number of channels.
[0052] The output of the fourth spatial mapping convolution module is: 40×40×(min(512,mc)×W), where 40×40 is the feature map size and (min(512,mc)×W) is the number of channels.
[0053] The parameters for the third C3k2 module include: True, n=2×d, and the output is: 40×40×(min(512,mc)×W), where True is the large convolution kernel for extracting bacterial features, and 40×40 is the feature map size.
[0054] The output of the fifth spatial mapping convolution module is: 20×20×(min(1024,mc)×W), where 20×20 is the feature map size and (min(1024,mc)×W) is the number of channels.
[0055] The parameters for the fourth C3k2 module are: True, n=2×d, and the output is: 20×20×(min(1024,mc)×W).
[0056] The SPPF module uses a 5×5 square convolution kernel, and the output is: 20×20×(min(1024,mc)×W), where 20×20 is the feature map size and (min(1024,mc)×W) is the number of channels.
[0057] The output of the routing-enhanced multi-head self-attention module is: 20×20×(min(1024,mc)×W).
[0058] The output of the first upsampling layer is: 20×20×(min(1024,mc)×W).
[0059] The parameters for the fifth C3k2 module are: False, n=2×d, and the output is: 40×40×(min(512,mc)×W).
[0060] The output of the second upsampling layer is: 80×80×(min(512,mc)×W).
[0061] The parameters for the sixth C3k2 module are: False, n=2×d, and the output is: 80×80×(min(256,mc)×W).
[0062] The parameters for the first Conv layer are: kernel size of 3, stride of 2, and output of 40×40×(min(256,mc)×W).
[0063] The parameters for the seventh C3k2 module are: False, n=2×d, and the output is: 40×40×(min(512,mc)×W).
[0064] The parameters for the second Conv layer are: kernel size of 3, stride of 2, and output of 20×20×(min(512,mc)×W).
[0065] The parameters for the eighth C3k2 module are: False, n=2×d, and the output is: 40×40×(min(1024,mc)×W).
[0066] In the feature downsampling stage of the backbone network, all the original strided convolutions are replaced with spatial mapping convolution modules. This module acts as a bridge connecting the feature extraction layers (C3k2) at each level, responsible for feature map size compression and channel expansion. By introducing spatial mapping convolution modules here to replace the traditional strided sampling operation (Stride=2), the model can losslessly transfer pixel information in the spatial dimension to the channel dimension, avoiding the feature loss problem caused by pixel discarding during continuous downsampling of tiny bacterial features (such as 0.5μm Gram-negative bacilli), and significantly improving the model's ability to perceive extremely small targets.
[0067] At the end of the backbone network, the original C2PSA module is replaced with a route-enhanced multi-head self-attention module. This module is located after the SPPF layer and before the neck network feature fusion. By introducing a two-layer route attention here, the model can effectively distinguish bacterial targets from red blood cell debris and crystalline impurities in the blood culture background at the highest semantic level.
[0068] In this embodiment, the spatial mapping convolution module in S5 handles inputs of size... Feature map The processing steps include: A1. Scale the scale factor to 2. Feature map Slicing and sampling were performed to obtain four sub-feature maps, among which, For feature map Length or width, The number of channels in the feature map. The identifier of the input feature map for the spatial mapping convolution module: A2. Concatenate the four sub-feature maps along the channel dimension to obtain the concatenated feature map; A3. Apply a standard convolution with a stride of 1 to the concatenated feature map to obtain... The fused feature map, where, This represents the number of channels in the fused feature map.
[0069] The four sub-feature maps obtained in A1 are as follows: , , , , in, The length or width of the feature map. The number of channels in the feature map. This is the first sub-feature map. This is the second sub-feature map. This is the third sub-feature map. This is the 4th sub-feature map. Indicates from index Initially, downsampling is performed with a step size of 2. for The feature map.
[0070] The splicing feature map in A2 is as follows: ,in, To stitch together the feature maps, For the concatenation operation, the four sub-feature maps are concatenated along the channel dimension to obtain a new feature. .at this time, The space size is halved, and the number of channels becomes 4 times the original. The dimension is This process preserves all pixel information from the original image without any loss of pixels.
[0071] The specific process of A3 includes: […]. Apply a standard convolutional layer with a stride of 1, increasing the number of channels from Adjust to target number of channels And perform feature fusion: Final output The dimension is .
[0072] This invention achieves downsampling through a spatial mapping convolution module, but avoids the information loss caused by traditional strided convolution (which directly skips pixels), thus significantly improving the ability to detect tiny bacteria.
[0073] To address the challenges of complex backgrounds and numerous interfering substances in positive blood culture smears, this invention introduces a route-enhanced multi-head self-attention module in the deep feature extraction stage. This module employs a two-layer route attention mechanism, dynamically allocating computational resources to regions containing bacteria while ignoring background regions. This two-layer routing mechanism filters out a large number of background impurities (such as red blood cell fragments and dye crystals) in the blood culture samples, allowing the model to focus on bacterial features.
[0074] In this embodiment, the route-enhanced multi-head self-attention module processes the input feature map. The processing steps include: B1. Feature Map Divided into A number of non-overlapping regions, among which... The identifier of the input feature map is used for the routing-enhanced multi-head self-attention module. , It is a positive integer. For feature map height, For feature map width, For feature map The number of channels; B2. Reshape each region to include The sequence of feature units Tokens is used to obtain the reconstructed feature map. ,in, The number of feature unit tokens, To reshape the feature map, It is the set of real numbers; B3. Calculate the reconstructed feature map for each region. The average value of each feature unit Token in the channel dimension is used to obtain the representative vector of the region; B4, will The representative vectors of each region are concatenated row by row to obtain the region-level feature matrix; B5. Perform linear transformations on the region-level feature matrices respectively to obtain the query matrix and the key matrix; B6. Calculate the adjacency matrix between regions based on the query matrix and the key matrix; B7. Based on the adjacency matrix, filter the regions with the highest scores and generate a routing index; B8. Based on the routing index, collect the key tensors and value tensors of the key regions; B9. Based on the key tensor and value tensor, the attention features are calculated through multi-head self-attention, and then the depthwise convolution enhancement term is superimposed to output the final feature tensor.
[0075] To identify regions with high correlation (i.e., where bacteria are present), we first average the values for each region to obtain a region-level representative vector, and then calculate the adjacency matrix between regions using matrix multiplication. : ,in, It is an adjacency matrix. This is a regional query matrix. The key matrix, This is a transpose operation. Then, the top-k operation is used to retain the first... Connect the most relevant regions to generate a routing index. : This step achieves coarse-grained filtering, eliminating useless background areas. It means "selecting the top scorer from the adjacency matrix". The operation "returns the index of each region" is performed based on the route index. Extract by index Operations to collect key and value tensors of critical regions: , , For the key tensor of all regions, For the value tensor of all regions, For the key region's key tensor, This is the value tensor for the critical region.
[0076] Finally, multi-head self-attention is computed only on the aggregated key-value pairs: , , in, For the final feature tensor, For multi-head self-attention calculation, For token-level query tensors, The depthwise convolution term is used to enhance local features. Scaling factor For activation function, This is for the transpose operation.
[0077] The routing-enhanced multi-head self-attention module enables the model to "skip" large blank or impurity areas when processing high-resolution microscopic images, and to perform refined feature extraction only on areas where bacteria are concentrated.
[0078] This invention uses a labeled dataset to train the improved model end-to-end, calculates the classification loss (VFL) and regression loss (DFL+CIoU), and updates the weights using backpropagation. The microscopic image to be tested is input into the trained model, which outputs the bacterial category, confidence score, and bounding box coordinates.
[0079] This invention enhances the edge and texture features of bacteria under low contrast and low brightness by color space enhancement and adaptive histogram equalization, making bacteria stand out more in complex backgrounds and further improving the model's accuracy in locating and classifying bacteria, making it more suitable for real-world identification scenarios of clinical Gram-stained blood culture samples.
[0080] Significant improvement in the detection capability of extremely small targets (solving the "feature loss" problem): Unlike existing general YOLO models that use strided convolution for "lossy" downsampling, this invention utilizes spatial mapping convolution module technology to transfer spatial pixel information losslessly into the depth channel. This allows the model to retain complete feature information when processing Gram-negative bacilli or micrococci with extremely low pixel proportions (0.5-2μm), effectively avoiding the problem of feature loss of small targets in deep networks, significantly improving the recall rate for low-concentration, small pathogens, and reducing clinical missed detections.
[0081] Enhanced robustness against complex backgrounds (solving the "background false detection" problem): Addressing the complex backgrounds of blood culture samples, which are often filled with red blood cell debris, protein deposits, and dye crystals, this invention introduces a route-enhanced multi-head self-attention module. Unlike existing technologies that perform indiscriminate calculations across the entire image, this invention dynamically assesses the importance of image regions, automatically filtering out useless background noise areas and concentrating computational resources on key areas where bacteria are present. This significantly reduces the false detection rate caused by similar background impurities and improves detection specificity.
[0082] A balance between high accuracy and computational efficiency is achieved: although an attention mechanism is introduced, the routing-enhanced multi-head self-attention module adopts a sparse routing calculation method, avoiding the huge computational overhead of traditional global attention. This invention significantly improves the accuracy of microscopic image recognition while maintaining a relatively fast inference speed, meeting the real-time and high-throughput requirements of clinical testing.
[0083] 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 identifying microscopic images of Gram-stained blood culture samples, characterized in that, Includes the following steps: S1. Acquire Gram-stained blood culture smear images using an optical microscope and label the pathogenic bacteria with rectangular boxes; S2. Perform color space conversion on the labeled Gram-stained blood culture smear image to obtain the L-channel image and calculate the gradient magnitude of the pixels. S3. Divide the L-channel image into blocks, calculate the dynamic shearing threshold based on the average gradient magnitude in the sub-blocks, and shear the grayscale histogram of each sub-block to obtain histogram equalization sub-blocks. S4. Eliminate block artifacts in each histogram equalization sub-block, stitch them together with the A channel image and B channel image, and transform them back to the RGB color space to obtain a contrast-enhanced image. S5. After scaling the contrast-enhanced image, input it into the enhanced YOLOV11 target detection network to obtain the category of pathogenic bacteria.
2. The method for identifying microscopic images of Gram-stained blood culture samples according to claim 1, characterized in that, S2 includes the following steps: S21. Convert the labeled Gram-stained blood culture smear image from RGB color space to LAB color space, extract the L channel, and obtain the L channel image. S22. Use the Sobel operator to calculate the horizontal and vertical gradients of the L-channel plot; S23. Based on the horizontal and vertical gradients, obtain the gradient magnitude of each pixel in the L channel image.
3. The method for identifying microscopic images of Gram-stained blood culture samples according to claim 2, characterized in that, The formula for calculating the horizontal gradient in S22 is as follows: , in, The horizontal gradient of a pixel. This is an L-channel plot; The formula for calculating the vertical gradient in S22 is as follows: , in, The vertical gradient of a pixel; The formula for calculating the gradient magnitude in S23 is as follows: , in, The gradient magnitude of a pixel. The x-coordinate of the pixel is The vertical coordinate of the pixel is denoted as .
4. The method for identifying microscopic images of Gram-stained blood culture samples according to claim 1, characterized in that, S3 includes the following steps: S31. Divide the L channel image into 8×8 non-overlapping sub-blocks; S32. Take the average value of each gradient magnitude in the sub-block to obtain the average gradient intensity of the corresponding sub-block; S33. Calculate the dynamic shear threshold based on the average gradient intensity of the sub-blocks; S34. For each sub-block, calculate the gray-level histogram, and trim the gray-level histogram based on the dynamic shearing threshold to obtain the histogram-equalized sub-block.
5. The method for identifying microscopic images of Gram-stained blood culture samples according to claim 4, characterized in that, The formula for calculating the dynamic shear threshold in S33 is as follows: , in, For the first Dynamic shearing threshold for each sub-block Based on the basic shear limit value, For the first The average gradient intensity of each sub-block For the maximum average gradient intensity, To minimize the average gradient intensity, To prevent parameters with a denominator of zero, For adjustment coefficients, This is the number of the sub-block.
6. The method for identifying microscopic images of Gram-stained blood culture samples according to claim 1, characterized in that, S4 includes the following steps: S41. Use bilinear interpolation to eliminate the block effect of each histogram equalization sub-block to obtain the L-enhanced channel map; S42. Merge the L enhancement channel image, A channel image, and B channel image, and transform them back to the RGB color space to obtain a contrast-enhanced image.
7. The method for identifying microscopic images of Gram-stained blood culture samples according to claim 1, characterized in that, The construction process of the enhanced YOLOv11 object detection network in S5 includes: replacing the traditional strided convolutional layer with a spatial mapping convolutional module in the YOLOv11 network, and replacing the C2PSA module in the YOLOv11 network with a route-enhanced multi-head self-attention module to obtain the enhanced YOLOv11 object detection network.
8. The method for identifying microscopic images of Gram-stained blood culture samples according to claim 7, characterized in that, The backbone network of the enhanced YOLOv11 object detection network includes, in sequence: a first spatial mapping convolutional module, a second spatial mapping convolutional module, a first C3k2 module, a third spatial mapping convolutional module, a second C3k2 module, a fourth spatial mapping convolutional module, a third C3k2 module, a fifth spatial mapping convolutional module, a fourth C3k2 module, an SPPF module, and a route-enhanced multi-head self-attention module.
9. The method for identifying microscopic images of Gram-stained blood culture samples according to claim 7 or 8, characterized in that, The S5 spatial mapping convolution module handles input sizes of... Feature map The processing steps include: A1. According to the scaling factor Feature map Slicing and sampling were performed to obtain four sub-feature maps, among which, For feature map Length or width, The number of channels in the feature map. The identifier of the feature map is used as input to the spatial mapping convolution module; A2. Concatenate the four sub-feature maps along the channel dimension to obtain the concatenated feature map; A3. Apply a standard convolution with a stride of 1 to the concatenated feature map to obtain... The feature maps are fused, where, This represents the number of channels in the fused feature map.
10. The method for identifying microscopic images of Gram-stained blood culture samples according to claim 7 or 8, characterized in that, The routing-enhanced multi-head self-attention module processes the input feature map. The processing steps include: B1. Feature Map Divided into A number of non-overlapping regions, among which... Identifier of the input feature map for the route-enhanced multi-head self-attention module. It is a positive integer; B2. Reshape each region to include The sequence of feature units Tokens is used to obtain the reconstructed feature map. ,in, The number of feature unit tokens, To reshape the feature map, For feature map The number of channels, It is the set of real numbers; B3. Calculate the reconstructed feature map for each region. The average value of each feature unit Token in the channel dimension is used to obtain the representative vector of the region; B4, will The representative vectors of each region are concatenated row by row to obtain the region-level feature matrix; B5. Perform linear transformations on the region-level feature matrices respectively to obtain the query matrix and the key matrix; B6. Calculate the adjacency matrix between regions based on the query matrix and the key matrix; B7. Based on the adjacency matrix, filter the regions with the highest scores and generate a routing index; B8. Based on the routing index, collect the key tensors and value tensors of the key regions; B9. Based on the key tensor and value tensor, the attention features are calculated through multi-head self-attention, and then the depthwise convolution enhancement term is superimposed to output the final feature tensor.