#include <aligner.h>
Inheritance diagram for EMAN::RTFSlowExhaustiveAligner:
Public Member Functions | |
virtual EMData * | align (EMData *this_img, EMData *to_img, const string &cmp_name, const Dict &cmp_params) 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 = "rtf_slow_exhaustive" |
This is very slow but can ensure localization of the global maximum
flip | Optional. This is the flipped version of the images that is being aligned. If specified it will be used for the handedness check, if not a flipped copy of the image will be made | |
maxshift | The maximum length of the detectable translational shift | |
transtep | The translation step to take when honing the alignment, which occurs after coarse alignment | |
angstep | The angular step (in degrees) to take in the exhaustive search for the solution angle. Typically very small i.e. 3 or smaller |
Definition at line 1120 of file aligner.h.
virtual EMData* EMAN::RTFSlowExhaustiveAligner::align | ( | EMData * | this_img, | |
EMData * | to_img | |||
) | const [inline, virtual] |
Implements EMAN::Aligner.
Definition at line 1125 of file aligner.h.
References align().
01126 { 01127 return align(this_img, to_img, "sqeuclidean", Dict()); 01128 }
EMData * RTFSlowExhaustiveAligner::align | ( | EMData * | this_img, | |
EMData * | to_img, | |||
const string & | cmp_name, | |||
const Dict & | cmp_params | |||
) | 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 1356 of file aligner.cpp.
References EMAN::EMConsts::deg2rad, EMAN::EMData::get_xsize(), InvalidParameterException, nx, EMAN::Aligner::params, EMAN::EMData::process(), EMAN::EMConsts::rad2deg, EMAN::EMData::set_attr(), EMAN::Dict::set_default(), t, and v.
Referenced by align().
01358 { 01359 01360 EMData *flip = params.set_default("flip", (EMData *) 0); 01361 int maxshift = params.set_default("maxshift", -1); 01362 01363 EMData *flipped = 0; 01364 01365 bool delete_flipped = true; 01366 if (flip) { 01367 delete_flipped = false; 01368 flipped = flip; 01369 } 01370 else { 01371 flipped = to->process("xform.flip", Dict("axis", "x")); 01372 } 01373 01374 int nx = this_img->get_xsize(); 01375 01376 if (maxshift < 0) { 01377 maxshift = nx / 10; 01378 } 01379 01380 float angle_step = params.set_default("angstep", 0.0f); 01381 if ( angle_step == 0 ) angle_step = atan2(2.0f, (float)nx); 01382 else { 01383 angle_step *= (float)EMConsts::deg2rad; //convert to radians 01384 } 01385 float trans_step = params.set_default("transtep",1.0f); 01386 01387 if (trans_step <= 0) throw InvalidParameterException("transstep must be greater than 0"); 01388 if (angle_step <= 0) throw InvalidParameterException("angstep must be greater than 0"); 01389 01390 01391 Dict shrinkfactor("n",2); 01392 EMData *this_img_shrink = this_img->process("math.medianshrink",shrinkfactor); 01393 EMData *to_shrunk = to->process("math.medianshrink",shrinkfactor); 01394 EMData *flipped_shrunk = flipped->process("math.medianshrink",shrinkfactor); 01395 01396 int bestflip = 0; 01397 float bestdx = 0; 01398 float bestdy = 0; 01399 01400 float bestang = 0; 01401 float bestval = FLT_MAX; 01402 01403 int half_maxshift = maxshift / 2; 01404 01405 01406 for (int dy = -half_maxshift; dy <= half_maxshift; ++dy) { 01407 for (int dx = -half_maxshift; dx <= half_maxshift; ++dx) { 01408 if (hypot(dx, dy) <= maxshift) { 01409 for (float ang = -angle_step * 2.0f; ang <= (float)2 * M_PI; ang += angle_step * 4.0f) { 01410 EMData v(*this_img_shrink); 01411 Transform t(Dict("type","2d","alpha",static_cast<float>(ang*EMConsts::rad2deg))); 01412 t.set_trans((float)dx,(float)dy); 01413 v.transform(t); 01414 // v.rotate_translate(ang*EMConsts::rad2deg, 0.0f, 0.0f, (float)dx, (float)dy, 0.0f); 01415 01416 float lc = v.cmp(cmp_name, to_shrunk, cmp_params); 01417 01418 if (lc < bestval) { 01419 bestval = lc; 01420 bestang = ang; 01421 bestdx = (float)dx; 01422 bestdy = (float)dy; 01423 bestflip = 0; 01424 } 01425 01426 lc = v.cmp(cmp_name,flipped_shrunk , cmp_params); 01427 if (lc < bestval) { 01428 bestval = lc; 01429 bestang = ang; 01430 bestdx = (float)dx; 01431 bestdy = (float)dy; 01432 bestflip = 1; 01433 } 01434 } 01435 } 01436 } 01437 } 01438 01439 if( to_shrunk ) 01440 { 01441 delete to_shrunk; 01442 to_shrunk = 0; 01443 } 01444 if( flipped_shrunk ) 01445 { 01446 delete flipped_shrunk; 01447 flipped_shrunk = 0; 01448 } 01449 if( this_img_shrink ) 01450 { 01451 delete this_img_shrink; 01452 this_img_shrink = 0; 01453 } 01454 01455 bestdx *= 2; 01456 bestdy *= 2; 01457 bestval = FLT_MAX; 01458 01459 float bestdx2 = bestdx; 01460 float bestdy2 = bestdy; 01461 float bestang2 = bestang; 01462 01463 for (float dy = bestdy2 - 3; dy <= bestdy2 + 3; dy += trans_step) { 01464 for (float dx = bestdx2 - 3; dx <= bestdx2 + 3; dx += trans_step) { 01465 if (hypot(dx, dy) <= maxshift) { 01466 for (float ang = bestang2 - angle_step * 6.0f; ang <= bestang2 + angle_step * 6.0f; ang += angle_step) { 01467 EMData v(*this_img); 01468 Transform t(Dict("type","2d","alpha",static_cast<float>(ang*EMConsts::rad2deg))); 01469 t.set_trans(dx,dy); 01470 v.transform(t); 01471 // v.rotate_translate(ang*EMConsts::rad2deg, 0.0f, 0.0f, (float)dx, (float)dy, 0.0f); 01472 01473 float lc = v.cmp(cmp_name, to, cmp_params); 01474 01475 if (lc < bestval) { 01476 bestval = lc; 01477 bestang = ang; 01478 bestdx = dx; 01479 bestdy = dy; 01480 bestflip = 0; 01481 } 01482 01483 lc = v.cmp(cmp_name, flipped, cmp_params); 01484 01485 if (lc < bestval) { 01486 bestval = lc; 01487 bestang = ang; 01488 bestdx = dx; 01489 bestdy = dy; 01490 bestflip = 1; 01491 } 01492 } 01493 } 01494 } 01495 } 01496 01497 if (delete_flipped) { delete flipped; flipped = 0; } 01498 01499 bestang *= (float)EMConsts::rad2deg; 01500 Transform t(Dict("type","2d","alpha",(float)bestang)); 01501 t.set_trans(bestdx,bestdy); 01502 01503 if (bestflip) { 01504 t.set_mirror(true); 01505 } 01506 01507 EMData* rslt = this_img->process("xform",Dict("transform",&t)); 01508 rslt->set_attr("xform.align2d",&t); 01509 01510 return rslt; 01511 }
virtual string EMAN::RTFSlowExhaustiveAligner::get_desc | ( | ) | const [inline, virtual] |
Implements EMAN::Aligner.
Definition at line 1134 of file aligner.h.
01135 { 01136 return "Experimental full 2D alignment with handedness check using more exhaustive search (not necessarily better than RTFBest)"; 01137 }
virtual string EMAN::RTFSlowExhaustiveAligner::get_name | ( | ) | const [inline, virtual] |
virtual TypeDict EMAN::RTFSlowExhaustiveAligner::get_param_types | ( | ) | const [inline, virtual] |
Implements EMAN::Aligner.
Definition at line 1144 of file aligner.h.
References EMAN::EMObject::EMDATA, EMAN::EMObject::FLOAT, EMAN::EMObject::INT, and EMAN::TypeDict::put().
01145 { 01146 TypeDict d; 01147 d.put("flip", EMObject::EMDATA,"Optional. This is the flipped version of the images that is being aligned. If specified it will be used for the handedness check, if not a flipped copy of the image will be made"); 01148 d.put("maxshift", EMObject::INT,"The maximum length of the detectable translational shift"); 01149 d.put("transtep", EMObject::FLOAT,"The translation step to take when honing the alignment, which occurs after coarse alignment"); 01150 d.put("angstep", EMObject::FLOAT,"The angular step (in degrees) to take in the exhaustive search for the solution angle. Typically very small i.e. 3 or smaller."); 01151 return d; 01152 }
static Aligner* EMAN::RTFSlowExhaustiveAligner::NEW | ( | ) | [inline, static] |
const string RTFSlowExhaustiveAligner::NAME = "rtf_slow_exhaustive" [static] |