Saving fast fourier transform (fft) plot to image

4 views (last 30 days)
I have a code that tries to plot the fast Fourier transform of an image. When I use imshow function, the result looks fine, but when I try to save the result into an image using imwrite function, it's not just the same thing! Do I lack some other parameters in order to save the actual result? Here is the code below:
%%INITIALIZE
c = 299792458; %speed of light
la = 633e-9; %wavelength
k = 2*pi/la; %wavenumber
L = .008; %side length(m)%.004
W = L; %width
M = 2^10; %number of samples 1024
N = M;
dx = L/M; %src sample interval
dy = W/N;
x = -L/2:dx:L/2-dx; %src coords
y = -W/2:dy:W/2-dy; %src coords
[X,Y]= meshgrid(x,y);
Z = X+1i*Y;
rho = sqrt(X.^2+Y.^2);
rho0 = 0.00005; %threshold in forming 2D boolean matrix
D = X.^2+Y.^2 <= rho0^2;%Binarize image, 0 kapag less than chosen rho.
phi = angle(Z)+pi;%+pi angle returns phase angle of complex elements
%%MAKE LAGUERRE-GAUSS BEAM
for i = -5:5
l = i;
f = 0.5;
u=D.*(rho.^abs(l)).*exp(1i*l*phi)+ D.*(rho.^abs(l)).*exp(1i*-l*2*phi);%Laguerre-Gauss
%Fast fourier transform (FFT)x
DP =fftshift(fft2(u));
DM = abs(DP).^2;
figure(1)
imagesc(DM)
axis image
imwrite(DM,[num2str(l),'fft.bmp'])
end
Any help and/or suggestion will be much appreciated. Thanks.

Answers (0)

Community Treasure Hunt

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

Start Hunting!