Upsampled image FFT contains NaNs.

조회 수: 2 (최근 30일)
raheem mian
raheem mian 2020년 1월 27일
댓글: Matt J 2020년 1월 27일
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
Matt J
Matt J 2020년 1월 27일
But there are no FFT operations in the code that you have posted...??
raheem mian
raheem mian 2020년 1월 27일
편집: raheem mian 2020년 1월 27일
My mistake. Added more code. I see Nan values in shift_vol. I see one NaN in cp_vol. I see a 0 in fftt but no Nans. I think the problem is the 0 in fftt. But I dont have this problem when I dont upsample the image. So I thought maybe I am upsampling incorrectly.

댓글을 달려면 로그인하십시오.

채택된 답변

Matt J
Matt J 2020년 1월 27일
편집: Matt J 2020년 1월 27일
You have a division by zero in this line,
res = y./scale;
That leads to NaNs in cp_vol and hence also in shift_vol.
  댓글 수: 2
raheem mian
raheem mian 2020년 1월 27일
Yeah I understand that but I need to do that calculation for phase correlation. I was wondering if my upsampling looks correct.
Matt J
Matt J 2020년 1월 27일
I don't see anything in your upsample() function that would generate NaNs, though that would be easy to check.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by