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