Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
ec66015
Add warnings ignores
nikvo1 May 31, 2026
326cc00
Add TTA calibration to calibrate with points widget
nikvo1 May 31, 2026
dcf7703
Change Test with TTA button on-hover description
nikvo1 May 31, 2026
294f74e
Add progress bar for calibration with aug
nikvo1 May 31, 2026
317abe7
Fix CLAHE error
nikvo1 May 31, 2026
b2250de
Fix progress bars error
nikvo1 May 31, 2026
ad87828
Remove bilateral filter 30 from augmentations list
nikvo1 May 31, 2026
a8728fc
Change sharpen augmentation name
nikvo1 May 31, 2026
1d808c0
Remove median filter kernel size 5 from augmentations pool
nikvo1 May 31, 2026
d13ca44
Add model name in TTA metadata
nikvo1 May 31, 2026
26e52d0
Fix progress bar frame number
nikvo1 May 31, 2026
1d64ebf
Add force_postprocess_type = True to all get_sliced_prediction functions
nikvo1 Jun 1, 2026
4260aae
Change sahi version to 0.12.0
nikvo1 Jun 1, 2026
c71e7f4
Add progress bar of sliced prediction in predict_on_single widget
nikvo1 Jun 1, 2026
6888682
Add toggle_activity_dock functions to predict_on_single widget
nikvo1 Jun 1, 2026
3dce50b
Add progress bar of sliced prediction in predict_one_stack widget
nikvo1 Jun 1, 2026
d9ea32d
Change frame number in new progress bar
nikvo1 Jun 1, 2026
58ac0d8
Add progress bar of sliced prediction in predict_two_stack widget
nikvo1 Jun 1, 2026
187111d
Change count_points widget to accept multiple images
nikvo1 Jun 1, 2026
539df55
Fix count_points widget registration in napari.yaml
nikvo1 Jun 1, 2026
fc2aaa3
Fix count_points widget registration in napari.yaml
nikvo1 Jun 1, 2026
2dfc2e1
Remove metadata creation from count_points widget
nikvo1 Jun 1, 2026
5bce9f7
Change default confidence thresholds to 0.2
nikvo1 Jun 1, 2026
bd10aac
Add running postprocessing notification to progress bar
nikvo1 Jun 1, 2026
6d9a6d0
Fix non-closing progress bar bug
nikvo1 Jun 1, 2026
312d4b1
Add model initialization progress bar
nikvo1 Jun 1, 2026
07ff191
Fix progress bar error
nikvo1 Jun 1, 2026
8bfa0b7
Add TTA to predict on single image widget
nikvo1 Jun 1, 2026
7b0306f
Change TTA checkbox and metadata placing
nikvo1 Jun 1, 2026
14039d1
Change save results block placing in predict on single widget
nikvo1 Jun 1, 2026
af08a73
Add debugging print for threshold change
nikvo1 Jun 1, 2026
d423d08
Add bounding boxes support for TTA in predict on single image widget
nikvo1 Jun 1, 2026
033c5fd
Add TTA to predict on single on 1-stack widget
nikvo1 Jun 1, 2026
9593696
Change placement of TTA checkbox in predict one stack widget
nikvo1 Jun 1, 2026
11b83d4
Fix progress bar in predict one stack widget
nikvo1 Jun 1, 2026
517e050
Add TTA to predict on 2-stack widget
nikvo1 Jun 1, 2026
b5d3db4
Update docs
nikvo1 Jun 1, 2026
9801da3
Update docs
nikvo1 Jun 1, 2026
18f3aee
Fix model initialization print error
nikvo1 Jun 1, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/Biological tasks guidelines/Population growth curves.rst
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ Step 8. Press **Calibrate**.

This calibration algorithm is fast and should quickly provide the result optimal confidence threshold in the line below the **Calibrate** button.

.. note:: If the accuracy isn't high enough, there are two ways of increasing it. You can finetune NuclePhaser model using `Colab notebook <https://colab.research.google.com/drive/1hKMVQqYS0I_GrkYvdz23tPc8FCv2oJvh?usp=sharing>`_ or use :doc:`TTA </General information/Test-time augmentations (TTA)>`.

Step 2: Applying the calibrated model to a stack of images
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Expand Down Expand Up @@ -215,8 +217,6 @@ Surprisingly, the most influential factor on waiting time is **number of objects
It's due to the fact that postprocess algorithm (NMS or NMM) has O(n\ :sup:`2`) `notation <https://en.wikipedia.org/wiki/Big_O_notation>`_, so it can take much more time than applying the deep learning algorithm itself.
In our practice, inference time for one image exceeds 10-20 minutes when there are close to 100,000 objects on an image.

.. hint:: You can track the process in the command line that you used to initiate the Napari (not available in standalone application). It provides an estimated time to process the whole stack.

.. figure:: ../Images/Stack_CLI.jpg
:scale: 50 %
:align: center
Expand Down
9 changes: 9 additions & 0 deletions docs/General information/Confidence threshold calibration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,12 @@ For more information, see :doc:`Calibrate with DAPI widget page </Widgets/Calibr
Two metrics are generated during tests: `MAPE <https://en.wikipedia.org/wiki/Mean_absolute_percentage_error>`_ and prediction-ground truth scatterplot.
The smaller the MAPE, the better. The closer predictions to the red line on scatterplot, the better.
For more detailed information about the metrics, see our `paper <https://www.biorxiv.org/content/10.1101/2025.05.13.653705v1>`_.

What if accuracy isn't high enough?
+++++++++++++++++++++++++++++++++++

If the accuracy of the model on your specific use case is considered low, there are certain options to increase it.
You can test another model from NuclePhaser model zoo. In our practice, small models sometimes better than large ones!
Also, you can try :doc:`TTA (test-time augmentations) </General information/Test-time augmentations (TTA)>`. It is a way of increasing accuracy by sacrificing inference time.
Finally, you can finetune NuclePhaser model on you specific use case using `Colab notebook <https://colab.research.google.com/drive/1hKMVQqYS0I_GrkYvdz23tPc8FCv2oJvh?usp=sharing>`_.
However, it requires fluorescent nuclear stain.
47 changes: 47 additions & 0 deletions docs/General information/Test-time augmentations (TTA).rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
Test-time augmentations (TTA)
=============================

Make sure you are familiar with :doc:`Confidence threshold calibration </General information/Confidence threshold calibration>`.

What are test-time augmentations (TTA)?
Put simply, they are a way to potentially increase accuracy by sacrificing inference time.

Imagine you have a calibration image, and the model has an error of 10% on it.
But what if, instead of using this native image, it would be slightly changed: contrasted, magnified or something else?
It is possible that model would be better at these augmented images.
For example, cells on calibration image are small, and resizing the image 1.5x resulted in error of 8%.
Or even better, when we average the results from native and magnified image, their respective errors cancel each other, and the result error can be even lower!

This is exactly what TTA are about.
On calibration stage, instead of running single calibration on native image, it gets augmented in the following ways:

**resize_1.5x** - image is increased in size 1.5x

**resize_2x** - image is increased in size 2x

**clahe** - `CLAHE (contrast-limited adaptive histogram equalization) <https://en.wikipedia.org/wiki/Adaptive_histogram_equalization#Contrast_Limited_AHE>`_ is applied to the image.

**gamma 1.5** - `gamma contrast <https://en.wikipedia.org/wiki/Gamma_correction>`_ with coefficient 1.5 is applied to the image

**invert** - all image intensities are inverted (255 becomes 0, 0 becomes 255 and so on)

**median_3** - `median filter <https://en.wikipedia.org/wiki/Median_filter>`_ with kernel size 3 is applied to the image

**bilateral_10** - `bilateral filter <https://en.wikipedia.org/wiki/Bilateral_filter>`_ with sigma value 10 is applied to the image

**sharpen** - `unsharp mask <https://en.wikipedia.org/wiki/Unsharp_masking>`_ is applied to the image.

Best threshold is found for each augmentation independently.
The image is used for calibration with each augmentation applied, and then it gets tested on each possible combination of these augmentations.

.. note:: How combination of augmentations work? Each augmentation is applied individually and results from them are averaged, not all of augmentations are applied simultaneously.

The main tradeoff is inference time. For example, the combination of 5 augmentations decreases the error from 10% to 9%.
It means that for increasing accuracy by 1% you will have to spend 5x more time on inference.

You can calibrate with TTA using :doc:`Calibrate with points widget </Widgets/Calibrate with points>`.
The widget creates a "TTA" subfolder in the given folder for storing the calibration results.
metadata_TTA.txt file is stored in that subfolder.
All inference (predict on single image, predict on 1-stack, predict on 2-stack) widgets have "Use TTA" checkbox and a field for selecting .txt file.
Select your metadata_TTA.txt calibration file, and widget will perform TTA automatically.
Widget will create a points layer for each augmentation, and the result .csv or .xlsx file will contain averaged counting results.
23 changes: 11 additions & 12 deletions docs/Installation/Installation.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
Installation instructions
=========================

Option 1: Using Anaconda (recommended)
Option 1 (simple): Using standalone napari app
+++++++++++++++++++++++++++++++++++++++++++++++

.. note:: The only disadvantage of this option is inability to install GPU-accelerated version of torch
1. Download and install napari as standalone app using `installation instructions <https://napari.org/stable/getting_started/installation.html#installation-bundle-conda>`_

2. Search, download and install napari-nuclephaser plugin by opening the app, navigating to Plugins window and choosing Install/Uninstall plugins.

Option 2 (recommended): Using Anaconda
++++++++++++++++++++++++++++++++++++++

We recommend installation using `Anaconda Distribution <https://www.anaconda.com/>`_
Expand All @@ -14,7 +22,7 @@ We recommend installation using `Anaconda Distribution <https://www.anaconda.com

.. code-block:: python

conda create --name napari-env anaconda
conda create --name napari-env python=3.10

4. Activate new environment using command

Expand Down Expand Up @@ -48,7 +56,7 @@ We recommend installation using `Anaconda Distribution <https://www.anaconda.com

Initialize plugin's widgets by opening Plugins window and choosing NuclePhaser.

Option 1 advanced: installation with GPU
Option 2 advanced: installation with GPU
++++++++++++++++++++++++++++++++++++++++

If you have `NVIDIA GPU with CUDA <https://developer.nvidia.com/cuda-gpus>`_, you can significantly increase plugin's speed.
Expand All @@ -75,12 +83,3 @@ To install GPU-powered version of the plugin, you first need to do all the steps
.. code-block:: python

pip3 install -U torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126

Option 2: Using standalone napari app (simpler)
+++++++++++++++++++++++++++++++++++++++++++++++

.. note:: Downsides of this option are: you can't install GPU-powered version and you will not have CLI (Command Line Interface) that prints detailed progress. Otherwise, it's the same.

1. Download and install napari as standalone app using `installation instructions <https://napari.org/dev/tutorials/fundamentals/installation_bundle_conda.html>`_

2. Search, download and install napari-nuclephaser plugin by opening the app, navigating to Plugins window and choosing Install/Uninstall plugins.
3 changes: 3 additions & 0 deletions docs/Widgets/Calibrate with points.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ For example, if you have an image 6400x6400 pixels, and Division size = 640, you
**Calibration proportion** determines which part of small images array will be used for calibration, and which part - for test.
If you have an array of 100 small images and Calibration proportion = 0,1, 10 of those images will be used for calibration, 90 - for test.

**Test with TTA** checkbox is used for running calibration and test with TTA (test-time augmentations).
Learn more at :doc:`page about TTA </General information/Test-time augmentations (TTA)>`.

**Save folder** is used for selecting a folder in which the calibration plot and metadata.txt files will be saved.
Inside this folder, a subfolder will be created with Expereiment name.

Expand Down
4 changes: 2 additions & 2 deletions docs/Widgets/Count points on single image.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Count points on single image
============================
Count points on images
======================

Description
+++++++++++
Expand Down
6 changes: 6 additions & 0 deletions docs/Widgets/Predict on 1-stack.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ Larger models can be downloaded on `NuclePhaser GitHub page <https://github.com/
Confidence threshold is the **most important paramter** for the task of counting objects.
Learn more about how to find the optimal threshold for your specific use case at :doc:`Confidence threshold calibration page </General information/Confidence threshold calibration>`.

**Use TTA** checkbox is used for running inference with TTA (test-time augmentations). Requires passing metadata_TTA.txt created by Calibrate with points widget.
Learn more at :doc:`page about TTA </General information/Test-time augmentations (TTA)>`.

**TTA metadata file** field is used for passing the metadata_TTA.txt file created by Calibrate with points widget.
Learn more at :doc:`page about TTA </General information/Test-time augmentations (TTA)>`.

**Save result** checkbox is used for selecting whether you need counting results or not.
If the task is to count the number of objects on each frame, check this box.
It will create a subfolder with **Experiment name** at **Save folder** location with .csv and/or .xlsx file with counting results, as well as metadata.txt file with all the parameters for exact reproduction of results.
Expand Down
6 changes: 6 additions & 0 deletions docs/Widgets/Predict on 2-stack.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ Larger models can be downloaded on `NuclePhaser GitHub page <https://github.com/
Confidence threshold is the **most important paramter** for the task of counting objects.
Learn more about how to find the optimal threshold for your specific use case at :doc:`Confidence threshold calibration page </General information/Confidence threshold calibration>`.

**Use TTA** checkbox is used for running inference with TTA (test-time augmentations). Requires passing metadata_TTA.txt created by Calibrate with points widget.
Learn more at :doc:`page about TTA </General information/Test-time augmentations (TTA)>`.

**TTA metadata file** field is used for passing the metadata_TTA.txt file created by Calibrate with points widget.
Learn more at :doc:`page about TTA </General information/Test-time augmentations (TTA)>`.

**Save result** checkbox is used for selecting whether you need counting results or not.
If the task is to count the number of objects on each frame, check this box.
It will create a subfolder with **Experiment name** at **Save folder** location with .csv and/or .xlsx file with counting results, as well as metadata.txt file with all the parameters for exact reproduction of results.
Expand Down
6 changes: 6 additions & 0 deletions docs/Widgets/Predict on single image.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ Select it if you want to generate Napari Shapes layer with a rectangle for each
**Show confidence** checkbox is used to add confidence scores for each bounding box.
Works only if **Generate bbox** checkbox is active.

**Use TTA** checkbox is used for running inference with TTA (test-time augmentations). Requires passing metadata_TTA.txt created by Calibrate with points widget.
Learn more at :doc:`page about TTA </General information/Test-time augmentations (TTA)>`.

**TTA metadata file** field is used for passing the metadata_TTA.txt file created by Calibrate with points widget.
Learn more at :doc:`page about TTA </General information/Test-time augmentations (TTA)>`.

**Confidence threshold** field is used to set up a confidence threshold for the YOLO model.
Confidence threshold is the **most important paramter** for the task of counting objects.
Learn more about how to find the optimal threshold for your specific use case at :doc:`Confidence threshold calibration page </General information/Confidence threshold calibration>`.
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
project = "napari-nuclephaser"
project_copyright = "2025, Nikita Voloshin"
author = "Nikita Voloshin"
release = "0.0.5"
release = "0.3.0"

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
Expand Down
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ To learn more about the algorithms behind the project, navigate to general infor
General information/Object detection overview.rst
General information/Sliced inference overview.rst
General information/Confidence threshold calibration.rst
General information/Test-time augmentations (TTA).rst

To learn more about widgets and their functions, navigate to the widget page you need:

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ dependencies = ["setuptools==80.10.2",
"ultralytics==8.3.141",
"yolov5",
"magicgui",
"sahi==0.11.36",
"sahi==0.12.0",
"scikit-image",
"torch==2.8.0",
"pathlib",
Expand Down
8 changes: 8 additions & 0 deletions src/napari_nuclephaser/calibrate_dapi.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import pathlib
import warnings
from datetime import datetime

import cv2
Expand All @@ -18,6 +19,9 @@

from napari_nuclephaser.utils import create_unique_subfolder, initialize_model

warnings.filterwarnings(action="ignore", category=FutureWarning)
warnings.filterwarnings(action="ignore", category=UserWarning)

matplotlib.use("Agg")
# cuda device check
cuda_available = "cuda:0" if cuda.is_available() else "cpu"
Expand Down Expand Up @@ -209,6 +213,7 @@ def split_image(image, size):
postprocess_match_metric=Match_metric,
postprocess_match_threshold=Intersection_threshold,
verbose=0,
force_postprocess_type=True,
)

dapi_count = int(len(dapi_result.object_prediction_list))
Expand All @@ -224,6 +229,7 @@ def split_image(image, size):
postprocess_match_metric=Match_metric,
postprocess_match_threshold=Intersection_threshold,
verbose=0,
force_postprocess_type=True,
)

detection_confidences = []
Expand Down Expand Up @@ -287,6 +293,7 @@ def split_image(image, size):
postprocess_match_metric=Match_metric,
postprocess_match_threshold=Intersection_threshold,
verbose=0,
force_postprocess_type=True,
)

dapi_count = len(dapi_result.object_prediction_list)
Expand All @@ -303,6 +310,7 @@ def split_image(image, size):
postprocess_match_metric=Match_metric,
postprocess_match_threshold=Intersection_threshold,
verbose=0,
force_postprocess_type=True,
)

phase_count = len(phase_result.object_prediction_list)
Expand Down
1 change: 1 addition & 0 deletions src/napari_nuclephaser/calibrate_known_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def calibrate_with_known_number(
postprocess_type=Postprocess,
postprocess_match_metric=Match_metric,
postprocess_match_threshold=Intersection_threshold,
force_postprocess_type=True,
)
result = result.to_coco_predictions()
print("Prediction is complete!")
Expand Down
Loading
Loading