tlambert03 / pycudadecon

Python wrapper for cudaDecon - GPU accelerated 3D deconvolution for microscopy
http://www.talleylambert.com/pycudadecon/
MIT License
59 stars 12 forks source link

Decon with Image directory (instead of a single .tif) is broken. #12

Closed snehashis-roy closed 1 year ago

snehashis-roy commented 4 years ago

Here is my code.

import numpy as np
import pycudadecon
import os
from pycudadecon import decon
from skimage.io import imread, imsave
from time import time

impath = '640/' # Folder containing 2D tiff files
psfpath = 'psf_padded.tif'  # A 16x64x64 array

y = imread(psfpath)
print(y.shape)
t1 = time()
result = decon(impath, y, fpattern='*.tif', n_iters=30, background=0, )
t2 = time()
print(result.max())
print(result.min())
print(t2-t1)
imsave('decon_result.tif', np.asarray(result,dtype=np.uint16), check_contrast=False)

Output is the following,

(16, 64, 64)
callednx=64, ny=64, nz=16
Center of mass is (30.000, 30.000, 7.600)
Background is 0.000
In radialft()
Traceback (most recent call last):
  File "pycudadecon_test.py", line 21, in <module>
    result = decon(impath, y, fpattern='*.tif', n_iters=30, background=0, )
  File "/home/roys5/miniconda3/lib/python3.6/site-packages/pycudadecon-0.1.2-py3.6.egg/pycudadecon/deconvolution.py", line 147, in decon
    with RLContext(shp, otf.path, **kwargs) as ctx:
  File "/home/roys5/miniconda3/lib/python3.6/site-packages/pycudadecon-0.1.2-py3.6.egg/pycudadecon/libcudawrapper.py", line 328, in __enter__
    rl_init(self.shape, self.otfpath, **self.kwargs)
  File "/home/roys5/miniconda3/lib/python3.6/site-packages/pycudadecon-0.1.2-py3.6.egg/pycudadecon/libcudawrapper.py", line 148, in rl_init
    nz, ny, nx = rawdata_shape
ValueError: not enough values to unpack (expected 3, got 2)

When input is a folder, the "rawdata_shape" is 2x1 tuple.

tlambert03 commented 4 years ago

I don't think I'm going to support deconvolving a folder like that. Too many use case variants. If you'd like to iterate through files in a folder yourself, you can do something like this:

for fname in os.listdir(imdir):
    decon(os.path.join(imdir, fname), y)

or use glob.glob