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 ()


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


Member Function Documentation

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

References EMAN::EMData::cmp(), 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(), EMAN::Transform::set_mirror(), EMAN::Transform::set_trans(), t, EMAN::EMData::transform(), and v.

Referenced by align().

00767 {
00768 
00769         EMData *flip = params.set_default("flip", (EMData *) 0);
00770         int maxshift = params.set_default("maxshift", -1);
00771 
00772         EMData *flipped = 0;
00773 
00774         bool delete_flipped = true;
00775         if (flip) {
00776                 delete_flipped = false;
00777                 flipped = flip;
00778         }
00779         else {
00780                 flipped = to->process("xform.flip", Dict("axis", "x"));
00781         }
00782 
00783         int nx = this_img->get_xsize();
00784 
00785         if (maxshift < 0) {
00786                 maxshift = nx / 10;
00787         }
00788 
00789         float angle_step =  params.set_default("angstep", 0.0f);
00790         if ( angle_step == 0 ) angle_step = atan2(2.0f, (float)nx);
00791         else {
00792                 angle_step *= (float)EMConsts::deg2rad; //convert to radians
00793         }
00794         float trans_step =  params.set_default("transtep",1.0f);
00795 
00796         if (trans_step <= 0) throw InvalidParameterException("transstep must be greater than 0");
00797         if (angle_step <= 0) throw InvalidParameterException("angstep must be greater than 0");
00798 
00799 
00800         Dict shrinkfactor("n",2);
00801         EMData *this_img_shrink = this_img->process("math.medianshrink",shrinkfactor);
00802         EMData *to_shrunk = to->process("math.medianshrink",shrinkfactor);
00803         EMData *flipped_shrunk = flipped->process("math.medianshrink",shrinkfactor);
00804 
00805         int bestflip = 0;
00806         float bestdx = 0;
00807         float bestdy = 0;
00808 
00809         float bestang = 0;
00810         float bestval = FLT_MAX;
00811 
00812         int half_maxshift = maxshift / 2;
00813 
00814 
00815         for (int dy = -half_maxshift; dy <= half_maxshift; ++dy) {
00816                 for (int dx = -half_maxshift; dx <= half_maxshift; ++dx) {
00817                         if (hypot(dx, dy) <= maxshift) {
00818                                 for (float ang = -angle_step * 2.0f; ang <= (float)2 * M_PI; ang += angle_step * 4.0f) {
00819                                         EMData v(*this_img_shrink);
00820                                         Transform t(Dict("type","2d","alpha",static_cast<float>(ang*EMConsts::rad2deg)));
00821                                         t.set_trans((float)dx,(float)dy);
00822                                         v.transform(t);
00823 //                                      v.rotate_translate(ang*EMConsts::rad2deg, 0.0f, 0.0f, (float)dx, (float)dy, 0.0f);
00824 
00825                                         float lc = v.cmp(cmp_name, to_shrunk, cmp_params);
00826 
00827                                         if (lc < bestval) {
00828                                                 bestval = lc;
00829                                                 bestang = ang;
00830                                                 bestdx = (float)dx;
00831                                                 bestdy = (float)dy;
00832                                                 bestflip = 0;
00833                                         }
00834 
00835                                         lc = v.cmp(cmp_name,flipped_shrunk , cmp_params);
00836                                         if (lc < bestval) {
00837                                                 bestval = lc;
00838                                                 bestang = ang;
00839                                                 bestdx = (float)dx;
00840                                                 bestdy = (float)dy;
00841                                                 bestflip = 1;
00842                                         }
00843                                 }
00844                         }
00845                 }
00846         }
00847 
00848         if( to_shrunk )
00849         {
00850                 delete to_shrunk;
00851                 to_shrunk = 0;
00852         }
00853         if( flipped_shrunk )
00854         {
00855                 delete flipped_shrunk;
00856                 flipped_shrunk = 0;
00857         }
00858         if( this_img_shrink )
00859         {
00860                 delete this_img_shrink;
00861                 this_img_shrink = 0;
00862         }
00863 
00864         bestdx *= 2;
00865         bestdy *= 2;
00866         bestval = FLT_MAX;
00867 
00868         float bestdx2 = bestdx;
00869         float bestdy2 = bestdy;
00870         float bestang2 = bestang;
00871 
00872         for (float dy = bestdy2 - 3; dy <= bestdy2 + 3; dy += trans_step) {
00873                 for (float dx = bestdx2 - 3; dx <= bestdx2 + 3; dx += trans_step) {
00874                         if (hypot(dx, dy) <= maxshift) {
00875                                 for (float ang = bestang2 - angle_step * 6.0f; ang <= bestang2 + angle_step * 6.0f; ang += angle_step) {
00876                                         EMData v(*this_img);
00877                                         Transform t(Dict("type","2d","alpha",static_cast<float>(ang*EMConsts::rad2deg)));
00878                                         t.set_trans(dx,dy);
00879                                         v.transform(t);
00880 //                                      v.rotate_translate(ang*EMConsts::rad2deg, 0.0f, 0.0f, (float)dx, (float)dy, 0.0f);
00881 
00882                                         float lc = v.cmp(cmp_name, to, cmp_params);
00883 
00884                                         if (lc < bestval) {
00885                                                 bestval = lc;
00886                                                 bestang = ang;
00887                                                 bestdx = dx;
00888                                                 bestdy = dy;
00889                                                 bestflip = 0;
00890                                         }
00891 
00892                                         lc = v.cmp(cmp_name, flipped, cmp_params);
00893 
00894                                         if (lc < bestval) {
00895                                                 bestval = lc;
00896                                                 bestang = ang;
00897                                                 bestdx = dx;
00898                                                 bestdy = dy;
00899                                                 bestflip = 1;
00900                                         }
00901                                 }
00902                         }
00903                 }
00904         }
00905 
00906         if (delete_flipped) { delete flipped; flipped = 0; }
00907 
00908         bestang *= (float)EMConsts::rad2deg;
00909         Transform t(Dict("type","2d","alpha",(float)bestang));
00910         t.set_trans(bestdx,bestdy);
00911 
00912         if (bestflip) {
00913                 t.set_mirror(true);
00914         }
00915 
00916         EMData* rslt = this_img->process("math.transform",Dict("transform",&t));
00917         rslt->set_attr("xform.align2d",&t);
00918 
00919         return rslt;
00920 }

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

Implements EMAN::Aligner.

Definition at line 512 of file aligner.h.

References align().

00513                 {
00514                         return align(this_img, to_img, "sqeuclidean", Dict());
00515                 }

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

00517                 {
00518                         return "rtf_slow_exhaustive";
00519                 }

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

Implements EMAN::Aligner.

Definition at line 521 of file aligner.h.

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

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

Definition at line 526 of file aligner.h.

00527                 {
00528                         return new RTFSlowExhaustiveAligner();
00529                 }

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

Implements EMAN::Aligner.

Definition at line 531 of file aligner.h.

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

00532                 {
00533                         TypeDict d;
00534                         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");
00535                         d.put("maxshift", EMObject::INT,"The maximum length of the detectable translational shift");
00536                         d.put("transtep", EMObject::FLOAT,"The translation step to take when honing the alignment, which occurs after coarse alignment");
00537                         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.");
00538                         return d;
00539                 }


The documentation for this class was generated from the following files:

Generated on Sat Nov 21 02:20:14 2009 for EMAN2 by  doxygen 1.5.6