Upsampled image FFT contains NaNs.
4 次查看(过去 30 天)
显示 更早的评论
I upsampled images and when I take the FFT I get NaN values. How can I prevent NaN values from showing when I take the fourier transform ?
Heres my code to upsample. Upsampling frames in a volume:
ps. ref is 3D
vol = upsample(ref);
pad = GetPad(fftr);
fftr = fftn(vol, pad);
fftt = fftn(tar, pad);
% calculate the power spectrum to remove the magnitude
cp_vol = CrossPowerSpectrum(fftr, fftt);
% go back to the time domain and find the peak
shift_vol = ifftn(cp_vol);
function [res] = CrossPowerSpectrum(A, B)
y = A.*conj(B);
scale = abs(y);
res = y./scale;
end
function [new_dim] = GetPad(vol)
dim = nextpow2(size(ref));
new_dim = 2.^dim;
end
function new_vol = upsample(vol)
m = 2;
[x,y,z] = size(vol);
new_vol = zeros(2*x,2*y,z);
for i = 1 : size(vol,3)
new_vol(1:m:end,1:m:end,i) = vol(:,:,i);
end
sz = m*m;
H = fspecial('average',[sz sz]);
for i = 1 : size(vol,3)
new_vol(:,:,i) = conv2(new_vol(:,:,i), H, 'same');
end
end
2 个评论
采纳的回答
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!