#include <processor.h>
Inheritance diagram for EMAN::FFTResampleProcessor:


Public Member Functions | |
| virtual EMData * | process (const EMData *const image) |
| To proccess an image out-of-place. | |
| virtual void | process_inplace (EMData *image) |
| To process an image in-place. | |
| string | get_desc () const |
| Get the descrition of this specific processor. | |
| string | get_name () const |
| Get the processor's name. | |
| TypeDict | get_param_types () const |
| Get processor parameter information in a dictionary. | |
Static Public Member Functions | |
| Processor * | NEW () |
Static Public Attributes | |
| const string | NAME = "math.fft.resample" |
Private Member Functions | |
| void | fft_resample (EMData *to, const EMData *const from, const float &sample_rate) |
| An internal function that encapsulates a routine common to both process and process inplace. | |
Hence it should probably be combined with a damping function near the edge Works for even/odd, 1D, 2D and 3D images (completely robust, tested)
| n | sampe_rate |
Definition at line 3506 of file processor.h.
|
||||||||||||||||
|
An internal function that encapsulates a routine common to both process and process inplace.
Definition at line 2089 of file processor.cpp. References EMAN::EMData::clip_inplace(), EMAN::EMData::depad_corner(), EMAN::EMData::do_fft_inplace(), EMAN::EMData::do_ift_inplace(), EMAN::EMData::get_ndim(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), EMAN::EMData::is_complex(), nx, ny, EMAN::EMData::process_inplace(), EMAN::EMData::set_fftodd(), and UnexpectedBehaviorException. Referenced by process(), and process_inplace(). 02089 {
02090 int nx = from->get_xsize();
02091 int ny = from->get_ysize();
02092 int nz = from->get_zsize();
02093
02094 int new_nx = static_cast<int>( static_cast<float> (nx) / sample_rate);
02095 int new_ny = static_cast<int>( static_cast<float> (ny) / sample_rate);
02096 int new_nz = static_cast<int>( static_cast<float> (nz) / sample_rate);
02097
02098 if (new_nx == 0) throw UnexpectedBehaviorException("The resample rate causes the pixel dimensions in the x direction to go to zero");
02099 if (new_ny == 0) new_ny = 1;
02100 if (new_nz == 0) new_nz = 1;
02101
02102 int ndim = from->get_ndim();
02103 if ( ndim < 3 ) {
02104 new_nz = 1;
02105 }
02106 if ( ndim < 2 ) {
02107 new_ny = 1;
02108 }
02109
02110 int fft_x_correction = 1;
02111 if (new_nx % 2 == 0) fft_x_correction = 2;
02112
02113 int fft_y_correction = 0;
02114 if (ny != 1 && new_ny % 2 == 0 && ny % 2 == 1) fft_y_correction = 1;
02115 else if (ny != 1 && new_ny % 2 == 1 && ny % 2 == 0) fft_y_correction = -1;
02116
02117 int fft_z_correction = 0;
02118 if (nz != 1 && new_nz % 2 == 0 && nz % 2 == 1) fft_z_correction = 1;
02119 else if (nz != 1 && new_nz % 2 == 1 && nz % 2 == 0) fft_z_correction = -1;
02120
02121 if ( ! to->is_complex()) to->do_fft_inplace();
02122
02123 if (ndim != 1) to->process_inplace("xform.fourierorigin.tocenter");
02124
02125 Region clip(0,(ny-new_ny)/2-fft_y_correction,(nz-new_nz)/2-fft_z_correction,new_nx+fft_x_correction,new_ny,new_nz);
02126 to->clip_inplace(clip);
02127
02128 if (fft_x_correction == 1) to->set_fftodd(true);
02129 else to->set_fftodd(false);
02130
02131 if (ndim != 1) to->process_inplace("xform.fourierorigin.tocorner");
02132
02133 to->do_ift_inplace();
02134 to->depad_corner();
02135
02136 }
|
|
|
Get the descrition of this specific processor. This function must be overwritten by a subclass.
Implements EMAN::Processor. Definition at line 3513 of file processor.h. 03514 {
03515 return "Robust resampling of an image by clipping its Fourier transform.";
03516 }
|
|
|
Get the processor's name. Each processor is identified by a unique name.
Implements EMAN::Processor. Definition at line 3518 of file processor.h. 03519 {
03520 return NAME;
03521 }
|
|
|
Get processor parameter information in a dictionary. Each parameter has one record in the dictionary. Each record contains its name, data-type, and description.
Reimplemented from EMAN::Processor. Definition at line 3527 of file processor.h. References EMAN::TypeDict::put(). 03528 {
03529 TypeDict d;
03530 d.put("n", EMObject::FLOAT, "The sample rate. Less than one enlarges the image, greater than one shrinks it.");
03531 return d;
03532 }
|
|
|
Definition at line 3522 of file processor.h. 03523 {
03524 return new FFTResampleProcessor();
03525 }
|
|
|
To proccess an image out-of-place. For those processors which can only be processed out-of-place, override this function to give the right behavior.
Reimplemented from EMAN::Processor. Definition at line 2054 of file processor.cpp. References EMAN::EMData::copy(), EMAN::EMData::do_fft(), fft_resample(), InvalidValueException, EMAN::EMData::is_complex(), EMAN::EMData::scale_pixel(), EMAN::Dict::set_default(), and EMAN::EMData::update(). 02055 {
02056 float sample_rate = params.set_default("n",0.0f);
02057 if (sample_rate <= 0.0F ) {
02058 throw InvalidValueException(sample_rate, "sample rate must be >0 ");
02059 }
02060
02061 EMData* result;
02062 if (image->is_complex()) result = image->copy();
02063 else result = image->do_fft();
02064 fft_resample(result,image,sample_rate);
02065 // The image may have been padded - we should shift it so that the phase origin is where FFTW expects it
02066 result->update();
02067 result->scale_pixel(sample_rate);
02068 return result;
02069 }
|
|
|
To process an image in-place. For those processors which can only be processed out-of-place, override this function to just print out some error message to remind user call the out-of-place version.
Implements EMAN::Processor. Definition at line 2071 of file processor.cpp. References fft_resample(), ImageFormatException, InvalidValueException, EMAN::EMData::is_complex(), EMAN::EMData::scale_pixel(), EMAN::Dict::set_default(), and EMAN::EMData::update(). 02072 {
02073 if (image->is_complex()) throw ImageFormatException("Error, the fft resampling processor does not work on complex images");
02074
02075
02076 float sample_rate = params.set_default("n",0.0f);
02077 if (sample_rate <= 0.0F ) {
02078 throw InvalidValueException(sample_rate, "sample rate (n) must be >0 ");
02079 }
02080
02081 fft_resample(image,image,sample_rate);
02082
02083 image->scale_pixel(sample_rate);
02084 image->update();
02085
02086
02087 }
|
|
|
Definition at line 127 of file processor.cpp. |
1.3.9.1