Microcystis population cell counting method fusing deep learning and adaptive clustering
By constructing a dual-branch deep learning network and an adaptive clustering strategy, the accuracy and efficiency issues of cell counting in Microcystis populations were solved, enabling high-precision detection and real-time monitoring in complex scenarios.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- INST OF AQUATIC LIFE ACAD SINICA
- Filing Date
- 2026-01-13
- Publication Date
- 2026-04-10
AI Technical Summary
Existing technologies for counting cells in Microcystis populations are cumbersome, time-consuming, and dependent on professional experience. Traditional image processing algorithms also suffer from low counting accuracy in complex scenarios.
By employing a method that integrates deep learning and adaptive clustering, a dual-branch network structure is constructed. The texture details and population distribution features of Microcystis are extracted in parallel through density estimation and target regression. An adaptive clustering algorithm is introduced to optimize the threshold strategy, thereby achieving accurate localization and counting of Microcystis population cells.
It significantly improves the accuracy and robustness of cell counting in Microcystis populations, enabling efficient and real-time cell count and spatial positioning in complex scenarios, and is suitable for emergency monitoring and online early warning of algal blooms.
Smart Images

Figure CN121838136A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application belongs to the technical field of water ecological environment monitoring, and particularly relates to a microcystis colony cell counting method fusing deep learning and adaptive clustering. BACKGROUND
[0002] The cell density of phytoplankton is one of the key indicators for evaluating the degree of water eutrophication and the intensity of water bloom. As one of the most common bloom blue-green algae, microcystis is easy to form aggregated groups and is widely distributed, so accurate counting of the number of single cells in the group is particularly important for accurately judging the scale of water bloom. The conventional phytoplankton cell counting method is mainly 0.1 ml counting frame-microscope counting method and filter membrane method. In recent years, there are also methods of using flow cytometry and other equipment to identify images and automatically count phytoplankton cells, in addition, there are also methods of using machine learning to predict phytoplankton.
[0003] However, the above methods each have its limitations. The traditional microscope counting method has a cumbersome operation process, is time-consuming, and is heavily dependent on the experience of professional technicians, so it is difficult to control the quality in actual work and the data consistency is poor. Although the automatic image recognition method is relatively simple to operate and significantly improves the efficiency, the accuracy of the determination result is highly dependent on the data algorithm and image quality. In particular, when facing microcystis and other complex groups that are easy to form, there is serious shielding or overlapping between cells, so the traditional image processing algorithm or the early machine learning model is difficult to realize accurate segmentation and positioning of the cells, resulting in a large deviation or even error of the cell counting result, which affects the actual application effect in environmental monitoring. SUMMARY
[0004] The purpose of the present application is to provide a microcystis colony cell counting method fusing deep learning and adaptive clustering, which is simple to operate, high in precision, and can locate and count each cell in the microcystis colony through deep learning and adaptive clustering.
[0005] In order to achieve the above purpose, the following technical solutions are adopted in the present application: The present application provides a microcystis colony cell counting method fusing deep learning and adaptive clustering, comprising the following steps: Step 1, collecting microcystis colony images and labeling the cell positions and quantities; Step 2, constructing a microcystis cell counting network; Step 3, inputting the microcystis colony images as input and the labeled points as output into the microcystis cell counting network of step 2 for training, and considering that the training is completed when a preset condition is met; Step 4, converting the microcystis data set into a gray-scale image and clustering according to the average gray level; Step 5, the clusters divided in step 4 are respectively sent to the data set trained in step 3 to determine the optimal positioning threshold of each cluster; Step 6, counting, that is, after the new microcystis colony image is determined after the grayscale conversion, the original image is sent to the trained counting network to obtain the position and quantity of microcystis after the threshold of the image is determined.
[0006] In the above technical solution, in step 1, collecting microcystis colony images and labeling cell positions and quantities specifically includes the following steps: Step 11, taking a microcystis colony cell image; Step 12, dot labeling of microcystis cell individuals, that is, a dot labeling point is marked as a coordinate for each microcystis cell; the dot labeling point is in the form of (x, y), wherein x is the horizontal coordinate of the microcystis, and y is the vertical coordinate of the microcystis; Step 13, the microcystis image is randomly divided into a training set and a test set according to a ratio of 4:1.
[0007] In the above technical solution, in step 2, the microcystis cell counting network is a double-branch network structure composed of a backbone network, a density branch, and a regression branch; The backbone network is a feature extraction layer of resnet50, used to preliminarily extract image features; The density branch is composed of a density encoding layer and a density head, wherein the density encoding layer is composed of five convolutional layers, and when the global feature vector extracted by the backbone network generates an intermediate feature vector , After that, the density head obtains a density output map, and the density head is composed of a 1x1 convolutional layer and a ReLU activation function, used to generate a density feature map, and the finally output density feature map will be input for the density branch loss function calculation, providing a supervision signal for the density estimation task of the model; The regression branch is composed of a Feature Transformer module, a standard Transformer Decoder module, and a regression head, the Feature Transformer module will extract the global feature vector from the backbone network and the intermediate feature vector generated in the density branch respectively after multi-layer perception (MLP) transformation, and then added and fused to obtain a preliminary fusion feature vector ; After that, the preliminary fusion feature vector is input into the standard Transformer encoder to realize modeling and feature enhancement of global dependency; then the feature vector from the previous stage After being processed by a multi-layer perception (MLP), the enhanced features are connected with themselves to generate enhanced features; the enhanced features are connected with features output by a Transformer encoder to further refine semantic representations; after repeating the fusion and encoding processes twice, high-level fused features obtained finally are input into a Transformer decoder; finally, vectors output by the Transformer decoder are sent to a regression head and a classification head respectively to obtain corresponding feature outputs, and the regression head and the classification head are composed of MLPs; The loss function of the counting network is divided into two parts, one being the loss of the density branch and the other being the loss of the regression branch, wherein the loss of the density branch is composed of a weighted sum of an optimal transport loss , a counting loss and a total variation loss The density loss can be represented by the following formula:
[0008] The optimal transport loss is obtained by solving an optimal transport matrix to minimize the overall transport cost between distributions:
[0009] wherein, and represent a predicted density distribution and a real distribution respectively, represents a transport cost from a position to a position , and is a set of feasible transport plans satisfying an edge constraint; The counting loss is a loss between a number predicted in the density branch and an actual number, and is selected as an L1 loss; The mathematical form of the total variation loss is as follows:
[0010] wherein, represents a density map predicted by a model, represents a pixel position; The regression branch introduces a Hungarian matching algorithm, first establishes an optimal matching relationship between a model prediction result and a real label by the Hungarian algorithm; subsequently, a prediction-real target pair matched is subjected to supervised learning of a category and a bounding box respectively, so as to realize an end-to-end collective target detection mechanism, and the regression loss For the supervised learning loss of categories and bounding boxes in the regression branch, L1 loss is chosen; The overall loss L is composed of density loss and regression loss composition, .
[0011] In the above technical solution, in step 3, the preset condition is that the training is considered complete when the number of training rounds reaches 1500.
[0012] In the above technical solution, in step 4, the number of clusters is set to 3. Then, the average gray value of the grayscale image is extracted, and the extracted grayscale features are clustered using the K-Means clustering method to generate a clustering model, distinguish different types of Microcystis populations and complete the population division.
[0013] In the above technical solution, in step 4, a Gaussian Mixture Model (GMM) based on a probability model is used to cluster the extracted grayscale features.
[0014] In the above technical solution, in step 4, the extracted grayscale features are clustered using the hierarchical clustering method, a cluster tree structure is constructed using distance metrics, and the Microcystis population is classified according to the splitting or merging process of the cluster tree.
[0015] In the above technical solution, in step 5, all data of a certain category are sequentially fed into the model for testing, and the detection threshold output by the model is adjusted step by step in the range of 0.05 to 0.95 with a step size of 0.05; when the counting result corresponding to a certain threshold is closest to the actual count, the threshold is determined as the optimal positioning threshold for that category.
[0016] In the above technical solution, in step 6, when counting the Microcystis population image to be detected, the image is first converted to grayscale, and its population category is determined based on the clustering model in step 4; then, according to the optimal positioning threshold corresponding to the category, the original image is input into the counting model trained in step 3, and the specific location and number of Microcystis cells are obtained by filtering the model output results according to the threshold.
[0017] The beneficial effects of this invention are as follows: (1) A dual-branch deep network structure for population feature perception. A dual-branch network framework that integrates density estimation and target regression is constructed to extract the texture details of Microcystis at the microscale and the population distribution features at the macroscale, respectively. The two types of features are dynamically integrated through an adaptive feature fusion module, thereby significantly improving the detection robustness and accuracy in complex scenes.
[0018] (2) Adaptive clustering threshold strategy based on Microcystis characteristics. A clustering algorithm designed for Microcystis characteristics is introduced to perform prior clustering on the prediction results to adapt to Microcystis populations of different orders of magnitude, different densities and overlapping areas, thereby automatically generating a more reasonable threshold and achieving more stable and accurate detection and inference.
[0019] (3) Highly efficient real-time quantity statistics and spatial positioning capabilities. The system can simultaneously output the number of Microcystis cells and their corresponding coordinates during the inference process, balancing detection accuracy and calculation speed. It is suitable for scenarios requiring rapid response, such as emergency monitoring and online early warning of Microcystis blooms. Attached Figure Description
[0020] Figure 1 It is the overall flowchart; Figure 2 This is a diagram of the overall structure of the counting network; Figure 3 This is a diagram of the Feature Transformer encoder structure. Detailed Implementation
[0021] To better illustrate the objectives, technical solutions, and advantages of this invention, the invention will be further described below in conjunction with specific embodiments. This invention can be embodied in many different forms and should not be construed as limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the inventive concept to those skilled in the art. This invention will be defined only by the claims.
[0022] This invention provides a method for counting cells in a Microcystis population that integrates deep learning and adaptive clustering, specifically including the following steps: Step 1: Collect images of Microcystis colonies and label cell locations and numbers. This includes the following steps: Step 11: Take images of the Microcystis colony cells.
[0023] Step 12: Label individual Microcystis cells, that is, mark each Microcystis cell with a coordinate point. The label point is in the form of (x, y), where x is the x-coordinate of Microcystis and y is the y-coordinate of Microcystis. Therefore, for a Microcystis population, its labeling form is (x1, y1), (x2, y2)...(x...y1)...(x...y2 ... n y n These markers are used to mark the location of cells in the Microcystis population and to determine the number of cells n in the Microcystis population.
[0024] Step 13: Randomly divide the Microcystis images into training and test sets at a ratio of 4:1.
[0025] Step 2: Construct a Microcystis cell counting network.
[0026] The specific network structure is a two-branch network structure, consisting of a backbone network, a density branch, and a regression branch.
[0027] The backbone network is the feature extraction layer of ResNet50, used to initially extract image features.
[0028] The density branch consists of a density coding layer and a density head, where the density coding layer consists of five convolutional layers. This is used when the backbone network extracts the global feature vector. The intermediate feature vector is generated after the density coding layer. back, The density output map is then obtained through a density head, which consists of a 1×1 convolutional layer and a ReLU activation function, used to generate the density feature map. The final output density feature map will be used as input for calculating the density branch loss function, providing a supervisory signal for the model's density estimation task.
[0029] The regression branch consists of a Feature Transformer module, a standard Transformer Decoder module, and a regression head. The Feature Transformer module extracts the global feature vector from the backbone network. Intermediate feature vectors generated in the density branch After being transformed by a multilayer perceptron (MLP), the features are summed and fused to obtain a preliminary fused feature vector. The feature vectors will then be initially fused. The input is fed into the standard Transformer encoder to model global dependencies and enhance features; then the feature vectors from the previous stage are... After processing by a multilayer perceptron (MLP), the feature is concatenated with itself to generate enhanced features; these enhanced features are then combined with the features output by the Transformer encoder. The features are then summed and fused, and fed into a new standard Transformer encoder to further refine the semantic representation. This fusion and encoding process is repeated twice, and the resulting high-level fused features are then fed into the Transformer decoder. Finally, the vectors output from the Transformer decoder are sent to the regression head and classification head, respectively, to obtain the corresponding feature outputs. Both the regression head and classification head are composed of MLPs.
[0030] The loss function of the counting network is divided into two parts: the loss of the density branch and the loss of the regression branch. The loss of the density branch is composed of the optimal transmission loss. Count loss Total variation loss The weighted sum composition, specifically, the density branch loss can be expressed by the following formula:
[0031] in, , , Both can be set to 1. , , The value can vary depending on the specific circumstances.
[0032] Optimal transmission loss By solving the optimal transfer matrix To minimize the overall transmission cost between distributions:
[0033] in, and These represent the predicted density distribution and the actual distribution, respectively. Indicates from position Arrive at the location The transmission cost (usually expressed as Euclidean distance or its square). This is the set of all feasible transport plans that satisfy the edge constraints.
[0034] Counting loss The loss between the predicted and actual quantities in the density branch is selected as L1 loss to constrain the overall quantity accuracy.
[0035] Total variation loss Initially applied to image denoising and reconstruction tasks, its core idea is to encourage stronger spatial continuity and structural consistency in the generated results by penalizing intensity variations between adjacent pixels. Its mathematical form can be expressed as:
[0036] in, This represents the density map predicted by the model. This represents the pixel location. This loss term reduces high-frequency noise and isolated responses in the density map by minimizing the absolute value of the local gradient, resulting in a smoother and more natural spatial distribution of the prediction results.
[0037] The regression branch incorporates the Hungarian matching algorithm. Specifically, it first establishes a one-to-one optimal matching relationship between model predictions and ground truth labels using the Hungarian algorithm; then, it performs supervised learning of the class and bounding box for each matched prediction-ground target pair, thus achieving an end-to-end ensemble object detection mechanism. Regression Loss For the supervised learning loss of categories and bounding boxes in the regression branch, L1 loss is chosen.
[0038] The overall loss L is composed of density loss and regression loss composition, .
[0039] Step 3: Use the image of the Microcystis colony as input and the labeled points as output to train the Microcystis cell counting network. The training is considered complete when the preset conditions are met.
[0040] The preset condition is that training is considered complete when 1500 training rounds are completed.
[0041] Step 4: Convert the Microcystis dataset into grayscale images and cluster them according to the average grayscale.
[0042] Because Microcystis colony images contain Microcystis cells of varying orders of magnitude and degree of overlap—such as colonies containing only single Microcystis cells, colonies containing a small number of Microcystis cells, and colonies containing a large number of Microcystis cells with significant overlap—these colonies exhibit significant differences in their image statistical characteristics. Based on this difference, the original Microcystis images are converted into grayscale images. After conversion, solitary colonies typically have lower grayscale values, small-scale colonies correspond to medium grayscale values, while large, heavily overlapping colonies exhibit higher grayscale values due to internal occlusion. Using the average grayscale value as a clustering feature can effectively distinguish the three types of colony structures. The clustering number is set to 3, and then the average grayscale value of the grayscale image is extracted. The K-Means clustering method is then used to cluster the above features to generate a clustering model used to distinguish different types of Microcystis colonies and complete the classification of the three types of colonies.
[0043] In the actual clustering process, features are standardized and centroids are initialized multiple times to improve the consistency and stability of the clustering results. The generated clustering results can be further used as the basis for subsequent image processing or classification strategies, enabling different categories of Microcystis populations to be processed differently, thereby improving the overall analysis effect.
[0044] In addition to the K-Means-based clustering method mentioned above, other clustering strategies can be employed to classify Microcystis populations to improve the method's versatility and avoid over-reliance on a single algorithm. For example, a Gaussian Mixture Model (GMM) based on a probabilistic model can be used to cluster the extracted grayscale features. This method achieves clustering by estimating the probability distribution of different categories. Compared to the hard partitioning of K-Means, GMM provides more flexible category boundaries, thus obtaining more stable clustering results even when the grayscale distribution of the population exhibits continuous changes or the transition between categories is ambiguous.
[0045] In addition, hierarchical clustering can be used to cluster features. This method does not require a preset number of clusters, but can construct a tree-like clustering structure using distance metrics, and classify Microcystis populations based on the splitting or merging process of the clustering tree. This approach is particularly suitable for image scenarios where the differences in population features vary hierarchically, and can further enhance the adaptability of clustering under different image complexities.
[0046] By introducing the aforementioned alternative clustering methods, this step significantly expands the range of supported algorithms while maintaining consistency in clustering principles. This makes the method more adaptable and robust, and helps maintain stable classification performance under different sampling conditions, lighting differences, or changes in image contrast.
[0047] Step 5: Input the clusters that were divided in Step 4 into the dataset trained in Step 3 to determine the optimal localization threshold for each cluster.
[0048] Specifically, the group data obtained in step 4 are input into the counting model trained in step 3 to determine the optimal localization threshold for each group. Specifically, all data for a certain category are sequentially fed into the model for testing, and the detection threshold output by the model is adjusted step-by-step in increments of 0.05 to 0.95. When the counting result corresponding to a certain threshold is closest to the true count, that threshold is determined as the optimal localization threshold for that category.
[0049] Step 6: Perform counting. After converting the new Microcystis population image to grayscale and determining the threshold of the image, the original image is then fed into the trained counting network to obtain the location and quantity of Microcystis.
[0050] Specifically, when counting images of Microcystis colonies to be detected, the image is first converted to grayscale, and its colony category is determined based on the clustering model in step 4. Then, according to the optimal localization threshold corresponding to the category, the original image is input into the counting model trained in step 3. The specific location and number of Microcystis cells are obtained by filtering the model output according to the threshold.
[0051] This invention constructs a density-regression dual-branch population feature perception network, introduces an adaptive clustering threshold strategy based on Microcystis population characteristics, and achieves synchronous real-time output of Microcystis cell number and spatial location information. This effectively improves the detection accuracy and stability of the system in complex scenarios, combining high efficiency and real-time performance, and can provide more reliable technical support for emergency monitoring and online early warning of Microcystis blooms.
[0052] Obviously, the above embodiments are merely illustrative examples for clear explanation and are not intended to limit the implementation. Those skilled in the art will recognize that other variations or modifications can be made based on the above description. It is neither necessary nor possible to exhaustively list all possible implementations here. However, obvious variations or modifications derived therefrom are still within the scope of protection of this invention.
Claims
1. A method for counting cells in a Microcystis population that integrates deep learning and adaptive clustering, characterized in that: Includes the following steps: Step 1: Collect images of Microcystis colonies and label cell locations and numbers; Step 2: Construct a Microcystis cell counting network; Step 3: Use the Microcystis colony image as input and the labeled points as output to train the Microcystis cell counting network from Step 2. Training is considered complete when the preset conditions are met. Step 4: Convert the Microcystis dataset into grayscale images and cluster them according to the average grayscale. Step 5: Input the clusters that were divided in Step 4 into the dataset trained in Step 3 to determine the optimal localization threshold for each cluster. Step 6: Counting is performed. After converting the new Microcystis population image to grayscale and determining the threshold of the image, the original image is then fed into the trained counting network to obtain the location and quantity of Microcystis.
2. The counting method according to claim 1, characterized in that: Step 1, collecting images of Microcystis colonies and labeling cell locations and numbers, specifically includes the following steps: Step 11: Take images of the Microcystis colony cells; Step 12: Mark individual cells of Microcystis, that is, mark a point as coordinate for each Microcystis cell; the marking point is in the form of (x, y), where x is the x-coordinate of Microcystis and y is the y-coordinate of Microcystis. Step 13: Randomly divide the Microcystis images into training and test sets at a ratio of 4:
1.
3. The counting method according to claim 1, characterized in that: In step 2, the Microcystis cell counting network is a bi-branched network structure, consisting of a backbone network, a density branch, and a regression branch; The backbone network is the feature extraction layer of ResNet50, used to initially extract image features; The density branch consists of a density coding layer and a density head, wherein the density coding layer consists of five convolutional layers, when the backbone network extracts the global feature vector. The intermediate feature vector is generated after the density coding layer. back, The density output map is then obtained through the density head, which consists of a 1×1 convolutional layer and a ReLU activation function. It is used to generate the density feature map. The final output density feature map will be used as the input for the density branch loss function calculation, providing a supervision signal for the model's density estimation task. The regression branch consists of a Feature Transformer module, a standard Transformer Decoder module, and a regression head. The Feature Transformer module extracts the global feature vector from the backbone network. Intermediate feature vectors generated in the density branch After being transformed by a multilayer perceptron (MLP), the features are summed and fused to obtain a preliminary fused feature vector. ; The feature vectors will then be initially fused. The input is fed into the standard Transformer encoder to achieve global dependency modeling and feature enhancement; Then take the feature vector from the previous stage After being processed by a multilayer perceptron (MLP), it is connected to itself to generate enhanced features; Combine enhanced features with features output by the Transformer encoder The features are added and fused, and then input into a new standard Transformer encoder to further refine the semantic representation. After repeating the above fusion and encoding process twice, the final high-level fused features are input into the Transformer decoder. Finally, the vectors output by the Transformer decoder are sent to the regression head and the classification head respectively to obtain the corresponding feature outputs. The regression head and the classification head are composed of MLPs. The loss function of the counting network is divided into two parts: the loss of the density branch and the loss of the regression branch. The loss of the density branch is composed of the optimal transmission loss. Count loss Total variation loss Weighted sum composition, density loss It can be expressed by the following formula: Optimal transmission loss By solving the optimal transfer matrix To minimize the overall transmission cost between distributions: in, and These represent the predicted density distribution and the actual distribution, respectively. Indicates from position Arrive at the location The transmission cost This is the set of all feasible transmission plans that satisfy the edge constraints. Counting loss The loss between the predicted quantity and the actual quantity in the density branch is selected as L1 loss; Total variation loss The mathematical form is: in, This represents the density map predicted by the model. Indicates pixel position; The regression branch incorporates the Hungarian matching algorithm. First, it establishes a one-to-one optimal matching relationship between model predictions and ground truth labels. Then, it performs supervised learning of the class and bounding box for each matched prediction-ground target pair, thus achieving an end-to-end ensemble object detection mechanism. The regression loss... For the supervised learning loss of categories and bounding boxes in the regression branch, L1 loss is chosen; The overall loss L is composed of density loss and regression loss composition, .
4. The counting method according to claim 1, characterized in that: In step 3, the preset condition is that training is considered complete when 1500 training rounds are completed.
5. The counting method according to claim 1, characterized in that: In step 4, the number of clusters is set to 3. Then, the average gray value of the grayscale image is extracted, and the extracted grayscale features are clustered using the K-Means clustering method to generate a clustering model, distinguish different types of Microcystis populations, and complete the population division.
6. The counting method according to claim 1, characterized in that: In step 4, the extracted grayscale features are clustered using a Gaussian Mixture Model (GMM) based on a probability model.
7. The counting method according to claim 1, characterized in that: In step 4, the extracted grayscale features are clustered using the hierarchical clustering method. A cluster tree structure is constructed using distance metrics, and the Microcystis population is classified according to the splitting or merging process of the cluster tree.
8. The counting method according to claim 1, characterized in that: In step 5, all data of a certain category are sequentially fed into the model for testing, and the detection threshold output by the model is adjusted step by step in increments of 0.05 within the range of 0.05 to 0.
95. When the count result corresponding to a certain threshold is closest to the actual count, that threshold is determined as the optimal positioning threshold for that category.
9. The counting method according to claim 1, characterized in that: In step 6, when counting the images of the Microcystis population to be detected, the image is first converted to grayscale, and its population category is determined based on the clustering model in step 4. Subsequently, based on the optimal localization threshold corresponding to the category, the original image is input into the counting model trained in step 3. The model output is then filtered according to the threshold to obtain the specific location and number of Microcystis cells.