I try to FFT a set of data (they are 10 pictures, with a 'T' draw in the middle) and calculate the spectrum magnitude in given areas.
Here is my code:
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
The picture above is the outcome after running my code. And the picture below is the areas I want to calculate.
I'm using
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)));
to calculate the spectrum magnitude, but the result of this is always -Inf
. This is mainly because mean(mean(Magq(1:150,300:340)))
and mean(mean(Magq(260:400,300:340)))
are both equal to -Inf
.
Could anyone please give me any hints why the result is -Inf
?
I would guess that some values of your q
variable are zero, so Magq = log(abs(q))
will return -Inf at those values. Maybe the mean
that you are looking for should be
log(abs(mean(mean(q(1:150,300:340)))))
Otherwise, if you just want to ignore the infinities, set them all to zero
Magq(~isfinite(Magq)) = 0
Before applying the mean
function as you did before