2 #include "FFT2D_free.hh"
4 #include "fftpack/fftpack.h"
10 template <
class StorageType>
14 WorkSize0_ = WorkSize1_ = 0;
15 WorkArray0_ = WorkArray1_ = NULL;
16 TmpArray0_ = TmpArray1_ = NULL;
17 TmpArraySize0_ = TmpArraySize1_ = 0;
22 template <
class StorageType>
30 template <
class StorageType>
36 if (sizex != WorkSize0_) {
42 if (sizey != WorkSize1_) {
50 if (WorkArray0_ == NULL) {
52 TmpArraySize0_ = 4 * WorkSize0_+15;
53 TmpArray0_ =
new float[TmpArraySize0_];
54 WorkArray0_ =
new float[2*WorkSize0_];
55 cffti_(&WorkSize0_,TmpArray0_);
57 if (WorkArray1_ == NULL) {
59 TmpArraySize1_ = 4 * WorkSize1_+15;
60 TmpArray1_ =
new float[TmpArraySize1_];
61 WorkArray1_ =
new float[2*WorkSize1_];
62 cffti_(&WorkSize1_,TmpArray1_);
64 Normalize_ = sizex * sizey;
69 template <
class StorageType>
75 unsigned int count = ComplexImg.
GetHeight();
76 for (
unsigned int j=0;j<count;j++){
77 WorkArray1_[j*2] = ida[j][col*2];
78 WorkArray1_[j*2+1] = ida[j][col*2+1];
82 template <
class StorageType>
88 memcpy(WorkArray0_,ida[row],ComplexImg.
GetWidth()*2*
sizeof(float));
94 template <
class StorageType>
99 memcpy(out_ida[row],WorkArray0_,ComplexImg.
GetWidth()*2*
sizeof(float));
104 template <
class StorageType>
109 unsigned int count = ComplexImg.
GetHeight();
110 for (
unsigned int j=0;j<count;j++){
111 out_ida[j][col*2] = WorkArray1_[j*2];
112 out_ida[j][col*2+1] = WorkArray1_[j*2+1];
118 template <
class StorageType>
123 BEXCEPTION(
"Can not FFT on more then one channel");
127 unsigned int NewNumCols = NumCols/2 +1;
129 ComplexOut.
Init(NewNumCols,NumRows,2);
132 Init(NumCols, NumRows);
135 for (
unsigned int j=0;j<NumRows; j++) {
136 memset(WorkArray0_,0,2*WorkSize0_*
sizeof(
float));
137 for (
unsigned int i=0;i<NumCols;i++)
138 WorkArray0_[i*2] = in_ida[j][i];
139 cfftf_(&WorkSize0_, WorkArray0_,TmpArray0_);
140 WorkArray0ToComplexRow_(TmpImg, j);
145 for (
unsigned int i=0;i<NewNumCols; i++) {
146 ComplexColumnToWorkArray1_(TmpImg,i);
147 cfftf_(&WorkSize1_,WorkArray1_,TmpArray1_);
148 WorkArray1ToComplexColumn_(ComplexOut,i);
152 template <
class StorageType>
156 unsigned int NumRows=ComplexIn.
GetHeight();
157 unsigned int NumCols=ComplexIn.
GetWidth();
158 unsigned int NewNumCols = (NumCols-1)*2;
159 res.
Init(NewNumCols,NumRows,2);
162 Init( NewNumCols,NumRows);
163 for (
unsigned int i=0;i<NumCols; i++) {
164 ComplexColumnToWorkArray1_(ComplexIn,i);
165 cfftb_(&WorkSize1_,WorkArray1_,TmpArray1_);
166 WorkArray1ToComplexColumn_(tmpImg,i);
167 WorkArray1ToComplexColumn_(tmpImg,NewNumCols-i-1);
174 for (
unsigned int j=0;j<NumRows; j++) {
175 ComplexRowToWorkArray0_(tmpImg,j);
176 cfftb_(&WorkSize0_,WorkArray0_,TmpArray0_);
177 for (
unsigned int i=0;i<NumCols*2; i++)
178 out_ida[j][i] = (StorageType)WorkArray0_[i];
182 template <
class StorageType>
189 for (
unsigned int i=0;i<count;i++)
190 data[i] = data[i]/
float(Normalize_);
195 template <
class StorageType>
206 for (
unsigned int i=0;i<count;i+=2){
207 out[j++] = sqrt(in[i]*in[i] + in[i+1]*in[i+1]);
218 #if defined(BUILD_IMAGE_FLOAT)
221 #if defined(BUILD_IMAGE_SHORT)
void Release()
reimplemented from ImageBase
void WorkArray1ToComplexColumn_(Image< float > &ComplexImg, unsigned int col)
bool IsEmpty() const
check if ImageData_ points to allocated image buffer or not
void Init(int sizex, int sizey)
unsigned int GetWidth() const
void WorkArray0ToComplexRow_(Image< float > &ComplexImg, unsigned int row)
unsigned int GetChannelCount() const
returns the number of Color channels, e.g.
unsigned int GetHeight() const
void ComplexRowToWorkArray0_(const Image< float > &ComplexImg, unsigned int row)
void Init(unsigned int Width, unsigned int Height, unsigned int channels=1, enum EStorageType storageType=ST_unsignedchar, const bool interleaved=true)
calls Init from ImageBase storageType is ignored, just dummy argument
const StorageType * GetImageData() const
overloaded GetImageData() from ImageBase
void GetMagnitude(const Image< float > &ComplexIn, Image< float > &value)
take the spectrum image (2-channel) and compute the absolute value for each pixel ...
Wrapper to the fftpack library from netlib (see fftpack/fft.c), implementing the fft (Fast Fourier Tr...
void Reverse(const Image< float > &ComplexIn, Image< StorageType > &res)
void Forward(const Image< StorageType > &in, Image< float > &ComplexOut)
apply FFT on
void ComplexColumnToWorkArray1_(const Image< float > &ComplexImg, unsigned int col)
void Normalize(Image< float > &Image)
apply normalisation on spectrum image, which is float-type
const StorageType ** GetImageDataArray() const
overloaded GetImageDataArray() from ImageBase