1

我正在尝试编写自己的 MATLAB 代码来计算逆氡变换(iradon),到目前为止,我已经成功地使用斜坡滤波器、汉明窗以及在空间中使用一维投影的卷积来重建图像根据 Kak 和 Shakey 的教科书,在我的代码中带有窗口 h 的域。但是,我认为如果我采用窗口 h 的 FFT 并将其乘以一维投影的 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('filter') 就会显示不同的结果。卷积似乎工作正常,但过滤方法并没有像我希望的那样工作。

任何人都可以看到问题吗?(抱歉,如果有任何多余的代码,我试图删掉大部分......我还应该提到这段代码是从某个地方借来的并进行了一些修改,但我不记得我在哪里找到它)。

提前致谢

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

4

1 回答 1

2

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

于 2017-01-26T20:36:35.420 回答