#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 | |
Aligner * | NEW () |
Static Public Attributes | |
const string | NAME = "refine" |
Refines a preliminary 2D alignment using a simplex algorithm. Subpixel precision.
Definition at line 853 of file aligner.h.
|
Implements EMAN::Aligner. Definition at line 859 of file aligner.h. References align(). 00860 { 00861 return align(this_img, to_img, "sqeuclidean", Dict()); 00862 }
|
|
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 1389 of file aligner.cpp. References EMAN::EMData::get_attr(), EMAN::Transform::get_params(), EMAN::EMData::get_xsize(), EMAN::Dict::has_key(), EMAN::Cmp::params, EMAN::EMData::process(), EMAN::EMData::set_attr(), EMAN::Dict::set_default(), status, t, and x. 01391 { 01392 01393 if (!to) { 01394 return 0; 01395 } 01396 01397 EMData *result; 01398 int mode = params.set_default("mode", 0); 01399 float saz = 0.0; 01400 float sdx = 0.0; 01401 float sdy = 0.0; 01402 float sscale = 1.0; 01403 bool mirror = false; 01404 Transform* t; 01405 if (params.has_key("xform.align2d") ) { 01406 t = params["xform.align2d"]; 01407 Dict params = t->get_params("2d"); 01408 saz = params["alpha"]; 01409 sdx = params["tx"]; 01410 sdy = params["ty"]; 01411 mirror = params["mirror"]; 01412 sscale = params["scale"]; 01413 } else { 01414 t = new Transform(); // is the identity 01415 } 01416 01417 // We do this to prevent the GSL routine from crashing on an invalid alignment 01418 if ((float)(this_img->get_attr("sigma"))==0.0 || (float)(to->get_attr("sigma"))==0.0) { 01419 result = this_img->process("xform",Dict("transform",t)); 01420 result->set_attr("xform.align2d",t); 01421 delete t; 01422 return result; 01423 } 01424 01425 float stepx = params.set_default("stepx",1.0f); 01426 float stepy = params.set_default("stepy",1.0f); 01427 // Default step is 5 degree - note in EMAN1 it was 0.1 radians 01428 float stepaz = params.set_default("stepaz",5.0f); 01429 float stepscale = params.set_default("stepscale",0.0f); 01430 01431 int np = 3; 01432 if (stepscale!=0.0) np++; 01433 Dict gsl_params; 01434 gsl_params["this"] = this_img; 01435 gsl_params["with"] = to; 01436 gsl_params["snr"] = params["snr"]; 01437 gsl_params["mirror"] = mirror; 01438 01439 const gsl_multimin_fminimizer_type *T = gsl_multimin_fminimizer_nmsimplex; 01440 gsl_vector *ss = gsl_vector_alloc(np); 01441 01442 01443 gsl_vector_set(ss, 0, stepx); 01444 gsl_vector_set(ss, 1, stepy); 01445 gsl_vector_set(ss, 2, stepaz); 01446 if (stepscale!=0.0) gsl_vector_set(ss,3,stepscale); 01447 01448 gsl_vector *x = gsl_vector_alloc(np); 01449 gsl_vector_set(x, 0, sdx); 01450 gsl_vector_set(x, 1, sdy); 01451 gsl_vector_set(x, 2, saz); 01452 if (stepscale!=0.0) gsl_vector_set(x,3,1.0); 01453 01454 Cmp *c = 0; 01455 01456 gsl_multimin_function minex_func; 01457 if (mode == 2) { 01458 minex_func.f = &refalifnfast; 01459 } 01460 else { 01461 c = Factory < Cmp >::get(cmp_name, cmp_params); 01462 gsl_params["cmp"] = (void *) c; 01463 minex_func.f = &refalifn; 01464 } 01465 01466 minex_func.n = np; 01467 minex_func.params = (void *) &gsl_params; 01468 01469 gsl_multimin_fminimizer *s = gsl_multimin_fminimizer_alloc(T, np); 01470 gsl_multimin_fminimizer_set(s, &minex_func, x, ss); 01471 01472 int rval = GSL_CONTINUE; 01473 int status = GSL_SUCCESS; 01474 int iter = 1; 01475 01476 float precision = params.set_default("precision",0.04f); 01477 int maxiter = params.set_default("maxiter",28); 01478 01479 // printf("Refine sx=%1.2f sy=%1.2f sa=%1.2f prec=%1.4f maxit=%d\n",stepx,stepy,stepaz,precision,maxiter); 01480 // 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)); 01481 01482 while (rval == GSL_CONTINUE && iter < maxiter) { 01483 iter++; 01484 status = gsl_multimin_fminimizer_iterate(s); 01485 if (status) { 01486 break; 01487 } 01488 rval = gsl_multimin_test_size(gsl_multimin_fminimizer_size(s), precision); 01489 } 01490 01491 int maxshift = params.set_default("maxshift",-1); 01492 01493 if (maxshift <= 0) { 01494 maxshift = this_img->get_xsize() / 4; 01495 } 01496 float fmaxshift = static_cast<float>(maxshift); 01497 if ( fmaxshift >= fabs((float)gsl_vector_get(s->x, 0)) && fmaxshift >= fabs((float)gsl_vector_get(s->x, 1)) && (stepscale==0 || (((float)gsl_vector_get(s->x, 3))<1.3 && ((float)gsl_vector_get(s->x, 3))<0.7)) ) 01498 { 01499 // 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)); 01500 Transform tsoln(Dict("type","2d","alpha",(float)gsl_vector_get(s->x, 2))); 01501 tsoln.set_mirror(mirror); 01502 tsoln.set_trans((float)gsl_vector_get(s->x, 0),(float)gsl_vector_get(s->x, 1)); 01503 if (stepscale!=0.0) tsoln.set_scale((float)gsl_vector_get(s->x, 3)); 01504 result = this_img->process("xform",Dict("transform",&tsoln)); 01505 result->set_attr("xform.align2d",&tsoln); 01506 } else { // The refine aligner failed - this shift went beyond the max shift 01507 // 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)); 01508 result = this_img->process("xform",Dict("transform",t)); 01509 result->set_attr("xform.align2d",t); 01510 } 01511 01512 delete t; 01513 t = 0; 01514 01515 gsl_vector_free(x); 01516 gsl_vector_free(ss); 01517 gsl_multimin_fminimizer_free(s); 01518 01519 if ( c != 0 ) delete c; 01520 return result; 01521 }
|
|
Implements EMAN::Aligner. Definition at line 869 of file aligner.h. 00870 { 00871 return "Refines a preliminary 2D alignment using a simplex algorithm. Subpixel precision."; 00872 }
|
|
Get the Aligner's name. Each Aligner is identified by a unique name.
Implements EMAN::Aligner. Definition at line 864 of file aligner.h. 00865 {
00866 return NAME;
00867 }
|
|
Implements EMAN::Aligner. Definition at line 879 of file aligner.h. References EMAN::TypeDict::put(). 00880 { 00881 TypeDict d; 00882 00883 d.put("mode", EMObject::INT, "Currently unused"); 00884 d.put("xform.align2d", EMObject::TRANSFORM, "The Transform storing the starting guess. If unspecified the identity matrix is used"); 00885 d.put("stepx", EMObject::FLOAT, "The x increment used to create the starting simplex. Default is 1"); 00886 d.put("stepy", EMObject::FLOAT, "The y increment used to create the starting simplex. Default is 1"); 00887 d.put("stepaz", EMObject::FLOAT, "The rotational increment used to create the starting simplex. Default is 5"); 00888 d.put("precision", EMObject::FLOAT, "The precision which, if achieved, can stop the iterative refinement before reaching the maximum iterations. Default is 0.04."); 00889 d.put("maxiter", EMObject::INT,"The maximum number of iterations that can be performed by the Simplex minimizer"); 00890 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."); 00891 d.put("stepscale", EMObject::FLOAT, "If set to any non-zero value, scale will be included in the alignment, and this will be the initial step. Images should be edgenormalized. If the scale goes beyond +-30% alignment will fail."); 00892 return d; 00893 }
|
|
Definition at line 874 of file aligner.h. 00875 { 00876 return new RefineAligner(); 00877 }
|
|
Definition at line 73 of file aligner.cpp. |