# devdeepsarkar/nucleiscope architecture

> Architecture diagram of the GitHub repository devdeepsarkar/nucleiscope, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/devdeepsarkar/nucleiscope
- Repository: https://github.com/devdeepsarkar/nucleiscope

## Overview

NucleiScope is a research tool for segmenting H&E-stained tissue images, separating touching nuclei, and reporting per-nucleus morphometry and tissue density. Its main user workflow loads an image or whole slide, runs tiled prediction and instance separation, measures nuclei, and writes summaries and density visualizations. A separate training and evaluation workflow prepares labeled crops, trains the U-Net, and scores predictions; the classical baseline provides a non-learning comparison. Connections below follow the README and shown source references; unsampled details are not inferred.

Main entry points: [`nucleiscope/infer.py`](https://github.com/devdeepsarkar/nucleiscope/blob/main/nucleiscope/infer.py) (Tiled inference), [`evaluate.py`](https://github.com/devdeepsarkar/nucleiscope/blob/main/evaluate.py) (Evaluation runner), [`nucleiscope/data.py`](https://github.com/devdeepsarkar/nucleiscope/blob/main/nucleiscope/data.py) (Labeled crops), [`train.py`](https://github.com/devdeepsarkar/nucleiscope/blob/main/train.py) (Model training)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_prep["Training data"]
  node_dataset["Labeled crops<br/>[data.py]"]
  node_stain["Stain handling<br/>[stain.py]"]
  node_trainer["Model training<br/>[train.py]"]
end

subgraph group_seg["Segmentation"]
  node_unet["U-Net<br/>[model.py]"]
  node_predictor["Tiled inference<br/>[infer.py]"]
  node_instances["Instance watershed<br/>[post.py]"]
  node_baseline["Classical baseline<br/>[baseline.py]"]
  node_wsi["Whole-slide engine<br/>[wsi.py]"]
  node_segment["Segmentation CLI<br/>[segment.py]"]
end

subgraph group_measure["Measurement"]
  node_morph["Nucleus morphometry<br/>[morph.py]"]
  node_outputs["Nuclei and density outputs<br/>[segment.py]"]
end

subgraph group_eval["Evaluation"]
  node_evaluator["Evaluation runner<br/>[evaluate.py]"]
  node_tuner["Threshold tuning<br/>[tune.py]"]
  node_metrics["Segmentation metrics<br/>[metrics.py]"]
end

node_user(("User / image"))

node_user -->|"provides image"| node_segment
node_segment -->|"runs slide"| node_wsi
node_segment -->|"configures predictor"| node_predictor
node_segment -->|"writes results"| node_outputs
node_wsi -->|"predicts blocks"| node_predictor
node_wsi -->|"separates nuclei"| node_instances
node_wsi -->|"measures instances"| node_morph
node_predictor -->|"runs model"| node_unet
node_predictor -->|"normalizes input"| node_dataset
node_dataset -->|"augments stains"| node_stain
node_trainer -->|"loads crops"| node_dataset
node_trainer -->|"trains model"| node_unet
node_trainer -->|"validates with"| node_predictor
node_trainer -->|"scores validation"| node_metrics
node_morph -->|"extracts hematoxylin"| node_stain
node_evaluator -->|"loads test split"| node_dataset
node_evaluator -->|"predicts tiles"| node_predictor
node_evaluator -->|"labels predictions"| node_instances
node_evaluator -->|"selects baseline"| node_baseline
node_evaluator -->|"scores predictions"| node_metrics
node_baseline -->|"uses stain handling"| node_stain
node_baseline -->|"uses watershed"| node_instances
node_tuner -->|"loads validation split"| node_dataset
node_tuner -->|"predicts tiles"| node_predictor
node_tuner -->|"tests thresholds"| node_instances
node_tuner -->|"selects by AJI"| node_metrics

click node_dataset "https://github.com/devdeepsarkar/nucleiscope/blob/main/nucleiscope/data.py"
click node_stain "https://github.com/devdeepsarkar/nucleiscope/blob/main/nucleiscope/stain.py"
click node_trainer "https://github.com/devdeepsarkar/nucleiscope/blob/main/train.py"
click node_unet "https://github.com/devdeepsarkar/nucleiscope/blob/main/nucleiscope/model.py"
click node_predictor "https://github.com/devdeepsarkar/nucleiscope/blob/main/nucleiscope/infer.py"
click node_instances "https://github.com/devdeepsarkar/nucleiscope/blob/main/nucleiscope/post.py"
click node_baseline "https://github.com/devdeepsarkar/nucleiscope/blob/main/nucleiscope/baseline.py"
click node_wsi "https://github.com/devdeepsarkar/nucleiscope/blob/main/nucleiscope/wsi.py"
click node_segment "https://github.com/devdeepsarkar/nucleiscope/blob/main/segment.py"
click node_morph "https://github.com/devdeepsarkar/nucleiscope/blob/main/nucleiscope/morph.py"
click node_outputs "https://github.com/devdeepsarkar/nucleiscope/blob/main/segment.py"
click node_evaluator "https://github.com/devdeepsarkar/nucleiscope/blob/main/evaluate.py"
click node_tuner "https://github.com/devdeepsarkar/nucleiscope/blob/main/tune.py"
click node_metrics "https://github.com/devdeepsarkar/nucleiscope/blob/main/nucleiscope/metrics.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_dataset,node_stain,node_trainer,node_user toneBlue
class node_unet,node_predictor,node_instances,node_baseline,node_wsi,node_segment toneAmber
class node_morph,node_outputs toneMint
class node_evaluator,node_tuner,node_metrics toneRose
```

## Components

### Training data

- [Labeled crops](https://github.com/devdeepsarkar/nucleiscope/blob/main/nucleiscope/data.py): `nucleiscope/data.py`
- [Stain handling](https://github.com/devdeepsarkar/nucleiscope/blob/main/nucleiscope/stain.py): `nucleiscope/stain.py`
- [Model training](https://github.com/devdeepsarkar/nucleiscope/blob/main/train.py): `train.py`

### Segmentation

- [U-Net](https://github.com/devdeepsarkar/nucleiscope/blob/main/nucleiscope/model.py): `nucleiscope/model.py`
- [Tiled inference](https://github.com/devdeepsarkar/nucleiscope/blob/main/nucleiscope/infer.py): `nucleiscope/infer.py`
- [Instance watershed](https://github.com/devdeepsarkar/nucleiscope/blob/main/nucleiscope/post.py): `nucleiscope/post.py`
- [Classical baseline](https://github.com/devdeepsarkar/nucleiscope/blob/main/nucleiscope/baseline.py): `nucleiscope/baseline.py`
- [Whole-slide engine](https://github.com/devdeepsarkar/nucleiscope/blob/main/nucleiscope/wsi.py): `nucleiscope/wsi.py`
- [Segmentation CLI](https://github.com/devdeepsarkar/nucleiscope/blob/main/segment.py): `segment.py`

### Measurement

- [Nucleus morphometry](https://github.com/devdeepsarkar/nucleiscope/blob/main/nucleiscope/morph.py): `nucleiscope/morph.py`
- [Nuclei and density outputs](https://github.com/devdeepsarkar/nucleiscope/blob/main/segment.py): `segment.py`

### Evaluation

- [Evaluation runner](https://github.com/devdeepsarkar/nucleiscope/blob/main/evaluate.py): `evaluate.py`
- [Threshold tuning](https://github.com/devdeepsarkar/nucleiscope/blob/main/tune.py): `tune.py`
- [Segmentation metrics](https://github.com/devdeepsarkar/nucleiscope/blob/main/nucleiscope/metrics.py): `nucleiscope/metrics.py`

### Other components

- **User / image**

## Connections

- User / image → Segmentation CLI: provides image (evidence: `README.md`)
- Segmentation CLI → Whole-slide engine: runs slide (evidence: `segment.py`)
- Segmentation CLI → Tiled inference: configures predictor (evidence: `segment.py`)
- Segmentation CLI → Nuclei and density outputs: writes results (evidence: `segment.py`)
- Whole-slide engine → Tiled inference: predicts blocks (evidence: `segment.py`)
- Whole-slide engine → Instance watershed: separates nuclei (evidence: `nucleiscope/wsi.py`)
- Whole-slide engine → Nucleus morphometry: measures instances (evidence: `nucleiscope/wsi.py`)
- Tiled inference → U-Net: runs model (evidence: `nucleiscope/infer.py`)
- Tiled inference → Labeled crops: normalizes input (evidence: `nucleiscope/infer.py`)
- Labeled crops → Stain handling: augments stains (evidence: `nucleiscope/data.py`)
- Model training → Labeled crops: loads crops (evidence: `train.py`)
- Model training → U-Net: trains model (evidence: `train.py`)
- Model training → Tiled inference: validates with (evidence: `train.py`)
- Model training → Segmentation metrics: scores validation (evidence: `train.py`)
- Nucleus morphometry → Stain handling: extracts hematoxylin (evidence: `nucleiscope/morph.py`)
- Evaluation runner → Labeled crops: loads test split (evidence: `evaluate.py`)
- Evaluation runner → Tiled inference: predicts tiles (evidence: `evaluate.py`)
- Evaluation runner → Instance watershed: labels predictions (evidence: `evaluate.py`)
- Evaluation runner → Classical baseline: selects baseline (evidence: `evaluate.py`)
- Evaluation runner → Segmentation metrics: scores predictions (evidence: `evaluate.py`)
- Classical baseline → Stain handling: uses stain handling (evidence: `nucleiscope/baseline.py`)
- Classical baseline → Instance watershed: uses watershed (evidence: `nucleiscope/baseline.py`)
- Threshold tuning → Labeled crops: loads validation split (evidence: `tune.py`)
- Threshold tuning → Tiled inference: predicts tiles (evidence: `tune.py`)
- Threshold tuning → Instance watershed: tests thresholds (evidence: `tune.py`)
- Threshold tuning → Segmentation metrics: selects by AJI (evidence: `tune.py`)
