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

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

AlignerNEW ()

Static Public Attributes

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

References align().

00820                 {
00821                         return align(this_img, to_img, "sqeuclidean", Dict());
00822                 }

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 1164 of file aligner.cpp.

References EMAN::EMData::cmp(), EMAN::EMData::get_xsize(), InvalidParameterException, nx, EMAN::EMData::process(), EMAN::EMData::set_attr(), EMAN::Dict::set_default(), EMAN::Transform::set_mirror(), EMAN::Transform::set_trans(), t, EMAN::EMData::transform(), and v.

01166 {
01167 
01168         EMData *flip = params.set_default("flip", (EMData *) 0);
01169         int maxshift = params.set_default("maxshift", -1);
01170 
01171         EMData *flipped = 0;
01172 
01173         bool delete_flipped = true;
01174         if (flip) {
01175                 delete_flipped = false;
01176                 flipped = flip;
01177         }
01178         else {
01179                 flipped = to->process("xform.flip", Dict("axis", "x"));
01180         }
01181 
01182         int nx = this_img->get_xsize();
01183 
01184         if (maxshift < 0) {
01185                 maxshift = nx / 10;
01186         }
01187 
01188         float angle_step =  params.set_default("angstep", 0.0f);
01189         if ( angle_step == 0 ) angle_step = atan2(2.0f, (float)nx);
01190         else {
01191                 angle_step *= (float)EMConsts::deg2rad; //convert to radians
01192         }
01193         float trans_step =  params.set_default("transtep",1.0f);
01194 
01195         if (trans_step <= 0) throw InvalidParameterException("transstep must be greater than 0");
01196         if (angle_step <= 0) throw InvalidParameterException("angstep must be greater than 0");
01197 
01198 
01199         Dict shrinkfactor("n",2);
01200         EMData *this_img_shrink = this_img->process("math.medianshrink",shrinkfactor);
01201         EMData *to_shrunk = to->process("math.medianshrink",shrinkfactor);
01202         EMData *flipped_shrunk = flipped->process("math.medianshrink",shrinkfactor);
01203 
01204         int bestflip = 0;
01205         float bestdx = 0;
01206         float bestdy = 0;
01207 
01208         float bestang = 0;
01209         float bestval = FLT_MAX;
01210 
01211         int half_maxshift = maxshift / 2;
01212 
01213 
01214         for (int dy = -half_maxshift; dy <= half_maxshift; ++dy) {
01215                 for (int dx = -half_maxshift; dx <= half_maxshift; ++dx) {
01216                         if (hypot(dx, dy) <= maxshift) {
01217                                 for (float ang = -angle_step * 2.0f; ang <= (float)2 * M_PI; ang += angle_step * 4.0f) {
01218                                         EMData v(*this_img_shrink);
01219                                         Transform t(Dict("type","2d","alpha",static_cast<float>(ang*EMConsts::rad2deg)));
01220                                         t.set_trans((float)dx,(float)dy);
01221                                         v.transform(t);
01222 //                                      v.rotate_translate(ang*EMConsts::rad2deg, 0.0f, 0.0f, (float)dx, (float)dy, 0.0f);
01223 
01224                                         float lc = v.cmp(cmp_name, to_shrunk, cmp_params);
01225 
01226                                         if (lc < bestval) {
01227                                                 bestval = lc;
01228                                                 bestang = ang;
01229                                                 bestdx = (float)dx;
01230                                                 bestdy = (float)dy;
01231                                                 bestflip = 0;
01232                                         }
01233 
01234                                         lc = v.cmp(cmp_name,flipped_shrunk , cmp_params);
01235                                         if (lc < bestval) {
01236                                                 bestval = lc;
01237                                                 bestang = ang;
01238                                                 bestdx = (float)dx;
01239                                                 bestdy = (float)dy;
01240                                                 bestflip = 1;
01241                                         }
01242                                 }
01243                         }
01244                 }
01245         }
01246 
01247         if( to_shrunk )
01248         {
01249                 delete to_shrunk;
01250                 to_shrunk = 0;
01251         }
01252         if( flipped_shrunk )
01253         {
01254                 delete flipped_shrunk;
01255                 flipped_shrunk = 0;
01256         }
01257         if( this_img_shrink )
01258         {
01259                 delete this_img_shrink;
01260                 this_img_shrink = 0;
01261         }
01262 
01263         bestdx *= 2;
01264         bestdy *= 2;
01265         bestval = FLT_MAX;
01266 
01267         float bestdx2 = bestdx;
01268         float bestdy2 = bestdy;
01269         float bestang2 = bestang;
01270 
01271         for (float dy = bestdy2 - 3; dy <= bestdy2 + 3; dy += trans_step) {
01272                 for (float dx = bestdx2 - 3; dx <= bestdx2 + 3; dx += trans_step) {
01273                         if (hypot(dx, dy) <= maxshift) {
01274                                 for (float ang = bestang2 - angle_step * 6.0f; ang <= bestang2 + angle_step * 6.0f; ang += angle_step) {
01275                                         EMData v(*this_img);
01276                                         Transform t(Dict("type","2d","alpha",static_cast<float>(ang*EMConsts::rad2deg)));
01277                                         t.set_trans(dx,dy);
01278                                         v.transform(t);
01279 //                                      v.rotate_translate(ang*EMConsts::rad2deg, 0.0f, 0.0f, (float)dx, (float)dy, 0.0f);
01280 
01281                                         float lc = v.cmp(cmp_name, to, cmp_params);
01282 
01283                                         if (lc < bestval) {
01284                                                 bestval = lc;
01285                                                 bestang = ang;
01286                                                 bestdx = dx;
01287                                                 bestdy = dy;
01288                                                 bestflip = 0;
01289                                         }
01290 
01291                                         lc = v.cmp(cmp_name, flipped, cmp_params);
01292 
01293                                         if (lc < bestval) {
01294                                                 bestval = lc;
01295                                                 bestang = ang;
01296                                                 bestdx = dx;
01297                                                 bestdy = dy;
01298                                                 bestflip = 1;
01299                                         }
01300                                 }
01301                         }
01302                 }
01303         }
01304 
01305         if (delete_flipped) { delete flipped; flipped = 0; }
01306 
01307         bestang *= (float)EMConsts::rad2deg;
01308         Transform t(Dict("type","2d","alpha",(float)bestang));
01309         t.set_trans(bestdx,bestdy);
01310 
01311         if (bestflip) {
01312                 t.set_mirror(true);
01313         }
01314 
01315         EMData* rslt = this_img->process("xform",Dict("transform",&t));
01316         rslt->set_attr("xform.align2d",&t);
01317 
01318         return rslt;
01319 }

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

Implements EMAN::Aligner.

Definition at line 828 of file aligner.h.

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

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

00824                 {
00825                         return NAME;
00826                 }

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

Implements EMAN::Aligner.

Definition at line 838 of file aligner.h.

References EMAN::TypeDict::put().

00839                 {
00840                         TypeDict d;
00841                         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");
00842                         d.put("maxshift", EMObject::INT,"The maximum length of the detectable translational shift");
00843                         d.put("transtep", EMObject::FLOAT,"The translation step to take when honing the alignment, which occurs after coarse alignment");
00844                         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.");
00845                         return d;
00846                 }

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

Definition at line 833 of file aligner.h.

00834                 {
00835                         return new RTFSlowExhaustiveAligner();
00836                 }


Member Data Documentation

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

Definition at line 72 of file aligner.cpp.


The documentation for this class was generated from the following files:
Generated on Tue Jul 12 13:51:07 2011 for EMAN2 by  doxygen 1.3.9.1