#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 1082 of file aligner.h.
|
Implements EMAN::Aligner. Definition at line 1087 of file aligner.h. References align(). 01088 { 01089 return align(this_img, to_img, "sqeuclidean", Dict()); 01090 }
|
|
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 1113 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. 01115 { 01116 EMData *flip = params.set_default("flip", (EMData *) 0); 01117 int maxshift = params.set_default("maxshift", this_img->get_xsize()/8); 01118 if (maxshift < 2) throw InvalidParameterException("maxshift must be greater than or equal to 2"); 01119 01120 int ny = this_img->get_ysize(); 01121 int xst = (int) floor(2 * M_PI * ny); 01122 xst = Util::calc_best_fft_size(xst); 01123 01124 Dict d("n",2); 01125 EMData *to_shrunk_unwrapped = to->process("math.medianshrink",d); 01126 01127 int to_copy_r2 = to_shrunk_unwrapped->get_ysize() / 2 - 2 - maxshift / 2; 01128 EMData *tmp = to_shrunk_unwrapped->unwrap(4, to_copy_r2, xst / 2, 0, 0, true); 01129 if( to_shrunk_unwrapped ) 01130 { 01131 delete to_shrunk_unwrapped; 01132 to_shrunk_unwrapped = 0; 01133 } 01134 to_shrunk_unwrapped = tmp; 01135 01136 EMData *to_shrunk_unwrapped_copy = to_shrunk_unwrapped->copy(); 01137 EMData* to_unwrapped = to->unwrap(4, to->get_ysize() / 2 - 2 - maxshift, xst, 0, 0, true); 01138 EMData *to_unwrapped_copy = to_unwrapped->copy(); 01139 01140 bool delete_flipped = true; 01141 EMData *flipped = 0; 01142 if (flip) { 01143 delete_flipped = false; 01144 flipped = flip; 01145 } 01146 else { 01147 flipped = to->process("xform.flip", Dict("axis", "x")); 01148 } 01149 EMData *to_shrunk_flipped_unwrapped = flipped->process("math.medianshrink",d); 01150 tmp = to_shrunk_flipped_unwrapped->unwrap(4, to_copy_r2, xst / 2, 0, 0, true); 01151 if( to_shrunk_flipped_unwrapped ) 01152 { 01153 delete to_shrunk_flipped_unwrapped; 01154 to_shrunk_flipped_unwrapped = 0; 01155 } 01156 to_shrunk_flipped_unwrapped = tmp; 01157 EMData *to_shrunk_flipped_unwrapped_copy = to_shrunk_flipped_unwrapped->copy(); 01158 EMData* to_flip_unwrapped = flipped->unwrap(4, to->get_ysize() / 2 - 2 - maxshift, xst, 0, 0, true); 01159 EMData* to_flip_unwrapped_copy = to_flip_unwrapped->copy(); 01160 01161 if (delete_flipped && flipped != 0) { 01162 delete flipped; 01163 flipped = 0; 01164 } 01165 01166 EMData *this_shrunk_2 = this_img->process("math.medianshrink",d); 01167 01168 float bestval = FLT_MAX; 01169 float bestang = 0; 01170 int bestflip = 0; 01171 float bestdx = 0; 01172 float bestdy = 0; 01173 01174 int half_maxshift = maxshift / 2; 01175 01176 int ur2 = this_shrunk_2->get_ysize() / 2 - 2 - half_maxshift; 01177 for (int dy = -half_maxshift; dy <= half_maxshift; dy += 1) { 01178 for (int dx = -half_maxshift; dx <= half_maxshift; dx += 1) { 01179 #ifdef _WIN32 01180 if (_hypot(dx, dy) <= half_maxshift) { 01181 #else 01182 if (hypot(dx, dy) <= half_maxshift) { 01183 #endif 01184 EMData *uw = this_shrunk_2->unwrap(4, ur2, xst / 2, dx, dy, true); 01185 EMData *uwc = uw->copy(); 01186 EMData *a = uw->calc_ccfx(to_shrunk_unwrapped); 01187 01188 uwc->rotate_x(a->calc_max_index()); 01189 float cm = uwc->cmp(cmp_name, to_shrunk_unwrapped_copy, cmp_params); 01190 if (cm < bestval) { 01191 bestval = cm; 01192 bestang = (float) (2.0 * M_PI * a->calc_max_index() / a->get_xsize()); 01193 bestdx = (float)dx; 01194 bestdy = (float)dy; 01195 bestflip = 0; 01196 } 01197 01198 01199 if( a ) 01200 { 01201 delete a; 01202 a = 0; 01203 } 01204 if( uw ) 01205 { 01206 delete uw; 01207 uw = 0; 01208 } 01209 if( uwc ) 01210 { 01211 delete uwc; 01212 uwc = 0; 01213 } 01214 uw = this_shrunk_2->unwrap(4, ur2, xst / 2, dx, dy, true); 01215 uwc = uw->copy(); 01216 a = uw->calc_ccfx(to_shrunk_flipped_unwrapped); 01217 01218 uwc->rotate_x(a->calc_max_index()); 01219 cm = uwc->cmp(cmp_name, to_shrunk_flipped_unwrapped_copy, cmp_params); 01220 if (cm < bestval) { 01221 bestval = cm; 01222 bestang = (float) (2.0 * M_PI * a->calc_max_index() / a->get_xsize()); 01223 bestdx = (float)dx; 01224 bestdy = (float)dy; 01225 bestflip = 1; 01226 } 01227 01228 if( a ) 01229 { 01230 delete a; 01231 a = 0; 01232 } 01233 01234 if( uw ) 01235 { 01236 delete uw; 01237 uw = 0; 01238 } 01239 if( uwc ) 01240 { 01241 delete uwc; 01242 uwc = 0; 01243 } 01244 } 01245 } 01246 } 01247 if( this_shrunk_2 ) 01248 { 01249 delete this_shrunk_2; 01250 this_shrunk_2 = 0; 01251 } 01252 if( to_shrunk_unwrapped ) 01253 { 01254 delete to_shrunk_unwrapped; 01255 to_shrunk_unwrapped = 0; 01256 } 01257 if( to_shrunk_unwrapped_copy ) 01258 { 01259 delete to_shrunk_unwrapped_copy; 01260 to_shrunk_unwrapped_copy = 0; 01261 } 01262 if( to_shrunk_flipped_unwrapped ) 01263 { 01264 delete to_shrunk_flipped_unwrapped; 01265 to_shrunk_flipped_unwrapped = 0; 01266 } 01267 if( to_shrunk_flipped_unwrapped_copy ) 01268 { 01269 delete to_shrunk_flipped_unwrapped_copy; 01270 to_shrunk_flipped_unwrapped_copy = 0; 01271 } 01272 bestdx *= 2; 01273 bestdy *= 2; 01274 bestval = FLT_MAX; 01275 01276 float bestdx2 = bestdx; 01277 float bestdy2 = bestdy; 01278 // Note I tried steps less than 1.0 (sub pixel precision) and it actually appeared detrimental 01279 // So my advice is to stick with dx += 1.0 etc unless you really are looking to fine tune this 01280 // algorithm 01281 for (float dy = bestdy2 - 3; dy <= bestdy2 + 3; dy += 1.0 ) { 01282 for (float dx = bestdx2 - 3; dx <= bestdx2 + 3; dx += 1.0 ) { 01283 01284 #ifdef _WIN32 01285 if (_hypot(dx, dy) <= maxshift) { 01286 #else 01287 if (hypot(dx, dy) <= maxshift) { 01288 #endif 01289 EMData *uw = this_img->unwrap(4, this_img->get_ysize() / 2 - 2 - maxshift, xst, (int)dx, (int)dy, true); 01290 EMData *uwc = uw->copy(); 01291 EMData *a = uw->calc_ccfx(to_unwrapped); 01292 01293 uwc->rotate_x(a->calc_max_index()); 01294 float cm = uwc->cmp(cmp_name, to_unwrapped_copy, cmp_params); 01295 01296 if (cm < bestval) { 01297 bestval = cm; 01298 bestang = (float)(2.0 * M_PI * a->calc_max_index() / a->get_xsize()); 01299 bestdx = dx; 01300 bestdy = dy; 01301 bestflip = 0; 01302 } 01303 01304 if( a ) 01305 { 01306 delete a; 01307 a = 0; 01308 } 01309 if( uw ) 01310 { 01311 delete uw; 01312 uw = 0; 01313 } 01314 if( uwc ) 01315 { 01316 delete uwc; 01317 uwc = 0; 01318 } 01319 uw = this_img->unwrap(4, this_img->get_ysize() / 2 - 2 - maxshift, xst, (int)dx, (int)dy, true); 01320 uwc = uw->copy(); 01321 a = uw->calc_ccfx(to_flip_unwrapped); 01322 01323 uwc->rotate_x(a->calc_max_index()); 01324 cm = uwc->cmp(cmp_name, to_flip_unwrapped_copy, cmp_params); 01325 01326 if (cm < bestval) { 01327 bestval = cm; 01328 bestang = (float)(2.0 * M_PI * a->calc_max_index() / a->get_xsize()); 01329 bestdx = dx; 01330 bestdy = dy; 01331 bestflip = 1; 01332 } 01333 01334 if( a ) 01335 { 01336 delete a; 01337 a = 0; 01338 } 01339 if( uw ) 01340 { 01341 delete uw; 01342 uw = 0; 01343 } 01344 if( uwc ) 01345 { 01346 delete uwc; 01347 uwc = 0; 01348 } 01349 } 01350 } 01351 } 01352 if( to_unwrapped ) {delete to_unwrapped;to_unwrapped = 0;} 01353 if( to_shrunk_unwrapped ) { delete to_shrunk_unwrapped; to_shrunk_unwrapped = 0;} 01354 if (to_unwrapped_copy) { delete to_unwrapped_copy; to_unwrapped_copy = 0; } 01355 if (to_flip_unwrapped) { delete to_flip_unwrapped; to_flip_unwrapped = 0; } 01356 if (to_flip_unwrapped_copy) { delete to_flip_unwrapped_copy; to_flip_unwrapped_copy = 0;} 01357 01358 bestang *= (float)EMConsts::rad2deg; 01359 Transform t(Dict("type","2d","alpha",(float)bestang)); 01360 t.set_pre_trans(Vec2f(-bestdx,-bestdy)); 01361 if (bestflip) { 01362 t.set_mirror(true); 01363 } 01364 01365 EMData* ret = this_img->process("xform",Dict("transform",&t)); 01366 ret->set_attr("xform.align2d",&t); 01367 01368 return ret; 01369 }
|
|
Implements EMAN::Aligner. Definition at line 1097 of file aligner.h. 01098 { 01099 return "Experimental full 2D alignment with handedness check using semi-exhaustive search (not necessarily better than RTFBest)"; 01100 }
|
|
Get the Aligner's name. Each Aligner is identified by a unique name.
Implements EMAN::Aligner. Definition at line 1092 of file aligner.h. 01093 {
01094 return NAME;
01095 }
|
|
Implements EMAN::Aligner. Definition at line 1107 of file aligner.h. References EMAN::TypeDict::put(). 01108 { 01109 TypeDict d; 01110 01111 d.put("flip", EMObject::EMDATA); 01112 d.put("maxshift", EMObject::INT, "Maximum translation in pixels"); 01113 return d; 01114 }
|
|
Definition at line 1102 of file aligner.h. 01103 { 01104 return new RTFExhaustiveAligner(); 01105 }
|
|
Definition at line 76 of file aligner.cpp. |