#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.
xform.align2d | The Transform storing the starting guess. If unspecified the identity matrix is used | |
stepx | The x increment used to create the starting simplex. Default is 1 | |
stepy | The y increment used to create the starting simplex. Default is 1 | |
stepaz | The rotational increment used to create the starting simplex. Default is 5 | |
precision | The precision which, if achieved, can stop the iterative refinement before reaching the maximum iterations. Default is 0.04 | |
maxiter | The maximum number of iterations. default=28 | |
maxshift | 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 | |
stepscale | 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 | |
verbose | This will cause debugging information to be printed on the screen for the iterative refinement. Larger numbers -> more info. default=0 |
Definition at line 1215 of file aligner.h.
|
Implements EMAN::Aligner. Definition at line 1221 of file aligner.h. References align(). 01222 { 01223 return align(this_img, to_img, "sqeuclidean", Dict()); 01224 }
|
|
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 1667 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. 01669 { 01670 01671 if (!to) { 01672 return 0; 01673 } 01674 01675 EMData *result; 01676 int mode = params.set_default("mode", 0); 01677 float saz = 0.0; 01678 float sdx = 0.0; 01679 float sdy = 0.0; 01680 float sscale = 1.0; 01681 bool mirror = false; 01682 Transform* t; 01683 if (params.has_key("xform.align2d") ) { 01684 t = params["xform.align2d"]; 01685 Dict params = t->get_params("2d"); 01686 saz = params["alpha"]; 01687 sdx = params["tx"]; 01688 sdy = params["ty"]; 01689 mirror = params["mirror"]; 01690 sscale = params["scale"]; 01691 } else { 01692 t = new Transform(); // is the identity 01693 } 01694 01695 // We do this to prevent the GSL routine from crashing on an invalid alignment 01696 if ((float)(this_img->get_attr("sigma"))==0.0 || (float)(to->get_attr("sigma"))==0.0) { 01697 result = this_img->process("xform",Dict("transform",t)); 01698 result->set_attr("xform.align2d",t); 01699 delete t; 01700 return result; 01701 } 01702 01703 float stepx = params.set_default("stepx",1.0f); 01704 float stepy = params.set_default("stepy",1.0f); 01705 // Default step is 5 degree - note in EMAN1 it was 0.1 radians 01706 float stepaz = params.set_default("stepaz",5.0f); 01707 float stepscale = params.set_default("stepscale",0.0f); 01708 01709 int np = 3; 01710 if (stepscale!=0.0) np++; 01711 Dict gsl_params; 01712 gsl_params["this"] = this_img; 01713 gsl_params["with"] = to; 01714 gsl_params["snr"] = params["snr"]; 01715 gsl_params["mirror"] = mirror; 01716 if (params.has_key("mask")) gsl_params["mask"]=params["mask"]; 01717 01718 const gsl_multimin_fminimizer_type *T = gsl_multimin_fminimizer_nmsimplex; 01719 gsl_vector *ss = gsl_vector_alloc(np); 01720 01721 01722 gsl_vector_set(ss, 0, stepx); 01723 gsl_vector_set(ss, 1, stepy); 01724 gsl_vector_set(ss, 2, stepaz); 01725 if (stepscale!=0.0) gsl_vector_set(ss,3,stepscale); 01726 01727 gsl_vector *x = gsl_vector_alloc(np); 01728 gsl_vector_set(x, 0, sdx); 01729 gsl_vector_set(x, 1, sdy); 01730 gsl_vector_set(x, 2, saz); 01731 if (stepscale!=0.0) gsl_vector_set(x,3,1.0); 01732 01733 Cmp *c = 0; 01734 01735 gsl_multimin_function minex_func; 01736 if (mode == 2) { 01737 minex_func.f = &refalifnfast; 01738 } 01739 else { 01740 c = Factory < Cmp >::get(cmp_name, cmp_params); 01741 gsl_params["cmp"] = (void *) c; 01742 minex_func.f = &refalifn; 01743 } 01744 01745 minex_func.n = np; 01746 minex_func.params = (void *) &gsl_params; 01747 01748 gsl_multimin_fminimizer *s = gsl_multimin_fminimizer_alloc(T, np); 01749 gsl_multimin_fminimizer_set(s, &minex_func, x, ss); 01750 01751 int rval = GSL_CONTINUE; 01752 int status = GSL_SUCCESS; 01753 int iter = 1; 01754 01755 float precision = params.set_default("precision",0.04f); 01756 int maxiter = params.set_default("maxiter",28); 01757 01758 // printf("Refine sx=%1.2f sy=%1.2f sa=%1.2f prec=%1.4f maxit=%d\n",stepx,stepy,stepaz,precision,maxiter); 01759 // 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)); 01760 01761 while (rval == GSL_CONTINUE && iter < maxiter) { 01762 iter++; 01763 status = gsl_multimin_fminimizer_iterate(s); 01764 if (status) { 01765 break; 01766 } 01767 rval = gsl_multimin_test_size(gsl_multimin_fminimizer_size(s), precision); 01768 } 01769 01770 int maxshift = params.set_default("maxshift",-1); 01771 01772 if (maxshift <= 0) { 01773 maxshift = this_img->get_xsize() / 4; 01774 } 01775 float fmaxshift = static_cast<float>(maxshift); 01776 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)) ) 01777 { 01778 // 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)); 01779 Transform tsoln(Dict("type","2d","alpha",(float)gsl_vector_get(s->x, 2))); 01780 tsoln.set_mirror(mirror); 01781 tsoln.set_trans((float)gsl_vector_get(s->x, 0),(float)gsl_vector_get(s->x, 1)); 01782 if (stepscale!=0.0) tsoln.set_scale((float)gsl_vector_get(s->x, 3)); 01783 result = this_img->process("xform",Dict("transform",&tsoln)); 01784 result->set_attr("xform.align2d",&tsoln); 01785 } else { // The refine aligner failed - this shift went beyond the max shift 01786 // 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)); 01787 result = this_img->process("xform",Dict("transform",t)); 01788 result->set_attr("xform.align2d",t); 01789 } 01790 01791 delete t; 01792 t = 0; 01793 01794 gsl_vector_free(x); 01795 gsl_vector_free(ss); 01796 gsl_multimin_fminimizer_free(s); 01797 01798 if (c != 0) delete c; 01799 return result; 01800 }
|
|
Implements EMAN::Aligner. Definition at line 1231 of file aligner.h. 01232 { 01233 return "Refines a preliminary 2D alignment using a simplex algorithm. Subpixel precision."; 01234 }
|
|
Get the Aligner's name. Each Aligner is identified by a unique name.
Implements EMAN::Aligner. Definition at line 1226 of file aligner.h. 01227 {
01228 return NAME;
01229 }
|
|
Implements EMAN::Aligner. Definition at line 1241 of file aligner.h. References EMAN::TypeDict::put(). 01242 { 01243 TypeDict d; 01244 01245 d.put("mode", EMObject::INT, "Currently unused"); 01246 d.put("xform.align2d", EMObject::TRANSFORM, "The Transform storing the starting guess. If unspecified the identity matrix is used"); 01247 d.put("stepx", EMObject::FLOAT, "The x increment used to create the starting simplex. Default is 1"); 01248 d.put("stepy", EMObject::FLOAT, "The y increment used to create the starting simplex. Default is 1"); 01249 d.put("stepaz", EMObject::FLOAT, "The rotational increment used to create the starting simplex. Default is 5"); 01250 d.put("precision", EMObject::FLOAT, "The precision which, if achieved, can stop the iterative refinement before reaching the maximum iterations. Default is 0.04."); 01251 d.put("maxiter", EMObject::INT,"The maximum number of iterations that can be performed by the Simplex minimizer. default=28"); 01252 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."); 01253 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."); 01254 d.put("mask", EMObject::EMDATA, "A mask to be applied to the image being aligned prior to each similarity comparison."); 01255 d.put("verbose", EMObject::INT, "This will cause debugging information to be printed on the screen for the iterative refinement. Larger numbers -> more info. default=0"); 01256 return d; 01257 }
|
|
Definition at line 1236 of file aligner.h. 01237 { 01238 return new RefineAligner(); 01239 }
|
|
Definition at line 78 of file aligner.cpp. |