#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 | |
static Processor * | NEW () |
Static Public Attributes | |
static 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 3581 of file processor.h.
|
An internal function that encapsulates a routine common to both process and process inplace.
Definition at line 2149 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(), EMAN::EMData::process_inplace(), EMAN::EMData::set_fftodd(), and UnexpectedBehaviorException. Referenced by process(), and process_inplace(). 02149 { 02150 int nx = from->get_xsize(); 02151 int ny = from->get_ysize(); 02152 int nz = from->get_zsize(); 02153 02154 int new_nx = static_cast<int>( static_cast<float> (nx) / sample_rate); 02155 int new_ny = static_cast<int>( static_cast<float> (ny) / sample_rate); 02156 int new_nz = static_cast<int>( static_cast<float> (nz) / sample_rate); 02157 02158 if (new_nx == 0) throw UnexpectedBehaviorException("The resample rate causes the pixel dimensions in the x direction to go to zero"); 02159 if (new_ny == 0) new_ny = 1; 02160 if (new_nz == 0) new_nz = 1; 02161 02162 int ndim = from->get_ndim(); 02163 if ( ndim < 3 ) { 02164 new_nz = 1; 02165 } 02166 if ( ndim < 2 ) { 02167 new_ny = 1; 02168 } 02169 02170 int fft_x_correction = 1; 02171 if (new_nx % 2 == 0) fft_x_correction = 2; 02172 02173 int fft_y_correction = 0; 02174 if (ny != 1 && new_ny % 2 == 0 && ny % 2 == 1) fft_y_correction = 1; 02175 else if (ny != 1 && new_ny % 2 == 1 && ny % 2 == 0) fft_y_correction = -1; 02176 02177 int fft_z_correction = 0; 02178 if (nz != 1 && new_nz % 2 == 0 && nz % 2 == 1) fft_z_correction = 1; 02179 else if (nz != 1 && new_nz % 2 == 1 && nz % 2 == 0) fft_z_correction = -1; 02180 02181 if ( ! to->is_complex()) to->do_fft_inplace(); 02182 02183 if (ndim != 1) to->process_inplace("xform.fourierorigin.tocenter"); 02184 02185 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); 02186 to->clip_inplace(clip); 02187 02188 if (fft_x_correction == 1) to->set_fftodd(true); 02189 else to->set_fftodd(false); 02190 02191 if (ndim != 1) to->process_inplace("xform.fourierorigin.tocorner"); 02192 02193 to->do_ift_inplace(); 02194 to->depad_corner(); 02195 02196 }
|
|
Get the descrition of this specific processor. This function must be overwritten by a subclass.
Implements EMAN::Processor. Definition at line 3588 of file processor.h.
|
|
Get the processor's name. Each processor is identified by a unique name.
Implements EMAN::Processor. Definition at line 3593 of file processor.h. References NAME. 03594 { 03595 return NAME; 03596 }
|
|
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 3602 of file processor.h. References EMAN::EMObject::FLOAT, and EMAN::TypeDict::put(). 03603 { 03604 TypeDict d; 03605 d.put("n", EMObject::FLOAT, "The sample rate. Less than one enlarges the image, greater than one shrinks it."); 03606 return d; 03607 }
|
|
Definition at line 3597 of file processor.h. 03598 { 03599 return new FFTResampleProcessor(); 03600 }
|
|
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 2114 of file processor.cpp. References EMAN::EMData::copy(), EMAN::EMData::do_fft(), fft_resample(), InvalidValueException, EMAN::EMData::is_complex(), EMAN::Processor::params, EMAN::EMData::scale_pixel(), EMAN::Dict::set_default(), and EMAN::EMData::update(). 02115 { 02116 float sample_rate = params.set_default("n",0.0f); 02117 if (sample_rate <= 0.0F ) { 02118 throw InvalidValueException(sample_rate, "sample rate must be >0 "); 02119 } 02120 02121 EMData* result; 02122 if (image->is_complex()) result = image->copy(); 02123 else result = image->do_fft(); 02124 fft_resample(result,image,sample_rate); 02125 // The image may have been padded - we should shift it so that the phase origin is where FFTW expects it 02126 result->update(); 02127 result->scale_pixel(sample_rate); 02128 return result; 02129 }
|
|
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 2131 of file processor.cpp. References fft_resample(), ImageFormatException, InvalidValueException, EMAN::EMData::is_complex(), EMAN::Processor::params, EMAN::EMData::scale_pixel(), EMAN::Dict::set_default(), and EMAN::EMData::update(). 02132 { 02133 if (image->is_complex()) throw ImageFormatException("Error, the fft resampling processor does not work on complex images"); 02134 02135 02136 float sample_rate = params.set_default("n",0.0f); 02137 if (sample_rate <= 0.0F ) { 02138 throw InvalidValueException(sample_rate, "sample rate (n) must be >0 "); 02139 } 02140 02141 fft_resample(image,image,sample_rate); 02142 02143 image->scale_pixel(sample_rate); 02144 image->update(); 02145 02146 02147 }
|
|
Definition at line 3609 of file processor.h. Referenced by get_name(). |