在MATLAB中过滤反投影并设计滤波器

时间:2016-04-05 11:52:10

标签: matlab tomography-reconstruction

我正在尝试编写自己的MATLAB代码来计算逆氡变换(iradon),到目前为止,我已成功使用斜坡滤波器,汉明窗口以及使用1D投影的卷积成功重建图像在空间域中,我的代码中有一个窗口h,基于Kak和Shakey的教科书。但是,我认为如果我采用窗口h的FFT并将其乘以1D投影的FFT,我应该能够获得相同的重建。不幸的是,我得到的是一团糟。

function [out] = myfbp4(arg2);


ph = phantom();
sino = radon(phantom,0:0.1:179);

rho2 = 183; % max rho
rho1 = -183; % min rho;
step = 1;
npos = 367;
dtheta = 0.1;
angles = deg2rad(0:dtheta:179);
nproj = length(angles);



n1 = ceil(log(npos)/log(2)); 
N = 2^n1;                  % smallest power of 2 greater than npos (for fft efficiency)
N = 1024;   % for zero padding
fs = 1; % sampling frequency
T = 1;  % sample spacing

% grid for reconstructed image
x1 = rho1:step:rho2;
y1 = rho1:step:rho2;

[yyy, xxx] = ndgrid(-y1, x1);


% build filter h according to Kak and Shakey 
h = -floor(npos/2):T:floor(npos/2);

for i = 1:length(h)
    if (mod(h(i),2) == 1) 
        h(i) = -1./(h(i)^2 * pi^2 * T^2);
    else
        h(i) = 0;
    end    
    h(ceil(npos/2)) = 1/(4*T^2);
end

%%%%%%%%%%%   RAMP FILTER   %%%%%%%%%%%%%%%%
%%%%%%%%%% this is un needed when using h %%
%%%%%%%%%% see below... %%%%%%%%%%%%%%%%%%%%
rampFilterNum = [0:1:N/2-1 -N/2:1:-1];
rampFilterAbs = abs(rampFilterNum);
rampFilter = rampFilterAbs *fs/N; 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


% positions made to correspond to N point fft
drho = (rho2 - rho1) / (npos-1);
rho  = rho1 + (0:(npos-1)) * drho;
positions = zeros(nproj, length(rho));
for i = 1:nproj,
  positions(i, :) = rho;
end

if (strcmp(arg2,'filter')) 
    % compute FT of h and multiply by fft projections
    fftProj = fft(sino, N);
    hfft = fft(h,N);
    fftProjFiltered = bsxfun(@times, hfft', fftProj);
    ifftProj = real(ifft(fftProjFiltered));
    filteredProjections = ifftProj;
end

if (strcmp(arg2,'conv')) 
    % make image my convolution of projections with h
    for iproj = 1:nproj
        sino(:, iproj) = conv(sino(:,iproj), h, 'same');
    end
    filteredProjections = sino;
end


% display the image through backprojection
fdata = zeros(size(xxx));
for iproj = 1:nproj
    theta = angles(iproj);
    rho1 = xxx*cos(theta) + yyy*sin(theta); % rotate coordinate system by theta
    %r = x1;
    r = positions(iproj,:);

    fdata1 = filteredProjections(1:npos,iproj); % filtered projections
    %fdata1  interp1(
    fdata2 = interp1(r, fdata1, rho1, 'linear', 0); 
    fdata = fdata + deg2rad(dtheta) * fdata2; %theta*fdata2;
end

out = fdata;
end

刚用完= myfbp4('conv')或myfbp4('过滤器')会显示不同的结果。似乎卷积工作正常,但过滤方法并不像我希望的那样有效。

有人能看到问题吗? (道歉,如果有任何冗余代码,我试图删除大部分代码......我还应该提到这个代码是从某个地方借来的并且稍微修改了一下,但我不记得我发现它的位置了。)

提前致谢

编辑:问题解决了。问题是我没有采用窗口h的傅里叶变换的绝对值来获得频率窗口。对于那些发现这个的人,hfft = abs(fft(h,N))应该替换hfft = fft(h,N)。

1 个答案:

答案 0 :(得分:2)

问题解决了。问题是我没有采用窗口h的傅里叶变换的绝对值来获得频率窗口。对于那些发现这个的人,hfft = abs(fft(h,N))应该替换hfft = fft(h,N)。