EMAN::RTFSlowExhaustiveAligner Class Reference

rotational, translational and flip alignment using exhaustive search. More...

#include <aligner.h>

Inheritance diagram for EMAN::RTFSlowExhaustiveAligner:

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

Collaboration graph
[legend]
List of all members.

Public Member Functions

virtual EMDataalign (EMData *this_img, EMData *to_img, const string &cmp_name, const Dict &cmp_params) 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 = "rtf_slow_exhaustive"

Detailed Description

rotational, translational and flip alignment using exhaustive search.

This is very slow but can ensure localization of the global maximum

Parameters:
flip Optional. This is the flipped version of the images that is being aligned. If specified it will be used for the handedness check, if not a flipped copy of the image will be made
maxshift The maximum length of the detectable translational shift
transtep The translation step to take when honing the alignment, which occurs after coarse alignment
angstep The angular step (in degrees) to take in the exhaustive search for the solution angle. Typically very small i.e. 3 or smaller

Definition at line 1120 of file aligner.h.


Member Function Documentation

virtual EMData* EMAN::RTFSlowExhaustiveAligner::align ( EMData this_img,
EMData to_img 
) const [inline, virtual]

Implements EMAN::Aligner.

Definition at line 1125 of file aligner.h.

References align().

01126                 {
01127                         return align(this_img, to_img, "sqeuclidean", Dict());
01128                 }

EMData * RTFSlowExhaustiveAligner::align ( EMData this_img,
EMData to_img,
const string &  cmp_name,
const Dict cmp_params 
) 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 1351 of file aligner.cpp.

References EMAN::EMConsts::deg2rad, EMAN::EMData::get_xsize(), InvalidParameterException, nx, EMAN::Aligner::params, EMAN::EMData::process(), EMAN::EMConsts::rad2deg, EMAN::EMData::set_attr(), EMAN::Dict::set_default(), t, and v.

Referenced by align().

01353 {
01354 
01355         EMData *flip = params.set_default("flip", (EMData *) 0);
01356         int maxshift = params.set_default("maxshift", -1);
01357 
01358         EMData *flipped = 0;
01359 
01360         bool delete_flipped = true;
01361         if (flip) {
01362                 delete_flipped = false;
01363                 flipped = flip;
01364         }
01365         else {
01366                 flipped = to->process("xform.flip", Dict("axis", "x"));
01367         }
01368 
01369         int nx = this_img->get_xsize();
01370 
01371         if (maxshift < 0) {
01372                 maxshift = nx / 10;
01373         }
01374 
01375         float angle_step =  params.set_default("angstep", 0.0f);
01376         if ( angle_step == 0 ) angle_step = atan2(2.0f, (float)nx);
01377         else {
01378                 angle_step *= (float)EMConsts::deg2rad; //convert to radians
01379         }
01380         float trans_step =  params.set_default("transtep",1.0f);
01381 
01382         if (trans_step <= 0) throw InvalidParameterException("transstep must be greater than 0");
01383         if (angle_step <= 0) throw InvalidParameterException("angstep must be greater than 0");
01384 
01385 
01386         Dict shrinkfactor("n",2);
01387         EMData *this_img_shrink = this_img->process("math.medianshrink",shrinkfactor);
01388         EMData *to_shrunk = to->process("math.medianshrink",shrinkfactor);
01389         EMData *flipped_shrunk = flipped->process("math.medianshrink",shrinkfactor);
01390 
01391         int bestflip = 0;
01392         float bestdx = 0;
01393         float bestdy = 0;
01394 
01395         float bestang = 0;
01396         float bestval = FLT_MAX;
01397 
01398         int half_maxshift = maxshift / 2;
01399 
01400 
01401         for (int dy = -half_maxshift; dy <= half_maxshift; ++dy) {
01402                 for (int dx = -half_maxshift; dx <= half_maxshift; ++dx) {
01403                         if (hypot(dx, dy) <= maxshift) {
01404                                 for (float ang = -angle_step * 2.0f; ang <= (float)2 * M_PI; ang += angle_step * 4.0f) {
01405                                         EMData v(*this_img_shrink);
01406                                         Transform t(Dict("type","2d","alpha",static_cast<float>(ang*EMConsts::rad2deg)));
01407                                         t.set_trans((float)dx,(float)dy);
01408                                         v.transform(t);
01409 //                                      v.rotate_translate(ang*EMConsts::rad2deg, 0.0f, 0.0f, (float)dx, (float)dy, 0.0f);
01410 
01411                                         float lc = v.cmp(cmp_name, to_shrunk, cmp_params);
01412 
01413                                         if (lc < bestval) {
01414                                                 bestval = lc;
01415                                                 bestang = ang;
01416                                                 bestdx = (float)dx;
01417                                                 bestdy = (float)dy;
01418                                                 bestflip = 0;
01419                                         }
01420 
01421                                         lc = v.cmp(cmp_name,flipped_shrunk , cmp_params);
01422                                         if (lc < bestval) {
01423                                                 bestval = lc;
01424                                                 bestang = ang;
01425                                                 bestdx = (float)dx;
01426                                                 bestdy = (float)dy;
01427                                                 bestflip = 1;
01428                                         }
01429                                 }
01430                         }
01431                 }
01432         }
01433 
01434         if( to_shrunk )
01435         {
01436                 delete to_shrunk;
01437                 to_shrunk = 0;
01438         }
01439         if( flipped_shrunk )
01440         {
01441                 delete flipped_shrunk;
01442                 flipped_shrunk = 0;
01443         }
01444         if( this_img_shrink )
01445         {
01446                 delete this_img_shrink;
01447                 this_img_shrink = 0;
01448         }
01449 
01450         bestdx *= 2;
01451         bestdy *= 2;
01452         bestval = FLT_MAX;
01453 
01454         float bestdx2 = bestdx;
01455         float bestdy2 = bestdy;
01456         float bestang2 = bestang;
01457 
01458         for (float dy = bestdy2 - 3; dy <= bestdy2 + 3; dy += trans_step) {
01459                 for (float dx = bestdx2 - 3; dx <= bestdx2 + 3; dx += trans_step) {
01460                         if (hypot(dx, dy) <= maxshift) {
01461                                 for (float ang = bestang2 - angle_step * 6.0f; ang <= bestang2 + angle_step * 6.0f; ang += angle_step) {
01462                                         EMData v(*this_img);
01463                                         Transform t(Dict("type","2d","alpha",static_cast<float>(ang*EMConsts::rad2deg)));
01464                                         t.set_trans(dx,dy);
01465                                         v.transform(t);
01466 //                                      v.rotate_translate(ang*EMConsts::rad2deg, 0.0f, 0.0f, (float)dx, (float)dy, 0.0f);
01467 
01468                                         float lc = v.cmp(cmp_name, to, cmp_params);
01469 
01470                                         if (lc < bestval) {
01471                                                 bestval = lc;
01472                                                 bestang = ang;
01473                                                 bestdx = dx;
01474                                                 bestdy = dy;
01475                                                 bestflip = 0;
01476                                         }
01477 
01478                                         lc = v.cmp(cmp_name, flipped, cmp_params);
01479 
01480                                         if (lc < bestval) {
01481                                                 bestval = lc;
01482                                                 bestang = ang;
01483                                                 bestdx = dx;
01484                                                 bestdy = dy;
01485                                                 bestflip = 1;
01486                                         }
01487                                 }
01488                         }
01489                 }
01490         }
01491 
01492         if (delete_flipped) { delete flipped; flipped = 0; }
01493 
01494         bestang *= (float)EMConsts::rad2deg;
01495         Transform t(Dict("type","2d","alpha",(float)bestang));
01496         t.set_trans(bestdx,bestdy);
01497 
01498         if (bestflip) {
01499                 t.set_mirror(true);
01500         }
01501 
01502         EMData* rslt = this_img->process("xform",Dict("transform",&t));
01503         rslt->set_attr("xform.align2d",&t);
01504 
01505         return rslt;
01506 }

virtual string EMAN::RTFSlowExhaustiveAligner::get_desc (  )  const [inline, virtual]

Implements EMAN::Aligner.

Definition at line 1134 of file aligner.h.

01135                 {
01136                         return "Experimental full 2D alignment with handedness check using more exhaustive search (not necessarily better than RTFBest)";
01137                 }

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

References NAME.

01130                 {
01131                         return NAME;
01132                 }

virtual TypeDict EMAN::RTFSlowExhaustiveAligner::get_param_types (  )  const [inline, virtual]

Implements EMAN::Aligner.

Definition at line 1144 of file aligner.h.

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

01145                 {
01146                         TypeDict d;
01147                         d.put("flip", EMObject::EMDATA,"Optional. This is the flipped version of the images that is being aligned. If specified it will be used for the handedness check, if not a flipped copy of the image will be made");
01148                         d.put("maxshift", EMObject::INT,"The maximum length of the detectable translational shift");
01149                         d.put("transtep", EMObject::FLOAT,"The translation step to take when honing the alignment, which occurs after coarse alignment");
01150                         d.put("angstep", EMObject::FLOAT,"The angular step (in degrees) to take in the exhaustive search for the solution angle. Typically very small i.e. 3 or smaller.");
01151                         return d;
01152                 }

static Aligner* EMAN::RTFSlowExhaustiveAligner::NEW (  )  [inline, static]

Definition at line 1139 of file aligner.h.

01140                 {
01141                         return new RTFSlowExhaustiveAligner();
01142                 }


Member Data Documentation

const string RTFSlowExhaustiveAligner::NAME = "rtf_slow_exhaustive" [static]

Definition at line 1154 of file aligner.h.

Referenced by get_name().


The documentation for this class was generated from the following files:
Generated on Thu May 3 10:08:48 2012 for EMAN2 by  doxygen 1.4.7