Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuntimeError: ffi_prep_cif_var failed when calling richardson_lucy_nc but not when calling richardson_lucy (python) #34

Open
OlivierBakker opened this issue Aug 23, 2024 · 6 comments

Comments

@OlivierBakker
Copy link

OlivierBakker commented Aug 23, 2024

Hi,

I am running into a runtime error during calling the non circular RL from python version, where it throws RuntimeError: ffi_prep_cif_var failed

The circular version richardson_lucy() does seem to work fine and produces quite good results. Any advice on if this could be a data issue (psf / data in wrong format) or a install issue would be appreciated as I'd like to test the nc version as I have some strong edges in my data.

I tried a bit of googling and looking at the source, and it seems like its an error between the python - C interaction but it goes a bit above my head.

Running on Ubuntu 22.04.4 with version python 3.10.0, clij2-fft 0.26, pyopencl 2024.2.7 and cuda 12.1 (full package list below).

In [1]: import tifffile
   ...: import pyopencl as cl
   ...: from clij2fft.richardson_lucy import richardson_lucy, richardson_lucy_nc

In [2]: img = tifffile.imread("img.tiff")

In [3]: psf = tifffile.imread("psf.tiff")

In [4]: res = richardson_lucy(img, psf, 500, 0.0002)
get lib

platform 0 NVIDIA CUDA
device name 0 NVIDIA A100-SXM4-80GB

Richardson Lucy Started
0 10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200 210 220 230 240 250 260 270 280 290 300 310 320 330 340 350 360 370 380 390 400 410 420 430 440 450 460 470 480 490 
Richardson Lucy Finished

In [5]: res = richardson_lucy_nc(img, psf, 500, 0.0002)
get lib
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Cell In[5], line 1
----> 1 res = richardson_lucy_nc(img, psf, 500, 0.0002)

File <path here> lib/python3.10/site-packages/clij2fft/richardson_lucy.py:128, in richardson_lucy_nc(img, psf, numiterations, regularizationfactor, lib, platform, device)
    125     lib = getlib()
    127 # the normalization factor is the valid region correlated with the PSF
--> 128 lib.convcorr3d_32f(int(normal.shape[2]), int(normal.shape[1]), int(normal.shape[0]), valid, shifted_psf, normal,1,platform,device)
    130 # get rid of any zeros in the normal to avoid divide by zero issues
    131 #normal[normal<0.00001]=1
    132 
    133 # deconvolution using clij2fft
    134 if regularizationfactor==0:

RuntimeError: ffi_prep_cif_var failed

EDIT:
I have tried running with np.ones to rule out an issue with my image / psfs following from: https://github.com/clij/clij2-fft/blob/master/python/interactive%20tests/test_richardson_lucy.py

It still gives the same issue

Python 3.10.0 | packaged by conda-forge | (default, Nov 20 2021, 02:24:10) [GCC 9.4.0]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.12.3 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from clij2fft.libs import getlib
   ...: from skimage.io import imread
   ...: from clij2fft.richardson_lucy import richardson_lucy, richardson_lucy_nc
   ...: import matplotlib.pyplot as plt
   ...: import numpy as np
   ...: import os
   ...: 

In [2]:     img = np.ones((256, 256, 128), dtype=np.float32)
   ...:     psf = np.ones((128, 128, 64), dtype=np.float32)

In [4]:     lib = getlib()

In [5]: result = richardson_lucy(img, psf, 100, 0, lib=lib,platform=0,device=0)

platform 0 NVIDIA CUDA
device name 0 NVIDIA A100-SXM4-80GB
2 warnings generated.

Richardson Lucy Started
0 10 20 30 40 50 60 70 80 90 
Richardson Lucy Finished

In [6]: result_nc = richardson_lucy_nc(img, psf, 100, 0, lib=lib)
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Cell In[6], line 1
----> 1 result_nc = richardson_lucy_nc(img, psf, 100, 0, lib=lib)

File /software/hgi/envs/conda/team217/ob7/tglow/lib/python3.10/site-packages/clij2fft/richardson_lucy.py:128, in richardson_lucy_nc(img, psf, numiterations, regularizationfactor, lib, platform, device)
    125     lib = getlib()
    127 # the normalization factor is the valid region correlated with the PSF
--> 128 lib.convcorr3d_32f(int(normal.shape[2]), int(normal.shape[1]), int(normal.shape[0]), valid, shifted_psf, normal,1,platform,device)
    130 # get rid of any zeros in the normal to avoid divide by zero issues
    131 #normal[normal<0.00001]=1
    132 
    133 # deconvolution using clij2fft
    134 if regularizationfactor==0:

RuntimeError: ffi_prep_cif_var failed

Package versions in my environment:

# Name                    Version                   Build  Channel
_libgcc_mutex             0.1                 conda_forge    conda-forge
_openmp_mutex             4.5                       2_gnu    conda-forge
aicsimageio               4.14.0                   pypi_0    pypi
aiobotocore               2.5.4                    pypi_0    pypi
aiohttp                   3.9.5                    pypi_0    pypi
aioitertools              0.11.0                   pypi_0    pypi
aiosignal                 1.3.1                    pypi_0    pypi
annotated-types           0.6.0                    pypi_0    pypi
asciitree                 0.3.3                    pypi_0    pypi
asttokens                 2.4.1              pyhd8ed1ab_0    conda-forge
async-timeout             4.0.3                    pypi_0    pypi
attrs                     23.2.0                   pypi_0    pypi
backcall                  0.2.0              pyh9f0ad1d_0    conda-forge
basicpy                   1.2.0                    pypi_0    pypi
beautifulsoup4            4.12.3                   pypi_0    pypi
bfio                      2.3.0                    pypi_0    pypi
bleach                    6.1.0                    pypi_0    pypi
botocore                  1.31.17                  pypi_0    pypi
bzip2                     1.0.8                hd590300_5    conda-forge
c-ares                    1.27.0               hd590300_0    conda-forge
ca-certificates           2024.6.2             hbcca054_0    conda-forge
cellpose                  3.0.8                    pypi_0    pypi
certifi                   2024.6.2           pyhd8ed1ab_0    conda-forge
charset-normalizer        3.3.2                    pypi_0    pypi
click                     8.1.7                    pypi_0    pypi
clij2-fft                 0.26                     pypi_0    pypi
cloudpickle               3.0.0                    pypi_0    pypi
contourpy                 1.2.0                    pypi_0    pypi
cuda-cudart               12.1.105                      0    nvidia
cuda-cupti                12.1.105                      0    nvidia
cuda-libraries            12.1.0                        0    nvidia
cuda-nvrtc                12.1.105                      0    nvidia
cuda-nvtx                 12.1.105                      0    nvidia
cuda-opencl               12.4.127                      0    nvidia
cuda-runtime              12.1.0                        0    nvidia
cycler                    0.12.1                   pypi_0    pypi
dask                      2024.4.2                 pypi_0    pypi
dask-expr                 1.0.14                   pypi_0    pypi
dask-image                2024.5.3                 pypi_0    pypi
decorator                 5.1.1              pyhd8ed1ab_0    conda-forge
defusedxml                0.7.1                    pypi_0    pypi
distributed               2024.4.2                 pypi_0    pypi
docopt                    0.6.2                    pypi_0    pypi
elementpath               4.4.0                    pypi_0    pypi
exceptiongroup            1.2.0              pyhd8ed1ab_2    conda-forge
executing                 2.0.1              pyhd8ed1ab_0    conda-forge
fasteners                 0.19                     pypi_0    pypi
fastjsonschema            2.19.1                   pypi_0    pypi
fastremap                 1.14.1                   pypi_0    pypi
filelock                  3.14.0                   pypi_0    pypi
fonttools                 4.50.0                   pypi_0    pypi
frozenlist                1.4.1                    pypi_0    pypi
fsspec                    2023.6.0                 pypi_0    pypi
funcsigs                  1.0.2                      py_3    conda-forge
gradient-free-optimizers  1.3.0                    pypi_0    pypi
hyperactive               4.6.0                    pypi_0    pypi
idna                      3.7                      pypi_0    pypi
imagecodecs               2024.1.1                 pypi_0    pypi
imageio                   2.27.0                   pypi_0    pypi
imageio-ffmpeg            0.4.9                    pypi_0    pypi
importlib-metadata        7.0.2              pyha770c72_0    conda-forge
importlib_metadata        7.0.2                hd8ed1ab_0    conda-forge
ipython                   8.12.3                   pypi_0    pypi
jax                       0.4.23                   pypi_0    pypi
jaxlib                    0.4.23                   pypi_0    pypi
jedi                      0.19.1             pyhd8ed1ab_0    conda-forge
jinja2                    3.1.4                    pypi_0    pypi
jmespath                  1.0.1                    pypi_0    pypi
joblib                    1.3.2                    pypi_0    pypi
jsonschema                4.22.0                   pypi_0    pypi
jsonschema-specifications 2023.12.1                pypi_0    pypi
jupyter-client            8.6.2                    pypi_0    pypi
jupyter-core              5.7.2                    pypi_0    pypi
jupyterlab-pygments       0.3.0                    pypi_0    pypi
kiwisolver                1.4.5                    pypi_0    pypi
lazy-loader               0.3                      pypi_0    pypi
ld_impl_linux-64          2.40                 h41732ed_0    conda-forge
lerc                      4.0.0                h27087fc_0    conda-forge
libabseil                 20220623.0      cxx17_h05df665_6    conda-forge
libblas                   3.9.0           21_linux64_openblas    conda-forge
libcblas                  3.9.0           21_linux64_openblas    conda-forge
libcublas                 12.1.0.26                     0    nvidia
libcufft                  11.0.2.4                      0    nvidia
libcufile                 1.9.1.3                       0    nvidia
libcurand                 10.3.5.147                    0    nvidia
libcusolver               11.4.4.55                     0    nvidia
libcusparse               12.0.2.55                     0    nvidia
libdeflate                1.20                 hd590300_0    conda-forge
libffi                    3.4.2                h7f98852_5    conda-forge
libgcc-ng                 13.2.0               h807b86a_5    conda-forge
libgfortran-ng            13.2.0               h69a702a_5    conda-forge
libgfortran5              13.2.0               ha4646dd_5    conda-forge
libgomp                   13.2.0               h807b86a_5    conda-forge
libgrpc                   1.51.1               h4fad500_1    conda-forge
libjpeg-turbo             3.0.0                hd590300_1    conda-forge
liblapack                 3.9.0           21_linux64_openblas    conda-forge
libnpp                    12.0.2.50                     0    nvidia
libnsl                    2.0.1                hd590300_0    conda-forge
libnvjitlink              12.1.105                      0    nvidia
libnvjpeg                 12.1.1.14                     0    nvidia
libopenblas               0.3.26          pthreads_h413a1c8_0    conda-forge
libprotobuf               3.21.12              hfc55251_2    conda-forge
libsqlite                 3.45.2               h2797004_0    conda-forge
libstdcxx-ng              13.2.0               h7e041cc_5    conda-forge
libtiff                   4.6.0                h1dd3fc0_3    conda-forge
libuuid                   2.38.1               h0b41bf4_0    conda-forge
libwebp-base              1.4.0                hd590300_0    conda-forge
libzlib                   1.2.13               hd590300_5    conda-forge
llvmlite                  0.42.0                   pypi_0    pypi
locket                    1.0.0                    pypi_0    pypi
lxml                      4.9.4                    pypi_0    pypi
mako                      1.3.5              pyhd8ed1ab_0    conda-forge
markupsafe                2.1.5           py310h2372a71_0    conda-forge
matplotlib                3.8.3                    pypi_0    pypi
matplotlib-inline         0.1.7              pyhd8ed1ab_0    conda-forge
mistune                   3.0.2                    pypi_0    pypi
ml_dtypes                 0.3.2           py310hcc13569_0    conda-forge
mpmath                    1.3.0                    pypi_0    pypi
mrc                       0.3.1                    pypi_0    pypi
msgpack                   1.0.8                    pypi_0    pypi
multidict                 6.0.5                    pypi_0    pypi
natsort                   8.4.0                    pypi_0    pypi
nbclient                  0.10.0                   pypi_0    pypi
nbconvert                 7.16.4                   pypi_0    pypi
nbformat                  5.10.4                   pypi_0    pypi
ncurses                   6.4.20240210         h59595ed_0    conda-forge
nd2                       0.10.1                   pypi_0    pypi
networkx                  3.2.1                    pypi_0    pypi
numba                     0.59.1                   pypi_0    pypi
numcodecs                 0.12.1                   pypi_0    pypi
numpy                     1.26.4          py310hb13e2d6_0    conda-forge
nvidia-cublas-cu12        12.1.3.1                 pypi_0    pypi
nvidia-cuda-cupti-cu12    12.1.105                 pypi_0    pypi
nvidia-cuda-nvrtc-cu12    12.1.105                 pypi_0    pypi
nvidia-cuda-runtime-cu12  12.1.105                 pypi_0    pypi
nvidia-cudnn-cu12         8.9.2.26                 pypi_0    pypi
nvidia-cufft-cu12         11.0.2.54                pypi_0    pypi
nvidia-curand-cu12        10.3.2.106               pypi_0    pypi
nvidia-cusolver-cu12      11.4.5.107               pypi_0    pypi
nvidia-cusparse-cu12      12.1.0.106               pypi_0    pypi
nvidia-nccl-cu12          2.20.5                   pypi_0    pypi
nvidia-nvjitlink-cu12     12.4.127                 pypi_0    pypi
nvidia-nvtx-cu12          12.1.105                 pypi_0    pypi
ocl-icd                   2.3.2                hd590300_1    conda-forge
ocl-icd-system            1.0.0                         1    conda-forge
ome-model                 6.3.6                    pypi_0    pypi
ome-types                 0.5.1.post1              pypi_0    pypi
ome-zarr                  0.8.3                    pypi_0    pypi
opencv-python-headless    4.9.0.80                 pypi_0    pypi
openssl                   3.3.1                h4ab18f5_1    conda-forge
opt-einsum                3.3.0                hd8ed1ab_2    conda-forge
opt_einsum                3.3.0              pyhc1e730c_2    conda-forge
packaging                 24.0                     pypi_0    pypi
pandas                    2.2.2                    pypi_0    pypi
pandocfilters             1.5.1                    pypi_0    pypi
parso                     0.8.4              pyhd8ed1ab_0    conda-forge
partd                     1.4.1                    pypi_0    pypi
pexpect                   4.9.0              pyhd8ed1ab_0    conda-forge
pickleshare               0.7.5                   py_1003    conda-forge
pillow                    10.3.0                   pypi_0    pypi
pims                      0.7                      pypi_0    pypi
pip                       24.0               pyhd8ed1ab_0    conda-forge
pipreqs                   0.5.0                    pypi_0    pypi
platformdirs              4.2.2              pyhd8ed1ab_0    conda-forge
pooch                     1.8.1                    pypi_0    pypi
prompt-toolkit            3.0.45                   pypi_0    pypi
psutil                    5.9.8                    pypi_0    pypi
ptyprocess                0.7.0              pyhd3deb0d_0    conda-forge
pure_eval                 0.2.2              pyhd8ed1ab_0    conda-forge
pyarrow                   17.0.0                   pypi_0    pypi
pydantic                  2.7.1                    pypi_0    pypi
pydantic-compat           0.1.2                    pypi_0    pypi
pydantic-core             2.18.2                   pypi_0    pypi
pygments                  2.18.0                   pypi_0    pypi
pyopencl                  2024.2.7        py310he6ccd79_0    conda-forge
pyparsing                 3.1.2                    pypi_0    pypi
pystackreg                0.2.7                    pypi_0    pypi
python                    3.10.0          h543edf9_3_cpython    conda-forge
python-dateutil           2.9.0.post0              pypi_0    pypi
python_abi                3.10                    4_cp310    conda-forge
pytools                   2024.1.5           pyhd8ed1ab_0    conda-forge
pytorch-cuda              12.1                 ha16c6d3_5    pytorch
pytz                      2024.1                   pypi_0    pypi
pywavelets                1.6.0                    pypi_0    pypi
pyyaml                    6.0.1                    pypi_0    pypi
pyzmq                     26.0.3                   pypi_0    pypi
re2                       2023.02.01           hcb278e6_0    conda-forge
readline                  8.2                  h8228510_1    conda-forge
redlionfish               0.9             py310hff52083_3    conda-forge
referencing               0.35.1                   pypi_0    pypi
reikna                    0.8.0              pyhd8ed1ab_0    conda-forge
requests                  2.32.3                   pypi_0    pypi
resource-backed-dask-array 0.1.0                    pypi_0    pypi
roifile                   2024.3.20                pypi_0    pypi
rpds-py                   0.18.1                   pypi_0    pypi
s3fs                      2023.6.0                 pypi_0    pypi
scikit-image              0.20.0                   pypi_0    pypi
scikit-learn              1.4.1.post1              pypi_0    pypi
scipy                     1.12.0          py310hb13e2d6_2    conda-forge
setuptools                69.2.0             pyhd8ed1ab_0    conda-forge
six                       1.16.0             pyh6c4a22f_0    conda-forge
slicerator                1.1.0                    pypi_0    pypi
sortedcontainers          2.4.0                    pypi_0    pypi
soupsieve                 2.5                      pypi_0    pypi
sqlite                    3.45.2               h2c6b66d_0    conda-forge
stack-data                0.6.3                    pypi_0    pypi
sympy                     1.12                     pypi_0    pypi
tblib                     3.0.0                    pypi_0    pypi
tglow-core                0.1.0                     dev_0    <develop>
threadpoolctl             3.4.0                    pypi_0    pypi
tifffile                  2022.4.8                 pypi_0    pypi
tinycss2                  1.3.0                    pypi_0    pypi
tk                        8.6.13          noxft_h4845f30_101    conda-forge
toolz                     0.12.1                   pypi_0    pypi
torch                     2.3.0                    pypi_0    pypi
torchaudio                2.3.0                    pypi_0    pypi
torchvision               0.18.0                   pypi_0    pypi
tornado                   6.4                      pypi_0    pypi
tqdm                      4.66.2                   pypi_0    pypi
traitlets                 5.14.3             pyhd8ed1ab_0    conda-forge
triton                    2.3.0                    pypi_0    pypi
typing-extensions         4.11.0                   pypi_0    pypi
typing_extensions         4.12.2             pyha770c72_0    conda-forge
tzdata                    2024.1                   pypi_0    pypi
urllib3                   1.26.18                  pypi_0    pypi
wcwidth                   0.2.13             pyhd8ed1ab_0    conda-forge
webencodings              0.5.1                    pypi_0    pypi
wheel                     0.42.0             pyhd8ed1ab_0    conda-forge
wrapt                     1.16.0                   pypi_0    pypi
xarray                    2024.3.0                 pypi_0    pypi
xmlschema                 3.3.0                    pypi_0    pypi
xsdata                    24.3.1                   pypi_0    pypi
xz                        5.2.6                h166bdaf_0    conda-forge
yarg                      0.1.9                    pypi_0    pypi
yarl                      1.9.4                    pypi_0    pypi
zarr                      2.15.0                   pypi_0    pypi
zict                      3.0.0                    pypi_0    pypi
zipp                      3.17.0             pyhd8ed1ab_0    conda-forge
zlib                      1.2.13               hd590300_5    conda-forge
zstd                      1.5.6                ha6fb4c9_0    conda-forge
@bnorthan
Copy link
Collaborator

How big is your image? My first thought is that you might be running out of memory (the non-circulant version uses more memory). If you are running out of memory you could try the dask version. Here is an example as to how to use the dask version https://github.com/clij/clij2-fft/blob/master/python/tests/test_richardson_lucy_dask.py.

If not a memory problem let me and I'll look into it further.

@OlivierBakker
Copy link
Author

Hi,

Thanks very much for the quick response! Not so sure it is a memory issue, as I the test image is very small (14,500,500), psf (31,47,47) and the gpu's we run have 80G of memory. I also tried it with a small array of np.ones of dimension (100, 100, 24) with psf (24, 24, 12) with the same result.

See log below:

Python 3.10.0 | packaged by conda-forge | (default, Nov 20 2021, 02:24:10) [GCC 9.4.0]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.12.3 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import tifffile
   ...: import pyopencl as cl
   ...: from clij2fft.richardson_lucy import richardson_lucy, richardson_lucy_nc
   ...: import numpy as np
   ...: 
   ...: platforms = cl.get_platforms()
   ...: 
   ...: devices=platforms[0].get_devices()
   ...: 
   ...: for device in devices:
   ...:     print(device)
   ...:     print(device.get_info(cl.device_info.GLOBAL_MEM_SIZE))
   ...: 
   ...: 
   ...: img = tifffile.imread("img.tiff")
   ...: psf = tifffile.imread("psf.tiff")
   ...: 
   ...: img.shape
   ...: psf.shape
<pyopencl.Device 'NVIDIA A100-SXM4-80GB' on 'NVIDIA CUDA' at 0x557a56c3f590>
84974239744
Out[1]: (31, 47, 47)

In [2]: img.shape
Out[2]: (14, 500, 500)

In [3]: psf.shape
Out[3]: (31, 47, 47)

In [4]: res = richardson_lucy(img, psf, 10, 0)
get lib

platform 0 NVIDIA CUDA
device name 0 NVIDIA A100-SXM4-80GB

Richardson Lucy Started
0 
Richardson Lucy Finished

In [5]: res = richardson_lucy_nc(img, psf, 10, 0)
get lib
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Cell In[5], line 1
----> 1 res = richardson_lucy_nc(img, psf, 10, 0)

File lib/python3.10/site-packages/clij2fft/richardson_lucy.py:128, in richardson_lucy_nc(img, psf, numiterations, regularizationfactor, lib, platform, device)
    125     lib = getlib()
    127 # the normalization factor is the valid region correlated with the PSF
--> 128 lib.convcorr3d_32f(int(normal.shape[2]), int(normal.shape[1]), int(normal.shape[0]), valid, shifted_psf, normal,1,platform,device)
    130 # get rid of any zeros in the normal to avoid divide by zero issues
    131 #normal[normal<0.00001]=1
    132 
    133 # deconvolution using clij2fft
    134 if regularizationfactor==0:

RuntimeError: ffi_prep_cif_var failed

In [6]: img = np.ones((100, 100, 24), dtype=np.float32)

In [7]: psf = np.ones((24, 24, 12), dtype=np.float32)

In [8]: res = richardson_lucy(img, psf, 10, 0)
get lib

platform 0 NVIDIA CUDA
device name 0 NVIDIA A100-SXM4-80GB
2 warnings generated.
2 warnings generated.
2 warnings generated.

Richardson Lucy Started
0 
Richardson Lucy Finished

In [9]: res = richardson_lucy_nc(img, psf, 10, 0)
get lib
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Cell In[9], line 1
----> 1 res = richardson_lucy_nc(img, psf, 10, 0)

File lib/python3.10/site-packages/clij2fft/richardson_lucy.py:128, in richardson_lucy_nc(img, psf, numiterations, regularizationfactor, lib, platform, device)
    125     lib = getlib()
    127 # the normalization factor is the valid region correlated with the PSF
--> 128 lib.convcorr3d_32f(int(normal.shape[2]), int(normal.shape[1]), int(normal.shape[0]), valid, shifted_psf, normal,1,platform,device)
    130 # get rid of any zeros in the normal to avoid divide by zero issues
    131 #normal[normal<0.00001]=1
    132 
    133 # deconvolution using clij2fft
    134 if regularizationfactor==0:

RuntimeError: ffi_prep_cif_var failed

@bnorthan
Copy link
Collaborator

Thanks for the additional feedback. I changed the interface to convcorr3d a few months ago and somehow did not update the Linux libs. I think I've fixed it, but let me know. Update clij2-fft, confirm that you have version 0.27 and try again.

Once you get it going I'd be interested to hear if the non-circulant version makes a difference for your image. I noticed your PSF size in z is longer than the image size. Is that correct? The non-circulant version should be able to handle that, however I haven't done a lot of testing with that scenario. What type of instrument are you using and how did you create the PSF?

@OlivierBakker
Copy link
Author

Hi,

Thanks for your very quick fix, it solves the issue, but I am now getting another error using v0.27 when calling the nc version:

Runtime error: ret returned -9999 at /home/bnorthan/code/i2k/clij/clij2-fft/native/clij2fft/clij2fft.cpp:1269c

Is this some kind of broken reference? I installed v0.27 through pip.

The image I get out seems to have a constant value for all pixels. The circulant version seems to work still. I also get this issue when I use the array of 1's.

Some off topic context:

I noticed your PSF size in z is longer than the image size. Is that correct?
With regards to the PSF, that is correct as I have not trimmed our psf here (There are some completely black planes that I should probably trim), the majority of the signal is within +-4 planes of the center of mass (more detaills below).

Some context of what we are hoping to do that are maybe a bit of topic (and maybe better moved to image sc?), please don't feel obligated to go through this, but as I am still learning about deconvolution, some expert advice would be welcome!

We are in a situtation where we run image aquistiaiton in high throughput on small cells (5 to 15um) which are not in a clean monolayer, so are a little limeted in how many z-planes we can aquire while keeping things manageble computationally (every plane can add about 500gb). We are planning to up the number of z-planes a bit in future experiments, but we will likely always have some edges in the z axis. Having experimented a bit however, in this non ideal senario where we have 0.5 / 0.6 plane spacing with 14-16 planes and some strong edges as we started the aquistion 0.5um up, the standard RL seems to work suprisingly well with suprsingly minimal artefacts, at least using the clij2 implementation (Below an example of the nuclei before and after). I didn't have much luck with redlionfish, as that gave strong artefacts, even with padding zeroes to the image.

However if you feel in this senerio where we will have cells with strong edges, attempting decon is not sensible, please let us know! If it would be better to capture more of the cell by increasing our z-spacing to lets say 0.6 or 0.7 (slightly over the Nyquist threshold of 0.5) but then we capture more of the cells, and have fewer edges, that would also be helpfull.

What type of instrument are you using and how did you create the PSF?
We are running an Opera Phenix, PSFs were generated from beads using averaging (more detaills below). I found that trimming the PSF too agressively seems to introduce some artefacts, and the results don't look as good as when I just included the whole thing. I have not tested yet just trimming the empty areas.

With the gamma at 0.2 to illustrate where the non-zero signal is:
image

With the gamma at 1:
image

Before:
image
image

After 100 iterations:
image
image

Detaills PSF generation:
Bead images were generated on z spacing of 0.1um, then selecting single beads without close neighbours, normalizing indiviual bead images, trimming outliers in intensity and then registering and averaging beads. Finally I center arround the center of mass and substract the background signal to make sure that is set at zero and normalize so the max intensity is one. As the image here is at 0.6um I sample every 6 planes starting from the center of the PSF image as the final PSF.

@bnorthan
Copy link
Collaborator

Hi @OlivierBakker

Your images from circulant RL actually pretty good, so not sure the non-circulant version will help you much. That being said I'd still like to figure out why it isn't working for you.

If you are able to post a sample of an image and one of your PSFs I can troubleshoot further. Either here or on ImageSC.

@imagesc-bot
Copy link

This issue has been mentioned on Image.sc Forum. There might be relevant details there:

https://forum.image.sc/t/issues-with-python-version-of-clij2-richardson-lucy-nc/101300/1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants