#include <aligner.h>
Inheritance diagram for EMAN::Refine3DAligner:
Public Member Functions | |
virtual EMData * | align (EMData *this_img, EMData *to_img, const string &cmp_name="sqeuclidean", 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 | |
Aligner * | NEW () |
Static Public Attributes | |
const string | NAME = "refine.3d" |
Refines a preliminary 3D alignment using a simplex algorithm. Subpixel precision. Target function for the simplex algorithm is a transformation of the 3D model by az, alt, phi, tx, ty, tz The simplex algorithm downs the function downhill in a ameboa like fasion, hence it may get stuck in a local minima if the two 3D models are already roughly aligned.
Definition at line 809 of file aligner.h.
|
Implements EMAN::Aligner. Definition at line 815 of file aligner.h. References align(). 00816 { 00817 return align(this_img, to_img, "sqeuclidean", Dict()); 00818 }
|
|
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 1447 of file aligner.cpp. References EMAN::EMData::cmp(), EMAN::EMData::get_ndim(), EMAN::EMData::get_xsize(), EMAN::Dict::has_key(), ImageDimensionException, NullPointerException, EMAN::Cmp::params, EMAN::EMData::process(), EMAN::EMData::set_attr(), EMAN::Dict::set_default(), status, t, and x. 01449 { 01450 01451 if (!to || !this_img) throw NullPointerException("Input image is null"); // not sure if this is necessary, it was there before I started 01452 01453 if (to->get_ndim() != 3 || this_img->get_ndim() != 3) throw ImageDimensionException("The Refine3D aligner only works for 3D images"); 01454 01455 float saz = 0.0; 01456 float sphi = 0.0; 01457 float salt = 0.0; 01458 float sdx = 0.0; 01459 float sdy = 0.0; 01460 float sdz = 0.0; 01461 bool mirror = false; 01462 Transform* t; 01463 if (params.has_key("xform.align3d") ) { 01464 // Unlike the 2d refine aligner, this class doesn't require the starting transform's 01465 // parameters to form the starting guess. Instead the Transform itself 01466 // is perturbed carefully (using quaternion rotation) to overcome problems that arise 01467 // when you use orthogonally-based Euler angles 01468 t = params["xform.align3d"]; 01469 }else { 01470 t = new Transform(); // is the identity 01471 } 01472 01473 int np = 6; // the number of dimensions 01474 Dict gsl_params; 01475 gsl_params["this"] = this_img; 01476 gsl_params["with"] = to; 01477 gsl_params["snr"] = params["snr"]; 01478 gsl_params["mirror"] = mirror; 01479 gsl_params["transform"] = t; 01480 Dict altered_cmp_params(cmp_params); 01481 if(cmp_name == "ccc.tomo"){ 01482 altered_cmp_params["zeroori"] = true; 01483 } 01484 01485 const gsl_multimin_fminimizer_type *T = gsl_multimin_fminimizer_nmsimplex; 01486 gsl_vector *ss = gsl_vector_alloc(np); 01487 01488 float stepx = params.set_default("stepx",1.0f); 01489 float stepy = params.set_default("stepy",1.0f); 01490 float stepz = params.set_default("stepz",1.0f); 01491 // Default step is 5 degree - note in EMAN1 it was 0.1 radians 01492 //float half_circle_step = 180.0f; // This shouldn't be altered 01493 //float stepphi = params.set_default("stephi",5.0f); 01494 //float stepdelta = params.set_default("stepdelta",5.0f); 01495 float stepaz = params.set_default("stepaz",5.0f); 01496 float stepalt = params.set_default("stepalt",5.0f); 01497 float stepphi = params.set_default("stepphi",5.0f); 01498 01499 gsl_vector_set(ss, 0, stepx); 01500 gsl_vector_set(ss, 1, stepy); 01501 gsl_vector_set(ss, 2, stepz); 01502 //gsl_vector_set(ss, 3, half_circle_step); 01503 //gsl_vector_set(ss, 4, stepdelta); 01504 //gsl_vector_set(ss, 5, stepphi); 01505 gsl_vector_set(ss, 3, stepaz); 01506 gsl_vector_set(ss, 4, stepalt); 01507 gsl_vector_set(ss, 5, stepphi); 01508 01509 gsl_vector *x = gsl_vector_alloc(np); 01510 gsl_vector_set(x, 0, sdx); 01511 gsl_vector_set(x, 1, sdy); 01512 gsl_vector_set(x, 2, sdz); 01513 gsl_vector_set(x, 3, saz); 01514 gsl_vector_set(x, 4, salt); 01515 gsl_vector_set(x, 5, sphi); 01516 01517 gsl_multimin_function minex_func; 01518 Cmp *c = Factory < Cmp >::get(cmp_name, altered_cmp_params); 01519 gsl_params["cmp"] = (void *) c; 01520 minex_func.f = &refalifn3d; 01521 01522 minex_func.n = np; 01523 minex_func.params = (void *) &gsl_params; 01524 01525 gsl_multimin_fminimizer *s = gsl_multimin_fminimizer_alloc(T, np); 01526 gsl_multimin_fminimizer_set(s, &minex_func, x, ss); 01527 01528 int rval = GSL_CONTINUE; 01529 int status = GSL_SUCCESS; 01530 int iter = 1; 01531 01532 float precision = params.set_default("precision",0.04f); 01533 int maxiter = params.set_default("maxiter",60); 01534 while (rval == GSL_CONTINUE && iter < maxiter) { 01535 iter++; 01536 status = gsl_multimin_fminimizer_iterate(s); 01537 if (status) { 01538 break; 01539 } 01540 rval = gsl_multimin_test_size(gsl_multimin_fminimizer_size(s), precision); 01541 } 01542 01543 int maxshift = params.set_default("maxshift",-1); 01544 01545 if (maxshift <= 0) { 01546 maxshift = this_img->get_xsize() / 4; 01547 } 01548 float fmaxshift = static_cast<float>(maxshift); 01549 EMData *result; 01550 if ( fmaxshift >= (float)gsl_vector_get(s->x, 0) && fmaxshift >= (float)gsl_vector_get(s->x, 1) && fmaxshift >= (float)gsl_vector_get(s->x, 2)) 01551 { 01552 01553 //float x = (float)gsl_vector_get(s->x, 0); 01554 //float y = (float)gsl_vector_get(s->x, 1); 01555 //float z = (float)gsl_vector_get(s->x, 2); 01556 //float arc = (float)gsl_vector_get(s->x, 3); 01557 //float delta = (float)gsl_vector_get(s->x, 4); 01558 //float phi = (float)gsl_vector_get(s->x, 5); 01559 01560 //Transform tsoln = refalin3d_perturb(t,delta,arc,phi,x,y,z); 01561 01562 //result = this_img->process("xform",Dict("transform",&tsoln)); 01563 //result->set_attr("xform.align3d",&tsoln); 01564 Dict parms; 01565 parms["type"] = "eman"; 01566 parms["tx"] = (float)gsl_vector_get(s->x, 0); 01567 parms["ty"] = (float)gsl_vector_get(s->x, 1); 01568 parms["tz"] = (float)gsl_vector_get(s->x, 2); 01569 parms["az"] = (float)gsl_vector_get(s->x, 3); 01570 parms["alt"] = (float)gsl_vector_get(s->x, 4); 01571 parms["phi"] = (float)gsl_vector_get(s->x, 5); 01572 01573 Transform tsoln(parms); 01574 result = this_img->process("xform",Dict("transform",&tsoln)); 01575 result->set_attr("xform.align3d",&tsoln); 01576 result->set_attr("score", result->cmp(cmp_name,to,cmp_params)); 01577 01578 } else { // The refine aligner failed - this shift went beyond the max shift 01579 result = this_img->process("xform",Dict("transform",t)); 01580 result->set_attr("xform.align3d",t); 01581 } 01582 01583 delete t; 01584 t = 0; 01585 01586 gsl_vector_free(x); 01587 gsl_vector_free(ss); 01588 gsl_multimin_fminimizer_free(s); 01589 01590 if ( c != 0 ) delete c; 01591 return result; 01592 }
|
|
Implements EMAN::Aligner. Definition at line 825 of file aligner.h. 00826 { 00827 return "Refines a preliminary 3D alignment using a simplex algorithm. Subpixel precision."; 00828 }
|
|
Get the Aligner's name. Each Aligner is identified by a unique name.
Implements EMAN::Aligner. Definition at line 820 of file aligner.h. 00821 {
00822 return NAME;
00823 }
|
|
Implements EMAN::Aligner. Definition at line 835 of file aligner.h. References EMAN::TypeDict::put(). 00836 { 00837 TypeDict d; 00838 d.put("xform.align3d", EMObject::TRANSFORM,"The Transform storing the starting guess. If unspecified the identity matrix is used"); 00839 d.put("stepx", EMObject::FLOAT, "The x increment used to create the starting simplex. Default is 1"); 00840 d.put("stepy", EMObject::FLOAT, "The y increment used to create the starting simplex. Default is 1"); 00841 d.put("stepz", EMObject::FLOAT, "The z increment used to create the starting simplex. Default is 1." ); 00842 d.put("stepaz", EMObject::FLOAT, "The az increment used to create the starting simplex. Default is 5." ); 00843 d.put("stepalt", EMObject::FLOAT, "The alt increment used to create the starting simplex. Default is 5." ); 00844 d.put("stepphi", EMObject::FLOAT, "The phi incremenent used to create the starting simplex. Default is 5." ); 00845 d.put("precision", EMObject::FLOAT, "The precision which, if achieved, can stop the iterative refinement before reaching the maximum iterations. Default is 0.04." ); 00846 d.put("maxiter", EMObject::INT, "The maximum number of iterations that can be performed by the Simplex minimizer. Default is 60."); 00847 d.put("maxshift", EMObject::INT,"Maximum translation in pixels in any direction. If the solution yields a shift beyond this value in any direction, then the refinement is judged a failure and the original alignment is used as the solution."); 00848 return d; 00849 }
|
|
Definition at line 830 of file aligner.h. 00831 { 00832 return new Refine3DAligner(); 00833 }
|
|
Definition at line 67 of file aligner.cpp. |