2
$\begingroup$

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?

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

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.

$\endgroup$
  • 2
    $\begingroup$ Wouldn't Fourier /@ tdomain do as well for the second part, given the noted dimensions of tdomain in OP? (+1) $\endgroup$ – MarcoB Oct 11 '17 at 21:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.