 |
Bsoft
2.1.0
Bernard's software package
|
Go to the documentation of this file.
52 return error_show(
"Bimage::fft", __FILE__, __LINE__);
54 if ( dir == FFTW_BACKWARD ) {
60 cout <<
"DEBUG Bimage::fft: datatype=" << datatype <<
" compoundtype=" << compoundtype << endl;
83 return error_show(
"Error in Bimage::fft_complex: Cannot Fourier transform - the data block is empty!", __FILE__, __LINE__);
88 long i, imgsize(x*y*z);
91 error_show(
"Error in Bimage::fft_complex", __FILE__, __LINE__);
97 if ( dir == FFTW_FORWARD ) cout <<
"Doing a forward FFT:" << endl;
98 else cout <<
"Doing a backward FFT:" << endl;
100 cout <<
"Using FFTW: Version " << FFTW_VERSION << endl;
102 cout <<
"Complex size: " <<
sizeof(
fft_complex) << endl;
103 cout <<
"Image size: " <<
size() << endl;
114 cout <<
"DEBUG Bimage::fft_complex: GCD FFTW3" << endl;
115 dispatch_apply(n, dispatch_get_global_queue(0, 0), ^(
size_t nn){
122 cout <<
"DEBUG Bimage::fft_complex: OpenMP FFTW3" << endl;
123 #pragma omp parallel for
125 for (
long nn=0; nn<n; nn++ ) {
135 double scale = 1.0/imgsize;
136 if ( norm_flag == 1 ) scale = sqrt(scale);
138 for ( i=0, imgsize *= n; i<imgsize; i++ )
set(i,
complex(i) * scale);
140 cout <<
"DEBUG Bimage::fft_complex: scale = " << scale << endl;
144 cout <<
"DEBUG Bimage::fft_complex: FFT done! (" << dir <<
")" << endl;
177 return error_show(
"Error in Bimage::fft_complex: Cannot Fourier transform - the data block is empty!", __FILE__, __LINE__);
182 long i, nn, imgsize(x*y*z);
185 error_show(
"Error in Bimage::fft_complex", __FILE__, __LINE__);
186 cerr <<
"The FFTW complex number size = " <<
sizeof(
fft_complex) <<
" (should be " << c*
data_type_size() <<
")!" << endl;
192 cout <<
"Using FFTW: Version " << FFTW_VERSION << endl;
194 cout <<
"Complex size: " <<
sizeof(
fft_complex) << endl;
195 cout <<
"Image size: " <<
size() << endl;
202 for ( nn=0; nn<n; nn++, data += imgsize ) {
208 double scale = 1.0L/imgsize;
209 if ( norm_flag == 1 ) scale = sqrt(scale);
211 cout <<
"DEBUG Bimage::fft_complex: scale = " << scale << endl;
213 for ( i=0, imgsize *= n; i<imgsize; i++ )
set(i,
complex(i) * scale);
216 cout <<
"DEBUG Bimage::fft_complex: FFT done!" << endl << endl;
242 cout <<
"DEBUG Bimage::change_transform_size: size=" << nusize << endl;
244 if ( z < 2 ) nusize[2] = 1;
245 Vector3<double> scale(nusize[0]*1.0L/x, nusize[1]*1.0L/y, nusize[2]*1.0L/z);
247 if ( nusize.
volume() < 1 )
return scale;
248 if ( nusize ==
size() )
return scale;
251 cout <<
"DEBUG Bimage::change_transform_size: scale=" << scale << endl;
254 cerr <<
"Error: Bimage::change_transform_size: Only complex numbers supported!" << endl;
258 long i, j, nn, xx, yy, zz, iy, iz;
259 long xold, yold, zold, zerox, zeroy, zeroz;
261 long ds(n*nusize.
volume());
268 nufom =
new float[ds];
269 for ( i=0; i<ds; i++ ) {
276 hold = (
size() - 1)/2;
280 cout <<
"DEBUG Bimage::change_transform_size: datasize=" << ds << endl;
283 cout <<
"Changing transform to size: " << nusize <<
" voxels" << endl << endl;
285 for ( j=nn=0; nn<n; nn++ ) {
286 for ( zz=0; zz<nusize[2]; zz++ ) {
288 if ( zz > h[2] ) zold -= d[2];
290 if ( zz > hold[2] && zz <= d[2] + hold[2] ) zeroz += 1;
291 iz = (nn*z + zold)*y;
292 for ( yy=0; yy<nusize[1]; yy++ ) {
294 if ( yy > h[1] ) yold -= d[1];
296 if ( yy > hold[1] && yy <= d[1] + hold[1] ) zeroy += 1;
298 for ( xx=0; xx<nusize[0]; xx++, j++ ) {
300 if ( xx > h[0] ) xold -= d[0];
302 if ( xx > hold[0] && xx <= d[0] + hold[0] ) zerox += 1;
306 if ( fom ) nufom[j] = fom[i];
313 cout <<
"DEBUG Bimage::change_transform_size: origin[" << n <<
"]=" <<
image[nn].
origin() << endl;
318 size(nusize[0], nusize[1], nusize[2]);
328 cout <<
"DEBUG Bimage::change_transform_size: sampling=" <<
sampling(0) << endl;
fft_plan fft_setup(fft_direction dir, int opt=0)
Sets up a plan for fast Fourier transforms.
void set(long j, double v)
Sets a single value at the given index.
void simple_to_complex()
A simple image is converted to a complex image.
Vector3< long > page_size()
int error_show(string message, string file, int line)
Displays the error with file and line reference.
Vector3< long > size() const
long data_type_size() const
Returns the size of the datatype in bytes.
void origin(double x, double y, double z)
Vector3< double > change_transform_size(Vector3< long > nusize)
Resizes a "standard" transform.
int fft_destroy_plan(fft_plan plan)
Deallocates a plan for fast Fourier transforms.
FourierType fourier_type()
CompoundType compound_type()
Utilities for timing functions.
int fftw(fft_plan plan, Complex< float > *a)
Fast Fourier transforms a data array.
Complex< double > complex(long j)
Returns a complex value at the given index.
Header file for image class.
Header file for general utilities.
fft_plan fft_setup_plan(long x, long y, long z, fft_direction dir, int opt)
Sets up a plan for fast Fourier transforms.
void origin(double ox, double oy, double oz)
void change_type(char letter)
Get the data type indicated by a single letter code.
fftwf_complex fft_complex
void sampling(double x, double y, double z)
unsigned char * data_pointer()
vector< Vector3< double > > sampling()
unsigned char * data_assign(unsigned char *nudata)
Assign image data.
void complex_to_real()
The real part of a complex image is written to a simple image.
long statistics()
Calculates the statistics for an image.