function fft_img = get_FFT() % ****************************************************************************************************************************
% Compute the FFT phase or Amplitude
CtrlFigHdl = GetFigHdl('CtrlFig');
ToggleButtonAmpHdl = findobj(CtrlFigHdl, 'Tag', 'ToggleButtonAmp');
ToggleButtonPhaseHdl = findobj(CtrlFigHdl, 'Tag', 'ToggleButtonPhase');
% detect if we want a Phase or Amplitude
if get(ToggleButtonAmpHdl, 'Value')
BufferType = 1; % FFT Amplitude type
elseif get(ToggleButtonPhaseHdl, 'Value')
BufferType = 2; % FFT Phase type
else
fft_img = [];
return;
end
CtrlFigUsrDat = get(CtrlFigHdl, 'UserData');
% Do we need to update the FFT?
if (BufferType == CtrlFigUsrDat.Current.BufferType) && ~isempty(CtrlFigUsrDat.Current.Buffer)
% No we don't
fft_img = CtrlFigUsrDat.Current.Buffer;
else
% we need to compute a new fft
% Notes: fft(uint16) is double; fft(single) is single; fft(double) is double
clear CtrlFigUsrDat; % Avoid duplication of data
CtrlFigUsrDat = ClearBuffer('main'); % makes room
% Get the ROI limits
[ROI_min_x ROI_max_x ROI_min_y ROI_max_y] = getROIlimits();
try
h = [];
% pre-allocation. We make it single as it's half the data needed and still good enough.
% The FFT computation below is converted in single as it is done, plane by plane
fft_img = zeros(ROI_max_y-ROI_min_y+1, ROI_max_x-ROI_min_x+1, CtrlFigUsrDat.Current.z_dim, 'single');
sizeOfSingle = 4;
h = waitbar(0,[num2str(size(fft_img,2)) ' * ' num2str(size(fft_img,1)) ' pixels * ', ...
num2str(size(fft_img,3)) ' frames * single (32 bpp) = ' num2str(numel(fft_img)*sizeOfSingle/(1024*1024),'%.2f'), ' MB'], ...
'Name', 'Computing FFT...', 'WindowStyle', 'modal');
set(h, 'HandleVisibility', 'off'); % do not integrate this into the line above
pause(0.1); % allow refresh
if BufferType == 1 % Amplitude
for i = ROI_min_x:ROI_max_x % along x
fft_img( : , i-ROI_min_x+1 , :) = abs(fft(single(get_RawData('ROI',i,':')),[],3));
if ishandle(h)
waitbar((i-ROI_min_x+1)/(ROI_max_x-ROI_min_x+1), h);
else
error('FFT aborted.');
end
end
else % Phase
for i = ROI_min_x:ROI_max_x % along x
fft_img( : , i-ROI_min_x+1 , :) = -angle(fft(single(get_RawData('ROI',i,':')),[],3));
if ishandle(h)
waitbar((i-ROI_min_x+1)/(ROI_max_x-ROI_min_x+1), h);
else
error('FFT aborted.');
end
end
end
% Update Buffer
CtrlFigUsrDat.Current.BufferType = BufferType;
CtrlFigUsrDat.Current.Buffer = fft_img;
setF(CtrlFigHdl, 'UserData', CtrlFigUsrDat);
catch FFTError
messageBox(FFTError.message, 1, 'FFT Error');
fft_img = []; % means it failed computing the FFT
end
if ishandle(h)
delete(h)
end
end
It would be nice if you post the link to what you have found :)
If you read this tutorial, you will see in the explanation part that the magnitude is
sqrt(Re² + Im²)
, so it contains both the information of real and imaginary part of the fft. What is in your opinion the to display the phase FFT? What this tutorial is displaying is the phase (angle between the line that pass through the point and the origin) and amplitude (the value at that point)yes I found this tutorial, so this image displayed can be considered as amplitude and phase image in the same time???
A little doc about it It seems that the magnitude is just in the center
and what about the phase image I want just the phase please.
... using the phase function in the same way as the mentioned tutorial?
thanks a lot
If you managed to do a phase image, then please add an answer with the code parts that did it and the results. Like this you can get also impressions and maybe corrections about it
ok but even with the tutorial it explains how to display FFT magnitude from one image however my application is to how display FFT magnitude and phase from many images, i explain more I should appliacte FFT for the same pixel of all images (like FFT signal) it means FFT for pixel 1.1 from im1 to imFinal and FFF for pixel 1.2 from im1 to imFinal... can you help me please.
Ok, the idea is simple and logic: You cannot reconstruct the image only from magnitude or only from phase, so the image in the output contains both magnitude and phase (or at least information about it, because
phase = atan(imag/real)
, and in the image you havereal
on x axis andimag
on y axis). I am not really sure how to extract just the phase, but I suppose that the phase function does it. From the phase you will be able to reconstruct just a kind of gradients image.Can you explain better what you need to do? Just for displaying the phase, apply phase on the image, see what you get and post it if you are not sure that it is correct.
my problem here it's not how to extract magnitude or phase but how to applicate FFT on 3D image sequence of images????
well ,I try to expess my self better, in fact I have n images and I want to applicate FFT in order to dispaly magnitude and phase images but itsn't like mentioned in the tutorial image by image I want to applicate FFT in the time at pixel1 in im1 at 1t then pixel1 in im2 at t2 then at pixel 1 in im3 at t3... is it clear??? please help me if you can.
So your problem is more like this one or like this one?
Or are you trying to filter noise in 3d image (image in time)?
Why not computing the FFT for all the images then compare them? Or doing a mean (if you want to filter the noise) of all?
Ok, this is getting long and the code is unreadable split in 5 comments with no formatting... You should update your question and make it beautiful ;)
Is this better now???