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

EMAN::Refine3DAligner Class Reference

Refine alignment. More...

#include <aligner.h>

Inheritance diagram for EMAN::Refine3DAligner:

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

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

static AlignerNEW ()

Static Public Attributes

static const string NAME = "refine.3d"

Detailed Description

Refine alignment.

Refines a preliminary 3D alignment using a simplex algorithm. Subpixel precision. Uses quaternions extensively, separates the in plane (phi) rotation and the 2 rotations that define a point on the sphere (POTS), manipulating them independently. The POTS is"jiggled" in a local circular sub manifold of the sphere (of radius stepdelta). Phi is allowed to vary as a normal variable. The result is combined into a single transform and then a similarity is computed, etc. Translation also varies.

Author:
David Woolford
Date:
June 23 2009

Definition at line 615 of file aligner.h.


Member Function Documentation

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

Implements EMAN::Aligner.

Definition at line 621 of file aligner.h.

References align().

00622                         {
00623                                 return align(this_img, to_img, "sqeuclidean", Dict());
00624                         }

EMData * Refine3DAligner::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 1263 of file aligner.cpp.

References EMAN::EMData::get_ndim(), EMAN::EMData::get_xsize(), EMAN::Dict::has_key(), ImageDimensionException, NullPointerException, EMAN::Aligner::params, phi, EMAN::EMData::process(), refalifn3d(), refalin3d_perturb(), EMAN::EMData::set_attr(), EMAN::Dict::set_default(), status, t, x, and y.

Referenced by align().

01265 {
01266 
01267         if (!to || !this_img) throw NullPointerException("Input image is null"); // not sure if this is necessary, it was there before I started
01268 
01269         if (to->get_ndim() != 3 || this_img->get_ndim() != 3) throw ImageDimensionException("The Refine3D aligner only works for 3D images");
01270 
01271         float saz = 0.0;
01272         float sphi = 0.0;
01273         float salt = 0.0;
01274         float sdx = 0.0;
01275         float sdy = 0.0;
01276         float sdz = 0.0;
01277         bool mirror = false;
01278         Transform* t;
01279         if (params.has_key("xform.align3d") ) {
01280                 // Unlike the 2d refine aligner, this class doesn't require the starting transform's
01281                 // parameters to form the starting guess. Instead the Transform itself
01282                 // is perturbed carefully (using quaternion rotation) to overcome problems that arise
01283                 // when you use orthogonally-based Euler angles
01284                 t = params["xform.align3d"];
01285         }else {
01286                 t = new Transform(); // is the identity
01287         }
01288 
01289         int np = 6; // the number of dimensions
01290         Dict gsl_params;
01291         gsl_params["this"] = this_img;
01292         gsl_params["with"] = to;
01293         gsl_params["snr"]  = params["snr"];
01294         gsl_params["mirror"] = mirror;
01295         gsl_params["transform"] = t;
01296 
01297         const gsl_multimin_fminimizer_type *T = gsl_multimin_fminimizer_nmsimplex;
01298         gsl_vector *ss = gsl_vector_alloc(np);
01299 
01300         float stepx = params.set_default("stepx",1.0f);
01301         float stepy = params.set_default("stepy",1.0f);
01302         float stepz = params.set_default("stepz",1.0f);
01303         // Default step is 5 degree - note in EMAN1 it was 0.1 radians
01304         float half_circle_step = 180.0f; // This shouldn't be altered
01305         float stepphi = params.set_default("stephi",5.0f);
01306         float stepdelta = params.set_default("stepdelta",5.0f);
01307 
01308         gsl_vector_set(ss, 0, stepx);
01309         gsl_vector_set(ss, 1, stepy);
01310         gsl_vector_set(ss, 2, stepz);
01311         gsl_vector_set(ss, 3, half_circle_step);
01312         gsl_vector_set(ss, 4, stepdelta);
01313         gsl_vector_set(ss, 5, stepphi);
01314 
01315         gsl_vector *x = gsl_vector_alloc(np);
01316         gsl_vector_set(x, 0, sdx);
01317         gsl_vector_set(x, 1, sdy);
01318         gsl_vector_set(x, 2, sdz);
01319         gsl_vector_set(x, 3, saz);
01320         gsl_vector_set(x, 4, salt);
01321         gsl_vector_set(x, 5, sphi);
01322 
01323         gsl_multimin_function minex_func;
01324         Cmp *c = Factory < Cmp >::get(cmp_name, cmp_params);
01325         gsl_params["cmp"] = (void *) c;
01326         minex_func.f = &refalifn3d;
01327 
01328         minex_func.n = np;
01329         minex_func.params = (void *) &gsl_params;
01330 
01331         gsl_multimin_fminimizer *s = gsl_multimin_fminimizer_alloc(T, np);
01332         gsl_multimin_fminimizer_set(s, &minex_func, x, ss);
01333 
01334         int rval = GSL_CONTINUE;
01335         int status = GSL_SUCCESS;
01336         int iter = 1;
01337 
01338         float precision = params.set_default("precision",0.04f);
01339         int maxiter = params.set_default("maxiter",60);
01340         while (rval == GSL_CONTINUE && iter < maxiter) {
01341                 iter++;
01342                 status = gsl_multimin_fminimizer_iterate(s);
01343                 if (status) {
01344                         break;
01345                 }
01346                 rval = gsl_multimin_test_size(gsl_multimin_fminimizer_size(s), precision);
01347         }
01348 
01349         int maxshift = params.set_default("maxshift",-1);
01350 
01351         if (maxshift <= 0) {
01352                 maxshift = this_img->get_xsize() / 4;
01353         }
01354         float fmaxshift = static_cast<float>(maxshift);
01355         EMData *result;
01356         if ( fmaxshift >= (float)gsl_vector_get(s->x, 0) && fmaxshift >= (float)gsl_vector_get(s->x, 1)  && fmaxshift >= (float)gsl_vector_get(s->x, 2))
01357         {
01358                 float x = (float)gsl_vector_get(s->x, 0);
01359                 float y = (float)gsl_vector_get(s->x, 1);
01360                 float z = (float)gsl_vector_get(s->x, 2);
01361 
01362                 float arc = (float)gsl_vector_get(s->x, 3);
01363                 float delta = (float)gsl_vector_get(s->x, 4);
01364                 float phi = (float)gsl_vector_get(s->x, 5);
01365 
01366                 Transform tsoln = refalin3d_perturb(t,delta,arc,phi,x,y,z);
01367 
01368                 result = this_img->process("xform",Dict("transform",&tsoln));
01369                 result->set_attr("xform.align3d",&tsoln);
01370 
01371         } else { // The refine aligner failed - this shift went beyond the max shift
01372                 result = this_img->process("xform",Dict("transform",t));
01373                 result->set_attr("xform.align3d",t);
01374         }
01375 
01376         delete t;
01377         t = 0;
01378 
01379         gsl_vector_free(x);
01380         gsl_vector_free(ss);
01381         gsl_multimin_fminimizer_free(s);
01382 
01383         if ( c != 0 ) delete c;
01384         return result;
01385 }

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

Implements EMAN::Aligner.

Definition at line 631 of file aligner.h.

00632                         {
00633                                 return "Refines a preliminary 3D alignment using a simplex algorithm. Subpixel precision.";
00634                         }

virtual string EMAN::Refine3DAligner::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 626 of file aligner.h.

References NAME.

00627                         {
00628                                 return NAME;
00629                         }

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

Implements EMAN::Aligner.

Definition at line 641 of file aligner.h.

References EMAN::EMObject::FLOAT, EMAN::EMObject::INT, EMAN::TypeDict::put(), and EMAN::EMObject::TRANSFORM.

00642                         {
00643                                 TypeDict d;
00644                                 d.put("xform.align3d", EMObject::TRANSFORM,"The Transform storing the starting guess. If unspecified the identity matrix is used");
00645                                 d.put("stepx", EMObject::FLOAT, "The x increment used to create the starting simplex. Default is 1");
00646                                 d.put("stepy", EMObject::FLOAT,"The y increment used to create the starting simplex. Default is 1");
00647                                 d.put("stepz", EMObject::FLOAT, "The z increment used to create the starting simplex. Default is 1." );
00648                                 d.put("stepphi", EMObject::FLOAT, "The phi incremenent used to creat the starting simplex. This is the increment applied to the inplane rotation. Default is 5." );
00649                                 d.put("stepdelta", EMObject::FLOAT,"The angular increment which represents a good initial step along the sphere, thinking in terms of quaternions. Default is 5.");
00650                                 d.put("precision", EMObject::FLOAT, "The precision which, if achieved, can stop the iterative refinement before reaching the maximum iterations. Default is 0.04." );
00651                                 d.put("maxiter", EMObject::INT, "The maximum number of iterations that can be performed by the Simplex minimizer. Default is 60.");
00652                                 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.");
00653                                 return d;
00654                         }

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

Definition at line 636 of file aligner.h.

00637                         {
00638                                 return new Refine3DAligner();
00639                         }


Member Data Documentation

const string Refine3DAligner::NAME = "refine.3d" [static]
 

Definition at line 656 of file aligner.h.

Referenced by get_name().


The documentation for this class was generated from the following files:
Generated on Tue May 25 17:36:14 2010 for EMAN2 by  doxygen 1.4.4