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