#include <aligner.h>


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