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:

[legend]
Collaboration diagram for EMAN::RefineAligner:
[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 562 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 568 of file aligner.h.

References align().

00569                 {
00570                         return align(this_img, to_img, "sqeuclidean", Dict());
00571                 }

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 1023 of file aligner.cpp.

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

01025 {
01026 
01027         if (!to) {
01028                 return 0;
01029         }
01030 
01031         int mode = params.set_default("mode", 0);
01032         float saz = 0.0;
01033         float sdx = 0.0;
01034         float sdy = 0.0;
01035         bool mirror = false;
01036         Transform* t;
01037         if (params.has_key("xform.align2d") ) {
01038                 t = params["xform.align2d"];
01039                 Dict params = t->get_params("2d");
01040                 saz = params["alpha"];
01041                 sdx = params["tx"];
01042                 sdy = params["ty"];
01043                 mirror = params["mirror"];
01044 
01045         } else {
01046                 t = new Transform(); // is the identity
01047         }
01048 
01049         int np = 3;
01050         Dict gsl_params;
01051         gsl_params["this"] = this_img;
01052         gsl_params["with"] = to;
01053         gsl_params["snr"]  = params["snr"];
01054         gsl_params["mirror"] = mirror;
01055 
01056 
01057 
01058         const gsl_multimin_fminimizer_type *T = gsl_multimin_fminimizer_nmsimplex;
01059         gsl_vector *ss = gsl_vector_alloc(np);
01060 
01061         float stepx = params.set_default("stepx",1.0f);
01062         float stepy = params.set_default("stepy",1.0f);
01063         // Default step is 5 degree - note in EMAN1 it was 0.1 radians
01064         float stepaz = params.set_default("stepaz",5.0f);
01065 
01066         gsl_vector_set(ss, 0, stepx);
01067         gsl_vector_set(ss, 1, stepy);
01068         gsl_vector_set(ss, 2, stepaz);
01069 
01070         gsl_vector *x = gsl_vector_alloc(np);
01071         gsl_vector_set(x, 0, sdx);
01072         gsl_vector_set(x, 1, sdy);
01073         gsl_vector_set(x, 2, saz);
01074 
01075         Cmp *c = 0;
01076 
01077         gsl_multimin_function minex_func;
01078         if (mode == 2) {
01079                 minex_func.f = &refalifnfast;
01080         }
01081         else {
01082                 c = Factory < Cmp >::get(cmp_name, cmp_params);
01083                 gsl_params["cmp"] = (void *) c;
01084                 minex_func.f = &refalifn;
01085         }
01086 
01087         minex_func.n = np;
01088         minex_func.params = (void *) &gsl_params;
01089 
01090         gsl_multimin_fminimizer *s = gsl_multimin_fminimizer_alloc(T, np);
01091         gsl_multimin_fminimizer_set(s, &minex_func, x, ss);
01092 
01093         int rval = GSL_CONTINUE;
01094         int status = GSL_SUCCESS;
01095         int iter = 1;
01096 
01097         float precision = params.set_default("precision",0.04f);
01098         int maxiter = params.set_default("maxiter",28);
01099 
01100 //      printf("Refine sx=%1.2f sy=%1.2f sa=%1.2f prec=%1.4f maxit=%d\n",stepx,stepy,stepaz,precision,maxiter);
01101 //      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));
01102 
01103         while (rval == GSL_CONTINUE && iter < maxiter) {
01104                 iter++;
01105                 status = gsl_multimin_fminimizer_iterate(s);
01106                 if (status) {
01107                         break;
01108                 }
01109                 rval = gsl_multimin_test_size(gsl_multimin_fminimizer_size(s), precision);
01110         }
01111 
01112         int maxshift = params.set_default("maxshift",-1);
01113 
01114         if (maxshift <= 0) {
01115                 maxshift = this_img->get_xsize() / 4;
01116         }
01117         float fmaxshift = static_cast<float>(maxshift);
01118         EMData *result;
01119         if ( fmaxshift >= fabs((float)gsl_vector_get(s->x, 0)) && fmaxshift >= fabs((float)gsl_vector_get(s->x, 1))  )
01120         {
01121 //              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));
01122                 Transform  tsoln(Dict("type","2d","alpha",(float)gsl_vector_get(s->x, 2)));
01123                 tsoln.set_mirror(mirror);
01124                 tsoln.set_trans((float)gsl_vector_get(s->x, 0),(float)gsl_vector_get(s->x, 1));
01125                 result = this_img->process("xform",Dict("transform",&tsoln));
01126                 result->set_attr("xform.align2d",&tsoln);
01127         } else { // The refine aligner failed - this shift went beyond the max shift
01128 //              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));
01129                 result = this_img->process("xform",Dict("transform",t));
01130                 result->set_attr("xform.align2d",t);
01131         }
01132 
01133         delete t;
01134         t = 0;
01135 
01136         gsl_vector_free(x);
01137         gsl_vector_free(ss);
01138         gsl_multimin_fminimizer_free(s);
01139 
01140         if ( c != 0 ) delete c;
01141         return result;
01142 }

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

Implements EMAN::Aligner.

Definition at line 578 of file aligner.h.

00579                 {
00580                         return "Refines a preliminary 2D alignment using a simplex algorithm. Subpixel precision.";
00581                 }

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 573 of file aligner.h.

00574                 {
00575                         return NAME;
00576                 }

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

Implements EMAN::Aligner.

Definition at line 588 of file aligner.h.

References EMAN::TypeDict::put().

00589                 {
00590                         TypeDict d;
00591 
00592                         d.put("mode", EMObject::INT, "Currently unused");
00593                         d.put("xform.align2d", EMObject::TRANSFORM, "The Transform storing the starting guess. If unspecified the identity matrix is used");
00594                         d.put("stepx", EMObject::FLOAT, "The x increment used to create the starting simplex. Default is 1");
00595                         d.put("stepy", EMObject::FLOAT, "The y increment used to create the starting simplex. Default is 1");
00596                         d.put("stepaz", EMObject::FLOAT, "The rotational increment used to create the starting simplex. Default is 5");
00597                         d.put("precision", EMObject::FLOAT, "The precision which, if achieved, can stop the iterative refinement before reaching the maximum iterations. Default is 0.04.");
00598                         d.put("maxiter", EMObject::INT,"The maximum number of iterations that can be performed by the Simplex minimizer");
00599                         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.");
00600                         return d;
00601                 }

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

Definition at line 583 of file aligner.h.

00584                 {
00585                         return new RefineAligner();
00586                 }


Member Data Documentation

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

Definition at line 62 of file aligner.cpp.


The documentation for this class was generated from the following files:
Generated on Fri Apr 30 15:39:12 2010 for EMAN2 by  doxygen 1.3.9.1