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