17#ifndef __image_filter_fft_h__
18#define __image_filter_fft_h__
22#include <unsupported/Eigen/FFT>
29#include "filter/base.h"
53 template <
class HeaderType>
54 FFT (
const HeaderType& in,
const bool inverse) :
59 for (
size_t axis = 0;
axis != std::min<size_t> (
size_t(3), in.ndim()); ++
axis)
70 if (i >= this->ndim())
71 throw Exception (
"Axis index " +
str(i) +
" for FFT image filter exceeds number of image dimensions (" +
str(this->ndim()) +
")");
77 void set_centre_zero (
const bool i)
83 template <
class InputComplexImageType,
class OutputComplexImageType>
84 void operator() (InputComplexImageType& input, OutputComplexImageType& output)
96 for (
size_t n = 0; n < axes.size(); ++n) {
97 if (axes[n] == *
axis) {
98 axes.erase (axes.begin() + n);
104 if (progress) ++(*progress);
108 for (
auto l =
Loop (output)(output); l; ++l) {
109 assign_pos_of (output).to (temp);
111 temp.index(*flip_axis) = (temp.index(*flip_axis) >= (temp.size (*flip_axis) / 2)) ?
112 (temp.index(*flip_axis) - (temp.size (*flip_axis) / 2)) :
113 (temp.index(*flip_axis) + (temp.size (*flip_axis) / 2));
114 output.value() = temp.value();
128 template <
class ComplexImageType>
131 FFTKernel (
const ComplexImageType& voxel,
const size_t FFT_axis,
const bool inverse_FFT) :
138 void operator () (
const Iterator& pos) {
139 assign_pos_of (pos).to (
vox);
162 template <
class ImageType>
163 void fft (ImageType&& vox,
const size_t axis,
const bool inverse =
false) {
165 for (
size_t n = 0; n < axes.size(); ++n)
167 axes.erase (axes.begin() + n);
170 Kernel (
const ImageType& v,
size_t axis,
bool inverse) :
171 data_in (v.size (
axis)), data_out (data_in.size()),
axis (
axis), inverse (inverse) { }
173 void operator ()(ImageType& v) {
177 fft.inv (data_out, data_in);
179 fft.fwd (data_out, data_in);
183 Eigen::FFT<double>
fft;
184 Eigen::Matrix<cdouble, Eigen::Dynamic, 1> data_in, data_out;
187 } kernel (vox,
axis, inverse);
static constexpr uint8_t CFloat64
void set_byte_order_native()
a filter to perform an FFT on an image
static Image scratch(const Header &template_header, const std::string &label="scratch image")
a dummy image to iterate over, useful for multi-threaded looping.
implements a progress meter to provide feedback to the user
Eigen::Matrix< cdouble, Eigen::Dynamic, 1 > data_out
void fft(ImageType &&vox, const size_t axis, const bool inverse=false)
Eigen::Matrix< cdouble, Eigen::Dynamic, 1 > data_in
vector< size_t > axes_to_process
FORCE_INLINE LoopAlongAxes Loop()
MR::default_type value_type
vector< size_t > order(const HeaderType &header, size_t from_axis=0, size_t to_axis=std::numeric_limits< size_t >::max())
sort range of axes with respect to their absolute stride.
std::complex< double > cdouble
std::string str(const T &value, int precision=0)
ThreadedLoopRunOuter< decltype(Loop(vector< size_t >()))> ThreadedLoop(const HeaderType &source, const vector< size_t > &outer_axes, const vector< size_t > &inner_axes)
Multi-threaded loop object.
void copy(InputImageType &&source, OutputImageType &&destination, size_t from_axis=0, size_t to_axis=std::numeric_limits< size_t >::max())