Skip to main content

Vectorfit

This code is distributed as accompanying software for Calibration-free estimation of field dependent aberrations for single molecule localization microscopy across large fields of view by Isabel Droste, Erik Schuitema, Sajjad A. Khan, Myron Hensgens, Stijn Heldens, Carlas S. Smith, Ben van Werkhoven, Hylkje Geertsema, Keith A. Lidke, Sjoerd Stallinga, and Bernd Rieger.

The paper is available here.

This code implements full vectorial point spread function (PSF) fitting for Single Molecule Localization Microscopy (SMLM) including field dependent aberrations that are estimated directly from the single molecule data.

The code is developed in MATLAB and includes a fast CPU/GPU implementation in C++ with CUDA support. This implementation can be accessed directly from MATLAB using MEX files.

Operating system

The CPU/GPU implementation has been tested on Linux and Windows.

Alternatively, the code can run entirely within MATLAB on both Linux and Windows without requiring compilation. However, this approach has significantly slower localization performance.

Requirements and installation

Linux CPU/GPU

The code was tested to work on Ubuntu 22.04 and Ubuntu 24.04 with Matlab R2024b, GCC 10 and CUDA 12.6.2, but may also work with other configurations. Make sure you use a version of GCC that is compatible with your version of Matlab. You can check the supported GCC compiler for your version of Matlab here.

Download or clone the repository

git clone https://gitlab.tudelft.nl/imphys/ci/vectorfit.git

The code requires Eigen3, FFTW, HDF5, and PkgConfig libraries. These are preinstalled in most high-performance computing environments. If you want to install them locally on Ubuntu you can use:

sudo apt install libeigen3-dev libfftw3-dev libhdf5-dev pkg-config

When running the code on an HPC environment, you need to load Matlab before compilation, together with a compatible version of GCC.

module load matlab/R2024b
module load compiler/gcc/10
module load cuda/12.6.2

omit the last line when running without GPU support.

To compile, please run the following commands inside the path of the source code. First, move to the cpp folder

cd cpp

Then, run the following commands to compile the code

mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DUSECUDA=1 ..
make

Omit the variable -DUSECUDA=1 to disable GPU support.

In case you get an error that looks like this

version 'GLIBCXX_3.4.32' not found (required by .../xxx.mexa64)

make sure you are using the correct version of GCC that is compatible with your version of matlab.

When running the code on an HPC environment with multiple versions of GCC installed, it can be the case that the systems picks up on the default GCC version, even when you loaded the correct version. In that case, you can force the correct GCC version using

export CC=/usr/bin/gcc-10
export CXX=/usr/bin/g++-10
export PATH=/usr/bin:$PATH

If that does not work, try:

export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libstdc++.so.6

To enable the CPU/GPU mode, set params.cpp = true in the parameter file. For the example code, the parameter file can be found in set_parameters_scripts/set_parameters_microtubules_3D. In addition, to use the GPU mode, set params.cpp_fitmode = "gpu-lowaccuracy" to perform the Fourier transforms in single precision and params.cpp_fitmode = "gpu" to perform the Fourier transforms in double precision. To use the CPU mode, set params.cpp_fitmode = "cpu".

The DIPImage toolbox for MATLAB is required, please see http://www.diplib.org for installation instructions.

Windows

The code was tested to work on Windows 11 with Matlab R2024b, but may also work with other configurations.

Download or clone the repository

git clone https://gitlab.tudelft.nl/imphys/ci/vectorfit.git

The code requires Eigen3, FFTW, HDF5, and PkgConfig libraries, which can be installed using vcpkg.'

First, install vcpkg using

git clone https://github.com/microsoft/vcpkg.git
cd vcpkg
.\bootstrap-vcpkg.bat

Then install required libraries

vcpkg install eigen3 fftw3 hdf5 pkgconf

Integrate vcpkg with Visual Studio

vcpkg integrate install

To compile, please run the following commands inside the path of the source code. First, move to the cpp folder in the command line

cd cpp

Run the following commands (be sure to have modified the path to vcpkg)

mkdir build
cd build
cmake -G "Visual Studio 17 2022" -A x64 -DCMAKE_BUILD_TYPE=Release -DUSECUDA=1 -DCMAKE_TOOLCHAIN_FILE=path/to/vcpkg/scripts/buildsystems/vcpkg.cmake ..

Omit the variable -DUSECUDA=1 to disable GPU support. Then, in a Powershell, move to the cpp folder and run

cd build
cmake --build . --config Release

Matlab

The code was tested to work with Matlab R2024b but may work with other versions as well. Download the code or clone the repository using

git clone https://gitlab.tudelft.nl/imphys/ci/vectorfit.git

The DIPImage toolbox for MATLAB is required, please see http://www.diplib.org for installation instructions. It is also necessary to install the Parallel Computing Toolbox, Image Processing Toolbox and Bioinformatics Toolbox that can be found in the MATLAB Add-ons.

No further compilation of the code is needed. To enable the purely Matlab mode, set params.cpp = false; in the parameter file. For the example code, the parameter file can be found in set_parameters_scripts/set_parameters_microtubules_3D.

Software Demo

Follow the steps below to apply the SMLM pipeline to a test dataset.

  • Download the test data and place the file microtubules_3D_data0001.tif in the folder vectorfit/data/0_raw_data/. This data contains the first 800 frames from the 3D microtuble dataset from Figure 2 from the article (This is 1% of the full dataset).

    When you are running the code on linux machine via ssh, you can copy the test data from your local machine to the linux machine via

    scp /path/to/local/file/microtubules_3D_data0001.tif username@remote_host:/path/to/vectorfit/data/0_raw_data/
    
  • The parameter file is located at set_parameter_scripts/set_parameters_microtubules_3D.m. It contains all the imaging and fitting parameters. When using your own data, you need adjust the parameters to your own microscope parameters. When you change the name of the parameter file, make sure to declare it at the top of each of the three scripts segmentation.m, estimate_aberrations.m and localize.m that we will run below.

  • When you are running the code on a high performance computing environment, you can load the required modules via

    module load matlab/R2024b cuda/12.6.2 diplib
    
  • When you are running the code in an environment that supports graphical output (such as the Matlab user interface, or when running Matlab from the terminal with matlab -nodesktop), make sure that params.show_plots = true in the parameter file to enable plot visualisation. Otherwise, set params.show_plots = false.

  • Start Matlab and add all scripts in the code directory to Matlab's path. You can do this by running

    addpath(genpath('rootDir'))
    

    where you replace rootDir with to path to the code directory, so for example: addpath(genpath('/home/idroste/vectorfit'))

  • Within Matlab, navigate into the root directory of the code, and run the scripts below:

  1. Run the segmentation script

    run('segmentation.m')
    

    This will segment the raw SMLM data into regions of iterest (ROIs). The expected output is

    Starting parallel pool (parpool) using the 'Threads' profile ...
    Connected to parallel pool with 12 workers.
    Found 1 files
    Input file = microtubules_3D_data0001.tif
    Found 800 frames
    Load 800 frames
    Finished loading 800 frames
    Elapsed time is 6.020052 seconds.
    Skip first 0 frames
    Found 169332 ROIs in file 1
    Saved segmentation in data/1_segmentation/segmentation_microtubules_3D_data0001.mat
    Elapsed time is 9.060499 seconds.
    
    Finished segmentation
    Elapsed time is 17.018615 seconds.
    Parallel pool using the 'Threads' profile is shutting down.
    

    When your output gives an error and shows Found 0 files on the third line, make sure that within Matlab you are inside the root directory of the code.

    Depending on your system, you may also get the error A minimum pool size of 10 was requested. The maximum thread-based pool size is currently 2. This is because MATLAB can use 10 compute threads internally, but thread-based parallel pool are limited to 2 workers on your system (in this case). To correct this, change params.nr_of_parallel_workers = feature('numcores'); to params.nr_of_parallel_workers = 2; in set_parameter_scripts/set_parameters_microtubules_3D.m.

    When plotting is enabled, the following 4 plots will appear:

    Segmentation image

    The upper left plot shows that raw SMLM data. You can step trough all of the frames by selecting Actions>Step through slices and then clicking the plot. The upper right plot can be used to determine the segmentation threshold. An optimal value lies slightly above the noise level. For the test data, the segmentation threshold is set to 15.5. You can change the segmentation threshold by changing the parameter params.segmentation_ROI_thr in the parameter file. The bottom left plot shows the centers of all ROIs in the field of view. The bottom right plot shows all segmented ROIs: you can step through them by selecting Actions>Step through slices and then clicking the plot.

    The segmented ROIs will be saved in the folder data/1_segmentation.

  2. Next, run the aberration estimation script

    run('estimate_aberrations.m')
    

    This will load the segmented ROIs and estimate the field dependent aberrations from a subset of 5000 ROIs. When plotting is enabled, the following 4 plots will appear:

    Aberration image

    The first plot shows the estimated aberration surfaces. The second plot shows the selected measured ROIs and the corresponding modeled PSFs, which you can step through by selecting Actions>Step through slices and then clicking the plot. The third plot shows the measured and modeled PSFs, averaged and upsampled on a 3x3 grid of the FOV. The fourth plot shows the evolution of gamma coefficients depending on the number of iterations.

    The estimated NAT coefficients can be found in theta_full.global. The output will be saved in data/2_estimate_aberrations/.

    [To do: add instruction on how to use the code for 2D data]

  3. Finally, run the localization script

    run('localize.m')
    

    This will localize all segmented ROIs using the estimated field dependent aberrations. When plotting is enabled, the final image will be rendered:

    Rendered image

    You can change the super-resolution pixel size and the rendered area of the FOV by adusting pixelsize, xlim and ylim at the bottom of the script localize.m.

    Use params.FlagOTF = true to use the precomputation of OTFs. This will only work in the CPU/GPU mode. The output localizations can be found in the array localizations and represent the parameters: [ID, x (nm), y (nm), z(nm), framenumber, CRLBx, CRLBy, CRLBz, Nph, bg]. The output will be saved in data/3_localize/.

Bead fitting

When you want to estimate aberrations from a z-stack of beads, use the script bead_fitting/fit_bead_aberrations.m. This code segments the raw data into 3D ROIs, and estimated the Zernike coefficient aberrations for each ROI separately. The parameters file set_parameters/set_parameters_nuclearlamin_240819_beads_crop.m can serve as an example parameter file for bead fitting.

Helpful notes

When using you own segmentation, make sure that your input to the rest of the code contains the following, where Ncfg is the total number of emitters:

allspots: Array of size [Mx,My,Mz,Ncfg] that contains the segmented ROIs

framelist: Array of size [1,Ncfg] that contains the framenumber of each ROI. NB: the first frame is 1 and not 0

ID: Array of size [1,Ncfg] that contains a unique number for each ROI. You can use 1,2,...,Ncfg

roixy: Array of size [2,Ncfg] that contains the pixel coordinates of the segmented ROIs within the FOV.

Troubleshooting and contributing

If you run into issues installing or using the software, please create an issue on the issue tracker, or contact the authors: Isabel Droste i.e.a.c.droste@tudelft.nl, Sjoerd Stallinga s.stallinga@tudelft.nl, Bernd Rieger b.rieger@tudelft.nl.

Metadata

Release files for vectorfit-py-cu12 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for vectorfit-py-cu12 0.3.1
File Actions
vectorfit_py_cu12-0.3.1-cp315-cp315-win_amd64.whl CPython 3.15 CPython 3.15 Windows x86-64 Details for vectorfit_py_cu12-0.3.1-cp315-cp315-win_amd64.whl
vectorfit_py_cu12-0.3.1-cp315-cp315-manylinux_2_34_x86_64.whl CPython 3.15 CPython 3.15 Linux glibc 2.34+ x86-64 Details for vectorfit_py_cu12-0.3.1-cp315-cp315-manylinux_2_34_x86_64.whl
vectorfit_py_cu12-0.3.1-cp314-cp314-win_amd64.whl CPython 3.14 CPython 3.14 Windows x86-64 Details for vectorfit_py_cu12-0.3.1-cp314-cp314-win_amd64.whl
vectorfit_py_cu12-0.3.1-cp314-cp314-manylinux_2_34_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.34+ x86-64 Details for vectorfit_py_cu12-0.3.1-cp314-cp314-manylinux_2_34_x86_64.whl
vectorfit_py_cu12-0.3.1-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details for vectorfit_py_cu12-0.3.1-cp313-cp313-win_amd64.whl
vectorfit_py_cu12-0.3.1-cp313-cp313-manylinux_2_34_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.34+ x86-64 Details for vectorfit_py_cu12-0.3.1-cp313-cp313-manylinux_2_34_x86_64.whl
vectorfit_py_cu12-0.3.1-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details for vectorfit_py_cu12-0.3.1-cp312-cp312-win_amd64.whl
vectorfit_py_cu12-0.3.1-cp312-cp312-manylinux_2_34_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.34+ x86-64 Details for vectorfit_py_cu12-0.3.1-cp312-cp312-manylinux_2_34_x86_64.whl
vectorfit_py_cu12-0.3.1-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details for vectorfit_py_cu12-0.3.1-cp311-cp311-win_amd64.whl
vectorfit_py_cu12-0.3.1-cp311-cp311-manylinux_2_34_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.34+ x86-64 Details for vectorfit_py_cu12-0.3.1-cp311-cp311-manylinux_2_34_x86_64.whl

Total release size: 574.7 MB

Release files / vectorfit_py_cu12-0.3.1-cp315-cp315-win_amd64.whl

Download URL vectorfit_py_cu12-0.3.1-cp315-cp315-win_amd64.whl
Size 101.1 MB
Tags CPython 3.15 Windows x86-64
SHA-256 checksum
How to use checksums
633ab9716439d051b6ba54aceb86038c9cdaf3c3b4bb6a1fbb10bffb605c3c51
BLAKE2b-256 checksum
How to use checksums
7de23e12a6282759ca10c1fef1ec1edc1fdc343584d83073268558a3b0f90f70
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.18

Release files / vectorfit_py_cu12-0.3.1-cp315-cp315-manylinux_2_34_x86_64.whl

Download URL vectorfit_py_cu12-0.3.1-cp315-cp315-manylinux_2_34_x86_64.whl
Size 13.3 MB
Tags CPython 3.15 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
98846deec720f3d093202861ce266d43de2e6b18e8c4c1e3a683efcfaa932cde
BLAKE2b-256 checksum
How to use checksums
b075ca788abed11f98da77cf220fab891cafae49893d793fa10aad37a33ac2f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.18

Release files / vectorfit_py_cu12-0.3.1-cp314-cp314-win_amd64.whl

Download URL vectorfit_py_cu12-0.3.1-cp314-cp314-win_amd64.whl
Size 101.1 MB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
e647dff7cb0b31a9e67e6a29923c44fc088ca0e9876533b2b446edd7d6652bb7
BLAKE2b-256 checksum
How to use checksums
ead041a82ba91f7bfe761a9c1cfc7fede9967bc9db98e7f74cc4d470f93b711b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.18

Release files / vectorfit_py_cu12-0.3.1-cp314-cp314-manylinux_2_34_x86_64.whl

Download URL vectorfit_py_cu12-0.3.1-cp314-cp314-manylinux_2_34_x86_64.whl
Size 13.3 MB
Tags CPython 3.14 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
fe26d93bd3e729bd5576ad97319e703b6a8ec640f03b58d862408ae5edee266c
BLAKE2b-256 checksum
How to use checksums
b2c5cc1be072f583525084e4181a5dd3ccb3dddbc5b8159c394dda2628a0c60d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.18

Release files / vectorfit_py_cu12-0.3.1-cp313-cp313-win_amd64.whl

Download URL vectorfit_py_cu12-0.3.1-cp313-cp313-win_amd64.whl
Size 102.0 MB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
66ec1ed84db1ea9a258b8348f197bf5816705a96a4d155bd27be536f5ef3c77d
BLAKE2b-256 checksum
How to use checksums
aea3ccf4ba0f7566e7e318e05bf2cf732c8344fed0184828f111df2beb2782a9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.18

Release files / vectorfit_py_cu12-0.3.1-cp313-cp313-manylinux_2_34_x86_64.whl

Download URL vectorfit_py_cu12-0.3.1-cp313-cp313-manylinux_2_34_x86_64.whl
Size 13.3 MB
Tags CPython 3.13 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
89ce606b01d4b142e949264bce37d3a78ac93150b66a7c3ec1ebe6d43aa9f3fe
BLAKE2b-256 checksum
How to use checksums
9e6cbaf4405c1b71a4b0c85e4d66558bef4c0dbc16fe83b1ec8d688d2d5f366b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.18

Release files / vectorfit_py_cu12-0.3.1-cp312-cp312-win_amd64.whl

Download URL vectorfit_py_cu12-0.3.1-cp312-cp312-win_amd64.whl
Size 102.0 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
75c2d42cb90b5b34fac70f7b68c85d16bb81fdb5b40e8191071813a2ee38d290
BLAKE2b-256 checksum
How to use checksums
bfdbbbe265445a9a67da6a65b4343f84e32e8129b758f546aba90e0f0dd4e8be
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.18

Release files / vectorfit_py_cu12-0.3.1-cp312-cp312-manylinux_2_34_x86_64.whl

Download URL vectorfit_py_cu12-0.3.1-cp312-cp312-manylinux_2_34_x86_64.whl
Size 13.3 MB
Tags CPython 3.12 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
72d10dc5368d3c45c273c37370c81f33b5c53f7bf5d9a9e32aa003601e74ec63
BLAKE2b-256 checksum
How to use checksums
522a6c3df87dfcddfff821ab850028fa861ce3b67135d2213ae6291b4c867f5e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.18

Release files / vectorfit_py_cu12-0.3.1-cp311-cp311-win_amd64.whl

Download URL vectorfit_py_cu12-0.3.1-cp311-cp311-win_amd64.whl
Size 102.0 MB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
46f00995ec7c288a48bface70e66092d4b4a57f6ed83db0ae0de1702d54344bd
BLAKE2b-256 checksum
How to use checksums
4cc280f78278f2d4db92738206f0f223c0ee52d7e25bbe3928cf9523fd53bcaf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.18

Release files / vectorfit_py_cu12-0.3.1-cp311-cp311-manylinux_2_34_x86_64.whl

Download URL vectorfit_py_cu12-0.3.1-cp311-cp311-manylinux_2_34_x86_64.whl
Size 13.3 MB
Tags CPython 3.11 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
2f5d402c446a8b2bbeada10599540db7a8236a26bebc57e1fbaf2b6ee13fcb69
BLAKE2b-256 checksum
How to use checksums
6bc3c31faa2b1f07fed2ac3d329fc8836c2e3ce5835ce10791815a68bdbf07a5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.18

Security for vectorfit-py-cu12 0.3.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page