#include <aligner.h>


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 () |
Refines a preliminary 2D alignment using a simplex algorithm. Subpixel precision.
Definition at line 544 of file aligner.h.
| EMData * RefineAligner::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 997 of file aligner.cpp.
References EMAN::Transform::get_params(), EMAN::EMData::get_xsize(), EMAN::Dict::has_key(), EMAN::Aligner::params, EMAN::EMData::process(), refalifn(), refalifnfast(), EMAN::EMData::set_attr(), EMAN::Dict::set_default(), EMAN::Transform::set_mirror(), EMAN::Transform::set_trans(), status, t, and x.
Referenced by align().
00999 { 01000 01001 if (!to) { 01002 return 0; 01003 } 01004 01005 int mode = params.set_default("mode", 0); 01006 float saz = 0.0; 01007 float sdx = 0.0; 01008 float sdy = 0.0; 01009 bool mirror = false; 01010 Transform* t; 01011 if (params.has_key("xform.align2d") ) { 01012 t = params["xform.align2d"]; 01013 Dict params = t->get_params("2d"); 01014 saz = params["alpha"]; 01015 sdx = params["tx"]; 01016 sdy = params["ty"]; 01017 mirror = params["mirror"]; 01018 01019 } else { 01020 t = new Transform(); // is the identity 01021 } 01022 01023 int np = 3; 01024 Dict gsl_params; 01025 gsl_params["this"] = this_img; 01026 gsl_params["with"] = to; 01027 gsl_params["snr"] = params["snr"]; 01028 gsl_params["mirror"] = mirror; 01029 01030 01031 01032 const gsl_multimin_fminimizer_type *T = gsl_multimin_fminimizer_nmsimplex; 01033 gsl_vector *ss = gsl_vector_alloc(np); 01034 01035 float stepx = params.set_default("stepx",1.0f); 01036 float stepy = params.set_default("stepy",1.0f); 01037 // Default step is 5 degree - note in EMAN1 it was 0.1 radians 01038 float stepaz = params.set_default("stepaz",5.0f); 01039 01040 gsl_vector_set(ss, 0, stepx); 01041 gsl_vector_set(ss, 1, stepy); 01042 gsl_vector_set(ss, 2, stepaz); 01043 01044 gsl_vector *x = gsl_vector_alloc(np); 01045 gsl_vector_set(x, 0, sdx); 01046 gsl_vector_set(x, 1, sdy); 01047 gsl_vector_set(x, 2, saz); 01048 01049 Cmp *c = 0; 01050 01051 gsl_multimin_function minex_func; 01052 if (mode == 2) { 01053 minex_func.f = &refalifnfast; 01054 } 01055 else { 01056 c = Factory < Cmp >::get(cmp_name, cmp_params); 01057 gsl_params["cmp"] = (void *) c; 01058 minex_func.f = &refalifn; 01059 } 01060 01061 minex_func.n = np; 01062 minex_func.params = (void *) &gsl_params; 01063 01064 gsl_multimin_fminimizer *s = gsl_multimin_fminimizer_alloc(T, np); 01065 gsl_multimin_fminimizer_set(s, &minex_func, x, ss); 01066 01067 int rval = GSL_CONTINUE; 01068 int status = GSL_SUCCESS; 01069 int iter = 1; 01070 01071 float precision = params.set_default("precision",0.04f); 01072 int maxiter = params.set_default("maxiter",28); 01073 01074 // printf("Refine sx=%1.2f sy=%1.2f sa=%1.2f prec=%1.4f maxit=%d\n",stepx,stepy,stepaz,precision,maxiter); 01075 // printf("%1.2f %1.2f %1.1f ->",(float)gsl_vector_get(s->x, 0),(float)gsl_vector_get(s->x, 1),(float)gsl_vector_get(s->x, 2)); 01076 01077 while (rval == GSL_CONTINUE && iter < maxiter) { 01078 iter++; 01079 status = gsl_multimin_fminimizer_iterate(s); 01080 if (status) { 01081 break; 01082 } 01083 rval = gsl_multimin_test_size(gsl_multimin_fminimizer_size(s), precision); 01084 } 01085 01086 int maxshift = params.set_default("maxshift",-1); 01087 01088 if (maxshift <= 0) { 01089 maxshift = this_img->get_xsize() / 4; 01090 } 01091 float fmaxshift = static_cast<float>(maxshift); 01092 EMData *result; 01093 if ( fmaxshift >= fabs((float)gsl_vector_get(s->x, 0)) && fmaxshift >= fabs((float)gsl_vector_get(s->x, 1)) ) 01094 { 01095 // printf(" Refine good %1.2f %1.2f %1.1f\n",(float)gsl_vector_get(s->x, 0),(float)gsl_vector_get(s->x, 1),(float)gsl_vector_get(s->x, 2)); 01096 Transform tsoln(Dict("type","2d","alpha",(float)gsl_vector_get(s->x, 2))); 01097 tsoln.set_mirror(mirror); 01098 tsoln.set_trans((float)gsl_vector_get(s->x, 0),(float)gsl_vector_get(s->x, 1)); 01099 result = this_img->process("math.transform",Dict("transform",&tsoln)); 01100 result->set_attr("xform.align2d",&tsoln); 01101 } else { // The refine aligner failed - this shift went beyond the max shift 01102 // printf(" Refine Failed %1.2f %1.2f %1.1f\n",(float)gsl_vector_get(s->x, 0),(float)gsl_vector_get(s->x, 1),(float)gsl_vector_get(s->x, 2)); 01103 result = this_img->process("math.transform",Dict("transform",t)); 01104 result->set_attr("xform.align2d",t); 01105 } 01106 01107 delete t; 01108 t = 0; 01109 01110 gsl_vector_free(x); 01111 gsl_vector_free(ss); 01112 gsl_multimin_fminimizer_free(s); 01113 01114 if ( c != 0 ) delete c; 01115 return result; 01116 }
| virtual EMData* EMAN::RefineAligner::align | ( | EMData * | this_img, | |
| EMData * | to_img | |||
| ) | const [inline, virtual] |
Implements EMAN::Aligner.
Definition at line 550 of file aligner.h.
References align().
00551 { 00552 return align(this_img, to_img, "sqeuclidean", Dict()); 00553 }
| virtual string EMAN::RefineAligner::get_name | ( | ) | const [inline, virtual] |
Get the Aligner's name.
Each Aligner is identified by a unique name.
Implements EMAN::Aligner.
Definition at line 555 of file aligner.h.
| virtual string EMAN::RefineAligner::get_desc | ( | ) | const [inline, virtual] |
Implements EMAN::Aligner.
Definition at line 560 of file aligner.h.
00561 { 00562 return "Refines a preliminary 2D alignment using a simplex algorithm. Subpixel precision."; 00563 }
| static Aligner* EMAN::RefineAligner::NEW | ( | ) | [inline, static] |
| virtual TypeDict EMAN::RefineAligner::get_param_types | ( | ) | const [inline, virtual] |
Implements EMAN::Aligner.
Definition at line 570 of file aligner.h.
References EMAN::EMObject::FLOAT, EMAN::EMObject::INT, EMAN::TypeDict::put(), and EMAN::EMObject::TRANSFORM.
00571 { 00572 TypeDict d; 00573 00574 d.put("mode", EMObject::INT, "Currently unused"); 00575 d.put("xform.align2d", EMObject::TRANSFORM, "The Transform storing the starting guess. If unspecified the identity matrix is used"); 00576 d.put("stepx", EMObject::FLOAT, "The x increment used to create the starting simplex. Default is 1"); 00577 d.put("stepy", EMObject::FLOAT, "The y increment used to create the starting simplex. Default is 1"); 00578 d.put("stepaz", EMObject::FLOAT, "The rotational increment used to create the starting simplex. Default is 5"); 00579 d.put("precision", EMObject::FLOAT, "The precision which, if achieved, can stop the iterative refinement before reaching the maximum iterations. Default is 0.04."); 00580 d.put("maxiter", EMObject::INT,"The maximum number of iterations that can be performed by the Simplex minimizer"); 00581 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."); 00582 return d; 00583 }
1.5.6