# Diatom segmentation and identification pilot

The first prototype should let a Patrick Center analyst open a microscope field, locate individual valves including fragments and members of overlapping groups, and review suggested identifications. Each accepted count should trace back to the valve in the original image. The pilot succeeds if an analyst can finish a slide faster while preserving agreement on which taxa are present and their relative abundance.

The current project goal is to identify genus for 95% of cases and species for 60%, while recovering partially occluded and overlapping diatoms. These targets are not yet demonstrated. The working evaluation protocol, baseline diagnostic, and issues requiring scientific agreement are in [EVALUATION.md](diatom_pilot/EVALUATION.md).

## Choose one microscopy workflow

Start with saved, full-resolution fields from one microscope and one project using prepared freshwater slides. A plausible first workflow is a quantitative periphyton count. The Center’s 2017 draft of protocol P-13-39 describes estimating taxon proportions from 600 valves and gives qualitative surveys a different stopping rule. Confirm the pilot project’s current procedure, counting unit, taxon codes, and output format with its analyst before implementing counting rules. [Patrick Center protocol P-13-39, revision 2 draft](https://data.neonscience.org/documents/10179/2247711/Drexel_Diatom_Slide_Identification_Revision2/8c7f970c-52fd-4538-b23b-ce0cf4792c8f)

## Build the pilot

1. **Replay a microscope transect.** Use the multi-plane scans in `scans/` as a virtual stage. Read only the requested field at its original resolution and let the analyst step through the focal planes at fixed slide coordinates. The first scan, GC104887a, has 40,336 × 40,336 pixels per plane, 13 planes, and 256 × 256 pixel tiles. Use the [scan inventory](results/scan-inventory.csv) and defer any scan that is still growing or whose required data cannot yet be read. Follow an analyst through a count and collect an example export. Record the field coordinates, focal plane, and pixel calibration so later input from a live microscope or its operator can feed the same review workflow.

2. **Create a local reference set.** Sample whole fields across independent samples and slides, including sparse fields, debris, touching valves, fragments, and specimens crossing the frame. Mark a visible point and rough extent for each recognizable valve, with an axis and focal plane when helpful. Trace a subset for mask diagnostics. Record count eligibility separately from taxon identity so a countable but unidentified valve remains visible in the totals. Use the lab’s taxon codes and allow genus-level and unresolved labels. Have two analysts independently mark a subset and resolve disagreements into a short annotation guide.

3. **Benchmark segmentation and classification separately.** Compare DINOv3 and YOLO instance proposals on crossings and partial valves. Allow a point, oriented axis or box as the review target. Train a classifier on expert-marked valve crops for a small group of common local taxa chosen by the analyst. Then test it on model-generated crops to see how missed or merged valves affect identification. Preserve native image detail and physical scale. Public freshwater data could supplement classifier training after reconciling taxon names. The UDE dataset includes boxes, circles, and rough polygons, so precise boundary evaluation needs expert-traced masks. [UDE DIATOMS in the Wild dataset paper](https://doi.org/10.1093/gigascience/giae087)

4. **Build the review loop.** Show the original field with togglable outlines, a magnified specimen view, a scale bar, and ranked taxon suggestions. Let the analyst add a missed valve, split a merged outline, reject debris, or leave an ID unresolved. Retain the proposed and reviewed records. Export one row per reviewed specimen with its sample, slide, field, outline reference, count decision, and taxon code, plus a per-sample count table. Confirm how adjacent fields are recorded so a valve visible twice contributes only once.

5. **Run a blinded comparison.** Reserve whole samples for testing before training. Keep every field, crop, and focal plane from a sample in the same partition. On held-out fields, measure how often every member of a crossing is recovered once, recall on partial valves, false detections per field, and correct taxon calls versus abstentions. On complete held-out counts, compare manual and assisted review time, taxon counts, and relative abundance against an independent expert count. Set acceptable disagreement with the lab using the double-read subset before examining test results.

## First working milestone

Take one short transect from a saved stack through a reviewed count export, including a real crossing and a partial valve, using analyst-marked locations and reviewed IDs. Reconcile every exported specimen with its field and the analyst’s tally. Use the offline pilot to determine what the eventual microscope interface needs to receive from the instrument or the person driving it, including how the operator indicates a new field versus a change of focus.
