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:

[legend]
Collaboration diagram for EMAN::Refine3DAligner:
[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.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 1255 of file aligner.cpp.

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

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

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.

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::TypeDict::put().

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                         }

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 63 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