#include <aligner.h>
Inheritance diagram for EMAN::RotationalAligner:
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 EMData * | align_180_ambiguous (EMData *this_img, EMData *to_img, int rfp_mode=0) |
Static Public Attributes | |
static const string | NAME = "rotational" |
rfp_mode | Either 0,1 or 2. A temporary flag for testing the rotational foot print. O is the original eman1 way. 1 is just using calc_ccf without padding. 2 is using calc_mutual_correlation without padding |
Definition at line 285 of file aligner.h.
virtual EMData* EMAN::RotationalAligner::align | ( | EMData * | this_img, | |
EMData * | to_img | |||
) | const [inline, virtual] |
Implements EMAN::Aligner.
Definition at line 291 of file aligner.h.
References align().
00292 { 00293 return align(this_img, to_img, "dot", Dict()); 00294 }
EMData * RotationalAligner::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 431 of file aligner.cpp.
References align_180_ambiguous(), EMAN::EMData::cmp(), EMAN::EMData::get_attr(), EMAN::Transform::get_rotation(), InvalidParameterException, EMAN::Aligner::params, EMAN::EMData::process(), EMAN::EMData::set_attr(), and EMAN::Dict::set_default().
Referenced by align().
00433 { 00434 if (!to) throw InvalidParameterException("Can not rotational align - the image to align to is NULL"); 00435 00436 #ifdef EMAN2_USING_CUDA 00437 if(EMData::usecuda == 1) { 00438 //if(!this_img->getcudarwdata()) this_img->copy_to_cuda(); 00439 //if(!to->getcudarwdata()) to->copy_to_cuda(); 00440 } 00441 #endif 00442 00443 // Perform 180 ambiguous alignment 00444 int rfp_mode = params.set_default("rfp_mode",0); 00445 EMData* rot_aligned = RotationalAligner::align_180_ambiguous(this_img,to,rfp_mode); 00446 Transform * tmp = rot_aligned->get_attr("xform.align2d"); 00447 Dict rot = tmp->get_rotation("2d"); 00448 float rotate_angle_solution = rot["alpha"]; 00449 delete tmp; 00450 00451 EMData *rot_align_180 = rot_aligned->process("math.rotate.180"); 00452 00453 // Generate the comparison metrics for both rotational candidates 00454 float rot_cmp = rot_aligned->cmp(cmp_name, to, cmp_params); 00455 float rot_180_cmp = rot_align_180->cmp(cmp_name, to, cmp_params); 00456 00457 // Decide on the result 00458 float score = 0.0; 00459 EMData* result = NULL; 00460 if (rot_cmp < rot_180_cmp){ 00461 result = rot_aligned; 00462 score = rot_cmp; 00463 delete rot_align_180; rot_align_180 = 0; 00464 } else { 00465 result = rot_align_180; 00466 score = rot_180_cmp; 00467 delete rot_aligned; rot_aligned = 0; 00468 rotate_angle_solution = rotate_angle_solution-180.0f; 00469 } 00470 00471 // Transform* t = get_align_attr("xform.align2d",result); 00472 // t->set_rotation(Dict("type","2d","alpha",rotate_angle_solution)); 00473 Transform tmp2(Dict("type","2d","alpha",rotate_angle_solution)); 00474 result->set_attr("xform.align2d",&tmp2); 00475 return result; 00476 }
EMData * RotationalAligner::align_180_ambiguous | ( | EMData * | this_img, | |
EMData * | to_img, | |||
int | rfp_mode = 0 | |||
) | [static] |
Definition at line 383 of file aligner.cpp.
References EMAN::EMData::calc_ccfx(), data, EMAN::Util::find_max(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), InvalidParameterException, EMAN::EMData::make_rotational_footprint(), EMAN::EMData::make_rotational_footprint_cmc(), EMAN::EMData::make_rotational_footprint_e1(), EMAN::EMData::process(), and EMAN::EMData::set_attr().
Referenced by EMAN::RotateTranslateAligner::align(), and align().
00383 { 00384 00385 // Make translationally invariant rotational footprints 00386 EMData* this_img_rfp, * to_rfp; 00387 if (rfp_mode == 0) { 00388 this_img_rfp = this_img->make_rotational_footprint_e1(); 00389 to_rfp = to->make_rotational_footprint_e1(); 00390 } else if (rfp_mode == 1) { 00391 this_img_rfp = this_img->make_rotational_footprint(); 00392 to_rfp = to->make_rotational_footprint(); 00393 } else if (rfp_mode == 2) { 00394 this_img_rfp = this_img->make_rotational_footprint_cmc(); 00395 to_rfp = to->make_rotational_footprint_cmc(); 00396 } else { 00397 throw InvalidParameterException("rfp_mode must be 0,1 or 2"); 00398 } 00399 int this_img_rfp_nx = this_img_rfp->get_xsize(); 00400 00401 // Do row-wise correlation, returning a sum. 00402 EMData *cf = this_img_rfp->calc_ccfx(to_rfp, 0, this_img->get_ysize()); 00403 00404 // Delete them, they're no longer needed 00405 delete this_img_rfp; this_img_rfp = 0; 00406 delete to_rfp; to_rfp = 0; 00407 00408 // Now solve the rotational alignment by finding the max in the column sum 00409 float *data = cf->get_data(); 00410 00411 float peak = 0; 00412 int peak_index = 0; 00413 Util::find_max(data, this_img_rfp_nx, &peak, &peak_index); 00414 00415 if( cf ) { 00416 delete cf; 00417 cf = 0; 00418 } 00419 float rot_angle = (float) (peak_index * 180.0f / this_img_rfp_nx); 00420 00421 // Return the result 00422 Transform tmp(Dict("type","2d","alpha",rot_angle)); 00423 cf=this_img->process("xform",Dict("transform",(Transform*)&tmp)); 00424 // Transform* t = get_set_align_attr("xform.align2d",cf,this_img); 00425 // Dict d("type","2d","alpha",rot_angle); 00426 // t->set_rotation(d); 00427 cf->set_attr("xform.align2d",&tmp); 00428 return cf; 00429 }
virtual string EMAN::RotationalAligner::get_desc | ( | ) | const [inline, virtual] |
Implements EMAN::Aligner.
Definition at line 301 of file aligner.h.
00302 { 00303 return "Performs rotational alignment,works accurately if the image is precentered, normally called internally in combination with translational and flip alignment"; 00304 }
virtual string EMAN::RotationalAligner::get_name | ( | ) | const [inline, virtual] |
virtual TypeDict EMAN::RotationalAligner::get_param_types | ( | ) | const [inline, virtual] |
Implements EMAN::Aligner.
Definition at line 313 of file aligner.h.
References EMAN::EMObject::INT, and EMAN::TypeDict::put().
00314 { 00315 TypeDict d; 00316 d.put("rfp_mode", EMObject::INT,"Either 0,1 or 2. A temporary flag for testing the rotational foot print. O is the original eman1 way. 1 is just using calc_ccf without padding. 2 is using calc_mutual_correlation without padding."); 00317 return d; 00318 }
static Aligner* EMAN::RotationalAligner::NEW | ( | ) | [inline, static] |
const string RotationalAligner::NAME = "rotational" [static] |