We provide the code to reproduce the results reported in
Sébastien Crombez, Cédric Ray, Chloé Exbrayat-Héritier,Florence Ruggiero, Nicolas Ducros, "Hyperspectral LSFM with DMD-only Shaping and Neural Network Reconstruction," (2025).
Contact: [email protected], CREATIS Laboratory, University of Lyon, France.
-
Create a conda environment
conda create --name hsflsm conda activate hsflsm
-
Install pytorch using conda. E.g.,
conda install pytorch torchvision torchaudio pytorch-cuda=12.4 -c pytorch -c nvidia conda install pip pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu128
Visit https://pytorch.org/get-started/locally/ if you need a different installation.
-
Install SPyRiT v2.4.1 and a few more packages:
pip install spyrit==2.4.1 pip install spyder-kernels pip install opencv-python pip install pysptools pip install girder-client pip install natsort
opencv-python is required for spectral registration. It is not only necessary to run
main_spectal_registration.py.
pysptools is required for spectral unmixing. It is not only necessary to run
main_unmix_filter_EGFP-DsRed_14.pyandmain_unmix_filter_mRFP-DsRed.py.
natsoft is required to sort the files. It is not only necessary to run
main_create_gif.py.
-
Get source code and navigate to the
/2025_hLSFM/foldergit clone https://github.com/openspyrit/spyrit-examples.git cd spyrit-examples/2025_hLSFM/ -
Download
- The raw measurements can be found here.
- The neural networks used for reconstruction can be found here. The covariance matrix used by the Tikhonov network can be found here.
- The reference spectra used for unmixing can be found here.
The directory structure should be
|---spyrit-examples
| |---2025_hLSFM
| | |---data
| | | |---2023_02_28_mRFP_DsRed_3D
| | | | |---Raw_data_chSPSIM_and_SPIM
| | | | | |---data_2023_02_28
| | | | | | |---RUN0001
| | | | | | |---RUN0002
| | | | | | |---
| | | |---2023_03_07_mRFP_DsRed_can_vs_had
| | | | |---
| | | |---2023_03_13_2023_03_14_eGFP_DsRed_3D
| | | | |---
| | | |---Reference_spectra
| | |---fonction
| | |---model
| | | |---tikho-net_unet_imagenet_ph_50_exp_N_512_M_128_epo_20_lr_0.001_sss_10_sdr_0.5_bs_20_reg_1e-07.pth
| | | |---
| | |---stat
| | | |---Cov_1_512x512.npy
| | |---main_colorize_EGFP-DsRed_14.py
| | |---main_colorize_mRFP-DsRed.py
| | |---
- Dataset 1 shows the raw measurements for one slice of the Tg(fli1:EGFP;olig2:DsRed) sample.
- Dataset 2 shows the abundance of EGFP (in green) and DsRed (in red) for all of the 25 slices of the Tg(fli1:EGFP;olig2:DsRed) sample. Many more visualizations of the abundance maps can be found here.
- Dataset 3 shows the conventional LSFM images for 21 slices of the Tg(fli1:EGFP;olig2:DsRed) sample. Other conventional LSFM images of the sample can be found here.
- Dataset 4 shows the abundance of mRFP (in cyan) and DsRed (in red) for all of the 20 slices of the Tg(sox10:mRFP;olig2:DsRed) sample. Many more visualizations of the abundance maps can be found here.
- Dataset 5 shows the conventional LSFM images for all slices of the Tg(sox10:mRFP;olig2:DsRed) sample. Other conventional LSFM images of the sample can be found here.
All the results are saved in
.\data\2023_03_07_mRFP_DsRed_can_vs_had\. They can also be found on our warehouse (see here).
- Run
main_preprocess_Fellgett.pyto generate the preprocessed measurements that will be saved in the subfolder.\Preprocess\ - Run
figure_3.pyto reconstruct hypercubes that will be saved in the subfolder.\Reconstruction\hypercube\and generate Fig. 3 of the paper.
All the results are saved in
.\data\2023_03_13_2023_03_14_eGFP_DsRed_3D\. They can also be found on our warehouse (see here).
- Run
main_preprocess_EGFP-DsRed.pyto generate the preprocessed measurements that will be saved in the subfolder.\Preprocess\ - Run
main_recon_net_EGFP-DsRed_14_all_slices.pyto reconstruct the hypercubes that will be saved in the subfolder.\Reconstruction\hypercube\. - Run (the first sections of)
main_spectal_registration.pyto compensate for a spectral shift. The resulting hypercubes will be saved in the subfolder.\Reconstruction\hypercube\*_shift\. - Run
main_unmix_filter_EGFP-DsRed_14.pyto estimate the map of the different components (i.e., DsRed, EGFP, and autofluorescence) in the sample by both spectral filtering and spectral unmixing.- The maps obtained by spectral filtering will be saved in the subfolder
.\Filtering_shift\. - The quantitative abundance maps obtained by spectral unmixing will be saved in the subfolder
.\Unmixing_shift\.
- The maps obtained by spectral filtering will be saved in the subfolder
- Run
main_visual_EGFP-DsRed_14.pyto visualise the filter maps and quantitative maps in color. The resulting visualisations will be saved in the subfolder.\Visualisation_shift\.
All the results are saved in
.\data\2023_02_28_mRFP_DsRed_3D\. They can also be found on our warehouse (see here).
- Run
main_preprocess_mRFP-DsRed.pyto generate the preprocessed measurements that will be saved in the subfolder.\Preprocess\ - Run
main_recon_net_mRFP-DsRed_14_all_slices.pyto reconstruct the hypercubes that will be saved in the subfolder.\Reconstruction\hypercube\. - Run (the last sections of)
main_spectal_registration.pyto compensate for a spectral shift. The resulting hypercubes will be saved in the subfolder.\Reconstruction\hypercube\*_shift\. - Run
main_unmix_filter_EGFP-DsRed_14.pyto estimate the map of the different components (i.e., DsRed, EGFP, and autofluorescence) in the sample by both spectral filtering and spectral unmixing.- The maps obtained by spectral filtering will be saved in the subfolder
.\Filtering_shift\. - The quantitative abundance maps obtained by spectral unmixing will be saved in the subfolder
.\Unmixing_shift\.
- The maps obtained by spectral filtering will be saved in the subfolder
- Run
main_unmix_filter_mRFP-DsRed.pyto visualise the filter maps and quantitative maps in color. The resulting visualisations will be saved in the subfolder.\Visualisation_shift\.
- The script
main_pattern_full_visu.pyreproduces the illumination patterns of Fig. S6 of the supplementary document. - The scripts
main_colorize_*.pyplot in color ("rainbow colors")- the raw measurements in
./Preprocess/Run*/, - the reconstructed hypercubes in
./Reconstruction/hypercube/tikhonet50_div1.5/RUN*/.
- the raw measurements in
- The script
main_stat.pyshows examples to compute mean and covariance matrices "in 2D". To compute mean and covariance "in 1D", as required by the Tikhonov step of the reconstruction, seestat_1.pyinspyrit.misc.statistics. - Training:
- See
train.shfor a typical shell script. train.pyis the main Python file (called intrain.sh).train_plot.pyload and plot the training loss.
- See