Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

2 watching

Forks

Repository files navigation

Model-Aware Self-Supervised Learning for 3D Fluorescence Microscopy Deconvolution

This project explores a self-supervised learning framework for deconvolving 3D fluorescence microscopy volumes without access to ground truth. We extend DeepContrast to 3D and simulate training data using a physics-based forward model (PSF + noise). Our pipeline supports realistic degradation, modular 3D U-Net training in JAX/Equinox, and evaluation across diverse noise/blur levels.

📂 Repository Structure

├── archive/                          # Old experimental notebooks
├── notebooks/                        # Sample Jupyter notebooks for data generation, PSF simulation, and evaluation
├── report_visualization/             # Sample Scripts and notebooks used for creating visualization for the report
├── scripts/                          # Sample Shell and Python scripts to automate dataset creation, training, and grid runs
├── simulator.py                      # Functions to simulate PSF degradation on volumes
├── train_unet3d.py                   # Training script for the 3D U-Net deconvolution model
├── unet3d_clean.py                   # Clean implementation of the 3D U-Net architecture (JAX/Equinox)
├── utils.py                          # Utility functions and helpers
├── environment.yml                   # Reproducible environment
├── .gitignore                        # Files and directories to ignore in version control
├── SemesterProjectReportFinal.pdf    # Report
└── README.md                         # Project overview and usage instructions

⚙️ Installation

This project requires Python 3.9+ and JAX-compatible hardware (CPU or GPU). You can use Miniconda to manage environments.

1. To create the conda environment

conda env create -f environment.yml

This will create a new environment called deconvolution (defined in the YAML file).

2. Activate the environment

conda activate deconvolution

🧪 Microscopy Image Simulator: simulator.py

The simulator.py script simulates 3D fluorescence microscopy images by convolving real or simulated biological sample with a point spread function (PSF), then adding realistic noise (Gaussian and Poisson) and a controllable background offset. This simulates measured images suitable for training or benchmarking deconvolution models.

📌 Features

  • Convolution with a default or custom 3D PSF
  • Additive Gaussian and Poisson noise
  • Background signal simulation
  • OME-TIFF input/output

🛠️ Usage

To process all .ome.tif files in a directory:

python simulator.py \
  --input_dir path/to/directory \
  --output_dir path/to/directory \
  --psf path/to/psf.npy \
  --sigma_g 0.001 \
  --alpha_p 100 \
  --background 10 \
  --label measured

For example, to create the "measured" samples from the original/ideal samples:

python simulator.py \
  --input_dir /home/dcorrea/deconvolution/data/tubes/ideal \
  --output_dir /home/dcorrea/deconvolution/data/tubes/Gaussian/measured \
  --psf /home/dcorrea/deconvolution/data/tubes/Gaussian/psf_gaussian.npy \
  --sigma_g 0.001 \
  --alpha_p 100 \
  --background 10 \
  --label measured

⚙️ Arguments

Argument Description
--input Path to a single 3D .ome.tif file, If --input is provided we only porcess that single single file.
--input_dir Input directory containing OME-TIFF files (.ome.tif). All such files will be processed.
--psf PSF file (.npy format). If not provided, a default PSF will be generated using the PSF generator.
--sigma_g Standard deviation of Gaussian noise (e.g. read noise) If not provided, no Gaussian noise will be added.
--alpha_p Poisson noise scaling factor. Scaling factor for converting intensities. If not provided, no Poisson noise will be added.
--background Background level as a percentage of max intensity (e.g., 10 = 10%)
--label Optional suffix label for output files (default: "degraded")
--output_dir Output directory where the simulated images will be saved (used when processing multiple files).
--visualize If set, shows the middle slice of the simulated volume (set to false if processing many files to avoid spam)

🖼️ Output

Each processed .ome.tif volume will result in a new file:

basename_degraded.ome.tif

Stored in the specified --output_dir.


🧠 Training Script: train_unet.py

This script trains the 3D U-Net (defined in unet3d_clean.py) on simulated fluorescence microscopy volumes to perform deconvolution. It uses 3D patches from matched ground truth and degraded inputs, and supports training with or without SSIM-based loss.


🛠️ Usage

python train_unet.py \
  --gt_dir data/ground_truth \
  --sim_dir data/simulated \
  --id run_ssimTrue \
  --epochs 40 \
  --batch_size 1 \
  --learning_rate 0.003 \
  --checkpoint_every 5 \
  --num_volumes 30 \
  --use_ssim \
  --ssim_weight 0.5 \
  --psf_file psfs/default_psf.npy

⚙️ Arguments

Argument Description
--gt_dir Directory with ground truth OME-TIFF volumes
--sim_dir Directory with simulated (blurred/noisy) OME-TIFF volumes
--id Unique run name used for the experiment folder
--epochs Number of training epochs
--batch_size Batch size for training (default: 1)
--learning_rate Learning rate for Adam optimizer
--checkpoint_every Save a model checkpoint every N epochs
--num_volumes Number of full 3D volumes to use for training
--use_ssim If set, SSIM loss is included alongside MAE
--ssim_weight Relative weight of SSIM in total loss
--psf_file PSF .npy file for visualization comparisons

📂 Output Structure

All outputs are saved in experiments/<run_id>/:

File Description
model_final.eqx Final trained model saved with Equinox serialization
model_epoch_*.eqx Model checkpoints saved every --checkpoint_every epochs
ideal.ome.tif Ground truth test volume used for evaluation
degr.ome.tif Degraded input volume for prediction
pred.ome.tif Final model prediction on test volume
epoch_X_comparison.png 4-panel visualization of GT / degraded / prediction / RL deconvolution for epoch X
loss_epoch_X.png Training/validation curves for epoch X showing total loss, MAE, and SSIM
train_debug.log Training progress and gradient stats per epoch
metrics.json Final summary with training/test losses, MAE, SSIM, and metadata

Visualization Samples

Each saved figure shows the central slice of the test volume:

  • Ground truth
  • Degraded input
  • Model prediction
  • Richardson–Lucy deconvolution (baseline)

📉 Loss & Metrics

Tracked and saved per epoch:

  • MAE: Mean absolute error (per voxel)
  • SSIM: Structural similarity (optional)
  • Total Loss: Combination of MAE + weighted SSIM

You can adjust the relative weight using --ssim_weight.


📦 Model Architecture

  • 3D U-Net with 2 downsampling and 2 upsampling blocks
  • Dropout in bottleneck and decoder
  • Optional bilinear vs transposed upsampling
  • Uses equinox modules for efficient and functional model definitions

📬 Contact

If there are any questions, you can reach me at daniela.correa@epfl.ch

📄 Semester Project Report (PDF)

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages