#include <aligner.h>
Inheritance diagram for EMAN::RefineAligner:
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 Public Attributes | |
static const string | NAME = "refine" |
Refines a preliminary 2D alignment using a simplex algorithm. Subpixel precision.
Definition at line 562 of file aligner.h.
|
Implements EMAN::Aligner. Definition at line 568 of file aligner.h. References align(). 00569 { 00570 return align(this_img, to_img, "sqeuclidean", Dict()); 00571 }
|
|
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 1023 of file aligner.cpp. References EMAN::EMData::get_attr(), 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(). 01025 { 01026 01027 if (!to) { 01028 return 0; 01029 } 01030 01031 EMData *result; 01032 int mode = params.set_default("mode", 0); 01033 float saz = 0.0; 01034 float sdx = 0.0; 01035 float sdy = 0.0; 01036 bool mirror = false; 01037 Transform* t; 01038 if (params.has_key("xform.align2d") ) { 01039 t = params["xform.align2d"]; 01040 Dict params = t->get_params("2d"); 01041 saz = params["alpha"]; 01042 sdx = params["tx"]; 01043 sdy = params["ty"]; 01044 mirror = params["mirror"]; 01045 01046 } else { 01047 t = new Transform(); // is the identity 01048 } 01049 01050 // We do this to prevent the GSL routine from crashing on an invalid alignment 01051 if ((float)(this_img->get_attr("sigma"))==0.0 || (float)(to->get_attr("sigma"))==0.0) { 01052 result = this_img->process("xform",Dict("transform",t)); 01053 result->set_attr("xform.align2d",t); 01054 delete t; 01055 return result; 01056 } 01057 01058 int np = 3; 01059 Dict gsl_params; 01060 gsl_params["this"] = this_img; 01061 gsl_params["with"] = to; 01062 gsl_params["snr"] = params["snr"]; 01063 gsl_params["mirror"] = mirror; 01064 01065 01066 01067 const gsl_multimin_fminimizer_type *T = gsl_multimin_fminimizer_nmsimplex; 01068 gsl_vector *ss = gsl_vector_alloc(np); 01069 01070 float stepx = params.set_default("stepx",1.0f); 01071 float stepy = params.set_default("stepy",1.0f); 01072 // Default step is 5 degree - note in EMAN1 it was 0.1 radians 01073 float stepaz = params.set_default("stepaz",5.0f); 01074 01075 gsl_vector_set(ss, 0, stepx); 01076 gsl_vector_set(ss, 1, stepy); 01077 gsl_vector_set(ss, 2, stepaz); 01078 01079 gsl_vector *x = gsl_vector_alloc(np); 01080 gsl_vector_set(x, 0, sdx); 01081 gsl_vector_set(x, 1, sdy); 01082 gsl_vector_set(x, 2, saz); 01083 01084 Cmp *c = 0; 01085 01086 gsl_multimin_function minex_func; 01087 if (mode == 2) { 01088 minex_func.f = &refalifnfast; 01089 } 01090 else { 01091 c = Factory < Cmp >::get(cmp_name, cmp_params); 01092 gsl_params["cmp"] = (void *) c; 01093 minex_func.f = &refalifn; 01094 } 01095 01096 minex_func.n = np; 01097 minex_func.params = (void *) &gsl_params; 01098 01099 gsl_multimin_fminimizer *s = gsl_multimin_fminimizer_alloc(T, np); 01100 gsl_multimin_fminimizer_set(s, &minex_func, x, ss); 01101 01102 int rval = GSL_CONTINUE; 01103 int status = GSL_SUCCESS; 01104 int iter = 1; 01105 01106 float precision = params.set_default("precision",0.04f); 01107 int maxiter = params.set_default("maxiter",28); 01108 01109 // printf("Refine sx=%1.2f sy=%1.2f sa=%1.2f prec=%1.4f maxit=%d\n",stepx,stepy,stepaz,precision,maxiter); 01110 // 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)); 01111 01112 while (rval == GSL_CONTINUE && iter < maxiter) { 01113 iter++; 01114 status = gsl_multimin_fminimizer_iterate(s); 01115 if (status) { 01116 break; 01117 } 01118 rval = gsl_multimin_test_size(gsl_multimin_fminimizer_size(s), precision); 01119 } 01120 01121 int maxshift = params.set_default("maxshift",-1); 01122 01123 if (maxshift <= 0) { 01124 maxshift = this_img->get_xsize() / 4; 01125 } 01126 float fmaxshift = static_cast<float>(maxshift); 01127 if ( fmaxshift >= fabs((float)gsl_vector_get(s->x, 0)) && fmaxshift >= fabs((float)gsl_vector_get(s->x, 1)) ) 01128 { 01129 // 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)); 01130 Transform tsoln(Dict("type","2d","alpha",(float)gsl_vector_get(s->x, 2))); 01131 tsoln.set_mirror(mirror); 01132 tsoln.set_trans((float)gsl_vector_get(s->x, 0),(float)gsl_vector_get(s->x, 1)); 01133 result = this_img->process("xform",Dict("transform",&tsoln)); 01134 result->set_attr("xform.align2d",&tsoln); 01135 } else { // The refine aligner failed - this shift went beyond the max shift 01136 // 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)); 01137 result = this_img->process("xform",Dict("transform",t)); 01138 result->set_attr("xform.align2d",t); 01139 } 01140 01141 delete t; 01142 t = 0; 01143 01144 gsl_vector_free(x); 01145 gsl_vector_free(ss); 01146 gsl_multimin_fminimizer_free(s); 01147 01148 if ( c != 0 ) delete c; 01149 return result; 01150 }
|
|
Implements EMAN::Aligner. Definition at line 578 of file aligner.h. 00579 { 00580 return "Refines a preliminary 2D alignment using a simplex algorithm. Subpixel precision."; 00581 }
|
|
Get the Aligner's name. Each Aligner is identified by a unique name.
Implements EMAN::Aligner. Definition at line 573 of file aligner.h. References NAME. 00574 { 00575 return NAME; 00576 }
|
|
Implements EMAN::Aligner. Definition at line 588 of file aligner.h. References EMAN::EMObject::FLOAT, EMAN::EMObject::INT, EMAN::TypeDict::put(), and EMAN::EMObject::TRANSFORM. 00589 { 00590 TypeDict d; 00591 00592 d.put("mode", EMObject::INT, "Currently unused"); 00593 d.put("xform.align2d", EMObject::TRANSFORM, "The Transform storing the starting guess. If unspecified the identity matrix is used"); 00594 d.put("stepx", EMObject::FLOAT, "The x increment used to create the starting simplex. Default is 1"); 00595 d.put("stepy", EMObject::FLOAT, "The y increment used to create the starting simplex. Default is 1"); 00596 d.put("stepaz", EMObject::FLOAT, "The rotational increment used to create the starting simplex. Default is 5"); 00597 d.put("precision", EMObject::FLOAT, "The precision which, if achieved, can stop the iterative refinement before reaching the maximum iterations. Default is 0.04."); 00598 d.put("maxiter", EMObject::INT,"The maximum number of iterations that can be performed by the Simplex minimizer"); 00599 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."); 00600 return d; 00601 }
|
|
Definition at line 583 of file aligner.h.
|
|
Definition at line 603 of file aligner.h. Referenced by get_name(). |