WeisongZhao / Sparse-SIM

Official MATLAB implementation of the "Sparse deconvolution" -v1.0.3
https://weisongzhao.github.io/Sparse-SIM/
Open Data Commons Open Database License v1.0
77 stars 13 forks source link

Is FFT operation neccesary in Hessian deblur? #11

Closed dixing0908 closed 2 years ago

dixing0908 commented 2 years ago

I notice that in https://github.com/WeisongZhao/Sparse-SIM/blob/02aa2753f24eac83dacd8e16be57b34b010d2f40/src_win/SHIter/SparseHessian_core.m#L76 operation_fft is a variable only depends on image shapes. It is always a small number compared to(fidelity/mu) +paral1^2 in https://github.com/WeisongZhao/Sparse-SIM/blob/02aa2753f24eac83dacd8e16be57b34b010d2f40/src_win/SHIter/SparseHessian_core.m#L77 So I tried to remove this number. Thus according to the formula in the supplementary information of your paper: image when the red column of item is removed, all the fft operation seems to be redundant. So to validate this idea, I modify https://github.com/WeisongZhao/Sparse-SIM/blob/master/src_win/SHIter/SparseHessian_core.m. Specifically, here is the detailed modification: Original code:

operationfft=1*xxfft+ 1*yyfft+(contiz^2)*zzfft+ 2*xyfft+ 2*(contiz)*xzfft+2*(contiz)*yzfft;
normlize = single((fidelity/mu) +paral1^2 +operationfft);
clear xxfft yyfft zzfft xyfft xzfft yzfft operationfft
if gpu==1
    f=gpuArray(f);
    normlize =gpuArray(normlize);
    bxx = gpuArray.zeros(sizeg,'single');
    byy = bxx;
    bzz = bxx;
    bxy =bxx;
    bxz =bxx;
    byz = bxx;
    bl1 =bxx;
else
    bxx = zeros(sizeg,'single');
    byy = bxx;
    bzz = bxx;
    bxy = bxx;
    bxz = bxx;
    byz = bxx;
    bl1 = bxx;
end
g_update = (fidelity/mu)*f;
for iter = 1:iteration
    tic;
    g_update = fftn(g_update);
    if iter>1
        g = real(ifftn(g_update./normlize));
    else
        g = real(ifftn(g_update./(fidelity/mu)));
    end
    g_update = (fidelity/mu)*f;

modified code without fft:

%operationfft=1*xxfft+ 1*yyfft+(contiz^2)*zzfft+ 2*xyfft+ 2*(contiz)*xzfft+2*(contiz)*yzfft;
normlize = single((fidelity/mu) +paral1^2 );%+operationfft);
clear xxfft yyfft zzfft xyfft xzfft yzfft %operationfft
if gpu==1
    f=gpuArray(f);
    normlize =gpuArray(normlize);
    bxx = gpuArray.zeros(sizeg,'single');
    byy = bxx;
    bzz = bxx;
    bxy =bxx;
    bxz =bxx;
    byz = bxx;
    bl1 =bxx;
else
    bxx = zeros(sizeg,'single');
    byy = bxx;
    bzz = bxx;
    bxy = bxx;
    bxz = bxx;
    byz = bxx;
    bl1 = bxx;
end
g_update = (fidelity/mu)*f;
for iter = 1:iteration
    tic;
    %g_update = fftn(g_update);
    if iter>1
        %g = real(ifftn(g_update./normlize));
        g = g_update./normlize;
    else
        %g = real(ifftn(g_update./(fidelity/mu)));
        g = g_update / (fidelity / mu);
    end
    g_update = (fidelity/mu)*f;

I have tested the codes on a test image from your open data https://github.com/WeisongZhao/Sparse-SIM/releases/download/v1.0.3/Example.Data.from.Manuscript.zip. It turns out that, on Fig4a_2DSIM_Actin.tif, the two codes achieves almost the same performance: SSIM between the outputs of two codes: 0.99988 cosine distance between the outputs of two codes: 1.16e-05 According to the result, It seems that fft operation is not neccessay. Any idea about this?

dixing0908 commented 2 years ago

origianl test image: image with fft: image

without fft: image

WeisongZhao commented 2 years ago

Hi Xing Di, This normalization term is neccesary in the mathematical expression, and maybe you are right this term can be removed in a numerical optimization because in some cases it may not influence the final results. But I wonder why should we remove this term?

dixing0908 commented 2 years ago

Hi Xing Di, This normalization term is neccesary in the mathematical expression, and maybe you are right this term can be removed in a numerical optimization because in some cases it may not influence the final results. But I wonder why should we remove this term?

Thank you so much for reply. From the view of algorithm implementation, remove redundant items in formula is often expected to optimize the simplicity of codes and speed of execution.
What my concern is that, when this item is removed, the formula can be simplified and the fft operations seems not necessary. As what my test demonstrated, when fft operations are removed, the result are not influenced. What confused me is why in paper the formula 16 have fft operations since it does not contribute to the final deblur results?

WeisongZhao commented 2 years ago

Actually, this is for the formula<->code consistency, and you can certainly remove these terms on your personal usage.