i m taking videoframes&applying 3-D FFT.but takes 2-3 hours for execution.Is there any way to speed up the code from 2-3 hours to few minutes (using e.g.vector​ization,pr​eallocatio​n or any other way)????

2 次查看(过去 30 天)
for t=1:100:T-31; %T is no of frames.... and i am taking selective frames from video f1= read(video,t); %read frames from video file video f2=rgb2gray(f1); I(:,:,t)=f2; %I is for storing database of all frames end
%code for 3-D Fourier Transform
for s=1:100:T-31
for u=1:r1 %r1 and c1 are dimensions of frame
for v=1:c1
dft=0;
mag(u,v,s)=0;
phase(u,v,s)=0;
for t=1:100:T-31
for x=1:r1
for y=1:c1
v1=exp(((-1j)*2*pi*(x-1)*(u-1))/r1);
v2=exp(((-1j)*2*pi*(y-1)*(v-1))/c1);
v3=exp(((-1j)*2*pi*(t-1)*(s-1))/(T-31));
dft=dft+ I(x,y,t)*((v1)*(v2)*(v3))/(r1*c1*(T-31));
dft1=(fftshift(dft));
mag(u,v,s)=mag(u,v,s)+log(1+abs(dft1));%magnitude spectrum
phase(u,v,s)=phase(u,v,s)+exp(1j*angle(dft));%phase spectrum
end
end
end
end
end
magstruct(s)=struct('magnitude',mag(:,:,s));%use of structure for storing magnitude data
phasestruct(s)=struct('phase',phase(:,:,s));%use of structure for storing phase data
end
%code for 3-d Inverse Fourier Transform
for t=1:100:T-31 for x=1:r1 for y=1:c1 idft(x,y,t)=0;
for s=1:100:T-31
for u=1:r1
for v=1:c1
z1=exp(((1j)*2*pi*(x-1)*(u-1))/r1);
z2=exp(((1j)*2*pi*(y-1)*(v-1))/c1);
z3=exp(((1j)*2*pi*(t-1)*(s-1))/(T-31));
idft(x,y,t)=idft(x,y,t)+ (phasestruct(s).phase(u,v))*((z1)*(z2)*(z3)); %reconstructin frm phase only
idft2(x,y,t)=idft(x,y,t).*conj(idft(x,y,t));
end
end
end
end
end
reconstruct(t)=struct('reconstructed',idft(:,:,t));
end

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Image Segmentation and Analysis 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by