EMAN2
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
EMAN::RotateInFSProcessor Class Reference

#include <processor.h>

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

Public Member Functions

virtual void process_inplace (EMData *image)
 To process an image in-place. More...
 
virtual EMDataprocess (const EMData *const image)
 To proccess an image out-of-place. More...
 
virtual string get_name () const
 Get the processor's name. More...
 
string get_desc () const
 Get the descrition of this specific processor. More...
 
virtual 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 = "rotateinfs"
 

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

Definition at line 9366 of file processor.h.

Member Function Documentation

◆ get_desc()

string EMAN::RotateInFSProcessor::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 9381 of file processor.h.

9382 {
9383 return "Rotates a Fourier object using a kernel.";
9384 }

◆ get_name()

virtual string EMAN::RotateInFSProcessor::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 9373 of file processor.h.

9374 {
9375 return NAME;
9376 }
static const string NAME
Definition: processor.h:9394

References NAME.

◆ get_param_types()

virtual TypeDict EMAN::RotateInFSProcessor::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 9385 of file processor.h.

9386 {
9387 TypeDict d;
9388 d.put("transform", EMObject::TRANSFORM, "transform");
9389 d.put("interpCutoff", EMObject::FLOAT, "cutoff for interpolation");
9390// d.put("offset", EMObject::FLOAT, "offset for FT centering");
9391// d.put("angle", EMObject::FLOAT, "angle");
9392 return d;
9393 }
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, EMAN::TypeDict::put(), and EMAN::EMObject::TRANSFORM.

◆ NEW()

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

Definition at line 9377 of file processor.h.

9378 {
9379 return new RotateInFSProcessor( );
9380 }

◆ process()

EMData * RotateInFSProcessor::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 14195 of file processor.cpp.

14196{
14197
14198 EMData* imageCp = image -> copy(); // This is the rotated image
14199 process_inplace(imageCp);
14200
14201 return imageCp;
14202}
EMData stores an image's data and defines core image processing routines.
Definition: emdata.h:82
virtual void process_inplace(EMData *image)
To process an image in-place.
EMData * copy() const
This file is a part of "emdata.h", to use functions in this file, you should "#include "emdata....

References copy(), and process_inplace().

◆ process_inplace()

void RotateInFSProcessor::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 14205 of file processor.cpp.

14206{
14207// float angle = params["angle"];
14208
14209
14210// Transform *rotNow = params.set_default("transform",&Transform());
14211 Transform *rotNow = params["transform"];
14212 float interpCutoff = params.set_default("interpCutoff",0.8f); // JFF, can you move this to input parameter?
14213// float interpCutoff = params["interpCutoff"]; // JFF, can you move this to input parameter?
14214// float interpCutoff =.8; // JFF, can you move this to input parameter?
14215
14216
14217 int debug=0;
14218
14219// error: conversion from 'EMAN::EMObject' to non-scalar type 'EMAN::Transform' requested
14220
14221
14222 // if 2N is size of image, then sizes of FFT are (2N+2,2N,2N) or (2N+2,2N,1)
14223 // if 2N+1 is size of image, then sizes of FFT are (2N+2,2N+1,2N+1) or (2N+2,2N+1,1)
14224
14225 int x_size = image->get_xsize(); //16
14226 int y_size = image->get_ysize(); int y_odd= (y_size%2);
14227 int z_size = image->get_zsize();
14228
14229// float size_check = abs(y_size-z_size)+abs(x_size-y_size-2+y_odd);
14230// if (size_check!=0) throw ImageDimensionException("Only cubic images");
14231 int size_check = abs(x_size-y_size-2+y_odd)+ abs(z_size-1)*abs(z_size-y_size);
14232 int N = x_size/2-1;
14233 int Mid = N+1;
14234 if (size_check!=0) throw ImageDimensionException("Only square or cubic images for now");
14235 if (image->is_real()) throw ImageDimensionException("Only for Fourier images");
14236// if (y_odd==0) throw ImageDimensionException("Only use odd images for now");
14237
14238 if (debug) printf("Mid=%d, x_size=%d, y_size=%d, N=%d, z_size=%d \n", Mid,x_size,y_size, N, z_size );
14239
14240 EMData* RotIm = image -> copy(); // This is the rotated image
14241 EMData* WeightIm = image -> copy(); WeightIm ->to_zero();// This is the Weight image for rotated image
14242 EMData* PhaseOrigIm = new EMData(N+1,2*N+1,z_size) ; PhaseOrigIm ->to_zero();// This is the Weight image for rotated image
14243 EMData* PhaseFinalIm = PhaseOrigIm -> copy(); PhaseFinalIm ->to_zero();// This is the Weight image for rotated image
14244 EMData* MagFinalIm = PhaseOrigIm -> copy(); MagFinalIm ->to_zero();// This is the Weight image for rotated image
14245
14246// float* data = image -> get_data();
14247// float* Rotdata = RotIm -> get_data(); // This is the data of the rotated image
14248// float* WeightData = WeightIm -> get_data(); //
14249
14250 float WeightNowX, WeightNowY, WeightNowZ ;
14251 int kxMin,kxMax, kyMin, kyMax, kzMin, kzMax, kxBefore, kyBefore, kzBefore ;
14252 float kxRT, kyRT, kzRT ;
14253
14254 Vec3f PosAfter;
14255 Vec3f PosBefore;
14256 Transform invRotNow;
14257 // Fill out real and imaginary full images
14258
14259 //int kz=0;
14260
14261 if (debug) {image -> write_image("OrigImageFFT.hdf");
14262 printf("Just wrote OrigImageFFT.hdf \n"); }
14263
14264
14265 for (kxBefore = 0; kxBefore <= N ; ++kxBefore) { // These are the kx, ky coordinates of the original image
14266 for (kyBefore = 0; kyBefore < y_size ; ++kyBefore) { // We need to rephase
14267 for (kzBefore = 0; kzBefore < z_size ; ++kzBefore) { // We need to rephase
14268
14269 // Now we need a
14270 float CurrentReal = RotIm -> get_value_at(2*kxBefore ,kyBefore, kzBefore);
14271 float CurrentImag = RotIm -> get_value_at(2*kxBefore+1,kyBefore, kzBefore);
14272
14273// fftOfxPRB3(1+mod(ik-Mid,N))=Grand*exp(-2*pi*1i*Mid*(ik-Mid)/x_size); % Phase to apply to centered version
14274
14275// float Phase = -2*pi*(kxBefore+kyBefore + kzBefore)*(Mid)/y_size;
14276 float Phase = -pi*(kxBefore+kyBefore + kzBefore)*x_size/y_size;
14277 // Phase = 0;
14278 float CosPhase = cos( Phase);
14279 float SinPhase = sin( Phase);
14280
14281 float NewRealValue = CosPhase*CurrentReal -SinPhase*CurrentImag;
14282 float NewImagValue = SinPhase*CurrentReal +CosPhase*CurrentImag;
14283
14284 RotIm ->set_value_at(2*kxBefore ,kyBefore, kzBefore, NewRealValue);
14285 RotIm ->set_value_at(2*kxBefore+1,kyBefore, kzBefore, NewImagValue);
14286 }}}
14287
14288 if (debug) {RotIm -> write_image("OrigImageFFTAfterPhaseCorrection.hdf");
14289 printf(" Just wrote OrigImageFFTAfterPhaseCorrection.hdf \n");}
14290
14291 // RotIm ->set_value_at(2*Mid-1,0, 0, 0);
14292 if (debug) printf(" Just about to start second loop \n");
14293
14294 image ->to_zero();
14295 invRotNow = rotNow ->inverse(); // no match for 'operator=' in 'PosBefore = EMAN::operator*(const EMAN::Transform&, const EMAN::Transform&)((
14296
14297
14298 for (int kxAfter = 0; kxAfter <= N ; ++kxAfter) { // These are the kx, ky, kz coordinates of the rotated image
14299 for (int kyAfter = -N; kyAfter < y_size-N ; ++kyAfter) { // referring to a properly centered version
14300 for (int kzAfter = -z_size/2; kzAfter <= z_size/2 ; ++kzAfter) {
14301
14302 // Now we need a
14303
14304 PosAfter = Vec3f(kxAfter, kyAfter, kzAfter);
14305 PosBefore = invRotNow*PosAfter;
14306 kxRT = PosBefore[0]; // This will be the off-lattice site, where the point was rotated from
14307 kyRT = PosBefore[1]; //
14308 kzRT = PosBefore[2]; //
14309
14310
14311 kxMin = ceil( kxRT-interpCutoff); kxMax = floor(kxRT+interpCutoff);
14312 kyMin = ceil( kyRT-interpCutoff); kyMax = floor(kyRT+interpCutoff);
14313 kzMin = ceil( kzRT-interpCutoff); kzMax = floor(kzRT+interpCutoff);
14314
14315
14316// printf("Block 0,kx=%d, ky=%d,kxMin=%d, kyMin=%d, kxMax=%d, kyMax=%d, kyAfter=%d \n",kxAfter,kyAfter,kxMin,kyMin, kxMax, kyMax, kyAfter);
14317 //continue;
14318 for (int kxI= kxMin; kxI <= kxMax; ++kxI){ // go through this
14319 for (int kyI= kyMin; kyI <= kyMax; ++kyI){ // and get values to interp
14320 for (int kzI= kzMin; kzI <= kzMax; ++kzI){ //
14321
14322//
14323 if (abs(kxI) >N) continue; // don't go off the lattice
14324 if (abs(kyI) >N) continue;
14325 if (abs(kzI) >z_size/2) continue;
14326
14327 float distx= abs(kxI-kxRT);
14328 float disty= abs(kyI-kyRT);
14329 float distz= abs(kzI-kzRT);
14330
14331 // fold kxI, kyI back into lattice if possible
14332 int IsComplexConj= 1;
14333
14334 if (kxI<0) IsComplexConj=-1;
14335 kxBefore= IsComplexConj*kxI; // The Proper coordinates will be
14336 kyBefore= IsComplexConj*kyI; // where the original data is stored
14337 kzBefore= IsComplexConj*kzI; // At this point kxBefore >=0, but not necessarily kyBefore
14338
14339 if ( kyBefore<0 ) kyBefore += y_size; // makes sure kyBefore is also >0
14340 if ( kzBefore<0 ) kzBefore += y_size; // makes sure kzBefore is also >0
14341
14342 WeightNowX = (distx ==0)? 1: (sin(pi*distx) /(pi*distx)) ;
14343 WeightNowY = (disty ==0)? 1: (sin(pi*disty) /(pi*disty)) ;
14344 WeightNowZ = (distz ==0)? 1: (sin(pi*distz) /(pi*distz)) ;
14345
14346
14347 float CurrentValue;
14348 float ToAdd;
14349 int kyAfterInd = (kyAfter+y_size)%(y_size);
14350 int kzAfterInd = (kzAfter+z_size)%(z_size);
14351
14352 // if (kxAfter==0) IsComplexConj*=-1;
14353
14354// if ((kxI+kyI)%1 ==0)
14355// printf("Block5,kx=%d, ky=%d,kxI=%d, kyI=%d, kxBefore=%d, kyBefore=%d \n",kxAfter,kyAfter,kxI,kyI, kxBefore,kyBefore);
14356// printf(" %d, %d, %d, %d, %d, %d, %d, %d \n",IsComplexConj,kxAfter,kyAfter, kyAfterInd,kxI,kyI, kxBefore,kyBefore);
14357
14358 CurrentValue = image -> get_value_at(2*kxAfter,kyAfterInd, kzAfterInd); // Update real part of Image
14359 ToAdd = WeightNowX*WeightNowY*WeightNowZ*(RotIm -> get_value_at(2*kxBefore,kyBefore, kzBefore));
14360 image -> set_value_at(2*kxAfter ,kyAfterInd , kzAfterInd, ToAdd + CurrentValue );
14361
14362
14363 CurrentValue = WeightIm -> get_value_at(kxAfter,kyAfterInd, kzAfterInd); // Update real part of Weight image
14364 ToAdd = WeightNowX*WeightNowY;
14365 WeightIm -> set_value_at(kxAfter , kyAfterInd , kzAfterInd, abs(ToAdd) + CurrentValue );
14366
14367 CurrentValue = image -> get_value_at(2*kxAfter+1,kyAfterInd); // Update imaginary part of image
14368 ToAdd = IsComplexConj*WeightNowX*WeightNowY*RotIm -> get_value_at(2*kxBefore+1,kyBefore, kzBefore );
14369 image -> set_value_at(2*kxAfter+1 , kyAfterInd , kzAfterInd, ToAdd + CurrentValue );
14370
14371
14372 }}}
14373
14374
14375 }}}
14376
14377// Set the image values to the rotated image, because we do it in place
14378
14379
14380 if (debug) { image -> write_image("RotImageBeforeFinalPhaseCorrection.hdf");
14381 printf(" Just wrote RotImageBeforeFinalPhaseCorrection.hdf \n"); }
14382
14383
14384 for (kxBefore = 0; kxBefore <= N ; ++kxBefore) { // This is the normalization step
14385 for (kyBefore = 0; kyBefore < y_size ; ++kyBefore) { // These are the kx, ky, kz coordinates of the original image
14386 for (kzBefore = 0; kzBefore < z_size ; ++kzBefore) {
14387
14388 float CurrentReal = image -> get_value_at(2*kxBefore , kyBefore, kzBefore);
14389 float CurrentImag = image -> get_value_at(2*kxBefore+1 , kyBefore, kzBefore);
14390
14391 PhaseFinalIm -> set_value_at(kxBefore,kyBefore, kzBefore, atan2(CurrentImag,CurrentReal));
14392 MagFinalIm -> set_value_at(kxBefore,kyBefore, kzBefore, sqrt(CurrentImag*CurrentImag+CurrentReal*CurrentReal) );
14393 float WeightNow = WeightIm -> get_value_at(kxBefore,kyBefore, kzBefore);
14394 if (WeightNow>0) {
14395 float val = (image->get_value_at(2*kxBefore , kyBefore, kzBefore))/WeightNow;
14396 image -> set_value_at(2*kxBefore , kyBefore, kzBefore, val);
14397 val = (image->get_value_at(2*kxBefore +1 , kyBefore, kzBefore))/WeightNow;
14398 image -> set_value_at(2*kxBefore +1 , kyBefore, kzBefore, val);
14399 }
14400
14401 }}}
14402
14403 if (debug) { printf(" Just did normalization step \n");}
14404
14405
14406 for ( kxBefore = 0; kxBefore < Mid ; ++kxBefore) { // This is the rephase step
14407 for ( kyBefore = 0; kyBefore < y_size ; ++kyBefore) {
14408 for ( kzBefore = 0; kzBefore < z_size ; ++kzBefore) {
14409
14410 float CurrentReal = image -> get_value_at(2*kxBefore ,kyBefore, kzBefore);
14411 float CurrentImag = image -> get_value_at(2*kxBefore+1,kyBefore, kzBefore);
14412
14413// float Phase = +2*pi*(kxBefore+kyBefore+kzBefore)*(Mid)/y_size;
14414 float Phase = pi*(kxBefore + kyBefore + kzBefore)*x_size/y_size;
14415 // Phase = 0; // Offset should be Mid-1
14416 float CosPhase = cos( Phase);
14417 float SinPhase = sin( Phase);
14418
14419 float NewRealValue = CosPhase*CurrentReal -SinPhase*CurrentImag;
14420 float NewImagValue = SinPhase*CurrentReal +CosPhase*CurrentImag;
14421
14422 image ->set_value_at(2*kxBefore, kyBefore, kzBefore, NewRealValue);
14423 image ->set_value_at(2*kxBefore+1,kyBefore, kzBefore, NewImagValue);
14424 }}}
14425
14426 if (debug) {
14427 image -> write_image("RotatedImageFFT.hdf");
14428 PhaseFinalIm -> write_image("PhaseImInFS.hdf"); // These are the phases,mags of the image when properly centered
14429 MagFinalIm -> write_image("MagFinalImInFS.hdf");
14430 WeightIm -> write_image("WeightIm.hdf");
14431 printf(" Just wrote RotatedImageFFT.hdf \n");
14432 }
14433
14434 image -> update();
14435
14436}
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
A Transform object is a somewhat specialized object designed specifically for EMAN2/Sparx storage of ...
Definition: transform.h:75
Transform inverse() const
Get the inverse of this transformation matrix.
Definition: transform.cpp:1327
void set_value_at(Vec3i loc, float val)
set_value_at with Vec3i
Definition: emdata_core.h:552
EMData * sqrt() const
return square root of current image
float get_value_at(int x, int y, int z) const
Get the pixel density value at coordinates (x,y,z).
Definition: emdata_core.h:221
void write_image(const string &filename, int img_index=0, EMUtil::ImageType imgtype=EMUtil::IMAGE_UNKNOWN, bool header_only=false, const Region *region=0, EMUtil::EMDataType filestoragetype=EMUtil::EM_FLOAT, bool use_host_endian=true)
write the header and data out to an image.
void update()
Mark EMData as changed, statistics, etc will be updated at need.
#define ImageDimensionException(desc)
Definition: exception.h:166
Vec3< float > Vec3f
Definition: vec3.h:693

References copy(), get_value_at(), ImageDimensionException, EMAN::Transform::inverse(), EMAN::Processor::params, EMAN::Dict::set_default(), set_value_at(), sqrt(), update(), and write_image().

Referenced by process().

Member Data Documentation

◆ NAME

const string RotateInFSProcessor::NAME = "rotateinfs"
static

Definition at line 9394 of file processor.h.

Referenced by get_name().


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