49 #include <Core/Utils/Exception.h>
58 extern std::size_t set_num_fftw_threads(std::size_t num_threads);
63 typedef itk::Image<float, 2> itk_image_t;
68 typedef itk_image_t::Pointer itk_imageptr_t;
73 typedef std::complex<float> fft_complex_t;
82 fft_data_t(
const unsigned int w,
const unsigned int h);
83 explicit fft_data_t(
const itk_imageptr_t & real);
85 const itk_imageptr_t & imag);
93 void resize(
const unsigned int w,
const unsigned int h);
95 void fill(
const float real,
const float imag = 0.0);
97 void setup(
const itk_imageptr_t & real,
98 const itk_imageptr_t & imag = itk_imageptr_t(NULL));
101 itk_imageptr_t component(
const bool imag = 0)
const;
102 inline itk_imageptr_t real()
const {
return component(0); }
103 inline itk_imageptr_t imag()
const {
return component(1); }
112 void apply_lp_filter(
const double r,
const double s = 0);
115 inline const fft_complex_t * data()
const {
return data_; }
116 inline fft_complex_t * data() {
return data_; }
118 inline unsigned int nx()
const {
return nx_; }
119 inline unsigned int ny()
const {
return ny_; }
121 inline const fft_complex_t & operator() (
const unsigned int & x,
122 const unsigned int & y)
const
125 inline fft_complex_t & operator() (
const unsigned int & x,
126 const unsigned int & y)
129 inline const fft_complex_t & at(
const unsigned int & x,
130 const unsigned int & y)
const
131 {
return data_[y + ny_ * x]; }
133 inline fft_complex_t & at(
const unsigned int & x,
134 const unsigned int & y)
135 {
return data_[y + ny_ * x]; }
138 fft_complex_t * data_;
148 fft(
const itk_image_t::Pointer & in,
fft_data_t & out);
172 bool ok = ifft(in, out);
176 CORE_THROW_EXCEPTION(
"ifft failed");
185 typedef fft_complex_t(*fn_fft_c_t)(
const fft_complex_t & in);
190 typedef fft_complex_t(*fn_fft_cc_t)(
const fft_complex_t & a,
191 const fft_complex_t & b);
197 elem_by_elem(fn_fft_c_t f,
198 const fft_data_t & in,
205 elem_by_elem(fft_complex_t(*f)(
const float & a,
206 const fft_complex_t & b),
208 const fft_data_t & b,
215 elem_by_elem(fft_complex_t(*f)(
const fft_complex_t & a,
217 const fft_data_t & a,
225 elem_by_elem(fft_complex_t(*f)(
const fft_complex_t & a,
226 const fft_complex_t & b),
227 const fft_complex_t & a,
228 const fft_data_t & b,
235 elem_by_elem(fft_complex_t(*f)(
const fft_complex_t & a,
236 const fft_complex_t & b),
237 const fft_data_t & a,
238 const fft_complex_t & b,
245 elem_by_elem(fn_fft_cc_t f,
246 const fft_data_t & a,
247 const fft_data_t & b,
257 conj(
const fft_data_t & in, fft_data_t & out)
258 { elem_by_elem(std::conj, in, out); }
264 conj(
const fft_data_t & in)
278 sqrt(
const fft_data_t & in, fft_data_t & out)
279 { elem_by_elem(std::sqrt, in, out); }
285 sqrt(
const fft_data_t & in)
296 template <
class a_t,
class b_t>
298 _mul(
const a_t & a,
const b_t & b)
306 template <
class a_t,
class b_t>
308 mul(
const a_t & a,
const b_t & b, fft_data_t & c)
309 { elem_by_elem(_mul, a, b, c); }
314 template <
class a_t,
class b_t>
316 mul(
const a_t & a,
const b_t & b)
319 mul<a_t, b_t>(a, b, c);
327 template <
class a_t,
class b_t>
329 _div(
const a_t & a,
const b_t & b)
337 template <
class a_t,
class b_t>
339 div(
const a_t & a,
const b_t & b, fft_data_t & c)
340 { elem_by_elem(_div, a, b, c); }
345 template <
class a_t,
class b_t>
347 div(
const a_t & a,
const b_t & b)
350 div<a_t, b_t>(a, b, c);
358 template <
class a_t,
class b_t>
360 _add(
const a_t & a,
const b_t & b)
368 template <
class a_t,
class b_t>
370 add(
const a_t & a,
const b_t & b, fft_data_t & c)
371 { elem_by_elem(_add, a, b, c); }
376 template <
class a_t,
class b_t>
378 add(
const a_t & a,
const b_t & b)
381 add<a_t, b_t>(a, b, c);
389 template <
class a_t,
class b_t>
391 _sub(
const a_t & a,
const b_t & b)
399 template <
class a_t,
class b_t>
401 sub(
const a_t & a,
const b_t & b, fft_data_t & c)
402 { elem_by_elem(_sub, a, b, c); }
407 template <
class a_t,
class b_t>
409 sub(
const a_t & a,
const b_t & b)
412 sub<a_t, b_t>(a, b, c);