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 173 of file aligner.h.


Member Function Documentation

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 88 of file aligner.cpp.

References EMAN::EMData::calc_ccf(), EMAN::EMData::calc_flcf(), EMAN::EMData::calc_max_location_wrap(), calc_max_location_wrap_cuda(), 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(), EMAN::Transform::set_trans(), t, EMAN::EMData::update(), and EMAN::EMData::zero_corner_circulant().

Referenced by align().

00090 {
00091         if (!this_img) {
00092                 return 0;
00093         }
00094 
00095         if (to && !EMUtil::is_same_size(this_img, to))
00096                 throw ImageDimensionException("Images must be the same size to perform translational alignment");
00097 
00098         EMData *cf = 0;
00099         int nx = this_img->get_xsize();
00100         int ny = this_img->get_ysize();
00101         int nz = this_img->get_zsize();
00102 
00103         int masked = params.set_default("masked",0);
00104         int useflcf = params.set_default("useflcf",0);
00105         bool use_cpu = true;
00106 #ifdef EMAN2_USING_CUDA
00107         if (this_img->gpu_operation_preferred() ) {
00108 //              cout << "Translate on GPU" << endl;
00109                 use_cpu = false;
00110                 cf = this_img->calc_ccf_cuda(to,false,false);
00111         }
00112 #endif // EMAN2_USING_CUDA
00113         if (use_cpu) {
00114                 if (useflcf) cf = this_img->calc_flcf(to);
00115                 else cf = this_img->calc_ccf(to);
00116         }
00117 
00118         // This is too expensive
00119         if (masked) {
00120                 EMData *msk=this_img->process("threshold.notzero");
00121                 EMData *sqr=to->process("math.squared");
00122                 EMData *cfn=msk->calc_ccf(sqr);
00123                 cfn->process_inplace("math.sqrt");
00124                 float *d1=cf->get_data();
00125                 float *d2=cfn->get_data();
00126                 for (int i=0; i<nx*ny*nz; i++) {
00127                         if (d2[i]!=0) d1[i]/=d2[i];
00128                 }
00129                 cf->update();
00130                 delete msk;
00131                 delete sqr;
00132                 delete cfn;
00133         }
00134 
00135 //
00136 
00137         int maxshiftx = params.set_default("maxshift",-1);
00138         int maxshifty = params["maxshift"];
00139         int maxshiftz = params["maxshift"];
00140         int nozero = params["nozero"];
00141 
00142         if (maxshiftx <= 0) {
00143                 maxshiftx = nx / 4;
00144                 maxshifty = ny / 4;
00145                 maxshiftz = nz / 4;
00146         }
00147 
00148         if (maxshiftx > nx / 2 - 1) maxshiftx = nx / 2 - 1;
00149         if (maxshifty > ny / 2 - 1)     maxshifty = ny / 2 - 1;
00150         if (maxshiftz > nz / 2 - 1) maxshiftz = nz / 2 - 1;
00151 
00152         if (nx == 1) maxshiftx = 0; // This is justhere for completeness really... plus it saves errors
00153         if (ny == 1) maxshifty = 0;
00154         if (nz == 1) maxshiftz = 0;
00155 
00156         // If nozero the portion of the image in the center (and its 8-connected neighborhood) is zeroed
00157         if (nozero) {
00158                 cf->zero_corner_circulant(1);
00159         }
00160 
00161         IntPoint peak;
00162 #ifdef EMAN2_USING_CUDA
00163         if (!use_cpu) {
00164                 EMDataForCuda tmp = cf->get_data_struct_for_cuda();
00165                 int* p = calc_max_location_wrap_cuda(&tmp,maxshiftx, maxshifty, maxshiftz);
00166                 peak = IntPoint(p[0],p[1],p[2]);
00167                 free(p);
00168         }
00169 #endif // EMAN2_USING_CUDA
00170         if (use_cpu) {
00171                 peak = cf->calc_max_location_wrap(maxshiftx, maxshifty, maxshiftz);
00172         }
00173         Vec3f cur_trans = Vec3f ( (float)-peak[0], (float)-peak[1], (float)-peak[2]);
00174 
00175         if (!to) {
00176                 cur_trans /= 2.0f; // If aligning theimage to itself then only go half way -
00177                 int intonly = params.set_default("intonly",false);
00178                 if (intonly) {
00179                         cur_trans[0] = floor(cur_trans[0] + 0.5f);
00180                         cur_trans[1] = floor(cur_trans[1] + 0.5f);
00181                         cur_trans[2] = floor(cur_trans[2] + 0.5f);
00182                 }
00183         }
00184 
00185         if( cf ){
00186                 delete cf;
00187                 cf = 0;
00188         }
00189         Dict params("trans",static_cast< vector<int> >(cur_trans));
00190         cf=this_img->process("math.translate.int",params);
00191         Transform t;
00192         t.set_trans(cur_trans);
00193         if ( nz != 1 ) {
00194 //              Transform* t = get_set_align_attr("xform.align3d",cf,this_img);
00195 //              t->set_trans(cur_trans);
00196                 cf->set_attr("xform.align3d",&t);
00197         } else if ( ny != 1 ) {
00198                 //Transform* t = get_set_align_attr("xform.align2d",cf,this_img);
00199                 cur_trans[2] = 0; // just make sure of it
00200                 t.set_trans(cur_trans);
00201                 cf->set_attr("xform.align2d",&t);
00202         }
00203 
00204         return cf;
00205 }

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

Implements EMAN::Aligner.

Definition at line 179 of file aligner.h.

References align().

00180                 {
00181                         return align(this_img, to_img, "", Dict());
00182                 }

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 184 of file aligner.h.

References NAME.

00185                 {
00186                         return NAME;
00187                 }

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

Implements EMAN::Aligner.

Definition at line 189 of file aligner.h.

00190                 {
00191                         return "Translational 2D and 3D alignment by cross-correlation";
00192                 }

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

Definition at line 194 of file aligner.h.

00195                 {
00196                         return new TranslationalAligner();
00197                 }

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

Implements EMAN::Aligner.

Definition at line 199 of file aligner.h.

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

00200                 {
00201                         TypeDict d;
00202                         d.put("intonly", EMObject::INT,"Integer pixel translations only");
00203                         d.put("useflcf", EMObject::INT,"Use Fast Local Correlation Function rather than CCF");
00204                         d.put("maxshift", EMObject::INT,"Maximum translation in pixels");
00205                         d.put("masked", EMObject::INT,"Treat zero pixels in 'this' as a mask for normalization (default false)");
00206                         d.put("nozero", EMObject::INT,"Zero translation not permitted (useful for CCD images)");
00207                         return d;
00208                 }


Member Data Documentation

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

Definition at line 210 of file aligner.h.

Referenced by get_name().


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

Generated on Sun Mar 21 02:20:08 2010 for EMAN2 by  doxygen 1.5.6