Metadata-Version: 2.1
Name: ndsafir
Version: 2026.1008a0
Summary: image denoising https://doi.org/10.1109/TMI.2009.2033991
Author: Jerome Boulanger
Author-Email: Unknown <jeromeb@mrc-lmb.cam.ac.uk>
License: 
         Copyright (c) 2025, Jerome Boulanger
         All rights reserved.
         
         Redistribution and use in source and binary forms, with or without
         modification, are permitted provided that the following conditions are met:
         
         * Redistributions of source code must retain the above copyright notice, this
           list of conditions and the following disclaimer.
         
         * Redistributions in binary form must reproduce the above copyright notice,
           this list of conditions and the following disclaimer in the documentation
           and/or other materials provided with the distribution.
         
         * Neither the name of copyright holder nor the names of its
           contributors may be used to endorse or promote products derived from
           this software without specific prior written permission.
         
         THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
         AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
         IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
         DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
         FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
         DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
         SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
         CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
         OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
         OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
         
Classifier: Development Status :: 4 - Beta
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering :: Image Processing
Requires-Python: >=3.10
Requires-Dist: numpy>=1.23
Provides-Extra: testing
Requires-Dist: scikit-image; extra == "testing"
Requires-Dist: matplotlib; extra == "testing"
Requires-Dist: seaborn; extra == "testing"
Requires-Dist: numpy>=1.23; extra == "testing"
Provides-Extra: dev
Requires-Dist: black; extra == "dev"
Requires-Dist: bumpver; extra == "dev"
Requires-Dist: isort; extra == "dev"
Requires-Dist: pip-tools; extra == "dev"
Requires-Dist: pytest; extra == "dev"
Provides-Extra: cli
Requires-Dist: bioio; extra == "cli"
Requires-Dist: bioio-czi; extra == "cli"
Requires-Dist: bioio-nd2; extra == "cli"
Requires-Dist: bioio-ome-zarr; extra == "cli"
Requires-Dist: bioio-ome-tiff; extra == "cli"
Requires-Dist: tqdm; extra == "cli"
Requires-Dist: dask-jobqueue; extra == "cli"
Requires-Dist: tqdm; extra == "cli"
Description-Content-Type: text/markdown

# ndsafir v2026.1011-alpha
[![Build Wheels](https://github.com/jboulanger/ndsafir/actions/workflows/wheels.yaml/badge.svg)](https://github.com/jboulanger/ndsafir/actions/workflows/wheels.yaml)
[![Python tests](https://github.com/jboulanger/ndsafir/actions/workflows/python_tests.yaml/badge.svg)](https://github.com/jboulanger/ndsafir/actions/workflows/python_tests.yaml)

Denoising of multi-dimensional microscopy images.


## Command line 

### Compilation

Install dependencies on ubuntu or debian with
```bash
sudo apt update
sudo apt install build-essential cmake libtiff-dev
```

To compile the code with a traditional makefile:
```bash
cd src
make release
```

To compile the code with CMake: 
```bash
mkdir build
cd build
cmake ../src
make
```

### Usage

Type `ndsafir -h` for help.

```
ndsafir 2026.1004-alpha - https://doi.org/10.1109/TMI.2009.2033991
    -i               0                        input (TIFF file)
    -o               0                        output (TIFF file)
    -patch           3,3,0,0,0                patch radius x,y,z,c,t
    -3D              true                     use 3D
    -time            true                     use time
    -noise           0                        noise model: gain,offset or gain,offset,readout
    -max_iter        4                        maximum number of iterations
    -pval            0.01                     p-value (0,1)
    -nthreads        12                       number of available threads
```

The input and output are TIFF file and support the hyperstack from ImageJ.

The patch radius can be tuned for each axis (x,y,z,c and time).

3D and time option will activate the use of 3d and time. 

The noise level (`-noise`) can be specified as 
- the noise standard deviation for Gaussisan noise
- a triplet gain, offset, readout for Poisson-Gaussian noise
- a pair of gain and noise offset 
If not specified it will be estimated.

The pvalue pval determines the threshold for detecting similar block or patches in the images.


## Python bindings

### Installation
```bash
git clone this repo
pip install ./ndsafir
```

### Usage in a script or notebook

```python
from skimage import data
import ndsafir
img = data.cat()
denoised = ndsafir.denoise(img,"gaussian",noise_std=5,axes="YXC")
```

### Usage as a command line

The module can be used as a command line tool too which allows to support more input format and use distributed computing using dask distributed.

For processing tif files:
```bash
python -m ndsafir --input input.tif --output output.tif
```

For processing ome-zarr with 16x256x256 chunks with 8 pixel overlap.
```bash
python -m ndsafir --input input.zarr --output output.zarr --chunk 1,1,16,256,256 --depth 0,0,8,8,8
```

For processing a czi file with 16,256x256 chunks with 8 pixel overlaps.
```bash
python -m ndsafir --input input.czi --output output.zarr --chunk 1,1,16,256,256 --depth 0,0,8,8,8
```

For processing an ome-zarr on a cluster with 12 workers (with 112 processors each):
```bash
python -m ndsafir --input input.czi --output output.zarr --chunk 1,1,16,256,256 --depth 0,0,8,8,8 --compute compute.yml
```

with compute.yml a file:
```yml
slurm:
   processes: 1
   cores: 112
   n_workers: 10
   memory: "64GB"
   queue: "cpu"
   walltime: '01:00:00'
   local_directory: $SLURM_SCRATCH_DIR

```

## Benchmark
A benchmarking bash script is in the `scripts` folder.

```bash
cd scripts
./benchmark.sh
```

Results are saved in a benchmark.csv file and can be analyzed using the notebook 'Analyze Benchmark.ipynb'.

Average PSNR for several datasets:

| dataset   |       5 |      10 |      15 |      20 |      25 |      30 |
|:----------|--------:|--------:|--------:|--------:|--------:|--------:|
| BSD68     | 36.7516 | 32.6167 | 30.5264 | 29.1308 | 28.0673 | 27.1925 |
| CBSD68    | 36.8811 | 32.9032 | 30.9022 | 29.563  | 28.5382 | 27.6981 |
| Fluo4     | 43.8542 | 39.4669 | 36.8542 | 34.9359 | 33.4384 | 32.1515 |
| Kodak24   | 37.5176 | 33.8983 | 31.9482 | 30.5841 | 29.528  | 28.6477 |
| McMaster  | 38.1061 | 34.5695 | 32.5226 | 31.0209 | 29.8129 | 28.808  |
| RNI15     | 35.3304 | 30.8142 | 28.9499 | 27.7385 | 26.8422 | 26.1281 |
| RNI6      | 35.7485 | 31.5641 | 29.6211 | 28.342  | 27.3921 | 26.6005 |
| Set12     | 37.2683 | 33.6293 | 31.6777 | 30.2513 | 29.0975 | 28.133  |



## Reference

J. Boulanger, C. Kervrann, P. Bouthemy, P. Elbau, J. -B. Sibarita and J. Salamero, "Patch-Based Nonlocal Functional for Denoising Fluorescence Microscopy Image Sequences," in IEEE Transactions on Medical Imaging, vol. 29, no. 2, pp. 442-454, Feb. 2010, doi: 10.1109/TMI.2009.2033991.
