EMAN::FFTResampleProcessor Class Reference

FFTResampleProcessor resamples an image by clipping the Fourier Transform This is the same as multipyling the FT by a box window, in real space this is a convolution that will induce rippling. More...

#include <processor.h>

Inheritance diagram for EMAN::FFTResampleProcessor:

Inheritance graph
[legend]
Collaboration diagram for EMAN::FFTResampleProcessor:

Collaboration graph
[legend]
List of all members.

Public Member Functions

virtual EMDataprocess (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 ProcessorNEW ()

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.

Detailed Description

FFTResampleProcessor resamples an image by clipping the Fourier Transform This is the same as multipyling the FT by a box window, in real space this is a convolution that will induce rippling.

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)

Author:
David Woolford
Date:
June 2009
Parameters:
n sampe_rate

Definition at line 3450 of file processor.h.


Member Function Documentation

void FFTResampleProcessor::fft_resample ( EMData to,
const EMData *const   from,
const float &  sample_rate 
) [private]

An internal function that encapsulates a routine common to both process and process inplace.

Parameters:
to the smaller image that will store the shrunken values
from the larger image that will be used to calculate the shrunken values
shrinkfactor the shrink amount

Definition at line 2058 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().

02058                                                                                                       {
02059         int nx = from->get_xsize();
02060         int ny = from->get_ysize();
02061         int nz = from->get_zsize();
02062 
02063         int new_nx = static_cast<int>( static_cast<float> (nx) / sample_rate);
02064         int new_ny = static_cast<int>( static_cast<float> (ny) / sample_rate);
02065         int new_nz = static_cast<int>( static_cast<float> (nz) / sample_rate);
02066 
02067         if (new_nx == 0) throw UnexpectedBehaviorException("The resample rate causes the pixel dimensions in the x direction to go to zero");
02068         if (new_ny == 0) new_ny = 1;
02069         if (new_nz == 0) new_nz = 1;
02070 
02071         int ndim = from->get_ndim();
02072         if ( ndim < 3 ) {
02073                 new_nz = 1;
02074         }
02075         if ( ndim < 2 ) {
02076                 new_ny = 1;
02077         }
02078 
02079         int fft_x_correction = 1;
02080         if (new_nx % 2 == 0) fft_x_correction = 2;
02081 
02082         int fft_y_correction = 0;
02083         if (ny != 1 && new_ny % 2 == 0 && ny % 2 == 1) fft_y_correction = 1;
02084         else if (ny != 1 && new_ny % 2 == 1 && ny % 2 == 0) fft_y_correction = -1;
02085 
02086         int fft_z_correction = 0;
02087         if (nz != 1 && new_nz % 2 == 0 && nz % 2 == 1) fft_z_correction = 1;
02088         else if (nz != 1 && new_nz % 2 == 1 && nz % 2 == 0) fft_z_correction = -1;
02089 
02090         if ( ! to->is_complex()) to->do_fft_inplace();
02091 
02092         if (ndim != 1) to->process_inplace("xform.fourierorigin.tocenter");
02093 
02094         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);
02095         to->clip_inplace(clip);
02096 
02097         if (fft_x_correction == 1) to->set_fftodd(true);
02098         else to->set_fftodd(false);
02099 
02100         if (ndim != 1) to->process_inplace("xform.fourierorigin.tocorner");
02101 
02102         to->do_ift_inplace();
02103         to->depad_corner();
02104 
02105 }

string EMAN::FFTResampleProcessor::get_desc (  )  const [inline, virtual]

Get the descrition of this specific processor.

This function must be overwritten by a subclass.

Returns:
The description of this processor.

Implements EMAN::Processor.

Definition at line 3457 of file processor.h.

03458                         {
03459                                 return "Robust resampling of an image by clipping its Fourier transform.";
03460                         }

string EMAN::FFTResampleProcessor::get_name (  )  const [inline, virtual]

Get the processor's name.

Each processor is identified by a unique name.

Returns:
The processor's name.

Implements EMAN::Processor.

Definition at line 3462 of file processor.h.

References NAME.

03463                         {
03464                                 return NAME;
03465                         }

TypeDict EMAN::FFTResampleProcessor::get_param_types (  )  const [inline, virtual]

Get processor parameter information in a dictionary.

Each parameter has one record in the dictionary. Each record contains its name, data-type, and description.

Returns:
A dictionary containing the parameter info.

Reimplemented from EMAN::Processor.

Definition at line 3471 of file processor.h.

References EMAN::EMObject::FLOAT, and EMAN::TypeDict::put().

03472                         {
03473                                 TypeDict d;
03474                                 d.put("n", EMObject::FLOAT, "The sample rate. Less than one enlarges the image, greater than one shrinks it.");
03475                                 return d;
03476                         }

static Processor* EMAN::FFTResampleProcessor::NEW (  )  [inline, static]

Definition at line 3466 of file processor.h.

03467                         {
03468                                 return new FFTResampleProcessor();
03469                         }

EMData * FFTResampleProcessor::process ( const EMData *const   image  )  [virtual]

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.

Parameters:
image The image will be copied, actual process happen on copy of image.
Returns:
the image processing result, may or may not be the same size of the input image

Reimplemented from EMAN::Processor.

Definition at line 2023 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().

02024 {
02025         float sample_rate = params.set_default("n",0.0f);
02026         if (sample_rate <= 0.0F  )  {
02027                 throw InvalidValueException(sample_rate,        "sample rate must be >0 ");
02028         }
02029 
02030         EMData* result;
02031         if (image->is_complex()) result = image->copy();
02032         else result = image->do_fft();
02033         fft_resample(result,image,sample_rate);
02034         // The image may have been padded - we should shift it so that the phase origin is where FFTW expects it
02035         result->update();
02036         result->scale_pixel(sample_rate);
02037         return result;
02038 }

void FFTResampleProcessor::process_inplace ( EMData image  )  [virtual]

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.

Parameters:
image The image to be processed.

Implements EMAN::Processor.

Definition at line 2040 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().

02041 {
02042         if (image->is_complex()) throw ImageFormatException("Error, the fft resampling processor does not work on complex images");
02043 
02044 
02045         float sample_rate = params.set_default("n",0.0f);
02046         if (sample_rate <= 0.0F  )  {
02047                 throw InvalidValueException(sample_rate,        "sample rate (n) must be >0 ");
02048         }
02049 
02050         fft_resample(image,image,sample_rate);
02051 
02052         image->scale_pixel(sample_rate);
02053         image->update();
02054 
02055 
02056 }


Member Data Documentation

const string FFTResampleProcessor::NAME = "math.fft.resample" [static]

Definition at line 3478 of file processor.h.

Referenced by get_name().


The documentation for this class was generated from the following files:
Generated on Mon Mar 7 18:02:43 2011 for EMAN2 by  doxygen 1.4.7