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 '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 curated patches and fine-tune the model
Fine-tuning is a two-stage workflow: curate training patches in napari, then run the training notebook.
A. Export curated patches from napari
- Keep the raw image and corrected label volume loaded.
- Open
Segmentation -> Finetune with Current Labels. - Click
Calculate Valid Patches. - Inspect the patch boxes and choose a
Patch ID. - Set the patch
Save Path. - Click
Curate Selected Patch. - In the new patch viewer, correct the labels with the
Basiccuration tools. - In
Save Curated Patch, clickSave.
Each saved sample is written as a paired TIFF image and label:
<save_path>/
├── imagesTr/
│ ├── patch_0001.tif
│ └── ...
└── labelsTr/
├── patch_0001.tif
└── ...
Use Clear Patch Boxes when you want to remove the patch overlays and return to normal curation.
B. Run fine-tuning from the notebook
- Expand the collapsed
Fine-tuneinstruction inside the same panel. - Open:
notebooks/02_finetune.ipynb
- Configure the notebook to use the curated patch directory.
- Run fine-tuning and obtain a new checkpoint.
- Return to
Segmentation -> Run Segmentation. - Select the new checkpoint in the
Checkpointfield and run segmentation again.
The napari panel prepares and exports training data, but it does not launch model training directly.
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.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file focus_3d-0.1.19.tar.gz.
File metadata
- Download URL: focus_3d-0.1.19.tar.gz
- Upload date:
- Size: 258.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.10.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
10a5fc621f19626ea6e1b476a208ac61675635e3f03df9a429c61ad599ab1b47
|
|
| MD5 |
811fd493d5790db1248a0b6f4e9eccdc
|
|
| BLAKE2b-256 |
5d10713f85235c0739f4c64f5a92bc73c566a0aa2412f1cfa3a91ad6e051fd5e
|
File details
Details for the file focus_3d-0.1.19-py3-none-any.whl.
File metadata
- Download URL: focus_3d-0.1.19-py3-none-any.whl
- Upload date:
- Size: 304.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.10.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
12482cdf7f5e77d6ad16a4878969258a21cd3094ffa334f7d93bcbceba70d5a1
|
|
| MD5 |
da4973e6e71b279f908edc39fcb7b038
|
|
| BLAKE2b-256 |
9c9ab1ef3b8fa3e2cd787f7af7f747a3829f27ed425d9ada5abf25caef565582
|