MyoSeg / README.md
skarugu's picture
Upload README.md
d3ac1e5 verified
|
Raw History Blame Contribute Delete
3.41 kB
---
title: MyoSeg
emoji: 🔬
colorFrom: red
colorTo: red
sdk: streamlit
sdk_version: "1.45.1"
app_file: src/streamlit_app.py
pinned: true
license: mit
---
# MyoSeg — Myotube & Nuclei Analyzer
**Version v12 (Oct 2026).** Default preset *Tuned to manual counts*: calibrated against 55 manually
counted C2C12 wells. Held-out error: fusion index ±4.9 points, MyHC⁺ % ±4.9, myotube count r = 0.80
(see `tuning/VALIDATION.md`). *Training defaults* reproduces the earlier v9 results.
Deep-learning quantification of myotubes and nuclei in C2C12 immunofluorescence
images (red = MyHC, blue = DAPI): nuclei, myotubes, MyHC⁺ nuclei, fusion index
(cytoplasm-hole or pixel-overlap), nuclei per myotube and myotube area.
## Code layout
| File | What it does |
|---|---|
| `src/myoseg_core.py` | The analysis engine — model, inference, postprocessing, metrics, quality checks, diagnosis. No Streamlit. |
| `src/streamlit_app.py` | The web app (UI only; calls the core). |
| `analyze_folder.py` | Command-line batch analysis using the same core. |
| `mcp_server.py` | MyoSeg as a tool for AI assistants (Model Context Protocol). |
| `benchmark.py` | Accuracy vs hand-labelled masks (Dice, count/FI error, uncertainty vs error). |
| `self_train.py` | Safe continual-learning / retraining pipeline. |
| `tests/` | v9 equivalence test, MCP end-to-end test, synthetic image generator. |
## Using the core from Python
```python
import sys; sys.path.insert(0, "src")
import myoseg_core as core
model, info = core.load_model("model_final.pt")
params = core.make_params("Dense culture rescue", px_um=0.65)
res = core.analyze_image(model, core.load_rgb("img.tif"), params)
print(core.public_metrics(res["metrics"]))
print(core.compare_presets(res["probs"], res["myc_full"], params)) # no extra inference
print(core.quality_check(core.load_rgb("img.tif"), params, res["probs"]))
print(core.diagnose(res["metrics"], params))
```
## Use MyoSeg from Claude (MCP server)
MyoSeg can be called directly by Claude Desktop, Claude Code or any MCP client.
Images stay on your computer and no API key is needed.
```bash
pip install -r requirements-mcp.txt
python mcp_server.py # the client normally launches this for you
```
**Claude Desktop** — add to `claude_desktop_config.json`, then restart Claude:
```json
{"mcpServers": {"myoseg": {"command": "python", "args": ["/ABSOLUTE/PATH/TO/myoseg/mcp_server.py"]}}}
```
**Claude Code:** `claude mcp add myoseg -- python /ABSOLUTE/PATH/TO/myoseg/mcp_server.py`
Then ask, for example: *"Analyze ~/data/day5/control and ~/data/day5/treated with MyoSeg
and compare the fusion index. Show me the overlay for the most uncertain image."*
Tools: `analyze_image`, `analyze_folder`, `compare_presets`, `compare_groups`
(Welch t, Mann-Whitney, Cohen's d), `quality_check`, `get_overlay`, `list_parameters`, `model_info`.
## Test-time augmentation and uncertainty
`tta="flip4"` or `"d8"` (sidebar: *Test-time augmentation*) averages the U-Net over
flipped/rotated copies. Every image also gets a `model_uncertainty` score
(0 = sure … 1 = coin-flip); uncertain images are queued for labelling and listed
first in the correction panel. Set `UNCERTAINTY_FLAG_THR` from `benchmark.py` output.
## Benchmark against your labels
```bash
python benchmark.py /path/to/HELD_OUT_data --tta none flip4 d8 --sizes 512 768
```
Use images the model was **not** trained on.