#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 | |
Aligner * | NEW () |
Static Public Attributes | |
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 814 of file aligner.h.
|
Implements EMAN::Aligner. Definition at line 819 of file aligner.h. References align(). 00820 { 00821 return align(this_img, to_img, "sqeuclidean", Dict()); 00822 }
|
|
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 1153 of file aligner.cpp. References EMAN::EMData::cmp(), EMAN::EMData::get_xsize(), InvalidParameterException, nx, EMAN::EMData::process(), EMAN::EMData::set_attr(), EMAN::Dict::set_default(), EMAN::Transform::set_mirror(), EMAN::Transform::set_trans(), t, EMAN::EMData::transform(), and v. 01155 { 01156 01157 EMData *flip = params.set_default("flip", (EMData *) 0); 01158 int maxshift = params.set_default("maxshift", -1); 01159 01160 EMData *flipped = 0; 01161 01162 bool delete_flipped = true; 01163 if (flip) { 01164 delete_flipped = false; 01165 flipped = flip; 01166 } 01167 else { 01168 flipped = to->process("xform.flip", Dict("axis", "x")); 01169 } 01170 01171 int nx = this_img->get_xsize(); 01172 01173 if (maxshift < 0) { 01174 maxshift = nx / 10; 01175 } 01176 01177 float angle_step = params.set_default("angstep", 0.0f); 01178 if ( angle_step == 0 ) angle_step = atan2(2.0f, (float)nx); 01179 else { 01180 angle_step *= (float)EMConsts::deg2rad; //convert to radians 01181 } 01182 float trans_step = params.set_default("transtep",1.0f); 01183 01184 if (trans_step <= 0) throw InvalidParameterException("transstep must be greater than 0"); 01185 if (angle_step <= 0) throw InvalidParameterException("angstep must be greater than 0"); 01186 01187 01188 Dict shrinkfactor("n",2); 01189 EMData *this_img_shrink = this_img->process("math.medianshrink",shrinkfactor); 01190 EMData *to_shrunk = to->process("math.medianshrink",shrinkfactor); 01191 EMData *flipped_shrunk = flipped->process("math.medianshrink",shrinkfactor); 01192 01193 int bestflip = 0; 01194 float bestdx = 0; 01195 float bestdy = 0; 01196 01197 float bestang = 0; 01198 float bestval = FLT_MAX; 01199 01200 int half_maxshift = maxshift / 2; 01201 01202 01203 for (int dy = -half_maxshift; dy <= half_maxshift; ++dy) { 01204 for (int dx = -half_maxshift; dx <= half_maxshift; ++dx) { 01205 if (hypot(dx, dy) <= maxshift) { 01206 for (float ang = -angle_step * 2.0f; ang <= (float)2 * M_PI; ang += angle_step * 4.0f) { 01207 EMData v(*this_img_shrink); 01208 Transform t(Dict("type","2d","alpha",static_cast<float>(ang*EMConsts::rad2deg))); 01209 t.set_trans((float)dx,(float)dy); 01210 v.transform(t); 01211 // v.rotate_translate(ang*EMConsts::rad2deg, 0.0f, 0.0f, (float)dx, (float)dy, 0.0f); 01212 01213 float lc = v.cmp(cmp_name, to_shrunk, cmp_params); 01214 01215 if (lc < bestval) { 01216 bestval = lc; 01217 bestang = ang; 01218 bestdx = (float)dx; 01219 bestdy = (float)dy; 01220 bestflip = 0; 01221 } 01222 01223 lc = v.cmp(cmp_name,flipped_shrunk , cmp_params); 01224 if (lc < bestval) { 01225 bestval = lc; 01226 bestang = ang; 01227 bestdx = (float)dx; 01228 bestdy = (float)dy; 01229 bestflip = 1; 01230 } 01231 } 01232 } 01233 } 01234 } 01235 01236 if( to_shrunk ) 01237 { 01238 delete to_shrunk; 01239 to_shrunk = 0; 01240 } 01241 if( flipped_shrunk ) 01242 { 01243 delete flipped_shrunk; 01244 flipped_shrunk = 0; 01245 } 01246 if( this_img_shrink ) 01247 { 01248 delete this_img_shrink; 01249 this_img_shrink = 0; 01250 } 01251 01252 bestdx *= 2; 01253 bestdy *= 2; 01254 bestval = FLT_MAX; 01255 01256 float bestdx2 = bestdx; 01257 float bestdy2 = bestdy; 01258 float bestang2 = bestang; 01259 01260 for (float dy = bestdy2 - 3; dy <= bestdy2 + 3; dy += trans_step) { 01261 for (float dx = bestdx2 - 3; dx <= bestdx2 + 3; dx += trans_step) { 01262 if (hypot(dx, dy) <= maxshift) { 01263 for (float ang = bestang2 - angle_step * 6.0f; ang <= bestang2 + angle_step * 6.0f; ang += angle_step) { 01264 EMData v(*this_img); 01265 Transform t(Dict("type","2d","alpha",static_cast<float>(ang*EMConsts::rad2deg))); 01266 t.set_trans(dx,dy); 01267 v.transform(t); 01268 // v.rotate_translate(ang*EMConsts::rad2deg, 0.0f, 0.0f, (float)dx, (float)dy, 0.0f); 01269 01270 float lc = v.cmp(cmp_name, to, cmp_params); 01271 01272 if (lc < bestval) { 01273 bestval = lc; 01274 bestang = ang; 01275 bestdx = dx; 01276 bestdy = dy; 01277 bestflip = 0; 01278 } 01279 01280 lc = v.cmp(cmp_name, flipped, cmp_params); 01281 01282 if (lc < bestval) { 01283 bestval = lc; 01284 bestang = ang; 01285 bestdx = dx; 01286 bestdy = dy; 01287 bestflip = 1; 01288 } 01289 } 01290 } 01291 } 01292 } 01293 01294 if (delete_flipped) { delete flipped; flipped = 0; } 01295 01296 bestang *= (float)EMConsts::rad2deg; 01297 Transform t(Dict("type","2d","alpha",(float)bestang)); 01298 t.set_trans(bestdx,bestdy); 01299 01300 if (bestflip) { 01301 t.set_mirror(true); 01302 } 01303 01304 EMData* rslt = this_img->process("xform",Dict("transform",&t)); 01305 rslt->set_attr("xform.align2d",&t); 01306 01307 return rslt; 01308 }
|
|
Implements EMAN::Aligner. Definition at line 828 of file aligner.h. 00829 { 00830 return "Experimental full 2D alignment with handedness check using more exhaustive search (not necessarily better than RTFBest)"; 00831 }
|
|
Get the Aligner's name. Each Aligner is identified by a unique name.
Implements EMAN::Aligner. Definition at line 823 of file aligner.h. 00824 {
00825 return NAME;
00826 }
|
|
Implements EMAN::Aligner. Definition at line 838 of file aligner.h. References EMAN::TypeDict::put(). 00839 { 00840 TypeDict d; 00841 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"); 00842 d.put("maxshift", EMObject::INT,"The maximum length of the detectable translational shift"); 00843 d.put("transtep", EMObject::FLOAT,"The translation step to take when honing the alignment, which occurs after coarse alignment"); 00844 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."); 00845 return d; 00846 }
|
|
Definition at line 833 of file aligner.h. 00834 { 00835 return new RTFSlowExhaustiveAligner(); 00836 }
|
|
Definition at line 72 of file aligner.cpp. |