EMAN::TranslationalAligner Class Reference
[a function or class that is CUDA enabled]

Translational 2D Alignment using cross correlation. More...

#include <aligner.h>

Inheritance diagram for EMAN::TranslationalAligner:

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

Collaboration graph
[legend]
List of all members.

Public Member Functions

virtual EMDataalign (EMData *this_img, EMData *to_img, const string &cmp_name="dot", const Dict &cmp_params=Dict()) const
 To align 'this_img' with another image passed in through its parameters.
virtual EMDataalign (EMData *this_img, EMData *to_img) const
virtual string get_name () const
 Get the Aligner's name.
virtual string get_desc () const
virtual TypeDict get_param_types () const

Static Public Member Functions

static AlignerNEW ()

Static Public Attributes

static const string NAME = "translational"

Detailed Description

Translational 2D Alignment using cross correlation.

It calculates the shift for a translational alignment, then do the translation.

Parameters:
intonly Integer pixel translations only
maxshift Maximum translation in pixels
nozero Zero translation not permitted (useful for CCD images)

Definition at line 241 of file aligner.h.


Member Function Documentation

virtual EMData* EMAN::TranslationalAligner::align ( EMData this_img,
EMData to_img 
) const [inline, virtual]

Implements EMAN::Aligner.

Definition at line 247 of file aligner.h.

References align().

00248                 {
00249                         return align(this_img, to_img, "dot", Dict());
00250                 }

EMData * TranslationalAligner::align ( EMData this_img,
EMData to_img,
const string &  cmp_name = "dot",
const Dict cmp_params = Dict() 
) const [virtual]

To align 'this_img' with another image passed in through its parameters.

The alignment uses a user-given comparison method to compare the two images. If none is given, a default one is used.

Parameters:
this_img The image to be compared.
to_img 'this_img" is aligned with 'to_img'.
cmp_name The comparison method to compare the two images.
cmp_params The parameter dictionary for comparison method.
Returns:
The aligned image.

Implements EMAN::Aligner.

Definition at line 248 of file aligner.cpp.

References EMAN::EMData::calc_ccf(), EMAN::EMData::calc_flcf(), EMAN::EMData::calc_max_location_wrap(), calc_max_location_wrap_cuda(), data, EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageDimensionException, EMAN::EMUtil::is_same_size(), nx, ny, EMAN::Aligner::params, EMAN::EMData::process(), EMAN::EMData::process_inplace(), EMAN::EMData::set_attr(), EMAN::Dict::set_default(), t, UnexpectedBehaviorException, EMAN::EMData::update(), and EMAN::EMData::zero_corner_circulant().

Referenced by align().

00250 {
00251         if (!this_img) {
00252                 return 0;
00253         }
00254 
00255         if (to && !EMUtil::is_same_size(this_img, to))
00256                 throw ImageDimensionException("Images must be the same size to perform translational alignment");
00257 
00258         EMData *cf = 0;
00259         int nx = this_img->get_xsize();
00260         int ny = this_img->get_ysize();
00261         int nz = this_img->get_zsize();
00262 
00263         int masked = params.set_default("masked",0);
00264         int useflcf = params.set_default("useflcf",0);
00265         bool use_cpu = true;
00266 
00267 #ifdef EMAN2_USING_CUDA
00268         if(EMData::usecuda == 1) {
00269                 //if(!this_img->getcudarwdata()) this_img->copy_to_cuda();
00270                 //if(to && !to->getcudarwdata()) to->copy_to_cuda();
00271                 //if (masked) throw UnexpectedBehaviorException("Masked is not yet supported in CUDA");
00272                 //if (useflcf) throw UnexpectedBehaviorException("Useflcf is not yet supported in CUDA");
00273                 //cout << "Translate on GPU" << endl;
00274                 //use_cpu = false;
00275                 //cf = this_img->calc_ccf(to);
00276         }
00277 #endif // EMAN2_USING_CUDA
00278         
00279         if (use_cpu) {
00280                 if (useflcf) cf = this_img->calc_flcf(to);
00281                 else cf = this_img->calc_ccf(to);
00282         }
00283         //return cf;
00284         // This is too expensive, esp for CUDA(we we can fix later
00285         if (masked) {
00286                 EMData *msk=this_img->process("threshold.notzero");
00287                 EMData *sqr=to->process("math.squared");
00288                 EMData *cfn=msk->calc_ccf(sqr);
00289                 cfn->process_inplace("math.sqrt");
00290                 float *d1=cf->get_data();
00291                 float *d2=cfn->get_data();
00292                 for (size_t i=0; i<(size_t)nx*ny*nz; ++i) {
00293                         if (d2[i]!=0) d1[i]/=d2[i];
00294                 }
00295                 cf->update();
00296                 delete msk;
00297                 delete sqr;
00298                 delete cfn;
00299         }
00300 
00301         int maxshiftx = params.set_default("maxshift",-1);
00302         int maxshifty = params["maxshift"];
00303         int maxshiftz = params["maxshift"];
00304         int nozero = params["nozero"];
00305 
00306         if (maxshiftx <= 0) {
00307                 maxshiftx = nx / 4;
00308                 maxshifty = ny / 4;
00309                 maxshiftz = nz / 4;
00310         }
00311 
00312         if (maxshiftx > nx / 2 - 1) maxshiftx = nx / 2 - 1;
00313         if (maxshifty > ny / 2 - 1)     maxshifty = ny / 2 - 1;
00314         if (maxshiftz > nz / 2 - 1) maxshiftz = nz / 2 - 1;
00315 
00316         if (nx == 1) maxshiftx = 0; // This is justhere for completeness really... plus it saves errors
00317         if (ny == 1) maxshifty = 0;
00318         if (nz == 1) maxshiftz = 0;
00319 
00320         // If nozero the portion of the image in the center (and its 8-connected neighborhood) is zeroed
00321         if (nozero) {
00322                 cf->zero_corner_circulant(1);
00323         }
00324         
00325         IntPoint peak;
00326 #ifdef EMAN2_USING_CUDA
00327         if (!use_cpu) {
00328                 cout << "USe CUDA TA 2" << endl;
00329                 if (nozero) throw UnexpectedBehaviorException("Nozero is not yet supported in CUDA");
00330                 CudaPeakInfo* data = calc_max_location_wrap_cuda(cf->getcudarwdata(), cf->get_xsize(), cf->get_ysize(), cf->get_zsize(), maxshiftx, maxshifty, maxshiftz);
00331                 peak = IntPoint(data->px,data->py,data->pz);
00332                 free(data);
00333         }
00334 #endif // EMAN2_USING_CUDA
00335         
00336         if (use_cpu) {
00337                 peak = cf->calc_max_location_wrap(maxshiftx, maxshifty, maxshiftz);
00338         }
00339         //cout << -peak[0] << " " << -peak[1] << " " << -peak[2] << endl;
00340         Vec3f cur_trans = Vec3f ( (float)-peak[0], (float)-peak[1], (float)-peak[2]);
00341         //cout << peak[0] << " " << peak[1] << endl;
00342 
00343         if (!to) {
00344                 cur_trans /= 2.0f; // If aligning theimage to itself then only go half way -
00345                 int intonly = params.set_default("intonly",false);
00346                 if (intonly) {
00347                         cur_trans[0] = floor(cur_trans[0] + 0.5f);
00348                         cur_trans[1] = floor(cur_trans[1] + 0.5f);
00349                         cur_trans[2] = floor(cur_trans[2] + 0.5f);
00350                 }
00351         }
00352 
00353         if( cf ){
00354                 delete cf;
00355                 cf = 0;
00356         }
00357         
00358         Dict params("trans",static_cast< vector<int> >(cur_trans));
00359         if (use_cpu){
00360                 cf=this_img->process("xform.translate.int",params);
00361         }
00362         Transform t;
00363         t.set_trans(cur_trans);
00364         
00365 #ifdef EMAN2_USING_CUDA
00366         if (!use_cpu) {
00367                 cout << "USe CUDA TA 3" << endl;
00368                 //this will work just fine....
00369                 cf = this_img->process("xform",Dict("transform",&t));
00370         }
00371 #endif // EMAN2_USING_CUDA
00372 
00373         if ( nz != 1 ) {
00374 //              Transform* t = get_set_align_attr("xform.align3d",cf,this_img);
00375 //              t->set_trans(cur_trans);
00376                 cf->set_attr("xform.align3d",&t);
00377         } else if ( ny != 1 ) {
00378                 //Transform* t = get_set_align_attr("xform.align2d",cf,this_img);
00379                 cur_trans[2] = 0; // just make sure of it
00380                 t.set_trans(cur_trans);
00381                 cf->set_attr("xform.align2d",&t);
00382         }
00383         return cf;
00384 }

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

Implements EMAN::Aligner.

Definition at line 257 of file aligner.h.

00258                 {
00259                         return "Translational 2D and 3D alignment by cross-correlation";
00260                 }

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

Get the Aligner's name.

Each Aligner is identified by a unique name.

Returns:
The Aligner's name.

Implements EMAN::Aligner.

Definition at line 252 of file aligner.h.

References NAME.

00253                 {
00254                         return NAME;
00255                 }

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

Implements EMAN::Aligner.

Definition at line 267 of file aligner.h.

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

00268                 {
00269                         TypeDict d;
00270                         d.put("intonly", EMObject::INT,"Integer pixel translations only");
00271                         d.put("useflcf", EMObject::INT,"Use Fast Local Correlation Function rather than CCF");
00272                         d.put("maxshift", EMObject::INT,"Maximum translation in pixels");
00273                         d.put("masked", EMObject::INT,"Treat zero pixels in 'this' as a mask for normalization (default false)");
00274                         d.put("nozero", EMObject::INT,"Zero translation not permitted (useful for CCD images)");
00275                         return d;
00276                 }

static Aligner* EMAN::TranslationalAligner::NEW (  )  [inline, static]

Definition at line 262 of file aligner.h.

00263                 {
00264                         return new TranslationalAligner();
00265                 }


Member Data Documentation

const string TranslationalAligner::NAME = "translational" [static]

Definition at line 278 of file aligner.h.

Referenced by get_name().


The documentation for this class was generated from the following files:
Generated on Tue Jun 11 12:42:35 2013 for EMAN2 by  doxygen 1.4.7