在Matlab中计算一个区域的频谱幅度

Calculating the spectrum magnitude in an area in Matlab

我尝试对一组数据进行 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

我猜测您的 q 变量的某些值为零,因此 Magq = log(abs(q)) 将 return -Inf 设为这些值。也许你要找的mean应该是

log(abs(mean(mean(q(1:150,300:340)))))

否则,如果您只想忽略无穷大,请将它们全部设置为零

Magq(~isfinite(Magq)) = 0

像之前那样应用 mean 函数之前