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

damping feature #33

Open k1moradi opened 2 years ago

k1moradi commented 2 years ago

Hi,

I am testing using this amazing software for the deconvolution of light-sheet microscope images. Recently, a paper is published in this regard. I managed to port the PSF generation part from Matlab to python. However, porting the deconvolution method to python will be very GPU inefficient if it is done on the python side and using CPU. (Since the image stack should be moved to GPU memory and back to CPU memory several times).

The deconvolution function has a damping component to allow the deconvolution of low-resolution images.

function deconvolved = deconGPU(stack, psf, niter, damping)     
    deconvolved = stack;        
    psf_inv = psf(end:-1:1, end:-1:1, end:-1:1); % spatially reversed psf 

    R = 1/26 * ones(3, 3, 3, 'single'); 
    R(2,2,2) = single(0);

    for i = 1 : niter 
        denom = convGPU(deconvolved, psf);
        denom(denom < eps('single')) = eps('single'); % protect against division by zero

        if damping == 0                       
            deconvolved_new = convGPU(stack ./ denom, psf_inv) .* deconvolved;
        else           
            deconvolved_new = (1 - damping) .* convGPU(stack ./ denom, psf_inv) .* deconvolved ...
                + damping .* convn(deconvolved, R, 'same');
        end
end

The damping parameter is a ratio between 0 and 1. I was wondering will you be able to implement this with Cuda directly in pycudaDecon?

tlambert03 commented 2 years ago

Hi @k1moradi, the core RL iteration loop is expressed in the cudaDecon library here. this library (pycudadecon) simply wraps that C code with a python interface... so that change would need to be proposed over there.

k1moradi commented 2 years ago

Hi Tally! I will copy this suggestion in the other repo as well. Feel free to delete this issue as needed. However, I am interested in seeing this option in the Python binding as well. That's why I put it here, in the first place. I have noticed that the command-line version of the tool has more features compared with the python binding.

k1moradi commented 2 years ago

BTW, what RL stands for?

tlambert03 commented 2 years ago

I am interested in seeing this option in the Python binding as well. That's why I put it here, in the first place.

sure, we can expose it if it gets added to the params there. but we can't expose it without it getting added there first.

BTW, what RL stands for?

RL = Richardson Lucy

that core loop in the code you posted above is an example of iterative Richardson-Lucy deconvolution