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

References align().

00757                 {
00758                         return align(this_img, to_img, "sqeuclidean", Dict());
00759                 }

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

01202 {
01203 
01204         if (!to) {
01205                 return 0;
01206         }
01207 
01208         EMData *result;
01209         int mode = params.set_default("mode", 0);
01210         float saz = 0.0;
01211         float sdx = 0.0;
01212         float sdy = 0.0;
01213         bool mirror = false;
01214         Transform* t;
01215         if (params.has_key("xform.align2d") ) {
01216                 t = params["xform.align2d"];
01217                 Dict params = t->get_params("2d");
01218                 saz = params["alpha"];
01219                 sdx = params["tx"];
01220                 sdy = params["ty"];
01221                 mirror = params["mirror"];
01222 
01223         } else {
01224                 t = new Transform(); // is the identity
01225         }
01226 
01227         // We do this to prevent the GSL routine from crashing on an invalid alignment
01228         if ((float)(this_img->get_attr("sigma"))==0.0 || (float)(to->get_attr("sigma"))==0.0) {
01229                 result = this_img->process("xform",Dict("transform",t));
01230                 result->set_attr("xform.align2d",t);
01231                 delete t;
01232                 return result;
01233         }
01234 
01235         int np = 3;
01236         Dict gsl_params;
01237         gsl_params["this"] = this_img;
01238         gsl_params["with"] = to;
01239         gsl_params["snr"]  = params["snr"];
01240         gsl_params["mirror"] = mirror;
01241 
01242 
01243 
01244         const gsl_multimin_fminimizer_type *T = gsl_multimin_fminimizer_nmsimplex;
01245         gsl_vector *ss = gsl_vector_alloc(np);
01246 
01247         float stepx = params.set_default("stepx",1.0f);
01248         float stepy = params.set_default("stepy",1.0f);
01249         // Default step is 5 degree - note in EMAN1 it was 0.1 radians
01250         float stepaz = params.set_default("stepaz",5.0f);
01251 
01252         gsl_vector_set(ss, 0, stepx);
01253         gsl_vector_set(ss, 1, stepy);
01254         gsl_vector_set(ss, 2, stepaz);
01255 
01256         gsl_vector *x = gsl_vector_alloc(np);
01257         gsl_vector_set(x, 0, sdx);
01258         gsl_vector_set(x, 1, sdy);
01259         gsl_vector_set(x, 2, saz);
01260 
01261         Cmp *c = 0;
01262 
01263         gsl_multimin_function minex_func;
01264         if (mode == 2) {
01265                 minex_func.f = &refalifnfast;
01266         }
01267         else {
01268                 c = Factory < Cmp >::get(cmp_name, cmp_params);
01269                 gsl_params["cmp"] = (void *) c;
01270                 minex_func.f = &refalifn;
01271         }
01272 
01273         minex_func.n = np;
01274         minex_func.params = (void *) &gsl_params;
01275 
01276         gsl_multimin_fminimizer *s = gsl_multimin_fminimizer_alloc(T, np);
01277         gsl_multimin_fminimizer_set(s, &minex_func, x, ss);
01278 
01279         int rval = GSL_CONTINUE;
01280         int status = GSL_SUCCESS;
01281         int iter = 1;
01282 
01283         float precision = params.set_default("precision",0.04f);
01284         int maxiter = params.set_default("maxiter",28);
01285 
01286 //      printf("Refine sx=%1.2f sy=%1.2f sa=%1.2f prec=%1.4f maxit=%d\n",stepx,stepy,stepaz,precision,maxiter);
01287 //      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));
01288 
01289         while (rval == GSL_CONTINUE && iter < maxiter) {
01290                 iter++;
01291                 status = gsl_multimin_fminimizer_iterate(s);
01292                 if (status) {
01293                         break;
01294                 }
01295                 rval = gsl_multimin_test_size(gsl_multimin_fminimizer_size(s), precision);
01296         }
01297 
01298         int maxshift = params.set_default("maxshift",-1);
01299 
01300         if (maxshift <= 0) {
01301                 maxshift = this_img->get_xsize() / 4;
01302         }
01303         float fmaxshift = static_cast<float>(maxshift);
01304         if ( fmaxshift >= fabs((float)gsl_vector_get(s->x, 0)) && fmaxshift >= fabs((float)gsl_vector_get(s->x, 1))  )
01305         {
01306 //              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));
01307                 Transform  tsoln(Dict("type","2d","alpha",(float)gsl_vector_get(s->x, 2)));
01308                 tsoln.set_mirror(mirror);
01309                 tsoln.set_trans((float)gsl_vector_get(s->x, 0),(float)gsl_vector_get(s->x, 1));
01310                 result = this_img->process("xform",Dict("transform",&tsoln));
01311                 result->set_attr("xform.align2d",&tsoln);
01312         } else { // The refine aligner failed - this shift went beyond the max shift
01313 //              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));
01314                 result = this_img->process("xform",Dict("transform",t));
01315                 result->set_attr("xform.align2d",t);
01316         }
01317 
01318         delete t;
01319         t = 0;
01320 
01321         gsl_vector_free(x);
01322         gsl_vector_free(ss);
01323         gsl_multimin_fminimizer_free(s);
01324 
01325         if ( c != 0 ) delete c;
01326         return result;
01327 }

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

Implements EMAN::Aligner.

Definition at line 766 of file aligner.h.

00767                 {
00768                         return "Refines a preliminary 2D alignment using a simplex algorithm. Subpixel precision.";
00769                 }

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

00762                 {
00763                         return NAME;
00764                 }

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

Implements EMAN::Aligner.

Definition at line 776 of file aligner.h.

References EMAN::TypeDict::put().

00777                 {
00778                         TypeDict d;
00779 
00780                         d.put("mode", EMObject::INT, "Currently unused");
00781                         d.put("xform.align2d", EMObject::TRANSFORM, "The Transform storing the starting guess. If unspecified the identity matrix is used");
00782                         d.put("stepx", EMObject::FLOAT, "The x increment used to create the starting simplex. Default is 1");
00783                         d.put("stepy", EMObject::FLOAT, "The y increment used to create the starting simplex. Default is 1");
00784                         d.put("stepaz", EMObject::FLOAT, "The rotational increment used to create the starting simplex. Default is 5");
00785                         d.put("precision", EMObject::FLOAT, "The precision which, if achieved, can stop the iterative refinement before reaching the maximum iterations. Default is 0.04.");
00786                         d.put("maxiter", EMObject::INT,"The maximum number of iterations that can be performed by the Simplex minimizer");
00787                         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.");
00788                         return d;
00789                 }

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

Definition at line 771 of file aligner.h.

00772                 {
00773                         return new RefineAligner();
00774                 }


Member Data Documentation

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

Definition at line 66 of file aligner.cpp.


The documentation for this class was generated from the following files:
Generated on Thu Dec 9 13:47:10 2010 for EMAN2 by  doxygen 1.3.9.1