Computer vision answers · Microscopy

How do I count cells or microorganisms in microscope images with computer vision?

Without clicking through every field of view by hand.

Short answer

Train an object detection model to find each cell in an image with Roboflow for free, then count the detections. Give each cell type or life stage its own class, and you get a separate count for each. Labeling touching cells one by one, and splitting large images into tiles, is what keeps counts accurate in crowded fields.

Roboflow agent · free to start

Skip the setup. Describe your images.

Describe your images and what you need to find. The agent sets up labeling, training and deployment with you.

Key facts

What you need
Microscope images and a detection model trained on your cells
What you get
A count per image and per class, with every cell marked
Image sources
Microscope camera captures, slide scans and exported files
Runs on
Cloud API, or a lab workstation running Docker
Microscopic image of blood cells with AI detection boxes identifying Red Blood Cells, White Blood Cells, and Platelets with confidence scores.

How to build cell counting, step by step

Five steps from a folder of microscope images to a count you can record.

  1. Collect images that match how you will run it

    Use images from the same microscope, magnification, stain and lighting you will count with. Include crowded and sparse fields of view, then add more images wherever the model misses cells.

  2. Label every cell, with one class per type

    Box every cell, including ones that touch or overlap, and give each cell type or life stage its own class. Roboflow Annotate can pre-label cells with SAM 3, so you correct boxes instead of drawing each one.

  3. Train a detection model for small objects

    Train an object detection model such as RF-DETR on your labeled images with Roboflow Train. If cells are only a few pixels wide, apply the Tile preprocessing step so each cell stays large enough to detect.

  4. Count the detections in each class

    Run the trained model on an image and count its detections by class name.

    Python
    import supervision as sv
    from collections import Counter
    from inference import get_model
    
    model = get_model("your-project/1")
    
    result = model.infer("slide_001.png", confidence=0.4)[0]
    detections = sv.Detections.from_inference(result)
    
    print(Counter(detections.data["class_name"]))
    # Counter({'active': 37, 'cyst': 12})

    Rather not write code? Ask the Roboflow agent to set this up for you

  5. Run every image and record the counts

    Build a Workflow that slices each large image into tiles, runs the model and returns the counts per class. Deploy it with Roboflow Deploy to the cloud API or a lab workstation, and save the counts for every image.

Why 2 million engineers build on Roboflow

  • Label faster

    Auto-label with SAM 3 or your own model, then fix the misses instead of drawing every box.

  • RF-DETR

    Roboflow’s open-source real-time detection model, built for accuracy (opens in a new tab) on small objects.

  • Logic built in

    Counting, zones, tracking and alerts are ready-made Workflow blocks, so there is less code to write.

  • Your model, your weights

    Use your trained weights on every plan, including free, through the open-source Inference package.

  • Run it anywhere

    Self-host on a workstation, Docker, an on-prem GPU or an edge device, or call the cloud API.