Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

EMAN::RefineAligner Class Reference

refine alignment. More...

#include <aligner.h>

Inheritance diagram for EMAN::RefineAligner:

Inheritance graph
[legend]
Collaboration diagram for EMAN::RefineAligner:

Collaboration graph
[legend]
List of all members.

Public Member Functions

virtual EMDataalign (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 EMDataalign (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

AlignerNEW ()

Static Public Attributes

const string NAME = "refine"

Detailed Description

refine alignment.

Refines a preliminary 2D alignment using a simplex algorithm. Subpixel precision.

Definition at line 853 of file aligner.h.


Member Function Documentation

virtual EMData* EMAN::RefineAligner::align EMData this_img,
EMData to_img
const [inline, virtual]
 

Implements EMAN::Aligner.

Definition at line 859 of file aligner.h.

References align().

00860                 {
00861                         return align(this_img, to_img, "sqeuclidean", Dict());
00862                 }

EMData * RefineAligner::align EMData this_img,
EMData to_img,
const string &  cmp_name = "dot",
const Dict cmp_params = Dict()
const [virtual]
 

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.

Parameters:
this_img The image to be compared.
to_img 'this_img" is aligned with 'to_img'.
cmp_name The comparison method to compare the two images.
cmp_params The parameter dictionary for comparison method.
Returns:
The aligned image.

Implements EMAN::Aligner.

Definition at line 1402 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.

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

virtual string EMAN::RefineAligner::get_desc  )  const [inline, virtual]
 

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                 }

virtual string EMAN::RefineAligner::get_name  )  const [inline, virtual]
 

Get the Aligner's name.

Each Aligner is identified by a unique name.

Returns:
The Aligner's name.

Implements EMAN::Aligner.

Definition at line 864 of file aligner.h.

00865                 {
00866                         return NAME;
00867                 }

virtual TypeDict EMAN::RefineAligner::get_param_types  )  const [inline, virtual]
 

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                 }

Aligner* EMAN::RefineAligner::NEW  )  [inline, static]
 

Definition at line 874 of file aligner.h.

00875                 {
00876                         return new RefineAligner();
00877                 }


Member Data Documentation

const string RefineAligner::NAME = "refine" [static]
 

Definition at line 73 of file aligner.cpp.


The documentation for this class was generated from the following files:
Generated on Tue Jul 12 13:50:22 2011 for EMAN2 by  doxygen 1.3.9.1