我尝试对一组数据进行FFT(它们是10张图片,中间有' T'绘制)并计算给定区域的光谱幅度。
这是我的代码:
for i=1:10
filename = sprintf('T%d.GIF', i);
%fourier transform and showing
f = imread(filename); %read in image
z = fft2(double(f)); % do fourier transform
q = fftshift(z); % puts u=0,v=0 in the centre
Magq = log(abs(q)); % magnitude spectrum
Phaseq=angle(q); % phase spectrum
imagesc(log(abs(q)+1)); % Usually for viewing purposes:
colorbar;
end
上图是运行我的代码后的结果。下面的图片是我想要计算的区域。
我正在使用
T(i,1)=mean(mean(Magq(1:150,300:340)))+mean(mean(Magq(260:400,300:340)))+mean(mean(Magq(190:210,160:320)))+mean(mean(Magq(190:210,320:480)));
计算频谱幅度,但结果总是-Inf
。这主要是因为mean(mean(Magq(1:150,300:340)))
和mean(mean(Magq(260:400,300:340)))
都等于-Inf
。
有人可以给我任何提示,为什么结果是-Inf
?
答案 0 :(得分:0)
我猜你的q
变量的某些值为零,因此Magq = log(abs(q))
将返回-Inf这些值。也许您正在寻找的mean
应该是
log(abs(mean(mean(q(1:150,300:340)))))
否则,如果您只想忽略无穷大,请将它们全部设为零
Magq(~isfinite(Magq)) = 0
在应用之前的mean
功能之前