#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 1391 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. 01393 { 01394 01395 if (!to) { 01396 return 0; 01397 } 01398 01399 EMData *result; 01400 int mode = params.set_default("mode", 0); 01401 float saz = 0.0; 01402 float sdx = 0.0; 01403 float sdy = 0.0; 01404 float sscale = 1.0; 01405 bool mirror = false; 01406 Transform* t; 01407 if (params.has_key("xform.align2d") ) { 01408 t = params["xform.align2d"]; 01409 Dict params = t->get_params("2d"); 01410 saz = params["alpha"]; 01411 sdx = params["tx"]; 01412 sdy = params["ty"]; 01413 mirror = params["mirror"]; 01414 sscale = params["scale"]; 01415 } else { 01416 t = new Transform(); // is the identity 01417 } 01418 01419 // We do this to prevent the GSL routine from crashing on an invalid alignment 01420 if ((float)(this_img->get_attr("sigma"))==0.0 || (float)(to->get_attr("sigma"))==0.0) { 01421 result = this_img->process("xform",Dict("transform",t)); 01422 result->set_attr("xform.align2d",t); 01423 delete t; 01424 return result; 01425 } 01426 01427 float stepx = params.set_default("stepx",1.0f); 01428 float stepy = params.set_default("stepy",1.0f); 01429 // Default step is 5 degree - note in EMAN1 it was 0.1 radians 01430 float stepaz = params.set_default("stepaz",5.0f); 01431 float stepscale = params.set_default("stepscale",0.0f); 01432 01433 int np = 3; 01434 if (stepscale!=0.0) np++; 01435 Dict gsl_params; 01436 gsl_params["this"] = this_img; 01437 gsl_params["with"] = to; 01438 gsl_params["snr"] = params["snr"]; 01439 gsl_params["mirror"] = mirror; 01440 01441 const gsl_multimin_fminimizer_type *T = gsl_multimin_fminimizer_nmsimplex; 01442 gsl_vector *ss = gsl_vector_alloc(np); 01443 01444 01445 gsl_vector_set(ss, 0, stepx); 01446 gsl_vector_set(ss, 1, stepy); 01447 gsl_vector_set(ss, 2, stepaz); 01448 if (stepscale!=0.0) gsl_vector_set(ss,3,stepscale); 01449 01450 gsl_vector *x = gsl_vector_alloc(np); 01451 gsl_vector_set(x, 0, sdx); 01452 gsl_vector_set(x, 1, sdy); 01453 gsl_vector_set(x, 2, saz); 01454 if (stepscale!=0.0) gsl_vector_set(x,3,1.0); 01455 01456 Cmp *c = 0; 01457 01458 gsl_multimin_function minex_func; 01459 if (mode == 2) { 01460 minex_func.f = &refalifnfast; 01461 } 01462 else { 01463 c = Factory < Cmp >::get(cmp_name, cmp_params); 01464 gsl_params["cmp"] = (void *) c; 01465 minex_func.f = &refalifn; 01466 } 01467 01468 minex_func.n = np; 01469 minex_func.params = (void *) &gsl_params; 01470 01471 gsl_multimin_fminimizer *s = gsl_multimin_fminimizer_alloc(T, np); 01472 gsl_multimin_fminimizer_set(s, &minex_func, x, ss); 01473 01474 int rval = GSL_CONTINUE; 01475 int status = GSL_SUCCESS; 01476 int iter = 1; 01477 01478 float precision = params.set_default("precision",0.04f); 01479 int maxiter = params.set_default("maxiter",28); 01480 01481 // printf("Refine sx=%1.2f sy=%1.2f sa=%1.2f prec=%1.4f maxit=%d\n",stepx,stepy,stepaz,precision,maxiter); 01482 // 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)); 01483 01484 while (rval == GSL_CONTINUE && iter < maxiter) { 01485 iter++; 01486 status = gsl_multimin_fminimizer_iterate(s); 01487 if (status) { 01488 break; 01489 } 01490 rval = gsl_multimin_test_size(gsl_multimin_fminimizer_size(s), precision); 01491 } 01492 01493 int maxshift = params.set_default("maxshift",-1); 01494 01495 if (maxshift <= 0) { 01496 maxshift = this_img->get_xsize() / 4; 01497 } 01498 float fmaxshift = static_cast<float>(maxshift); 01499 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)) ) 01500 { 01501 // 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)); 01502 Transform tsoln(Dict("type","2d","alpha",(float)gsl_vector_get(s->x, 2))); 01503 tsoln.set_mirror(mirror); 01504 tsoln.set_trans((float)gsl_vector_get(s->x, 0),(float)gsl_vector_get(s->x, 1)); 01505 if (stepscale!=0.0) tsoln.set_scale((float)gsl_vector_get(s->x, 3)); 01506 result = this_img->process("xform",Dict("transform",&tsoln)); 01507 result->set_attr("xform.align2d",&tsoln); 01508 } else { // The refine aligner failed - this shift went beyond the max shift 01509 // 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)); 01510 result = this_img->process("xform",Dict("transform",t)); 01511 result->set_attr("xform.align2d",t); 01512 } 01513 01514 delete t; 01515 t = 0; 01516 01517 gsl_vector_free(x); 01518 gsl_vector_free(ss); 01519 gsl_multimin_fminimizer_free(s); 01520 01521 if ( c != 0 ) delete c; 01522 return result; 01523 }
|
|
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. |