26 #include "FFT2D_Tiles.hh"
28 #include <Base/Debug/Error.hh>
34 template <
class InputStorageType,
class OutputStorageType>
44 template <
class InputStorageType,
class OutputStorageType>
51 template <
class InputStorageType,
class OutputStorageType>
53 Init(
int width,
int height,
int tilewidth,
int tileheight)
56 if (this->_SizeX!=0 || this->_SizeY!=0 || this->_OutNum!=0 || this->_out || this->_in || this->_p_forward){
57 BIASERR(
"FFT2D_Tiles: call Release() before calling Init() a second time");
58 BIASEXIT(EXIT_FAILURE,
"FFT2D_Tiles: call Release() before calling Init() a second time");
64 this->_TileSizeX = tileheight;
65 this->_TileSizeY = tilewidth;
66 this->_NumTilesX = this->_SizeX / this->_TileSizeX;
67 if (this->_SizeX % this->_TileSizeX >0) this->_NumTilesX++;
68 this->_NumTilesY = this->_SizeY / this->_TileSizeY;
69 if (this->_SizeY % this->_TileSizeY >0) this->_NumTilesY++;
73 this->_Size = this->_TileSizeX*this->_TileSizeY;
74 this->_OutSizeY = (this->_TileSizeY>>1)+1;
75 this->_OutNum=this->_TileSizeX * this->_OutSizeY;
76 this->_out =(fftw_complex*)fftw_malloc(
sizeof(fftw_complex) * this->_OutNum);
77 this->_in = (
double*)fftw_malloc(
sizeof(
double) * this->_Size);
79 this->_p_forward = fftw_plan_dft_r2c_2d(this->_TileSizeX, this->_TileSizeY, this->_in, this->_out, FFTW_MEASURE);
80 this->_p_reverse = fftw_plan_dft_c2r_2d(this->_TileSizeX, this->_TileSizeY, this->_out, this->_in, FFTW_MEASURE);
88 template <
class InputStorageType,
class OutputStorageType>
92 if (this->_p_forward) fftw_destroy_plan(this->_p_forward);
93 if (this->_in) fftw_free(this->_in);
94 if (this->_out) fftw_free(this->_out);
97 this->_p_forward=NULL;
98 this->_SizeX=this->_SizeY=this->_Size=this->_OutNum=0;
102 template <
class InputStorageType,
class OutputStorageType>
106 BIASERR(
"not implemented");
111 template <
class InputStorageType,
class OutputStorageType>
115 BIASERR(
"not implemented");
123 template <
class InputStorageType,
class OutputStorageType>
129 dst.
Init(this->_OutSizeY, this->_SizeX, 2);
131 fftw_complex *outp = this->_out;
133 for (
int i=0;i<this->_OutNum; i++){
134 *oimgp = (OutputStorageType) (*outp)[0];
136 *oimgp = (OutputStorageType) (*outp)[1];
146 template <
class InputStorageType,
class OutputStorageType>
152 BIASERR(
"not implemented");
158 template <
class InputStorageType,
class OutputStorageType>
163 InputStorageType **Iida ;
165 if ( ((
int) src.
GetHeight() != this->_TileSizeX * this->_NumTilesX)
166 || ((
int) src.
GetWidth() != this->_TileSizeY * this->_NumTilesY)) {
168 tmpImg.
ZeroPad( this->_TileSizeX * this->_NumTilesX, this->_TileSizeY * this->_NumTilesY );
177 dst.
Init( this->_OutSizeY * this->_NumTilesY,this->_TileSizeX * this->_NumTilesX,1);
181 for (
int ty=0; ty<this->_NumTilesY; ty++) {
182 for (
int tx=0; tx<this->_NumTilesX; tx++) {
183 double *inp = this->_in;
184 fftw_complex *outp = this->_out;
187 for (
int y = ty*this->_TileSizeY; y<(ty+1)*this->_TileSizeY; y++)
188 for (
int x = tx*this->_TileSizeX; x<(tx+1)*this->_TileSizeX; x++) {
192 fftw_execute(this->_p_forward);
194 for (
int y = ty*this->_OutSizeY; y<(ty+1)*this->_OutSizeY; y++)
195 for (
int x = tx*this->_TileSizeX; x<(tx+1)*this->_TileSizeX; x++) {
197 Oida[x][y] = (OutputStorageType) sqrt((*outp[0]* *outp[0]) +
198 (*outp[1]* *outp[1]));
211 template <
class InputStorageType,
class OutputStorageType>
218 dst.
Init(this->_SizeX, this->_SizeY,1);
220 double *inp = this->_in;
222 for (
int i=0;i<this->_Size; i++){
223 *oimgp = (InputStorageType) *inp;
239 #if defined(BUILD_IMAGE_FLOAT)
242 #if defined(BUILD_IMAGE_DOUBLE)
245 #if defined(BUILD_IMAGE_UCHAR) && defined(BUILD_IMAGE_FLOAT)
248 #if defined(BUILD_IMAGE_UCHAR) && defined(BUILD_IMAGE_DOUBLE)
void Release()
reimplemented from ImageBase
void Release()
cal this before a second call to Init()
bool IsEmpty() const
check if ImageData_ points to allocated image buffer or not
virtual void Init(int, int)
Wrapper to the fftw3 library, which is supposed to perform the FFT patch- (tile-) wise...
int ZeroPad(const unsigned int newwidth, const unsigned int newheight, unsigned char bgcolor=0)
backward compatibility interface for Pad.
virtual int Reverse_(const Image< OutputStorageType > &src)
unsigned int GetWidth() const
virtual int Filter(const Image< InputStorageType > &src, Image< OutputStorageType > &dst)
dst.GetChannelCount()==2*src.GetCHannelCount() The result is not normalized!
virtual int Forward_(const Image< InputStorageType > &src)
virtual int TransformAbs(const Image< InputStorageType > &src, Image< OutputStorageType > &dst)
Transform forward and get absolute value from complex result The result is not normalized! ...
virtual int TransformReverse(const Image< OutputStorageType > &src, Image< InputStorageType > &dst)
Transform reverse, src must be of _SizeX,_OutSizeY,2.
unsigned int GetHeight() const
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
const StorageType ** GetImageDataArray() const
overloaded GetImageDataArray() from ImageBase