2

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?

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
Gerry Harp
  • 121
  • 2

1 Answers1

2

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.

bill s
  • 68,936
  • 4
  • 101
  • 191
  • 2
    Wouldn't Fourier /@ tdomain do as well for the second part, given the noted dimensions of tdomain in OP? (+1) – MarcoB Oct 11 '17 at 21:44