Here's an example - the grid of features is space every 20 meters, the frequency found at 0.05/m corresponds to the frequency of dots.
clc
close all
clear all
dx_m = 1;
dy_m = 1;
nx = 101;
ny = nx;
imgData = zeros(1,nx);
imgData(10:20:nx-9) = 1;
imgData = imgData.*imgData';
if (mod(nx,2) == 0)
X1D = dx_m.*[-nx/2:1:nx/2-1];
else
X1D = dx_m.*[-(nx-1)/2:1:(nx-1)/2];
end
if (mod(ny,2) == 0)
Y1D = dy_m.*[-ny/2:1:ny/2-1];
else
Y1D = dy_m.*[-(ny-1)/2:1:(ny-1)/2];
end
figure('Color','white');
subplot(2,1,1)
imagesc(X1D,Y1D,imgData);
title({'Image Data'},'fontsize',12);
axis equal
axis tight
colorbar
set(gca,'fontweight','bold');
xlabel('X [m]'); ylabel('Y [m]');
dfy = 1/(ny*dy_m);
dfx = 1/(nx*dx_m);
if (mod(nx,2) == 0)
FX = dfy.*[-nx/2:1:nx/2-1];
else
FX = dfy.*[-(nx-1)/2:1:(nx-1)/2];
end
if (mod(ny,2) == 0)
FY = dfy.*[-ny/2:1:ny/2-1];
else
FY = dfy.*[-(ny-1)/2:1:(ny-1)/2];
end
subplot(2,1,2)
imagesc(FX,FY,(abs(fftshift(fft2(imgData)))));
axis equal; axis tight; colorbar
set(gca,'fontweight','bold');
xlabel('Frequency [1/m]'); ylabel('Frequency [1/m]');
title('FFT2D Output','fontsize',12);
Adding the ability to rotate the image
clc
close all
clear all
dx_m = 1;
dy_m = 1;
nx = 101;
ny = nx;
rotation = 30;
imgData = zeros(1,nx);
imgData(10:20:nx-9) = 1;
imgData = imgData.*imgData';
imgData = imrotate(imgData,rotation,'crop');
if (mod(nx,2) == 0)
X1D = dx_m.*[-nx/2:1:nx/2-1];
else
X1D = dx_m.*[-(nx-1)/2:1:(nx-1)/2];
end
if (mod(ny,2) == 0)
Y1D = dy_m.*[-ny/2:1:ny/2-1];
else
Y1D = dy_m.*[-(ny-1)/2:1:(ny-1)/2];
end
figure('Color','white');
subplot(2,1,1)
imagesc(X1D,Y1D,imgData);
title({'Image Data'},'fontsize',12);
axis equal
axis tight
colorbar
set(gca,'fontweight','bold');
xlabel('X [m]'); ylabel('Y [m]');
dfy = 1/(ny*dy_m);
dfx = 1/(nx*dx_m);
if (mod(nx,2) == 0)
FX = dfy.*[-nx/2:1:nx/2-1];
else
FX = dfy.*[-(nx-1)/2:1:(nx-1)/2];
end
if (mod(ny,2) == 0)
FY = dfy.*[-ny/2:1:ny/2-1];
else
FY = dfy.*[-(ny-1)/2:1:(ny-1)/2];
end
subplot(2,1,2)
imagesc(FX,FY,(abs(fftshift(fft2(imgData)))));
axis equal; axis tight; colorbar
set(gca,'fontweight','bold');
xlabel('Frequency [1/m]'); ylabel('Frequency [1/m]');
title('FFT2D Output','fontsize',12);