Research
An automatic counting algorithm for the quantification and uncertainty analysis of the number of microglial cells trainable in small and heterogeneous datasets
Overview Research area: Computational engineering and biomedical image analysis, specifically automated counting of immunohistochemically stained cells (microglial cells) coupled with uncertainty quan

- arXiv
- 2602.22974
- Published
- 2026-02-26
- Authors
- L. Martino, M. M. Garcia, P. S. Paradas, E. Curbelo
AI summary
Overview
Research area: Computational engineering and biomedical image analysis, specifically automated counting of immunohistochemically stained cells (microglial cells) coupled with uncertainty quantification, using non-parametric kernel regression.
Technical level: Intermediate. The algorithm itself is simple in its basic form, but the paper assumes familiarity with regression, non-parametric smoothers, cross-validation, and RGB color filtering.
Scope: The paper proposes a two-stage pipeline — color-threshold feature extraction followed by a kernel smoother — that counts microglial cells in rat lumbar spinal cord cross-sections while avoiding cell detection, remaining trainable on small datasets, and returning an uncertainty estimate alongside each prediction.
What This Paper Is About
Counting microglial cells in stained tissue images is normally done by hand, which is slow, requires extensive personnel training, and is prone to intra- and inter-operator variability. Existing automatic alternatives either report only total labeled area and intensity rather than cell number, or require deep-learning models whose training depends on pixel-level labeling of every cell in images of uniform size.
This paper takes a different route: it skips detection entirely and treats counting as a regression problem. High-resolution RGB images are converted into several binary filtered images using color threshold vectors; clusters of black pixels are counted in each; and a kernel smoother maps those counts to the expert's cell count, producing a non-negative prediction with a variance estimate.
Key Contributions
-
A two-stage counting framework (P1 + P2). P1 is a tailored color-threshold filter that performs dimension reduction and denoising, converting each high-resolution image into a vector of non-negative integer counts. P2 is a kernel smoother that regresses those counts onto the expert-provided number of microglial cells.
-
The kernel counter (KC), a non-parametric and non-linear counting algorithm with one hyper-parameter. In its basic version only the scalar η must be tuned (by leave-one-out cross-validation, or set by a rule of thumb). Because it is non-parametric, its complexity grows with the dataset size D, so it can interpolate heterogeneous data as well as work in small datasets.
-
Closed-form uncertainty quantification and support for multiple expert opinions. The prediction variance is computed directly from a formula (no bootstrap or resampling), and an isotropic multi-output extension can accept counts from several experts for the same image.
-
Robustness extensions and released code. The paper proposes adaptive thresholds based on color histograms and quantiles, three strategies for encoding expert uncertainty (soft labels, per-image weights β_d, and lower/upper bounds), and provides Matlab code and the analyzed images.
Main Findings
-
Counting-without-detection is viable. The authors report that numerical experiments with artificial and real datasets, including images from the Department of Basic Health Sciences, Faculty of Health Sciences of the Rey Juan Carlos University, Madrid, gave "very promising results." Specific quantitative metrics are not reported in the available text.
-
Non-negativity is guaranteed. Because the prediction is a weighted sum of non-negative expert counts with non-negative weights, the estimate is always ≥ 0, and can be converted to an integer by rounding.
-
Predictions are bounded by the training outputs. The estimate always lies between the minimum and maximum expert count in the database. Adding images therefore expands the range of values the algorithm can predict.
-
One hyper-parameter controls the underfitting/overfitting trade-off. As η approaches infinity, all weights become 1/D and the prediction reduces to the arithmetic mean of the expert counts. As η approaches zero, the prediction becomes the nearest-neighbor value N_{d*}, meaning the KC contains the nearest-neighbor algorithm as a special case. The optimal η* is expected to decrease as D grows.
-
The paper states that neural networks or other parametric algorithms can satisfy only one of the two requirements — flexibility on heterogeneous data or trainability on small datasets — but not both, whereas the KC can.
-
Clustering bias is self-correcting in principle. The Matlab clustering routine used to count black objects tends to overestimate, for example by counting a large microglial cell twice when part of it is disconnected. The paper argues this is acceptable provided the same clustering scheme is used for every image, because the kernel smoother corrects the systematic bias as D grows.
-
Signal-to-noise ratio is extremely low. On average, non-microglial pixels outnumber microglial pixels by roughly 10⁴, which motivates the filtering stage.
-
Threshold choice has an interpretable effect. Very small threshold values keep only dark pixels, yielding few objects but few artifacts; increasing thresholds captures more of each cell but also more artifacts. Once all microglial cells are included, further increases only add false positives.
Methodology in Plain English
The method has two clearly separated parts.
Part 1 — Turning images into numbers. Each pixel in an RGB image is described by three values (red, green, blue), each between 0 and 1. The researchers define a threshold vector t = [t1, t2, t3] and build a black-and-white image where a pixel becomes black only if all three of its color values are at or below the corresponding threshold. Using T different threshold vectors produces T binary filtered images per medical image. Any clustering routine that finds connected islands of black pixels can then count the objects in each filtered image; the paper uses a pre-established Matlab function for this. For the d-th image, the result is a vector r_d = [r_1d, r_2d, ..., r_Td] of object counts, paired with the expert's cell count N_d. The example in the paper uses N_d = 4 and T = 4, with 6 additional objects playing the role of irrelevant artifacts.
Part 2 — Learning to map counts to cell numbers. With D labeled images, the counting problem becomes a regression problem. The KC proceeds in three steps:
- Standardization: each of the T count columns is centered and scaled using its mean and standard deviation.
- Weighting: the Euclidean distance between the standardized vector of the new image and each stored image is computed, then converted into a weight via a Gaussian kernel with bandwidth η. Distances are thus turned into similarity weights, which are normalized to sum to one.
- Prediction: the estimate for the new image is the weighted average of the stored expert counts.
The single hyper-parameter η can be learned by leave-one-out cross-validation using any suitable metric, or initialized with the rule of thumb given in the paper. A variance estimate for the prediction is obtained directly from the weighted squared differences between each expert count and its own smoothed value, avoiding bootstrap procedures. The authors also note that more flexible variants are possible, for instance assigning a separate η_d to each image, at the cost of D hyper-parameters.
The paper additionally suggests converting fixed thresholds into probability values based on color histograms across the database, then turning those into quantile values for each new image. This adapts the filtering to images with different lighting or clarity and doubles as a simple data augmentation procedure.
Why This Matters
Impact on research. Manual counting remains the benchmark technique for microglial quantification, yet it is laborious, monotonous, and subject to both intra- and inter-operator variability. The paper's approach simplifies dataset creation considerably: experts only need to count cells rather than label every microglial pixel, and images no longer need uniform dimensions. Adding explicit uncertainty estimates addresses a gap the authors identify in deep-learning alternatives, where uncertainty propagation and label uncertainty remain challenging.
Real-world applications:
- Neuroscience and neuroimmunology research, where microglial size and number change upon activation and are studied in chronic neurodegenerative diseases such as Alzheimer's and Parkinson's disease, as well as chronic pain.
- Histology and pathology laboratories performing 3,3-Diaminobenzidine (DAB) immunohistochemistry on lumbar spinal cord cross-sections, where counting immunopositive cells normally requires detection plus manual annotation.
- Multi-center studies where images from different laboratories differ in magnification, resolution, brightness, saturation, contrast, and color shifts, and where the adaptive-threshold procedure is intended to help.
- Settings where several experts score the same image, since the KC directly handles multiple opinions per image rather than requiring a single consensus label.
Industry relevance. The paper targets the practical bottleneck that the dataset size D is limited by costly human work in terms of effort, time, and budget. A method that trains from one hyper-parameter and tolerates heterogeneous image quality lowers the barrier to deploying automated quantification in pharmaceutical and contract-research workflows, where ELISA and western blot are not applicable to homogenized tissue samples for this type of cell quantification.
Future Directions
-
Replacing the regression module. The authors explicitly state that practitioners may substitute the kernel smoother in P2 with a deep learning approach or any other alternative, provided the requirements listed for P2 (non-negativity, non-linearity, small-dataset trainability, optional extra flexibility, uncertainty estimates, and support for expert uncertainty) are satisfied.
-
Choosing thresholds more systematically. The paper notes that performance depends on the choice of threshold vectors and defers details to Appendix B, while proposing adaptive quantile-based thresholds as a mitigation. Determining optimal thresholds remains an open question.
-
Richer uncertainty modelling. The paper suggests that correlations or higher moments could also be estimated, beyond the variance formulas given, and describes three strategies for encoding expert uncertainty that could be developed further.
-
Validating scaling behaviour. The paper argues that as D grows, the optimal η* approaches zero and the algorithm gains flexibility, but the specific quantitative experiments supporting this claim, along with the full numerical results, are not detailed in the available text.
Target Audience
This paper is most useful for biomedical imaging researchers and computational scientists working on cell quantification in histology, particularly those dealing with small, heterogeneous datasets and needing uncertainty estimates. It also suits neuroscientists studying microglia who want a lightweight, trainable alternative to manual counting or to deep-learning pipelines requiring pixel-level annotation. Statisticians and machine-learning practitioners interested in non-parametric regression applied to counting problems will find the kernel counter formulation and its variance estimator relevant. Reviewers assessing reproducibility should note that Matlab code and the analyzed images are provided at the link given in the paper.
Authors’ abstract
Counting immunopositive cells on biological tissues generally requires either manual annotation or (when available) automatic rough systems, for scanning signal surface and intensity in whole slide imaging. In this work, we tackle the problem of counting microglial cells in lumbar spinal cord cross-sections of rats by omitting cell detection and focusing only on the counting task. Manual cell counting is, however, a time-consuming task and additionally entails extensive personnel training. The classic automatic color-based methods roughly inform about the total labeled area and intensity (protein quantification) but do not specifically provide information on cell number. Since the images to be analyzed have a high resolution but a huge amount of pixels contain just noise or artifacts, we first perform a pre-processing generating several filtered images {(providing a tailored, efficient feature extraction)}. Then, we design an automatic kernel counter that is a non-parametric and non-linear method. The proposed scheme can be easily trained in small datasets since, in its basic version, it relies only on one hyper-parameter. However, being non-parametric and non-linear, the proposed algorithm is flexible enough to express all the information contained in rich and heterogeneous datasets as well (providing the maximum overfit if required). Furthermore, the proposed kernel counter also provides uncertainty estimation of the given prediction, and can directly tackle the case of receiving several expert opinions over the same image. Different numerical experiments with artificial and real datasets show very promising results. Related Matlab code is also provided.