How to obtain FFT for a certain region for multiple images and plot FFT

2 views (last 30 days)
clc;
clear all;
%% Pre setting
path_name_ref = 'C:\Users\test\Desktop\reference';
imghei = 640; %(pixel)
imgwid = 880; %(pixel)
deltaZ = 71.972;
wScale = 1/0.992;
lamda_Start = 400;%Wavelength Start
lamda_End = 790;%Wavelength End
lamda_Start_A = 400;
lamda_End_A = 685;
deltaZ = deltaZ*wScale;
lists = dir(path_name_ref);
n = length(lists);
imgnum_n=length(lists)-3;
imgnum = imgnum_n;
K_Start = floor(2*imgnum*deltaZ/lamda_End+1);
K_End = floor(2*imgnum*deltaZ/lamda_Start+1);
K_Real = (1:1:imgnum-1)*pi()/imgnum/deltaZ*1000;
K_Start_A = floor(2*imgnum*deltaZ/lamda_End_A+1);
K_End_A = floor(2*imgnum*deltaZ/lamda_Start_A+1);
%% Read Image
Data_Ref=zeros(imghei,imgwid,imgnum);
TMP=zeros(imghei,imgwid,3);
tDataR=zeros(imghei,imgwid);
valueR=zeros(imghei,imgwid);
RefFFTData=zeros(imghei,imgwid,imgnum);
ReflectanceData=zeros(imghei,imgwid,imgnum);
PlotData=zeros(imgnum);
for i=2:imgnum_n+1
TMP(:,:,:)=imread(sprintf('%s\\referenceimage_ (%d)',path_name_ref,i),'BMP');
Data(:,:,i-1)=TMP(:,:,1);
end
for i=1:imghei
for j=1:imgwid
tDataR = squeeze(Data(i,j,:))';
valueR = mean(tDataR(imgnum_n-20:imgnum_n));
Data_Ref(i,j,imgnum_n+1:imgnum) = valueR;
end
end
% plot(tDataR);
% title('Scan Domain')
% xlabel('Reference Scan Position')
% ylabel('Intensity')
%% FFT
%Perform FFT on the average of the center of 20 x 20 pixels
sum_ref = zeros(imgnum,1);
ref_size = 10;
for i=imghei/2-ref_size:imghei/2+ref_size
for j=imgwid/2-ref_size:imgwid/2+ref_size
Tmpft_ref=abs(fft(squeeze(Data_Ref(i,j,:))));
RefFFTData(i,j,:)=Tmpft_ref;
sum_ref = sum_ref + Tmpft_ref;
end
end
sum_ref = sum_ref/(ref_size*2+1)/(ref_size*2+1);
%Plot Graph
Hello. After running approximately 206 consecutive images and obtaining the intensity at a certain location for each of these images, I want to perform Fast Fourier Transform on the data and get a graph where the line is linear. However, for some reason, the sum_ref and Tmpft_ref come out as 1x203 and all the values come out as zero values, as the data is not filled. In this case, how do plot the FFT graph and fix the code so that the values dont all come out as zero? Thank you!
  2 Comments
Subhadeep Koley
Subhadeep Koley on 5 Nov 2019
Edited: Subhadeep Koley on 5 Nov 2019
The Data_Ref variable which you have calculated from the Data variable is 0. Therefore, the variable Tmpft_ref is also 0 as it is being calculated from the variable Data_Ref only. Can you explain what exactly you want to calculate in Data_Ref

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!