How CNNs Learn to Classify White Blood Cells Under the Microscope

A look at how a simple convolutional neural network can tell eosinophils, lymphocytes, monocytes and neutrophils apart from microscope images, and where this fits into NHS haematology labs.

▶ Open the simulation

Why counting blood cells by eye is slow and error-prone

Every full blood count that flags something unusual eventually lands in front of a biomedical scientist who has to sit at a microscope and manually classify white blood cells (leukocytes) one by one. This process, called the differential white cell count, sorts cells into categories such as neutrophils, lymphocytes, monocytes and eosinophils, because the relative proportions of each type carry diagnostic meaning: a spike in neutrophils often points to a bacterial infection, a rise in eosinophils suggests an allergic or parasitic reaction, and abnormal lymphocyte counts can be an early sign of leukaemia. Manual counting is accurate in skilled hands but slow, subjective, and a genuine bottleneck in busy haematology laboratories, including those serving NHS Blood and Transplant and NHS pathology networks that process thousands of samples a day.

Automating even a first-pass classification with a computer vision model does not replace the biomedical scientist, but it can pre-sort images, flag likely abnormal cells for priority review, and cut the routine workload dramatically.

Turning a microscope image into numbers a network can use

A digital microscope image is just a grid of pixel values, each holding a red, green and blue intensity. A convolutional neural network (CNN) is built specifically to find patterns in that kind of grid. Instead of looking at the whole image at once, small filters (sometimes just 3x3 pixels) slide across the picture, each one learning to detect a very local pattern — the curve of a cell membrane, a patch of granular cytoplasm, the dense, irregular shape of a nucleus. Early layers pick up simple edges and colour gradients; as the filters stack up through the network, later layers combine those simple signals into much more complex shapes, eventually representing entire structures like a multi-lobed neutrophil nucleus or the large, round nucleus that almost fills a lymphocyte.

A typical simple architecture for this task chains three blocks of convolution, batch normalisation and max-pooling, each block halving the image's width and height while increasing the number of feature channels (for example 32, then 64, then 128 filters). The final feature map is flattened and passed through a couple of fully connected layers ending in a softmax output — one probability for each of the four white cell types the model has been asked to distinguish. Dropout layers are added before the final classification to randomly disable some connections during training, which stops the network from memorising quirks of individual training images rather than learning generalisable cell features.

Training on labelled cell images

Training data for this kind of task typically comes from datasets of several thousand labelled microscope images split into training and test sets, each image already tagged by an expert with its correct cell type. During training the network is shown a batch of images, makes a guess, and is corrected against the known answer using a loss function that measures how wrong it was; an optimiser (commonly Adam) nudges every filter's weights slightly to reduce that error, repeating the process over many passes (epochs) through the data. Because microscope images vary in orientation, lighting and staining intensity between labs, image augmentation — random rotations, small shifts and horizontal flips applied on the fly — helps the model cope with that real-world variability rather than overfitting to one lab's exact conditions.

Two safety valves are standard practice: early stopping halts training automatically once performance on a held-out validation set stops improving (protecting against overfitting), and only the checkpoint with the best validation accuracy is kept as the final model.

Reading the results: accuracy alone is not enough

Once trained, the model's performance is checked on images it has never seen. Overall accuracy is the headline number, but for a four-way classification problem a confusion matrix tells a much more useful story: it shows exactly which cell types get mixed up with each other. Neutrophils and eosinophils, for instance, share some visual features (both are granulocytes with lobed nuclei) and are more likely to be confused with each other than with lymphocytes, which look quite different under the microscope. Per-class accuracy — checking how well the model does on each individual cell type rather than averaging everything together — matters clinically too, because missing a rare but important abnormal cell type is a far more serious failure than a small dip in overall accuracy.

From notebook to laboratory: what would need to change

A model like this, trained end-to-end in a single notebook session, is a reasonable proof of concept but a long way from something that could sit inside an NHS laboratory information management system (LIMS). Real deployment would need training on far larger and more diverse datasets collected from multiple hospitals and multiple microscope/camera combinations, validation against expert haematologists on genuinely held-out data, formal regulatory clearance as a medical device (in the UK, that means engaging with the MHRA's software-as-a-medical-device framework), and the ability to flag abnormal or cancerous-looking cells — a much harder problem than sorting healthy cell types, since it also requires the model to say "I do not know" rather than forcing every unusual cell into one of a small number of known categories.

Transfer learning — starting from a network already pretrained on millions of general images and fine-tuning it on blood cell data — typically improves both accuracy and the amount of data needed compared with training a small custom CNN completely from scratch, and would likely be the next step for a more serious version of this kind of tool.

Frequently Asked Questions

What is a differential white blood cell count?

It is the breakdown of white blood cells into their sub-types (neutrophils, lymphocytes, monocytes, eosinophils and basophils), expressed as percentages or absolute counts. The pattern of these proportions helps clinicians distinguish between infections, allergies, and blood disorders.

Could this kind of model replace a biomedical scientist?

No. Even well-validated cell classification models are used as decision-support tools that pre-sort or flag images for review, not as a replacement for a trained professional's final sign-off, particularly for anything abnormal.

Why does the model need thousands of training images?

CNNs learn their filters purely from examples. With too few images they tend to memorise specific pictures rather than the general visual features that define each cell type, which shows up as good training performance but poor performance on new, unseen images.

What is the difference between a simple CNN and transfer learning here?

A simple CNN is built and trained entirely from scratch on the blood cell dataset. Transfer learning instead starts from a network already trained on a very large, unrelated image dataset and adapts its learned features to the new task, which usually needs less data and less training time to reach good accuracy.

What did you find?

Add reproduction steps (optional)