# Fourier transform along only one dimension of 2D array

I'm a relative newbie to Mathematica

Before you flag me as duplicate, note that I have read and studied "Fourier transform over a custom dimension" as best I can. I cannot understand the answer, it uses a lot of advanced notation. I can't even tell if this is the same question or not.

I have a 2D array generated from an image:

tdomain = ImageData[Import["filename.png"]]


I want to fourier transform this array along only one of the dimensions, the rows. The 2D Fourier also runs transform over the columns, not what I want. Can you please help me to Fourier transform only the rows?

I have tried every which way with the function Fourier. It seems to me that it should support my goal, but I can't get it to do anything useful.

Following the answer in "Fourier transform over a custom dimension", I experimented with the Map function, but the documentation is so terse I can't figure it out.

Finally, I wrote a for loop, which seems to work. Here is a working example:

In[168]:= tdomain = ImageData[Import["filename.jpg"]]
In[169]:= Dimensions[tdomain]
Out[169]= {218, 1012}
In[170]:= fdomain = Array[0 &, {218, 1012}]

In[184]:= For[i = 1, i < 219, i++,
trow = tdomain[[i]];
frow = Fourier[trow];
fdomain[[i]] = frow;
]

(* Then, for fun *)
Image[Re[fdomain]]


There has got to be a better way, right?

• I think what you are doing can be reduced to Image[Re[Fourier /@ tdomain]] Oct 11, 2017 at 21:47
• For the benefit of readers, you could link to the previous question: Fourier transform over a custom dimension
– user484
Nov 14, 2017 at 16:57

## 1 Answer

It might be worth trying to figure out Map. Here's one way to re-express your loop:

tdomain = ImageData[Import["filename.jpg"]];
fdomain = Fourier[tdomain[[#]]] & /@ Range[218]


/@ is Map, and the syntax says to fill # with each entry of Range[218]. Or, as MarcoB points out, you can map directly over the rows:

fdomain = Fourier /@ tdomain


which applies the Fourier function to each element (in this case, each row) of tdomain.

• Wouldn't Fourier /@ tdomain do as well for the second part, given the noted dimensions of tdomain in OP? (+1) Oct 11, 2017 at 21:44