EMAN2
Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | List of all members
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]

Public Member Functions

virtual EMDataprocess (const EMData *const image)
 To proccess an image out-of-place. More...
 
virtual void process_inplace (EMData *image)
 To process an image in-place. More...
 
string get_desc () const
 Get the descrition of this specific processor. More...
 
string get_name () const
 Get the processor's name. More...
 
TypeDict get_param_types () const
 Get processor parameter information in a dictionary. More...
 
- Public Member Functions inherited from EMAN::Processor
virtual ~Processor ()
 
virtual void process_list_inplace (vector< EMData * > &images)
 To process multiple images using the same algorithm. More...
 
virtual Dict get_params () const
 Get the processor parameters in a key/value dictionary. More...
 
virtual void set_params (const Dict &new_params)
 Set the processor parameters using a key/value dictionary. More...
 

Static Public Member Functions

static ProcessorNEW ()
 
- Static Public Member Functions inherited from EMAN::Processor
static string get_group_desc ()
 Get the description of this group of processors. More...
 
static void EMFourierFilterInPlace (EMData *fimage, Dict params)
 Compute a Fourier-filter processed image in place. More...
 
static EMDataEMFourierFilter (EMData *fimage, Dict params)
 Compute a Fourier-processor processed image without altering the original image. More...
 

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. More...
 

Additional Inherited Members

- Public Types inherited from EMAN::Processor
enum  fourier_filter_types {
  TOP_HAT_LOW_PASS , TOP_HAT_HIGH_PASS , TOP_HAT_BAND_PASS , TOP_HOMOMORPHIC ,
  GAUSS_LOW_PASS , GAUSS_HIGH_PASS , GAUSS_BAND_PASS , GAUSS_INVERSE ,
  GAUSS_HOMOMORPHIC , BUTTERWORTH_LOW_PASS , BUTTERWORTH_HIGH_PASS , BUTTERWORTH_HOMOMORPHIC ,
  KAISER_I0 , KAISER_SINH , KAISER_I0_INVERSE , KAISER_SINH_INVERSE ,
  SHIFT , TANH_LOW_PASS , TANH_HIGH_PASS , TANH_HOMOMORPHIC ,
  TANH_BAND_PASS , RADIAL_TABLE , CTF_
}
 Fourier filter Processor type enum. More...
 
- Protected Attributes inherited from EMAN::Processor
Dict params
 

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 (fixed by Pawel Penczek, 2017)
Date
June 2009
Parameters
nsampe_rate

Definition at line 5130 of file processor.h.

Member Function Documentation

◆ fft_resample()

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
tothe smaller image that will store the shrunken values
fromthe larger image that will be used to calculate the shrunken values
shrinkfactorthe shrink amount

Definition at line 3074 of file processor.cpp.

3074 {
3075 int nx = from->get_xsize();
3076 int ny = from->get_ysize();
3077 int nz = from->get_zsize();
3078
3079 int new_nx = static_cast<int>( static_cast<float> (nx) / sample_rate);
3080 int new_ny = static_cast<int>( static_cast<float> (ny) / sample_rate);
3081 int new_nz = static_cast<int>( static_cast<float> (nz) / sample_rate);
3082
3083 if (new_nx == 0) throw UnexpectedBehaviorException("The resample rate causes the pixel dimensions in the x direction to go to zero");
3084 if (new_ny == 0) new_ny = 1;
3085 if (new_nz == 0) new_nz = 1;
3086
3087 int ndim = from->get_ndim();
3088 if ( ndim < 3 ) {
3089 new_nz = 1;
3090 }
3091 if ( ndim < 2 ) {
3092 new_ny = 1;
3093 }
3094
3095 int fft_x_correction = 1;
3096 if (new_nx % 2 == 0) fft_x_correction = 2;
3097
3098 int fft_y_correction = 0;
3099 if (ny != 1 && new_ny % 2 == 0 && ny % 2 == 1) fft_y_correction = 1;
3100 else if (ny != 1 && new_ny % 2 == 1 && ny % 2 == 0) fft_y_correction = -1;
3101
3102 int fft_z_correction = 0;
3103 if (nz != 1 && new_nz % 2 == 0 && nz % 2 == 1) fft_z_correction = 1;
3104 else if (nz != 1 && new_nz % 2 == 1 && nz % 2 == 0) fft_z_correction = -1;
3105
3106 if ( ! to->is_complex()) to->do_fft_inplace();
3107
3108 if (ndim != 1) to->process_inplace("xform.fourierorigin.tocenter");
3109
3110 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);
3111 to->clip_inplace(clip);
3112
3113 if (fft_x_correction == 1) to->set_fftodd(true);
3114 else to->set_fftodd(false);
3115
3116 if (ndim != 1) to->process_inplace("xform.fourierorigin.tocorner");
3117
3118 to->do_ift_inplace();
3119 to->depad_corner();
3120
3121}
void clip_inplace(const Region &area, const float &fill_value=0)
Clip the image inplace - clipping region must be smaller than the current region internally memory is...
Definition: emdata.cpp:350
Region defines a 2D or 3D rectangular region specified by its origin coordinates and all edges' sizes...
Definition: geometry.h:497
#define UnexpectedBehaviorException(desc)
Definition: exception.h:400

References EMAN::EMData::clip_inplace(), and UnexpectedBehaviorException.

◆ get_desc()

string EMAN::FFTResampleProcessor::get_desc ( ) const
inlinevirtual

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 5137 of file processor.h.

5138 {
5139 return "Robust resampling of an image by clipping its Fourier transform.";
5140 }

◆ get_name()

string EMAN::FFTResampleProcessor::get_name ( ) const
inlinevirtual

Get the processor's name.

Each processor is identified by a unique name.

Returns
The processor's name.

Implements EMAN::Processor.

Definition at line 5142 of file processor.h.

5143 {
5144 return NAME;
5145 }
static const string NAME
Definition: processor.h:5158

References NAME.

◆ get_param_types()

TypeDict EMAN::FFTResampleProcessor::get_param_types ( ) const
inlinevirtual

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 5151 of file processor.h.

5152 {
5153 TypeDict d;
5154 d.put("n", EMObject::FLOAT, "The sample rate. Less than one enlarges the image, greater than one shrinks it.");
5155 return d;
5156 }
TypeDict is a dictionary to store <string, EMObject::ObjectType> pair.
Definition: emobject.h:305
void put(const string &key, EMObject::ObjectType o, const string &desc="")
Definition: emobject.h:330

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

◆ NEW()

static Processor * EMAN::FFTResampleProcessor::NEW ( )
inlinestatic

Definition at line 5146 of file processor.h.

5147 {
5148 return new FFTResampleProcessor();
5149 }
FFTResampleProcessor resamples an image by clipping the Fourier Transform This is the same as multipy...
Definition: processor.h:5131

◆ process()

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
imageThe 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 2989 of file processor.cpp.

2990{
2991 if (image->is_complex()) throw ImageFormatException("FFTResampleProcessor does not support complex images.");
2992
2993 float sample_rate = params.set_default("n",0.0f);
2994 if (sample_rate <= 0.0F ) {
2995 throw InvalidValueException(sample_rate, "downsampling must be >0 ");
2996 }
2997
2998 int nx=image->get_xsize();
2999 int ny=image->get_ysize();
3000 int nz=image->get_zsize();
3001
3002 int nnx=(int)floor(nx/sample_rate+0.5f);
3003 int nny=(ny==1?1:(int)floor(ny/sample_rate+0.5f));
3004 int nnz=(nz==1?1:(int)floor(nz/sample_rate+0.5f));
3005
3006 if (nnx==nx && nny==ny && nnz==nz) return image->copy();
3007
3008 EMData *result;
3009 //downsample
3010 if (nnx<nx||nny<ny||nnz<nz) {
3011 // the type casting here is because FourTruncate was not defined to be const (but it is)
3012 result=((EMData *)image)->FourTruncate(nnx, nny, nnz, 1, 0); // nnx,nny,nnz,returnreal,normalize
3013 } //upscale
3014 else {
3015 // the type casting here is because FourTruncate was not defined to be const (but it is)
3016 result=((EMData *)image)->FourInterpol(nnx, nny, nnz, 1, 0); // nnx,nny,nnz,returnreal,normalize
3017 }
3018 result->scale_pixel((float)nx/(float)nnx);
3019 result->update();
3020 return result;
3021
3022
3023// EMData* result;
3024// if (image->is_complex()) result = image->copy();
3025// else result = image->do_fft();
3026// fft_resample(result,image,sample_rate);
3027 // The image may have been padded - we should shift it so that the phase origin is where FFTW expects it
3028// result->update();
3029// result->scale_pixel(sample_rate);
3030// return result;
3031}
type set_default(const string &key, type val)
Default setting behavior This can be achieved using a template - d.woolford Jan 2008 (before there wa...
Definition: emobject.h:569
EMData stores an image's data and defines core image processing routines.
Definition: emdata.h:82
#define InvalidValueException(val, desc)
Definition: exception.h:285
#define ImageFormatException(desc)
Definition: exception.h:147

References ImageFormatException, InvalidValueException, EMAN::Processor::params, and EMAN::Dict::set_default().

◆ process_inplace()

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
imageThe image to be processed.

Implements EMAN::Processor.

Definition at line 3033 of file processor.cpp.

3034{
3035 float sample_rate = params.set_default("n",0.0f);
3036 if (sample_rate <= 0.0F ) {
3037 throw InvalidValueException(sample_rate, "sample rate (n) must be >0 ");
3038 }
3039 //if (image->is_complex()) throw ImageFormatException("Error, the fft resampling processor does not work on complex images");
3040
3041 int nx=image->get_xsize();
3042 int ny=image->get_ysize();
3043 int nz=image->get_zsize();
3044
3045 int nnx=(int)floor(nx/sample_rate+0.5f);
3046 int nny=(ny==1?1:(int)floor(ny/sample_rate+0.5f));
3047 int nnz=(nz==1?1:(int)floor(nz/sample_rate+0.5f));
3048
3049 if (nnx==nx && nny==ny && nnz==nz) return;
3050
3051 EMData *result;
3052 //downsample
3053 if (nnx<nx||nny<ny||nnz<nz) {
3054 // the type casting here is because FourTruncate was not defined to be const (but it is)
3055 result=((EMData *)image)->FourTruncate(nnx, nny, nnz, 1, 0); // nnx,nny,nnz,returnreal,normalize
3056 } //upscale
3057 else {
3058 // the type casting here is because FourTruncate was not defined to be const (but it is)
3059 result=((EMData *)image)->FourInterpol(nnx, nny, nnz, 1, 0); // nnx,nny,nnz,returnreal,normalize
3060 }
3061
3062 image->set_size(nnx,nny,nnz);
3063 memcpy(image->get_data(),result->get_data(),nnx*nny*nnz*sizeof(float));
3064 image->scale_pixel((float)nx/(float)nnx);
3065 image->update();
3066 delete result;
3067
3068 //fft_resample(image,image,sample_rate);
3069
3070 //image->scale_pixel(sample_rate);
3071
3072}

References InvalidValueException, EMAN::Processor::params, and EMAN::Dict::set_default().

Member Data Documentation

◆ NAME

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

Definition at line 5158 of file processor.h.

Referenced by get_name().


The documentation for this class was generated from the following files: