#include <aligner.h>
Inheritance diagram for EMAN::RTFExhaustiveAligner:
Public Member Functions | |
virtual EMData * | align (EMData *this_img, EMData *to_img, const string &cmp_name="dot", const Dict &cmp_params=Dict()) 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 | |
Aligner * | NEW () |
Static Public Attributes | |
const string | NAME = "rtf_exhaustive" |
slow
flip | ||
maxshift | Maximum translation in pixels |
Definition at line 770 of file aligner.h.
|
Implements EMAN::Aligner. Definition at line 775 of file aligner.h. References align(). 00776 { 00777 return align(this_img, to_img, "sqeuclidean", Dict()); 00778 }
|
|
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.
Implements EMAN::Aligner. Definition at line 894 of file aligner.cpp. References EMAN::Util::calc_best_fft_size(), EMAN::EMData::calc_ccfx(), EMAN::EMData::calc_max_index(), EMAN::EMData::cmp(), EMAN::EMData::copy(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), InvalidParameterException, ny, EMAN::EMData::process(), EMAN::EMData::rotate_x(), EMAN::EMData::set_attr(), EMAN::Dict::set_default(), EMAN::Transform::set_mirror(), EMAN::Transform::set_pre_trans(), t, EMAN::EMData::unwrap(), and EMAN::Vec2f. 00896 { 00897 EMData *flip = params.set_default("flip", (EMData *) 0); 00898 int maxshift = params.set_default("maxshift", this_img->get_xsize()/8); 00899 if (maxshift < 2) throw InvalidParameterException("maxshift must be greater than or equal to 2"); 00900 00901 int ny = this_img->get_ysize(); 00902 int xst = (int) floor(2 * M_PI * ny); 00903 xst = Util::calc_best_fft_size(xst); 00904 00905 Dict d("n",2); 00906 EMData *to_shrunk_unwrapped = to->process("math.medianshrink",d); 00907 00908 int to_copy_r2 = to_shrunk_unwrapped->get_ysize() / 2 - 2 - maxshift / 2; 00909 EMData *tmp = to_shrunk_unwrapped->unwrap(4, to_copy_r2, xst / 2, 0, 0, true); 00910 if( to_shrunk_unwrapped ) 00911 { 00912 delete to_shrunk_unwrapped; 00913 to_shrunk_unwrapped = 0; 00914 } 00915 to_shrunk_unwrapped = tmp; 00916 00917 EMData *to_shrunk_unwrapped_copy = to_shrunk_unwrapped->copy(); 00918 EMData* to_unwrapped = to->unwrap(4, to->get_ysize() / 2 - 2 - maxshift, xst, 0, 0, true); 00919 EMData *to_unwrapped_copy = to_unwrapped->copy(); 00920 00921 bool delete_flipped = true; 00922 EMData *flipped = 0; 00923 if (flip) { 00924 delete_flipped = false; 00925 flipped = flip; 00926 } 00927 else { 00928 flipped = to->process("xform.flip", Dict("axis", "x")); 00929 } 00930 EMData *to_shrunk_flipped_unwrapped = flipped->process("math.medianshrink",d); 00931 tmp = to_shrunk_flipped_unwrapped->unwrap(4, to_copy_r2, xst / 2, 0, 0, true); 00932 if( to_shrunk_flipped_unwrapped ) 00933 { 00934 delete to_shrunk_flipped_unwrapped; 00935 to_shrunk_flipped_unwrapped = 0; 00936 } 00937 to_shrunk_flipped_unwrapped = tmp; 00938 EMData *to_shrunk_flipped_unwrapped_copy = to_shrunk_flipped_unwrapped->copy(); 00939 EMData* to_flip_unwrapped = flipped->unwrap(4, to->get_ysize() / 2 - 2 - maxshift, xst, 0, 0, true); 00940 EMData* to_flip_unwrapped_copy = to_flip_unwrapped->copy(); 00941 00942 if (delete_flipped && flipped != 0) { 00943 delete flipped; 00944 flipped = 0; 00945 } 00946 00947 EMData *this_shrunk_2 = this_img->process("math.medianshrink",d); 00948 00949 float bestval = FLT_MAX; 00950 float bestang = 0; 00951 int bestflip = 0; 00952 float bestdx = 0; 00953 float bestdy = 0; 00954 00955 int half_maxshift = maxshift / 2; 00956 00957 int ur2 = this_shrunk_2->get_ysize() / 2 - 2 - half_maxshift; 00958 for (int dy = -half_maxshift; dy <= half_maxshift; dy += 1) { 00959 for (int dx = -half_maxshift; dx <= half_maxshift; dx += 1) { 00960 #ifdef _WIN32 00961 if (_hypot(dx, dy) <= half_maxshift) { 00962 #else 00963 if (hypot(dx, dy) <= half_maxshift) { 00964 #endif 00965 EMData *uw = this_shrunk_2->unwrap(4, ur2, xst / 2, dx, dy, true); 00966 EMData *uwc = uw->copy(); 00967 EMData *a = uw->calc_ccfx(to_shrunk_unwrapped); 00968 00969 uwc->rotate_x(a->calc_max_index()); 00970 float cm = uwc->cmp(cmp_name, to_shrunk_unwrapped_copy, cmp_params); 00971 if (cm < bestval) { 00972 bestval = cm; 00973 bestang = (float) (2.0 * M_PI * a->calc_max_index() / a->get_xsize()); 00974 bestdx = (float)dx; 00975 bestdy = (float)dy; 00976 bestflip = 0; 00977 } 00978 00979 00980 if( a ) 00981 { 00982 delete a; 00983 a = 0; 00984 } 00985 if( uw ) 00986 { 00987 delete uw; 00988 uw = 0; 00989 } 00990 if( uwc ) 00991 { 00992 delete uwc; 00993 uwc = 0; 00994 } 00995 uw = this_shrunk_2->unwrap(4, ur2, xst / 2, dx, dy, true); 00996 uwc = uw->copy(); 00997 a = uw->calc_ccfx(to_shrunk_flipped_unwrapped); 00998 00999 uwc->rotate_x(a->calc_max_index()); 01000 cm = uwc->cmp(cmp_name, to_shrunk_flipped_unwrapped_copy, cmp_params); 01001 if (cm < bestval) { 01002 bestval = cm; 01003 bestang = (float) (2.0 * M_PI * a->calc_max_index() / a->get_xsize()); 01004 bestdx = (float)dx; 01005 bestdy = (float)dy; 01006 bestflip = 1; 01007 } 01008 01009 if( a ) 01010 { 01011 delete a; 01012 a = 0; 01013 } 01014 01015 if( uw ) 01016 { 01017 delete uw; 01018 uw = 0; 01019 } 01020 if( uwc ) 01021 { 01022 delete uwc; 01023 uwc = 0; 01024 } 01025 } 01026 } 01027 } 01028 if( this_shrunk_2 ) 01029 { 01030 delete this_shrunk_2; 01031 this_shrunk_2 = 0; 01032 } 01033 if( to_shrunk_unwrapped ) 01034 { 01035 delete to_shrunk_unwrapped; 01036 to_shrunk_unwrapped = 0; 01037 } 01038 if( to_shrunk_unwrapped_copy ) 01039 { 01040 delete to_shrunk_unwrapped_copy; 01041 to_shrunk_unwrapped_copy = 0; 01042 } 01043 if( to_shrunk_flipped_unwrapped ) 01044 { 01045 delete to_shrunk_flipped_unwrapped; 01046 to_shrunk_flipped_unwrapped = 0; 01047 } 01048 if( to_shrunk_flipped_unwrapped_copy ) 01049 { 01050 delete to_shrunk_flipped_unwrapped_copy; 01051 to_shrunk_flipped_unwrapped_copy = 0; 01052 } 01053 bestdx *= 2; 01054 bestdy *= 2; 01055 bestval = FLT_MAX; 01056 01057 float bestdx2 = bestdx; 01058 float bestdy2 = bestdy; 01059 // Note I tried steps less than 1.0 (sub pixel precision) and it actually appeared detrimental 01060 // So my advice is to stick with dx += 1.0 etc unless you really are looking to fine tune this 01061 // algorithm 01062 for (float dy = bestdy2 - 3; dy <= bestdy2 + 3; dy += 1.0 ) { 01063 for (float dx = bestdx2 - 3; dx <= bestdx2 + 3; dx += 1.0 ) { 01064 01065 #ifdef _WIN32 01066 if (_hypot(dx, dy) <= maxshift) { 01067 #else 01068 if (hypot(dx, dy) <= maxshift) { 01069 #endif 01070 EMData *uw = this_img->unwrap(4, this_img->get_ysize() / 2 - 2 - maxshift, xst, (int)dx, (int)dy, true); 01071 EMData *uwc = uw->copy(); 01072 EMData *a = uw->calc_ccfx(to_unwrapped); 01073 01074 uwc->rotate_x(a->calc_max_index()); 01075 float cm = uwc->cmp(cmp_name, to_unwrapped_copy, cmp_params); 01076 01077 if (cm < bestval) { 01078 bestval = cm; 01079 bestang = (float)(2.0 * M_PI * a->calc_max_index() / a->get_xsize()); 01080 bestdx = dx; 01081 bestdy = dy; 01082 bestflip = 0; 01083 } 01084 01085 if( a ) 01086 { 01087 delete a; 01088 a = 0; 01089 } 01090 if( uw ) 01091 { 01092 delete uw; 01093 uw = 0; 01094 } 01095 if( uwc ) 01096 { 01097 delete uwc; 01098 uwc = 0; 01099 } 01100 uw = this_img->unwrap(4, this_img->get_ysize() / 2 - 2 - maxshift, xst, (int)dx, (int)dy, true); 01101 uwc = uw->copy(); 01102 a = uw->calc_ccfx(to_flip_unwrapped); 01103 01104 uwc->rotate_x(a->calc_max_index()); 01105 cm = uwc->cmp(cmp_name, to_flip_unwrapped_copy, cmp_params); 01106 01107 if (cm < bestval) { 01108 bestval = cm; 01109 bestang = (float)(2.0 * M_PI * a->calc_max_index() / a->get_xsize()); 01110 bestdx = dx; 01111 bestdy = dy; 01112 bestflip = 1; 01113 } 01114 01115 if( a ) 01116 { 01117 delete a; 01118 a = 0; 01119 } 01120 if( uw ) 01121 { 01122 delete uw; 01123 uw = 0; 01124 } 01125 if( uwc ) 01126 { 01127 delete uwc; 01128 uwc = 0; 01129 } 01130 } 01131 } 01132 } 01133 if( to_unwrapped ) {delete to_unwrapped;to_unwrapped = 0;} 01134 if( to_shrunk_unwrapped ) { delete to_shrunk_unwrapped; to_shrunk_unwrapped = 0;} 01135 if (to_unwrapped_copy) { delete to_unwrapped_copy; to_unwrapped_copy = 0; } 01136 if (to_flip_unwrapped) { delete to_flip_unwrapped; to_flip_unwrapped = 0; } 01137 if (to_flip_unwrapped_copy) { delete to_flip_unwrapped_copy; to_flip_unwrapped_copy = 0;} 01138 01139 bestang *= (float)EMConsts::rad2deg; 01140 Transform t(Dict("type","2d","alpha",(float)bestang)); 01141 t.set_pre_trans(Vec2f(-bestdx,-bestdy)); 01142 if (bestflip) { 01143 t.set_mirror(true); 01144 } 01145 01146 EMData* ret = this_img->process("xform",Dict("transform",&t)); 01147 ret->set_attr("xform.align2d",&t); 01148 01149 return ret; 01150 }
|
|
Implements EMAN::Aligner. Definition at line 785 of file aligner.h. 00786 { 00787 return "Experimental full 2D alignment with handedness check using semi-exhaustive search (not necessarily better than RTFBest)"; 00788 }
|
|
Get the Aligner's name. Each Aligner is identified by a unique name.
Implements EMAN::Aligner. Definition at line 780 of file aligner.h. 00781 {
00782 return NAME;
00783 }
|
|
Implements EMAN::Aligner. Definition at line 795 of file aligner.h. References EMAN::TypeDict::put(). 00796 { 00797 TypeDict d; 00798 00799 d.put("flip", EMObject::EMDATA); 00800 d.put("maxshift", EMObject::INT, "Maximum translation in pixels"); 00801 return d; 00802 }
|
|
Definition at line 790 of file aligner.h. 00791 { 00792 return new RTFExhaustiveAligner(); 00793 }
|
|
Definition at line 71 of file aligner.cpp. |