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 1390 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.

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

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 Mon May 2 13:29:19 2011 for EMAN2 by  doxygen 1.3.9.1