LightSaver is a powerful data analysis package designed for fluorescent C. elegans imaging. Developed by Samuel Freitas with contributions from Raul Castro-Portugez, Vanessa Hofschneider, and Lainey Wait at the University of Arizona (Sutphin Lab) in the Microbiology (MCB) and Biomedical Engineering (BME) departments.
Note: LightSaver is available in both MATLAB and Python — choose whichever you're most comfortable with. Both versions produce near-identical results and output the same files.
GitHub Desktop is a free application that lets you download and update LightSaver without using a terminal or command line.
- Download and install GitHub Desktop: https://github.com/apps/desktop
- Create a free GitHub account at https://github.com — it's recommended not to use your
.eduemail for this - Open GitHub Desktop, go to File > Clone Repository (or press
Ctrl+Shift+O) - Click the URL tab at the top of the dialog
- Paste this URL and click Clone:
https://github.com/Sam-Freitas/LightSaver
LightSaver will be downloaded to your computer, typically into your Documents/GitHub/LightSaver folder.
Prefer using a terminal instead? Click here.
Open a terminal (PowerShell, Command Prompt, or macOS Terminal) and run:
git clone https://github.com/Sam-Freitas/LightSaverRequired MATLAB Toolboxes:
- Computer Vision Toolbox (install this first — it will automatically install the Image Processing Toolbox as well)
To install: go to Apps (top bar in MATLAB) → Get More Apps → search for Computer Vision Toolbox → Install
Required Python Modules:
matplotlib, natsort, numpy, opencv_python, opencv_python_headless, pandas, PyQt6, PyQt6_sip, scipy, scikit-image
Installation steps:
- Open a terminal (PowerShell on Windows, or Terminal on macOS/Linux)
- Navigate to the
scripts_pythonfolder inside the LightSaver directory - Run the following command, replacing the path with your actual path:
python -m pip install -r /path/to/scripts_python/requirements.txtTip: In GitHub Desktop, you can right-click the repository and choose Open in Terminal to open a terminal already pointed at the correct folder.
Warning
Never work directly on your original images. Always copy your data to a new folder first and run LightSaver on the copy. The script can modify files (e.g. naming schemas), so it is essential to keep your raw data untouched and separate.
LightSaver expects your images to be organized in a specific folder structure. This structure is required even if you only have a single timepoint.
Required folder layout:
Experiment Folder/ ← This is what you select when running the script
Day 1/ ← Timepoint folders, named D1, D2, etc.
image_D1_1.tiff
image_D1_2.tiff
Day 2/
image_D2_1.tiff
image_D2_2.tiff
The script scans folders recursively and automatically sorts timepoints by day number (D1, D2, D3, etc.).
Image naming rules:
- Each image name should describe the experiment, timepoint, and replicate — for example:
skn-1-HT115-EV_D1_1.tiff - The general convention is:
experiment-name_DayN_replicateN.tiff - The replicate number at the end of each filename is used to group replicates together automatically
- Make sure all image names are consistent with each other. The script automatically removes any part of the filename that is identical across all images in order to generate clean export labels. Inconsistent naming is the most common cause of unexpected results
- Numbers matching the pattern
001,002...009are automatically stripped from filenames — these are typically added by microscope export software and are not needed
Both MATLAB and Python versions run identically and produce the same output files.
- Open MATLAB
- Open
Lightsaver_batch.mfrom thescripts_matlabfolder - Press F5 or click the Run button
- A parameters dialog will appear — fill in your experiment-specific settings and click OK
- A folder browser will open — navigate to and select your overarching Experiment Folder (the top-level folder containing all your day subfolders)
- LightSaver will process all images and show a progress bar
- When complete, the Exported images folder will open automatically (usually located at
Documents/GitHub/LightSaver/Exported images)
- Open
LightSaver_batch.pyfrom thescripts_pythonfolder in your Python IDE (VS Code is recommended and tested) - Press F5 or click Run
- A parameters dialog will appear — fill in your experiment-specific settings and click OK
- A folder browser will open — navigate to and select your overarching Experiment Folder
- LightSaver will process all images and show a progress bar
- When complete, the Exported images folder will open automatically
After processing, LightSaver produces the following files inside your Experiment Folder:
| File | Description |
|---|---|
data.csv (MATLAB) / data_python.csv (Python) |
Raw per-image measurements: integrated fluorescence intensity and area for each detected worm |
Analyzed_data.csv (MATLAB) / Analyzed_data_python.csv (Python) |
Summary statistics across replicates and timepoints |
output_figures/ |
Automatically generated plots of your experiment data |
Exported images/ |
Side-by-side processed image previews showing the original, segmentation mask, and masked fluorescence |
Both the MATLAB and Python versions produce equivalent data — the column names and structure of the CSVs are the same. The only difference is the filename (
data.csvvsdata_python.csv).
Worms are being detected as one large blob?
- Re-run with the "Use large blob fix" option enabled in the parameters dialog
Images are extremely noisy or the results look wrong?
- MATLAB users: run
Lightsaver_script.mon individual sub-experiment folders manually, then usebad_images_fix.mto correct problem images before re-running the batch script
Results look unexpected or grouping seems wrong?
- Check your image filenames first. Make sure they follow the
experiment-name_DayN_replicateN.tiffconvention and are consistent across all images in the experiment
No images found / script stops immediately?
- Make sure your images have the
.tifor.tiffextension - Make sure your images are inside day-numbered subfolders (e.g.,
D1/,D2/), not loose in the experiment folder
This approach is only needed if your data is extremely noisy and you need to manually review and fix individual images using bad_images_fix.m before proceeding.
- Open
Lightsaver_script.min MATLAB - Set your parameters manually in the script
- Run the script and select the folder containing the
.tiffimages for that sub-experiment - A
data.csvfile will be created in that folder - If needed, run
bad_images_fix.mto correct problem images, then repeat
When using the batch script (recommended), data analysis and figure export run automatically at the end of processing.
If you need to re-run analysis separately:
- Open and run
Data_analysis_and_export.min MATLAB - Select your overarching Experiment Folder from the dropdown
- Verify that
Analyzed_data.csvand theoutput_figures/directory have been created

