Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

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

AlignerNEW ()

Static Public Attributes

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

References align().

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

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 118 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(), CudaPeakInfo::px, CudaPeakInfo::py, CudaPeakInfo::pz, EMAN::EMData::set_attr(), EMAN::Dict::set_default(), EMAN::Transform::set_trans(), t, UnexpectedBehaviorException, EMAN::EMData::update(), EMAN::Vec3f, and EMAN::EMData::zero_corner_circulant().

00120 {
00121         if (!this_img) {
00122                 return 0;
00123         }
00124 
00125         if (to && !EMUtil::is_same_size(this_img, to))
00126                 throw ImageDimensionException("Images must be the same size to perform translational alignment");
00127 
00128         EMData *cf = 0;
00129         int nx = this_img->get_xsize();
00130         int ny = this_img->get_ysize();
00131         int nz = this_img->get_zsize();
00132 
00133         int masked = params.set_default("masked",0);
00134         int useflcf = params.set_default("useflcf",0);
00135         bool use_cpu = true;
00136 
00137 #ifdef EMAN2_USING_CUDA
00138         if(EMData::usecuda == 1) {
00139                 //if(!this_img->getcudarwdata()) this_img->copy_to_cuda();
00140                 //if(to && !to->getcudarwdata()) to->copy_to_cuda();
00141                 //if (masked) throw UnexpectedBehaviorException("Masked is not yet supported in CUDA");
00142                 //if (useflcf) throw UnexpectedBehaviorException("Useflcf is not yet supported in CUDA");
00143                 //cout << "Translate on GPU" << endl;
00144                 //use_cpu = false;
00145                 //cf = this_img->calc_ccf(to);
00146         }
00147 #endif // EMAN2_USING_CUDA
00148         
00149         if (use_cpu) {
00150                 if (useflcf) cf = this_img->calc_flcf(to);
00151                 else cf = this_img->calc_ccf(to);
00152         }
00153         //return cf;
00154         // This is too expensive, esp for CUDA(we we can fix later
00155         if (masked) {
00156                 EMData *msk=this_img->process("threshold.notzero");
00157                 EMData *sqr=to->process("math.squared");
00158                 EMData *cfn=msk->calc_ccf(sqr);
00159                 cfn->process_inplace("math.sqrt");
00160                 float *d1=cf->get_data();
00161                 float *d2=cfn->get_data();
00162                 for (size_t i=0; i<(size_t)nx*ny*nz; ++i) {
00163                         if (d2[i]!=0) d1[i]/=d2[i];
00164                 }
00165                 cf->update();
00166                 delete msk;
00167                 delete sqr;
00168                 delete cfn;
00169         }
00170 
00171         int maxshiftx = params.set_default("maxshift",-1);
00172         int maxshifty = params["maxshift"];
00173         int maxshiftz = params["maxshift"];
00174         int nozero = params["nozero"];
00175 
00176         if (maxshiftx <= 0) {
00177                 maxshiftx = nx / 4;
00178                 maxshifty = ny / 4;
00179                 maxshiftz = nz / 4;
00180         }
00181 
00182         if (maxshiftx > nx / 2 - 1) maxshiftx = nx / 2 - 1;
00183         if (maxshifty > ny / 2 - 1)     maxshifty = ny / 2 - 1;
00184         if (maxshiftz > nz / 2 - 1) maxshiftz = nz / 2 - 1;
00185 
00186         if (nx == 1) maxshiftx = 0; // This is justhere for completeness really... plus it saves errors
00187         if (ny == 1) maxshifty = 0;
00188         if (nz == 1) maxshiftz = 0;
00189 
00190         // If nozero the portion of the image in the center (and its 8-connected neighborhood) is zeroed
00191         if (nozero) {
00192                 cf->zero_corner_circulant(1);
00193         }
00194         
00195         IntPoint peak;
00196 #ifdef EMAN2_USING_CUDA
00197         if (!use_cpu) {
00198                 cout << "USe CUDA TA 2" << endl;
00199                 if (nozero) throw UnexpectedBehaviorException("Nozero is not yet supported in CUDA");
00200                 CudaPeakInfo* data = calc_max_location_wrap_cuda(cf->getcudarwdata(), cf->get_xsize(), cf->get_ysize(), cf->get_zsize(), maxshiftx, maxshifty, maxshiftz);
00201                 peak = IntPoint(data->px,data->py,data->pz);
00202                 free(data);
00203         }
00204 #endif // EMAN2_USING_CUDA
00205         
00206         if (use_cpu) {
00207                 peak = cf->calc_max_location_wrap(maxshiftx, maxshifty, maxshiftz);
00208         }
00209         //cout << -peak[0] << " " << -peak[1] << " " << -peak[2] << endl;
00210         Vec3f cur_trans = Vec3f ( (float)-peak[0], (float)-peak[1], (float)-peak[2]);
00211         //cout << peak[0] << " " << peak[1] << endl;
00212 
00213         if (!to) {
00214                 cur_trans /= 2.0f; // If aligning theimage to itself then only go half way -
00215                 int intonly = params.set_default("intonly",false);
00216                 if (intonly) {
00217                         cur_trans[0] = floor(cur_trans[0] + 0.5f);
00218                         cur_trans[1] = floor(cur_trans[1] + 0.5f);
00219                         cur_trans[2] = floor(cur_trans[2] + 0.5f);
00220                 }
00221         }
00222 
00223         if( cf ){
00224                 delete cf;
00225                 cf = 0;
00226         }
00227         
00228         Dict params("trans",static_cast< vector<int> >(cur_trans));
00229         if (use_cpu){
00230                 cf=this_img->process("math.translate.int",params);
00231         }
00232         Transform t;
00233         t.set_trans(cur_trans);
00234         
00235 #ifdef EMAN2_USING_CUDA
00236         if (!use_cpu) {
00237                 cout << "USe CUDA TA 3" << endl;
00238                 //this will work just fine....
00239                 cf = this_img->process("xform",Dict("transform",&t));
00240         }
00241 #endif // EMAN2_USING_CUDA
00242 
00243         if ( nz != 1 ) {
00244 //              Transform* t = get_set_align_attr("xform.align3d",cf,this_img);
00245 //              t->set_trans(cur_trans);
00246                 cf->set_attr("xform.align3d",&t);
00247         } else if ( ny != 1 ) {
00248                 //Transform* t = get_set_align_attr("xform.align2d",cf,this_img);
00249                 cur_trans[2] = 0; // just make sure of it
00250                 t.set_trans(cur_trans);
00251                 cf->set_attr("xform.align2d",&t);
00252         }
00253         return cf;
00254 }

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

Implements EMAN::Aligner.

Definition at line 190 of file aligner.h.

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

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

00186                 {
00187                         return NAME;
00188                 }

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

Implements EMAN::Aligner.

Definition at line 200 of file aligner.h.

References EMAN::TypeDict::put().

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

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

Definition at line 195 of file aligner.h.

00196                 {
00197                         return new TranslationalAligner();
00198                 }


Member Data Documentation

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

Definition at line 58 of file aligner.cpp.


The documentation for this class was generated from the following files:
Generated on Tue Jul 12 13:51:02 2011 for EMAN2 by  doxygen 1.3.9.1