This is really ancient code that should do what you need.
It was written on MMA version 3 or 4 (or 5??) - I don't remember - and I have not tested it on newer versions.
If it does not work you'll probably have to find a newer procedure to extract the dimensions from an image.
So, here's the code, it works on a matrix of values and gives you a matrix that represents the (generally complex) FFT you are after:
FFT2D[mat_] := Module[{ft, hshift, wshift},
ft = Fourier[mat];
{hshift, wshift} = IntegerPart[(# + .5)/2] & /@ Dimensions[ft];
Transpose[RotateLeft[
Transpose[RotateLeft[
ft,
hshift]],
wshift]]
]
This is how I used it back then (again, you might have to adjust the code, possibly by changing ListDensityPlot
with ArrayPlot
)
mat = GrayScaleMatrix["Image1.bmp"];
(* this was a silly conversion from color to grayscale, see later *)
{hshift, wshift} = IntegerPart[(# + .5)/2] & /@ Dimensions[mat]
(* this is just extracting the dimensions of the image*)
ListDensityPlot[mat, MeshRange -> {{-wshift, wshift}, {-hshift, hshift}}]
(* and this is plotting it to show the gray scaled image *)
Instead of Fourier
, I would use FFT2D
. That's it.
fft = FFT2D[mat];
Plotting might require the previously extracted information about the image's dimensions.
ListDensityPlot[Abs[fft], MeshRange -> {{-wshift, wshift}, {-hshift, hshift}}]
Addendum - And this is the procedure I used to convert color bitmaps into gray scale ones (I wanted to experiment with actual pictures and I did not have the time to figure out how to properly create a gray scaled version). I include it here just in case you want to try with the actual data it has worked for me
GrayScaleMatrix[filename_String] := Module[{pic},
pic = Import[filename];
pic[[1, 1]] /. {r_, g_, b_} :> (.3r + .6g + .1b)
]
fftshift
. It's not really an issue withArrayPlot
, it's an question of visualizing the result of the Fourier transform. $\endgroup$