#include <aligner.h>
Inheritance diagram for EMAN::RTFSlowExhaustiveAligner:
Public Member Functions | |
virtual EMData * | align (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 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 = "rtf_slow_exhaustive" |
This is very slow but can ensure localization of the global maximum
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 523 of file aligner.h.
virtual EMData* EMAN::RTFSlowExhaustiveAligner::align | ( | EMData * | this_img, | |
EMData * | to_img | |||
) | const [inline, virtual] |
Implements EMAN::Aligner.
Definition at line 528 of file aligner.h.
References align().
00529 { 00530 return align(this_img, to_img, "sqeuclidean", Dict()); 00531 }
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.
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 791 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().
00793 { 00794 00795 EMData *flip = params.set_default("flip", (EMData *) 0); 00796 int maxshift = params.set_default("maxshift", -1); 00797 00798 EMData *flipped = 0; 00799 00800 bool delete_flipped = true; 00801 if (flip) { 00802 delete_flipped = false; 00803 flipped = flip; 00804 } 00805 else { 00806 flipped = to->process("xform.flip", Dict("axis", "x")); 00807 } 00808 00809 int nx = this_img->get_xsize(); 00810 00811 if (maxshift < 0) { 00812 maxshift = nx / 10; 00813 } 00814 00815 float angle_step = params.set_default("angstep", 0.0f); 00816 if ( angle_step == 0 ) angle_step = atan2(2.0f, (float)nx); 00817 else { 00818 angle_step *= (float)EMConsts::deg2rad; //convert to radians 00819 } 00820 float trans_step = params.set_default("transtep",1.0f); 00821 00822 if (trans_step <= 0) throw InvalidParameterException("transstep must be greater than 0"); 00823 if (angle_step <= 0) throw InvalidParameterException("angstep must be greater than 0"); 00824 00825 00826 Dict shrinkfactor("n",2); 00827 EMData *this_img_shrink = this_img->process("math.medianshrink",shrinkfactor); 00828 EMData *to_shrunk = to->process("math.medianshrink",shrinkfactor); 00829 EMData *flipped_shrunk = flipped->process("math.medianshrink",shrinkfactor); 00830 00831 int bestflip = 0; 00832 float bestdx = 0; 00833 float bestdy = 0; 00834 00835 float bestang = 0; 00836 float bestval = FLT_MAX; 00837 00838 int half_maxshift = maxshift / 2; 00839 00840 00841 for (int dy = -half_maxshift; dy <= half_maxshift; ++dy) { 00842 for (int dx = -half_maxshift; dx <= half_maxshift; ++dx) { 00843 if (hypot(dx, dy) <= maxshift) { 00844 for (float ang = -angle_step * 2.0f; ang <= (float)2 * M_PI; ang += angle_step * 4.0f) { 00845 EMData v(*this_img_shrink); 00846 Transform t(Dict("type","2d","alpha",static_cast<float>(ang*EMConsts::rad2deg))); 00847 t.set_trans((float)dx,(float)dy); 00848 v.transform(t); 00849 // v.rotate_translate(ang*EMConsts::rad2deg, 0.0f, 0.0f, (float)dx, (float)dy, 0.0f); 00850 00851 float lc = v.cmp(cmp_name, to_shrunk, cmp_params); 00852 00853 if (lc < bestval) { 00854 bestval = lc; 00855 bestang = ang; 00856 bestdx = (float)dx; 00857 bestdy = (float)dy; 00858 bestflip = 0; 00859 } 00860 00861 lc = v.cmp(cmp_name,flipped_shrunk , cmp_params); 00862 if (lc < bestval) { 00863 bestval = lc; 00864 bestang = ang; 00865 bestdx = (float)dx; 00866 bestdy = (float)dy; 00867 bestflip = 1; 00868 } 00869 } 00870 } 00871 } 00872 } 00873 00874 if( to_shrunk ) 00875 { 00876 delete to_shrunk; 00877 to_shrunk = 0; 00878 } 00879 if( flipped_shrunk ) 00880 { 00881 delete flipped_shrunk; 00882 flipped_shrunk = 0; 00883 } 00884 if( this_img_shrink ) 00885 { 00886 delete this_img_shrink; 00887 this_img_shrink = 0; 00888 } 00889 00890 bestdx *= 2; 00891 bestdy *= 2; 00892 bestval = FLT_MAX; 00893 00894 float bestdx2 = bestdx; 00895 float bestdy2 = bestdy; 00896 float bestang2 = bestang; 00897 00898 for (float dy = bestdy2 - 3; dy <= bestdy2 + 3; dy += trans_step) { 00899 for (float dx = bestdx2 - 3; dx <= bestdx2 + 3; dx += trans_step) { 00900 if (hypot(dx, dy) <= maxshift) { 00901 for (float ang = bestang2 - angle_step * 6.0f; ang <= bestang2 + angle_step * 6.0f; ang += angle_step) { 00902 EMData v(*this_img); 00903 Transform t(Dict("type","2d","alpha",static_cast<float>(ang*EMConsts::rad2deg))); 00904 t.set_trans(dx,dy); 00905 v.transform(t); 00906 // v.rotate_translate(ang*EMConsts::rad2deg, 0.0f, 0.0f, (float)dx, (float)dy, 0.0f); 00907 00908 float lc = v.cmp(cmp_name, to, cmp_params); 00909 00910 if (lc < bestval) { 00911 bestval = lc; 00912 bestang = ang; 00913 bestdx = dx; 00914 bestdy = dy; 00915 bestflip = 0; 00916 } 00917 00918 lc = v.cmp(cmp_name, flipped, cmp_params); 00919 00920 if (lc < bestval) { 00921 bestval = lc; 00922 bestang = ang; 00923 bestdx = dx; 00924 bestdy = dy; 00925 bestflip = 1; 00926 } 00927 } 00928 } 00929 } 00930 } 00931 00932 if (delete_flipped) { delete flipped; flipped = 0; } 00933 00934 bestang *= (float)EMConsts::rad2deg; 00935 Transform t(Dict("type","2d","alpha",(float)bestang)); 00936 t.set_trans(bestdx,bestdy); 00937 00938 if (bestflip) { 00939 t.set_mirror(true); 00940 } 00941 00942 EMData* rslt = this_img->process("xform",Dict("transform",&t)); 00943 rslt->set_attr("xform.align2d",&t); 00944 00945 return rslt; 00946 }
virtual string EMAN::RTFSlowExhaustiveAligner::get_desc | ( | ) | const [inline, virtual] |
Implements EMAN::Aligner.
Definition at line 537 of file aligner.h.
00538 { 00539 return "Experimental full 2D alignment with handedness check using more exhaustive search (not necessarily better than RTFBest)"; 00540 }
virtual string EMAN::RTFSlowExhaustiveAligner::get_name | ( | ) | const [inline, virtual] |
virtual TypeDict EMAN::RTFSlowExhaustiveAligner::get_param_types | ( | ) | const [inline, virtual] |
Implements EMAN::Aligner.
Definition at line 547 of file aligner.h.
References EMAN::EMObject::EMDATA, EMAN::EMObject::FLOAT, EMAN::EMObject::INT, and EMAN::TypeDict::put().
00548 { 00549 TypeDict d; 00550 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"); 00551 d.put("maxshift", EMObject::INT,"The maximum length of the detectable translational shift"); 00552 d.put("transtep", EMObject::FLOAT,"The translation step to take when honing the alignment, which occurs after coarse alignment"); 00553 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."); 00554 return d; 00555 }
static Aligner* EMAN::RTFSlowExhaustiveAligner::NEW | ( | ) | [inline, static] |
const string RTFSlowExhaustiveAligner::NAME = "rtf_slow_exhaustive" [static] |