FOCUS-3D
FOCUS-3D provides a user-friendly napari plugin for interactive 3D cell segmentation, manual curation, model fine-tuning, and analysis. Users can run automatic 3D segmentation with pretrained FOCUS-3D models, manually correct segmentation errors, perform one-click segmentation, prepare curated patches for human-in-the-loop fine-tuning, reconstruct selected 3D cell instances, and compute quantitative statistics within the same napari workflow. Our website is https://www.quiclab.org.cn/focus-3d.
Installation
1. Create a new environment
conda create -n focus3d python=3.10 -y
conda activate focus3d
2. Install torch
For CUDA 12.x, replace cu12x with your specific CUDA-compatible PyTorch build. For example, for CUDA 12.6:
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu126
Please check the official PyTorch installation guide if you need another CUDA version.
3. Install FOCUS-3D
pip install -U "focus-3d[gui]"
4. Download pretrained model
Users can download the pretrained model for 3D segmentation: https://huggingface.co/Qinghua-thu/FOCUS-3D/.
5. Install detectron2 (optional, only for Linux model fine-tuning)
For Linux, FOCUS-3D requires Detectron2 for segmentation model fine-tuning. Please install Detectron2 according to the official guide:
https://detectron2.readthedocs.io/en/latest/tutorials/install.html
For most Linux environments, the official source installation command is:
python -m pip install --no-build-isolation 'git+https://github.com/facebookresearch/detectron2.git'
6. Launch napari
python -m napari
Recommended Workflow
Step 1 — Load and inspect the image
- In napari, open
Plugins -> 3D Segmentation (FOCUS-3D). - Load a raw 3D microscopy image:
- use
File -> Open Folderfor a.zarrdataset, which is recommended for large volumes; - use
File -> Open File(s)for.tifor.tiffimages.
- use
- Open the
Basictab and useDisplay Settingswhen the raw image is difficult to inspect:- move the
MinimumandMaximumsliders to adjust contrast; - click
Autofor percentile-based contrast adjustment;
- move the
Step 2 — Run automatic 3D segmentation
- Open the
Segmentationtab. - In
Run Segmentation, set the parameters that are most likely to vary between datasets:- Z Ratio — the physical Z-to-XY spacing ratio. Use
1.0for isotropic data. - Output Path — the directory used for the segmentation result.
- Checkpoint — the pretrained or fine-tuned checkpoint.
- Cell radius (pixel) — the approximate cell radius in the XY plane.
- Background intensity — patches or cells with grayscale values less than this value will be removed.
- Min size (3D) and Max size (3D) — remove small or large instances.
- Z Ratio — the physical Z-to-XY spacing ratio. Use
- Use
Advancedonly when you need to change the GPU, configuration file, normalization percentiles, patch stride, batch size, or stitching thresholds. See the complete menu reference for parameter definitions and defaults. - Click
Run 3D Segmentation.
After inference, FOCUS-3D loads a label layer into napari. The inference outputs are saved to the specified output path in both TIFF and Zarr formats.
Step 3 — Inspect and curate the segmentation
-
Return to the
Basictab. -
Click
Enter Curation Mode, then click a cell label to select it. -
Correct common errors:
- use
Add to Labelto recover missing regions; - use
Subtract from Labelto remove incorrect regions; - use
Add New Labelfor a missed cell; - use
Delete Current Zfor a slice-specific error; - use
Delete All Zto remove an incorrect 3D instance; - use
Delete Inside ROI (All Z)to remove multiple labels in a selected region.
For detailed instructions on label-editing operations and keyboard shortcuts, see Manual Curation.
- use
-
For labels stored in Zarr format, edits are written directly to the underlying Zarr data, so no separate save step is required. Labels loaded from TIFF are edited in memory and must be saved manually from the
Savepanel after curation.
Step 4 — Use one-click segmentation when needed
One-click segmentation can accelerate the curation.
- Keep both the raw image and segmentation label layer loaded.
- Open
Segmentation -> One-click segmentation. - Click
Enter Inactive Modeto load the local refinement model and activate interactive refinement. - Click the target cell in the viewer and inspect the updated label.
- Click
Exit Inactive Modeafter finishing.
Step 5 — Analyze the segmentation results
Open the Analysis tab after the segmentation has been checked.
Reconstruct one selected cell
- Select a non-background cell in the label layer.
- Set the
Z Ratio. - Click
Reconstruct Selected Label. - Save the reconstructed mesh as
.npzwhen needed.
Inspect the full volume in 3D
- Set the physical
Z Ratio. - Click
Switch to 3D View. - Rotate and inspect the image and labels.
- Click
Switch to 2D Viewto return to slice navigation.
Run morphometry analysis
- Set the physical voxel size in Z, Y, and X.
- Choose an output folder.
- Run one or more tasks:
Basic Informationfor cell morphology and optional intensity measurements;Neighborhood Analysisfor centroid-based local organization;Contact Graph Analysisfor face-touching cell relationships;Clusteringfor feature-based cell grouping.
- Use
Show featureto map supported results back to the napari label volume.
Step 6 — Prepare training data and fine-tune the model
Fine-tuning consists of preparing annotated training data and then running the fine-tuning notebook.
A. Prepare training data
There are two ways to prepare the annotations:
-
If the entire volume has been annotated: you do not need to use
Calculate Valid Patchesin napari. Provide the fully annotated raw image and label volume to the fine-tuning notebook. The notebook includes code to automatically crop the full volume into training patches and organize them intoimagesTrandlabelsTr. -
If annotating the entire volume is impractical: use the napari plugin to curate selected patches:
- Keep the raw image and corrected label volume loaded.
- Open
Segmentation -> Finetune with Current Labels. - Click
Calculate Valid Patches. - Choose a
Patch IDand set theSave Path. - Click
Curate Selected Patch. - Correct the labels in the patch viewer and click
Save.
Curated patches are saved as:
<save_path>/
├── imagesTr/
│ ├── patch_0001.tif
│ └── ...
└── labelsTr/
├── patch_0001.tif
└── ...
Use Clear Patch Boxes to remove the patch overlays when finished.
B. Run fine-tuning from the notebook
The fine-tuning notebook is not included in the pip installation and must be downloaded separately from the FOCUS-3D repository.
Open:
notebooks/02_finetune.ipynb
If using a fully annotated volume, first run the notebook section that crops it into training patches. If patches were already exported from napari, directly set the notebook to use the prepared imagesTr and labelsTr directories.
Run fine-tuning to obtain a new checkpoint, then return to Segmentation -> Run Segmentation, select the new checkpoint in the Checkpoint field, and run segmentation again.
The napari plugin can assist with patch preparation, while model fine-tuning itself is performed in the notebook.
Detailed Interface Reference
The complete descriptions of all controls are maintained in:
Issues
If you encounter a problem, please file an issue with a detailed description, relevant logs, and a minimal example when possible. You can also contact zhangqh24@mails.tsinghua.edu.cn.
Citing
Please contact us before the paper is published.
Metadata
Release files for focus-3d 0.1.20
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| focus_3d-0.1.20.tar.gz | 258.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| focus_3d-0.1.20-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 563.5 kB
Release files / focus_3d-0.1.20.tar.gz
| Download URL | focus_3d-0.1.20.tar.gz |
|---|---|
| Size | 258.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ba9600a7b92f3bd185085774097e85b78016fd11d676e369112f8d714c0d177e
|
|
BLAKE2b-256 checksum How to use checksums |
aa75e404b0edba432704de6a7d2d666dfce0f8301eda63a3f12ccd5ffa52c463
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.20
|
Release files / focus_3d-0.1.20-py3-none-any.whl
| Download URL | focus_3d-0.1.20-py3-none-any.whl |
|---|---|
| Size | 304.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7a0d5b61f0baa96867b2093b556046de9fe4532ce22463fba7c7232af0f93a42
|
|
BLAKE2b-256 checksum How to use checksums |
979f8f64fb8ce3d624d880cbba69d63110fd6bd13a3f2220febe377d0f9b1077
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.20
|