#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 | |
Aligner * | NEW () |
Static Public Attributes | |
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 1126 of file aligner.h.
|
Implements EMAN::Aligner. Definition at line 1131 of file aligner.h. References align(). 01132 { 01133 return align(this_img, to_img, "sqeuclidean", Dict()); 01134 }
|
|
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.
Implements EMAN::Aligner. Definition at line 1372 of file aligner.cpp. References EMAN::EMData::cmp(), EMAN::EMData::get_xsize(), InvalidParameterException, nx, EMAN::EMData::process(), EMAN::EMData::set_attr(), EMAN::Dict::set_default(), EMAN::Transform::set_mirror(), EMAN::Transform::set_trans(), t, EMAN::EMData::transform(), and v. 01374 { 01375 01376 EMData *flip = params.set_default("flip", (EMData *) 0); 01377 int maxshift = params.set_default("maxshift", -1); 01378 01379 EMData *flipped = 0; 01380 01381 bool delete_flipped = true; 01382 if (flip) { 01383 delete_flipped = false; 01384 flipped = flip; 01385 } 01386 else { 01387 flipped = to->process("xform.flip", Dict("axis", "x")); 01388 } 01389 01390 int nx = this_img->get_xsize(); 01391 01392 if (maxshift < 0) { 01393 maxshift = nx / 10; 01394 } 01395 01396 float angle_step = params.set_default("angstep", 0.0f); 01397 if ( angle_step == 0 ) angle_step = atan2(2.0f, (float)nx); 01398 else { 01399 angle_step *= (float)EMConsts::deg2rad; //convert to radians 01400 } 01401 float trans_step = params.set_default("transtep",1.0f); 01402 01403 if (trans_step <= 0) throw InvalidParameterException("transstep must be greater than 0"); 01404 if (angle_step <= 0) throw InvalidParameterException("angstep must be greater than 0"); 01405 01406 01407 Dict shrinkfactor("n",2); 01408 EMData *this_img_shrink = this_img->process("math.medianshrink",shrinkfactor); 01409 EMData *to_shrunk = to->process("math.medianshrink",shrinkfactor); 01410 EMData *flipped_shrunk = flipped->process("math.medianshrink",shrinkfactor); 01411 01412 int bestflip = 0; 01413 float bestdx = 0; 01414 float bestdy = 0; 01415 01416 float bestang = 0; 01417 float bestval = FLT_MAX; 01418 01419 int half_maxshift = maxshift / 2; 01420 01421 01422 for (int dy = -half_maxshift; dy <= half_maxshift; ++dy) { 01423 for (int dx = -half_maxshift; dx <= half_maxshift; ++dx) { 01424 if (hypot(dx, dy) <= maxshift) { 01425 for (float ang = -angle_step * 2.0f; ang <= (float)2 * M_PI; ang += angle_step * 4.0f) { 01426 EMData v(*this_img_shrink); 01427 Transform t(Dict("type","2d","alpha",static_cast<float>(ang*EMConsts::rad2deg))); 01428 t.set_trans((float)dx,(float)dy); 01429 v.transform(t); 01430 // v.rotate_translate(ang*EMConsts::rad2deg, 0.0f, 0.0f, (float)dx, (float)dy, 0.0f); 01431 01432 float lc = v.cmp(cmp_name, to_shrunk, cmp_params); 01433 01434 if (lc < bestval) { 01435 bestval = lc; 01436 bestang = ang; 01437 bestdx = (float)dx; 01438 bestdy = (float)dy; 01439 bestflip = 0; 01440 } 01441 01442 lc = v.cmp(cmp_name,flipped_shrunk , cmp_params); 01443 if (lc < bestval) { 01444 bestval = lc; 01445 bestang = ang; 01446 bestdx = (float)dx; 01447 bestdy = (float)dy; 01448 bestflip = 1; 01449 } 01450 } 01451 } 01452 } 01453 } 01454 01455 if( to_shrunk ) 01456 { 01457 delete to_shrunk; 01458 to_shrunk = 0; 01459 } 01460 if( flipped_shrunk ) 01461 { 01462 delete flipped_shrunk; 01463 flipped_shrunk = 0; 01464 } 01465 if( this_img_shrink ) 01466 { 01467 delete this_img_shrink; 01468 this_img_shrink = 0; 01469 } 01470 01471 bestdx *= 2; 01472 bestdy *= 2; 01473 bestval = FLT_MAX; 01474 01475 float bestdx2 = bestdx; 01476 float bestdy2 = bestdy; 01477 float bestang2 = bestang; 01478 01479 for (float dy = bestdy2 - 3; dy <= bestdy2 + 3; dy += trans_step) { 01480 for (float dx = bestdx2 - 3; dx <= bestdx2 + 3; dx += trans_step) { 01481 if (hypot(dx, dy) <= maxshift) { 01482 for (float ang = bestang2 - angle_step * 6.0f; ang <= bestang2 + angle_step * 6.0f; ang += angle_step) { 01483 EMData v(*this_img); 01484 Transform t(Dict("type","2d","alpha",static_cast<float>(ang*EMConsts::rad2deg))); 01485 t.set_trans(dx,dy); 01486 v.transform(t); 01487 // v.rotate_translate(ang*EMConsts::rad2deg, 0.0f, 0.0f, (float)dx, (float)dy, 0.0f); 01488 01489 float lc = v.cmp(cmp_name, to, cmp_params); 01490 01491 if (lc < bestval) { 01492 bestval = lc; 01493 bestang = ang; 01494 bestdx = dx; 01495 bestdy = dy; 01496 bestflip = 0; 01497 } 01498 01499 lc = v.cmp(cmp_name, flipped, cmp_params); 01500 01501 if (lc < bestval) { 01502 bestval = lc; 01503 bestang = ang; 01504 bestdx = dx; 01505 bestdy = dy; 01506 bestflip = 1; 01507 } 01508 } 01509 } 01510 } 01511 } 01512 01513 if (delete_flipped) { delete flipped; flipped = 0; } 01514 01515 bestang *= (float)EMConsts::rad2deg; 01516 Transform t(Dict("type","2d","alpha",(float)bestang)); 01517 t.set_trans(bestdx,bestdy); 01518 01519 if (bestflip) { 01520 t.set_mirror(true); 01521 } 01522 01523 EMData* rslt = this_img->process("xform",Dict("transform",&t)); 01524 rslt->set_attr("xform.align2d",&t); 01525 01526 return rslt; 01527 }
|
|
Implements EMAN::Aligner. Definition at line 1140 of file aligner.h. 01141 { 01142 return "Experimental full 2D alignment with handedness check using more exhaustive search (not necessarily better than RTFBest)"; 01143 }
|
|
Get the Aligner's name. Each Aligner is identified by a unique name.
Implements EMAN::Aligner. Definition at line 1135 of file aligner.h. 01136 {
01137 return NAME;
01138 }
|
|
Implements EMAN::Aligner. Definition at line 1150 of file aligner.h. References EMAN::TypeDict::put(). 01151 { 01152 TypeDict d; 01153 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"); 01154 d.put("maxshift", EMObject::INT,"The maximum length of the detectable translational shift"); 01155 d.put("transtep", EMObject::FLOAT,"The translation step to take when honing the alignment, which occurs after coarse alignment"); 01156 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."); 01157 return d; 01158 }
|
|
Definition at line 1145 of file aligner.h. 01146 { 01147 return new RTFSlowExhaustiveAligner(); 01148 }
|
|
Definition at line 77 of file aligner.cpp. |