Lucy-Richardson加速算法以及PSF计算MATLAB代码

前面我们介绍了Lucy-Richardson的加速算法,这里给出其implement和PSF的显微成像计算公式。

https://blog.csdn.net/weixin_41923961/article/details/81157082 

function result=Accelaration_DeconvLucy(data,psf,iteration,method)
%-----------------------------------------------
%Inputs:
% data      single diffraction limit image
% psf        PSF
%iteration Maximum deconvolution iterations {example:20}
%method accelarate method{'NoAcce'(normal),'Acce1','Acce2','Acce3'}
%------------------------------------------------
%Output:
% result     Lucy-Richardson deconvolution result
%------------------------------------------------
% reference:
% [1].D. S. C. Biggs and M. Andrews, "Acceleration of iterative image restoration
% algorithms," Appl. Opt. 36(8), 1766�1775 (1997).

%   Copyright  2018 Weisong Zhao et al
%
%    This program is free software: you can redistribute it and/or modify
%    it under the terms of the GNU General Public License as published by
%    the Free Software Foundation, either version 3 of the License, or
%    (at your option) any later version.
%
%    This program is distributed in the hope that it will be useful,
%    but WITHOUT ANY WARRANTY; without even the implied warranty of
%    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%    GNU General Public License for more details.
%
%    You should have received a copy of the GNU General Public License
%    along with this program.  If not, see <http://www.gnu.org/licenses/>.
psf= psf./sum(sum(psf));
psf0=psf;
B=floor(max(size(data,1),size(data,2))/4);
data=padarray(data, [B,B] , 'replicate');
% move the PSF so that the maximum is at pixel 1 in the corner
psfm=psf;
psf = zeros(size(data,1),size(data,2));
psf(1 : size(psfm,1), 1 : size(psfm,2)) = psfm;
[~,idx] = max(psf(:));
[x,y,~] = ind2sub(size(psf), idx);
psf = circshift(psf, -[x,y,1] + 1);
otf = fftn(psf);
fprintf('Start deconvolution\n')
% Richardson Lucy update rule
rliter = @(estimate, data, otf)fftn(data./ max(ifftn(otf .* fftn(estimate)), 1e-6));
switch method
    case'NoAcce'
        estimate=data;
        estimate=max(estimate,0.001);
        for iter = 1:iteration
            if mod(iter,10)==0
                fprintf('iteration %d \n',iter)
            end
            estimate= estimate.*ifftn(conj(otf).*rliter(estimate,data,otf));
            estimate=max(estimate,1e-5);
            %             estimate=estimate./max(max(estimate));
        end
        result=estimate(B:end-B, B:end-B)./max(max(estimate(B:end-B, B:end-B)));
    case 'Acce1'
        estimate=data;
        estimate=max(estimate,0.001);
        k=2;
        for iter = 1:iteration
            if mod(iter,10)==0
                fprintf('iteration %d \n',iter)
            end
            estimate= estimate.*(ifftn(conj(otf).*rliter(estimate,data,otf))).^k;
            %         estimate=estimate./max(max(estimate));
            estimate=max(estimate,1e-5);
        end
        result=estimate(B:end-B, B:end-B)./max(max(estimate(B:end-B, B:end-B)));
    case 'Acce2'
        estimate=data;
        estimate=max(estimate,0.001);
        delta=2;
        for iter = 1:iteration
            if mod(iter,10)==0
                fprintf('iteration %d \n',iter)
            end
            estimatek=estimate;
            estimate= estimate.*ifftn(conj(otf).*rliter(estimate,data,otf));
            between_k_and_k1=estimate-estimatek;
            estimate=estimate+delta*between_k_and_k1;
            estimate=max(estimate,0.00001);
            estimate=estimate./max(max(estimate));
        end
        result=estimate(B:end-B, B:end-B)./max(max(estimate(B:end-B, B:end-B)));
    case 'Acce3'
        yk=data;
        xk=zeros(size(data));
        vk=zeros(size(data));
        for iter = 1:iteration
            xk_update=xk;
            xk= max(yk.*real(ifftn(conj(otf).*rliter(yk,data,otf)))./real(ifftn(fftn(ones(size(data))).*otf)),0.00001);
            vk_update=vk;
            vk=max(xk-yk,0.00001);
            if iter==1
                alpha=0;
            else
                alpha=sum(sum(vk_update.*vk))/(sum(sum(vk_update.*vk_update))+eps);
                alpha=max(min(alpha,1),0);
            end
            yk=max(xk+alpha*(xk-xk_update),0.00001);
        end
        result=yk(B+1:end-B, B+1:end-B)./max(max(yk(B+1:end-B, B+1:end-B)));
end
function Ipsf=Generate_PSF(pixel,lamda,NA,n,z)
%-----------------------------------------------
%Source code for generating PSF
%pixel     pixel size {example:65*10^-9}
%lamda   wavelength {example:532*10^-9}
%NA        NA {example:1.49}
%n          number of psf {example:64}
%z          defocus length {example:1*10^-6}
%------------------------------------------------
%Output:
% Ipsf    PSF

%-------------------------------------------------------------------------------------
%                    Copyright  2018 Weisong Zhao
%    This program is free software: you can redistribute it and/or modify
%    it under the terms of the GNU General Public License as published by
%    the Free Software Foundation, either version 3 of the License, or
%    (at your option) any later version.
%
%    This program is distributed in the hope that it will be useful,
%    but WITHOUT ANY WARRANTY; without even the implied warranty of
%    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%    GNU General Public License for more details.
%
%    You should have received a copy of the GNU General Public License
%    along with this program.  If not, see <http://www.gnu.org/licenses/>.
%-------------------------------------------------------------------------------------
%%
if nargin < 4 || isempty(n)
    n=32;
end
if nargin < 5 || isempty(z)
    z=0;
end
sin2=((1-(1-NA^2))/2);
u=8*pi*z*sin2/lamda;
h=@(r,p) 2*exp((1i*u*(p.^2))/2).*besselj(0,2*pi*r*NA/lamda.*p);
x=-n*pixel:pixel:n*pixel;
[X,Y]=meshgrid(x,x);
[~,s1]=cart2pol(X,Y);
idx=s1<=1;
IP=zeros(size(X));
k=1;
for f=1:1:size(s1)
    for j=1:1:size(s1)
        if idx(f,j)==0
            IP(f,j)=0;
        else
            o=s1(idx);
            r=o(k);
            k=k+1;
            II=@(p)h(r,p);
            IP(f,j)=integral(II,0,1);
        end
    end
end
Ipsf=abs(IP.^2);
Ipsf=Ipsf./sum(sum( Ipsf));

 

  • 10
    点赞
  • 61
    收藏
    觉得还不错? 一键收藏
  • 22
    评论
### 回答1: Lucy-Richardson算法是一种图像恢复算法,用于去除图像模糊和噪声。它基于最小二乘法和迭代算法,通过不断迭代来逼近原始图像。在Matlab中,可以使用imdeconv函数来实现Lucy-Richardson算法。该函数需要输入模糊图像、点扩散函数和迭代次数等参数,输出恢复后的图像。具体使用方法可以参考Matlab官方文档或相关教程。 ### 回答2: Lucy-Richardson算法是一种重建图像的迭代算法,它可以根据观测数据进行图像重构。这个算法常用于生物医学影像、荧光影像等的图像重建中。 该算法是基于最大似然估计的迭代算法。它的步骤如下: 1. 构造待重建图像和观测数据之间的模型。 2. 对观测数据进行预处理,包括噪声去除、去模糊等。 3. 初始化待重建图像。 4. 在每一轮迭代中,根据当前的估计值计算出预测数据。 5. 根据预测数据和观测数据的残差来更新待重建图像。 6. 重复执行步骤4、5直到算法收敛。 在Matlab中,可以通过调用该算法中的函数实现图像重建。具体来说,可以使用“deconvlucy”函数来对图像进行去模糊,并使用“mat2gray”函数来转换图像格式。此外,还可以使用“imshow”函数来展示结果图像。 总的来说,Lucy-Richardson算法是一种强大的图像重建工具,可以对医学影像、荧光影像等进行高效的重建。在实践中,通过Matlab中的函数来实现该算法,可以使图像处理更加便捷。 ### 回答3: Lucy-Richardson算法是一种图像重建算法,它是基于最小二乘准则的迭代算法,能够在高噪声条件下对模糊图像进行重建,通常应用于单个点源的图像恢复。 Lucy-Richardson算法的原理是通过迭代修正图像的点扩散函数和图像本身,使得修正后的图像可以最大程度地逼近原始图像。这个过程不断进行直到达到指定迭代次数或误差范围,从而得到重建后的清晰图像。该算法具有保边缘特性,能够保留原始图像的边缘信息,而不像其他算法会产生模糊或虚影。 在MATLAB中实现Lucy-Richardson算法稍微有点复杂,因为需要定义点扩散函数、生成点扩散矩阵、设置迭代次数等。一般来说,可以先将图像表示为矩阵形式,在MATLAB中使用for循环实现算法的迭代,同时比较修正后的矩阵与原矩阵的误差进行调整。此外,如果需要对复杂的大尺寸图像进行处理,还需要考虑算法的时间和空间复杂度问题。 总的来说,Lucy-Richardson算法是一种有效的图像重建算法,能够在高噪声和单点源的情况下对模糊图像进行修复。在MATLAB中实现该算法需要了解基本的图像处理原理和MATLAB语言基础,同时注意算法的迭代次数和误差判断,避免出现过拟合或欠拟合的情况。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 22
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值