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

References align().

00717                 {
00718                         return align(this_img, to_img, "sqeuclidean", Dict());
00719                 }

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 968 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.

00970 {
00971 
00972         EMData *flip = params.set_default("flip", (EMData *) 0);
00973         int maxshift = params.set_default("maxshift", -1);
00974 
00975         EMData *flipped = 0;
00976 
00977         bool delete_flipped = true;
00978         if (flip) {
00979                 delete_flipped = false;
00980                 flipped = flip;
00981         }
00982         else {
00983                 flipped = to->process("xform.flip", Dict("axis", "x"));
00984         }
00985 
00986         int nx = this_img->get_xsize();
00987 
00988         if (maxshift < 0) {
00989                 maxshift = nx / 10;
00990         }
00991 
00992         float angle_step =  params.set_default("angstep", 0.0f);
00993         if ( angle_step == 0 ) angle_step = atan2(2.0f, (float)nx);
00994         else {
00995                 angle_step *= (float)EMConsts::deg2rad; //convert to radians
00996         }
00997         float trans_step =  params.set_default("transtep",1.0f);
00998 
00999         if (trans_step <= 0) throw InvalidParameterException("transstep must be greater than 0");
01000         if (angle_step <= 0) throw InvalidParameterException("angstep must be greater than 0");
01001 
01002 
01003         Dict shrinkfactor("n",2);
01004         EMData *this_img_shrink = this_img->process("math.medianshrink",shrinkfactor);
01005         EMData *to_shrunk = to->process("math.medianshrink",shrinkfactor);
01006         EMData *flipped_shrunk = flipped->process("math.medianshrink",shrinkfactor);
01007 
01008         int bestflip = 0;
01009         float bestdx = 0;
01010         float bestdy = 0;
01011 
01012         float bestang = 0;
01013         float bestval = FLT_MAX;
01014 
01015         int half_maxshift = maxshift / 2;
01016 
01017 
01018         for (int dy = -half_maxshift; dy <= half_maxshift; ++dy) {
01019                 for (int dx = -half_maxshift; dx <= half_maxshift; ++dx) {
01020                         if (hypot(dx, dy) <= maxshift) {
01021                                 for (float ang = -angle_step * 2.0f; ang <= (float)2 * M_PI; ang += angle_step * 4.0f) {
01022                                         EMData v(*this_img_shrink);
01023                                         Transform t(Dict("type","2d","alpha",static_cast<float>(ang*EMConsts::rad2deg)));
01024                                         t.set_trans((float)dx,(float)dy);
01025                                         v.transform(t);
01026 //                                      v.rotate_translate(ang*EMConsts::rad2deg, 0.0f, 0.0f, (float)dx, (float)dy, 0.0f);
01027 
01028                                         float lc = v.cmp(cmp_name, to_shrunk, cmp_params);
01029 
01030                                         if (lc < bestval) {
01031                                                 bestval = lc;
01032                                                 bestang = ang;
01033                                                 bestdx = (float)dx;
01034                                                 bestdy = (float)dy;
01035                                                 bestflip = 0;
01036                                         }
01037 
01038                                         lc = v.cmp(cmp_name,flipped_shrunk , cmp_params);
01039                                         if (lc < bestval) {
01040                                                 bestval = lc;
01041                                                 bestang = ang;
01042                                                 bestdx = (float)dx;
01043                                                 bestdy = (float)dy;
01044                                                 bestflip = 1;
01045                                         }
01046                                 }
01047                         }
01048                 }
01049         }
01050 
01051         if( to_shrunk )
01052         {
01053                 delete to_shrunk;
01054                 to_shrunk = 0;
01055         }
01056         if( flipped_shrunk )
01057         {
01058                 delete flipped_shrunk;
01059                 flipped_shrunk = 0;
01060         }
01061         if( this_img_shrink )
01062         {
01063                 delete this_img_shrink;
01064                 this_img_shrink = 0;
01065         }
01066 
01067         bestdx *= 2;
01068         bestdy *= 2;
01069         bestval = FLT_MAX;
01070 
01071         float bestdx2 = bestdx;
01072         float bestdy2 = bestdy;
01073         float bestang2 = bestang;
01074 
01075         for (float dy = bestdy2 - 3; dy <= bestdy2 + 3; dy += trans_step) {
01076                 for (float dx = bestdx2 - 3; dx <= bestdx2 + 3; dx += trans_step) {
01077                         if (hypot(dx, dy) <= maxshift) {
01078                                 for (float ang = bestang2 - angle_step * 6.0f; ang <= bestang2 + angle_step * 6.0f; ang += angle_step) {
01079                                         EMData v(*this_img);
01080                                         Transform t(Dict("type","2d","alpha",static_cast<float>(ang*EMConsts::rad2deg)));
01081                                         t.set_trans(dx,dy);
01082                                         v.transform(t);
01083 //                                      v.rotate_translate(ang*EMConsts::rad2deg, 0.0f, 0.0f, (float)dx, (float)dy, 0.0f);
01084 
01085                                         float lc = v.cmp(cmp_name, to, cmp_params);
01086 
01087                                         if (lc < bestval) {
01088                                                 bestval = lc;
01089                                                 bestang = ang;
01090                                                 bestdx = dx;
01091                                                 bestdy = dy;
01092                                                 bestflip = 0;
01093                                         }
01094 
01095                                         lc = v.cmp(cmp_name, flipped, cmp_params);
01096 
01097                                         if (lc < bestval) {
01098                                                 bestval = lc;
01099                                                 bestang = ang;
01100                                                 bestdx = dx;
01101                                                 bestdy = dy;
01102                                                 bestflip = 1;
01103                                         }
01104                                 }
01105                         }
01106                 }
01107         }
01108 
01109         if (delete_flipped) { delete flipped; flipped = 0; }
01110 
01111         bestang *= (float)EMConsts::rad2deg;
01112         Transform t(Dict("type","2d","alpha",(float)bestang));
01113         t.set_trans(bestdx,bestdy);
01114 
01115         if (bestflip) {
01116                 t.set_mirror(true);
01117         }
01118 
01119         EMData* rslt = this_img->process("xform",Dict("transform",&t));
01120         rslt->set_attr("xform.align2d",&t);
01121 
01122         return rslt;
01123 }

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

Implements EMAN::Aligner.

Definition at line 725 of file aligner.h.

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

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

00721                 {
00722                         return NAME;
00723                 }

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

Implements EMAN::Aligner.

Definition at line 735 of file aligner.h.

References EMAN::TypeDict::put().

00736                 {
00737                         TypeDict d;
00738                         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");
00739                         d.put("maxshift", EMObject::INT,"The maximum length of the detectable translational shift");
00740                         d.put("transtep", EMObject::FLOAT,"The translation step to take when honing the alignment, which occurs after coarse alignment");
00741                         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.");
00742                         return d;
00743                 }

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

Definition at line 730 of file aligner.h.

00731                 {
00732                         return new RTFSlowExhaustiveAligner();
00733                 }


Member Data Documentation

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

Definition at line 65 of file aligner.cpp.


The documentation for this class was generated from the following files:
Generated on Thu Dec 9 13:47:10 2010 for EMAN2 by  doxygen 1.3.9.1