41#include <gsl/gsl_multimin.h>
44#ifdef EMAN2_USING_CUDA
49#ifdef SPARX_USING_CUDA
50 #include <sparx/cuda/cuda_ccf.h>
53#define EMAN2_ALIGNER_DEBUG 0
57const string TranslationalAligner::NAME =
"translational";
58const string RotationalAligner::NAME =
"rotational";
59const string RotationalAlignerBispec::NAME =
"rotational_bispec";
60const string RotationalAlignerIterative::NAME =
"rotational_iterative";
61const string RotatePrecenterAligner::NAME =
"rotate_precenter";
62const string RotateTranslateAligner::NAME =
"rotate_translate";
63const string RotateTranslateAlignerBispec::NAME =
"rotate_translate_bispec";
64const string RotateTranslateScaleAligner::NAME =
"rotate_translate_scale";
65const string RotateTranslateAlignerIterative::NAME =
"rotate_translate_iterative";
66const string RotateTranslateScaleAlignerIterative::NAME =
"rotate_trans_scale_iter";
67const string RotateTranslateAlignerPawel::NAME =
"rotate_translate_resample";
68const string RotateTranslateBestAligner::NAME =
"rotate_translate_best";
69const string RT2DTreeAligner::NAME =
"rotate_translate_tree";
70const string RotateFlipAligner::NAME =
"rotate_flip";
71const string RotateFlipAlignerIterative::NAME =
"rotate_flip_iterative";
72const string RotateTranslateFlipAligner::NAME =
"rotate_translate_flip";
73const string RotateTranslateFlipScaleAligner::NAME =
"rotate_trans_flip_scale";
74const string RotateTranslateFlipAlignerIterative::NAME =
"rotate_translate_flip_iterative";
75const string RotateTranslateFlipScaleAlignerIterative::NAME =
"rotate_trans_flip_scale_iter";
76const string RotateTranslateFlipAlignerPawel::NAME =
"rotate_translate_flip_resample";
77const string RTFExhaustiveAligner::NAME =
"rtf_exhaustive";
78const string RTFSlowExhaustiveAligner::NAME =
"rtf_slow_exhaustive";
79const string RefineAligner::NAME =
"refine";
80const string RefineAlignerCG::NAME =
"refinecg";
81const string SymAlignProcessorQuat::NAME =
"symalignquat";
82const string SymAlignProcessor::NAME =
"symalign";
83const string Refine3DAlignerGrid::NAME =
"refine_3d_grid";
84const string Refine3DAlignerQuaternion::NAME =
"refine_3d";
85const string RT3DGridAligner::NAME =
"rotate_translate_3d_grid";
86const string RT3DSphereAligner::NAME =
"rotate_translate_3d";
87const string RT3DTreeAligner::NAME =
"rotate_translate_3d_tree";
88const string RT3DLocalTreeAligner::NAME =
"rotate_translate_3d_local_tree";
89const string RT2Dto3DTreeAligner::NAME =
"rotate_translate_2d_to_3d_tree";
90const string RT3DSymmetryAligner::NAME =
"rotate_symmetry_3d";
91const string FRM2DAligner::NAME =
"frm2d";
92const string ScaleAligner::NAME =
"scale";
97 force_add<TranslationalAligner>();
98 force_add<RotationalAligner>();
99 force_add<RotationalAlignerBispec>();
100 force_add<RotationalAlignerIterative>();
101 force_add<RotatePrecenterAligner>();
102 force_add<RotateTranslateAligner>();
103 force_add<RotateTranslateAlignerBispec>();
104 force_add<RotateTranslateScaleAligner>();
105 force_add<RotateTranslateAlignerIterative>();
106 force_add<RotateTranslateScaleAlignerIterative>();
107 force_add<RotateTranslateAlignerPawel>();
108 force_add<RT2DTreeAligner>();
109 force_add<RotateFlipAligner>();
110 force_add<RotateFlipAlignerIterative>();
111 force_add<RotateTranslateFlipAligner>();
112 force_add<RotateTranslateFlipScaleAligner>();
113 force_add<RotateTranslateFlipAlignerIterative>();
114 force_add<RotateTranslateFlipScaleAlignerIterative>();
115 force_add<RotateTranslateFlipAlignerPawel>();
116 force_add<RTFExhaustiveAligner>();
117 force_add<RTFSlowExhaustiveAligner>();
118 force_add<SymAlignProcessor>();
119 force_add<RefineAligner>();
120 force_add<RefineAlignerCG>();
121 force_add<SymAlignProcessorQuat>();
122 force_add<Refine3DAlignerGrid>();
123 force_add<Refine3DAlignerQuaternion>();
124 force_add<RT3DGridAligner>();
125 force_add<RT3DSphereAligner>();
126 force_add<RT2Dto3DTreeAligner>();
127 force_add<RT3DTreeAligner>();
128 force_add<RT3DLocalTreeAligner>();
129 force_add<RT3DSymmetryAligner>();
130 force_add<FRM2DAligner>();
131 force_add<ScaleAligner>();
142 const string & cmp_name,
const Dict& cmp_params)
const
154 float* oridata = this_img->get_data();
163 float bestscore = 1.0e37;
165 for(
float i = max; i > min; i-=step){
168 float* des_data = xform->transform(this_img,t);
169 this_img->set_data(des_data);
174 float score = aligned->cmp(cmp_name, to, cmp_params);
175 if(score < bestscore){
178 if(result != 0)
delete result;
182 result->set_attr(
"xform.align2d",tt);
193 this_img->set_data(oridata);
197 if (proc != 0)
delete proc;
204 const string& cmp_name,
const Dict& cmp_params)
const
214 float* oridata = this_img->get_data();
221 float bestscale = 1.0;
222 float bestscore = 1.0e37;
224 for(
float i = max; i > min; i-=step){
226 float* des_data = xform->transform(this_img,t);
227 this_img->set_data(des_data);
231 float score = this_img->cmp(cmp_name, to, cmp_params);
232 if(score < bestscore){
242 this_img->set_data(oridata);
249 EMData* result = this_img->process(
"xform",
Dict(
"transform",&t));
250 result->set_attr(
"scalefactor",bestscale);
251 if (proc != 0)
delete proc;
262 const string&,
const Dict&)
const
272 int nx = this_img->get_xsize();
273 int ny = this_img->get_ysize();
274 int nz = this_img->get_zsize();
280#ifdef EMAN2_USING_CUDA
281 if(EMData::usecuda == 1) {
293 if (useflcf) cf = this_img->
calc_flcf(to);
299 EMData *msk=this_img->process(
"threshold.notzero");
300 EMData *sqr=to->process(
"math.squared");
302 cfn->process_inplace(
"math.sqrt");
303 float *d1=cf->get_data();
304 float *d2=cfn->get_data();
305 for (
size_t i=0; i<(size_t)nx*ny*nz; ++i) {
306 if (d2[i]!=0) d1[i]/=d2[i];
315 int maxshifty =
params[
"maxshift"];
316 int maxshiftz =
params[
"maxshift"];
317 int nozero =
params[
"nozero"];
319 if (maxshiftx <= 0) {
325 if (maxshiftx > nx / 2 - 1) maxshiftx = nx / 2 - 1;
326 if (maxshifty > ny / 2 - 1) maxshifty = ny / 2 - 1;
327 if (maxshiftz > nz / 2 - 1) maxshiftz = nz / 2 - 1;
329 if (nx == 1) maxshiftx = 0;
330 if (ny == 1) maxshifty = 0;
331 if (nz == 1) maxshiftz = 0;
339#ifdef EMAN2_USING_CUDA
341 cout <<
"USe CUDA TA 2" << endl;
351 peak = cf->calc_max_location_wrap(maxshiftx, maxshifty, maxshiftz, &maxvalue);
354 Vec3f cur_trans =
Vec3f ( (
float)-peak[0], (
float)-peak[1], (
float)-peak[2]);
361 cur_trans[0] = floor(cur_trans[0] + 0.5f);
362 cur_trans[1] = floor(cur_trans[1] + 0.5f);
363 cur_trans[2] = floor(cur_trans[2] + 0.5f);
372 Dict params(
"trans",
static_cast< vector<int>
>(cur_trans));
374 cf=this_img->process(
"xform.translate.int",
params);
379#ifdef EMAN2_USING_CUDA
381 cout <<
"USe CUDA TA 3" << endl;
383 cf = this_img->process(
"xform",
Dict(
"transform",&t));
390 cf->set_attr(
"xform.align3d",&t);
391 cf->set_attr(
"score_align",-maxvalue);
392 }
else if ( ny != 1 ) {
396 cf->set_attr(
"xform.align2d",&t);
397 cf->set_attr(
"score_align",-maxvalue);
404 EMData* this_img_bispec, * to_bispec;
409 this_img_bispec=this_img->process(
"math.harmonicpow",
Dict(
"rfp",1));
410 to_bispec=to->process(
"math.harmonicpow",
Dict(
"rfp",1));
412 this_img_bispec=this_img->process(
"math.bispectrum.slice",
Dict(
"rfp",rfp,
"size",size));
413 to_bispec=to->process(
"math.bispectrum.slice",
Dict(
"rfp",rfp,
"size",size));
415 int this_img_rfp_nx = this_img_bispec->get_xsize();
418 EMData *cf = this_img_bispec->
calc_ccfx(to_bispec, 0, this_img->get_ysize(),
false,
false,
false);
421 delete this_img_bispec;
425 float *data = cf->get_data();
433 float rot_angle = (float) (peak_index * 360.0f / this_img_rfp_nx);
437 cf=this_img->process(
"xform",
Dict(
"transform",(
Transform*)&tmp));
441 cf->set_attr(
"xform.align2d",&tmp);
449 EMData* this_img_rfp, * to_rfp;
453 }
else if (rfp_mode == 1) {
456 }
else if (rfp_mode == 2) {
462 int this_img_rfp_nx = this_img_rfp->get_xsize();
465 EMData *cf = this_img_rfp->
calc_ccfx(to_rfp, 0, this_img->get_ysize(),
false,
false,zscore);
474 delete this_img_rfp; this_img_rfp = 0;
475 delete to_rfp; to_rfp = 0;
478 float *data = cf->get_data();
488 float rot_angle = (float) (peak_index * 180.0f / this_img_rfp_nx);
492 cf=this_img->process(
"xform",
Dict(
"transform",(
Transform*)&tmp));
496 cf->set_attr(
"xform.align2d",&tmp);
501 const string& cmp_name,
const Dict& cmp_params)
const
505#ifdef EMAN2_USING_CUDA
506 if(EMData::usecuda == 1) {
518 Transform * tmp = rot_aligned->get_attr(
"xform.align2d");
520 float rotate_angle_solution = rot[
"alpha"];
528 EMData *rot_align_180 = rot_aligned->process(
"math.rotate.180");
531 float rot_cmp = rot_aligned->cmp(cmp_name, to, cmp_params);
532 float rot_180_cmp = rot_align_180->cmp(cmp_name, to, cmp_params);
537 if (rot_cmp < rot_180_cmp){
538 result = rot_aligned;
540 delete rot_align_180; rot_align_180 = 0;
542 result = rot_align_180;
544 delete rot_aligned; rot_aligned = 0;
545 rotate_angle_solution = rotate_angle_solution-180.0f;
550 Transform tmp2(
Dict(
"type",
"2d",
"alpha",rotate_angle_solution));
551 result->set_attr(
"xform.align2d",&tmp2);
557 const string&,
const Dict&)
const
563 int ny = this_img->get_ysize();
565 EMData *e1 = this_img->
unwrap(4, ny * 7 / 16, size, 0, 0, 1);
569 float *data = cf->get_data();
574 float a = (float) ((1.0f - 1.0f * peak_index / size) * 180. * 2);
578 EMData* rslt = this_img->process(
"xform",
Dict(
"transform",&rot));
579 rslt->set_attr(
"xform.align2d",&rot);
610 const string &,
const Dict&)
const
616 EMData * this_img_polar = this_img->
unwrap(r1,r2,-1,0,0,
true);
617 int this_img_polar_nx = this_img_polar->get_xsize();
619 EMData * cf = this_img_polar->
calc_ccfx(to_polar, 0, this_img->get_ysize());
622 delete to_polar; to_polar = 0;
623 delete this_img_polar; this_img_polar = 0;
625 float * data = cf->get_data();
631 float rot_angle = (float) (peak_index * 360.0f / this_img_polar_nx);
637 rotimg->set_attr(
"xform.align2d",&tmp);
644 const string & cmp_name,
const Dict& cmp_params)
const
649 trans_params[
"intonly"] = 0;
659 EMData * moving_img = this_img;
660 for(
int it = 0; it < maxiter; it++){
663 EMData * trans_align = moving_img->align(
"translational", to, trans_params, cmp_name, cmp_params);
664 Transform * tt = trans_align->get_attr(
"xform.align2d");
669 EMData * rottrans_align = trans_align->align(
"rotational_iterative", to, rot_params, cmp_name, cmp_params);
670 Transform * rt = rottrans_align->get_attr(
"xform.align2d");
672 delete trans_align; trans_align = 0;
673 delete rottrans_align; rottrans_align = 0;
677 if(it > 0){
delete moving_img;}
679 moving_img = this_img->process(
"xform",
Dict(
"transform",&t));
683 moving_img->set_attr(
"xform.align2d", &t);
689 const string & cmp_name,
const Dict& cmp_params)
const
706 const string & cmp_name,
const Dict& cmp_params)
const
708 if (cmp_name !=
"dot" && cmp_name !=
"ccc")
throw InvalidParameterException(
"Resample aligner only works for dot and ccc");
715 if(this_img->get_xsize()/2 - 1 - r2 - maxtx <= 0 || (r2 == -1 && maxtx > 0))
throw InvalidParameterException(
"nx/2 - 1 - r2 - tx must be greater than or = 0");
716 if(this_img->get_ysize()/2 - 1 - r2 - maxty <= 0 || (r2 == -1 && maxty > 0))
throw InvalidParameterException(
"ny/2 - 1 - r2 - ty must be greater than or = 0");
719 float best_peak = -1.0e37;
720 int best_peak_index = 0;
725 for(
int x = -maxtx;
x <= maxtx;
x++){
726 for(
int y = -maxty;
y <= maxty;
y++){
730 EMData * cf = this_img_polar->
calc_ccfx(to_polar, 0, this_img_polar->get_ysize());
732 polarxsize = this_img_polar->get_xsize();
735 delete to_polar; to_polar = 0;
736 delete this_img_polar; this_img_polar = 0;
738 float *data = cf->get_data();
744 if(peak > best_peak) {
746 best_peak_index = peak_index;
753 float rot_angle = (float) (best_peak_index * 360.0f / polarxsize);
756 Transform tmptt(
Dict(
"type",
"2d",
"alpha",0,
"tx",-best_tx,
"ty",-best_ty));
757 Transform tmprot(
Dict(
"type",
"2d",
"alpha",rot_angle,
"tx",0,
"ty",0));
760 rotimg->set_attr(
"xform.align2d",&total);
767 const string & cmp_name,
const Dict& cmp_params)
const
770#ifdef EMAN2_USING_CUDA
771 if(EMData::usecuda == 1) {
781 Transform * tmp = rot_align->get_attr(
"xform.align2d");
783 float rotate_angle_solution = rot[
"alpha"];
786 EMData *rot_align_180 = rot_align->process(
"math.rotate.180");
789 trans_params[
"intonly"] = 0;
795 EMData* rot_trans = rot_align->align(
"translational", to, trans_params, cmp_name, cmp_params);
802 EMData* rot_180_trans = rot_align_180->align(
"translational", to, trans_params, cmp_name, cmp_params);
803 if( rot_align_180 ) {
804 delete rot_align_180;
809 float cmp1 = rot_trans->cmp(cmp_name, to, cmp_params);
810 float cmp2 = rot_180_trans->cmp(cmp_name, to, cmp_params);
814 if( rot_180_trans ) {
815 delete rot_180_trans;
825 result = rot_180_trans;
826 rotate_angle_solution -= 180.f;
829 Transform* t = result->get_attr(
"xform.align2d");
831 result->set_attr(
"xform.align2d",t);
845 EMData *rot_align = this_img->align(
"rotational_bispec", to,
Dict(
"rfpn",rfp,
"size",size,
"harmonic",harmonic));
846 Transform * tmp = rot_align->get_attr(
"xform.align2d");
848 float rotate_angle_solution = rot[
"alpha"];
852 trans_params[
"intonly"] =
false;
856 EMData* rot_trans = rot_align->align(
"translational", to, trans_params, cmp_name, cmp_params);
859 Transform* t = rot_trans->get_attr(
"xform.align2d");
863 EMData *result=this_img->process(
"xform",
Dict(
"transform",t));
864 result->set_attr(
"xform.align2d",t);
872 const string & cmp_name,
const Dict& cmp_params)
const
888 bool delete_flag =
false;
890 flipped = to->process(
"xform.flip",
Dict(
"axis",
"x"));
894 EMData *rot_trans_align_flip=0;
895 EMData *rot_trans_align=0;
900 if (usebispec || useharmonic) {
903 rot_trans_align = this_img->align(
"rotate_translate_bispec",to,rt_params,cmp_name, cmp_params);
906 rot_trans_align_flip = this_img->align(
"rotate_translate_bispec", flipped, rt_params, cmp_name, cmp_params);
907 Transform * t = rot_trans_align_flip->get_attr(
"xform.align2d");
909 rot_trans_align_flip->set_attr(
"xform.align2d",t);
914 Dict rt_params(
"maxshift",
params[
"maxshift"],
"rfp_mode",
params.
set_default(
"rfp_mode",2),
"useflcf",
params.
set_default(
"useflcf",0),
"zscore",
params.
set_default(
"zscore",0));
915 rot_trans_align = this_img->align(
"rotate_translate",to,rt_params,cmp_name, cmp_params);
918 rot_trans_align_flip = this_img->align(
"rotate_translate", flipped, rt_params, cmp_name, cmp_params);
919 Transform * t = rot_trans_align_flip->get_attr(
"xform.align2d");
921 rot_trans_align_flip->set_attr(
"xform.align2d",t);
926 float cmp1 = rot_trans_align->cmp(cmp_name, to, cmp_params);
927 float cmp2 = rot_trans_align_flip->cmp(cmp_name, flipped, cmp_params);
939 if( rot_trans_align_flip ) {
940 delete rot_trans_align_flip;
941 rot_trans_align_flip = 0;
943 result = rot_trans_align;
946 if( rot_trans_align ) {
947 delete rot_trans_align;
950 result = rot_trans_align_flip;
951 result->process_inplace(
"xform.flip",
Dict(
"axis",
"x"));
958 const string & cmp_name,
const Dict& cmp_params)
const
974 const string & cmp_name,
const Dict& cmp_params)
const
978 EMData *rot_trans_align = this_img->align(
"rotate_translate_iterative",to,rt_params,cmp_name, cmp_params);
982 bool delete_flag =
false;
984 flipped = to->process(
"xform.flip",
Dict(
"axis",
"x"));
988 EMData * rot_trans_align_flip = this_img->align(
"rotate_translate_iterative", flipped, rt_params, cmp_name, cmp_params);
989 Transform* t = rot_trans_align_flip->get_attr(
"xform.align2d");
991 rot_trans_align_flip->set_attr(
"xform.align2d",t);
995 float cmp1 = rot_trans_align->cmp(cmp_name, to, cmp_params);
996 float cmp2 = rot_trans_align_flip->cmp(cmp_name, flipped, cmp_params);
1008 if( rot_trans_align_flip ) {
1009 delete rot_trans_align_flip;
1010 rot_trans_align_flip = 0;
1012 result = rot_trans_align;
1015 if( rot_trans_align ) {
1016 delete rot_trans_align;
1017 rot_trans_align = 0;
1019 result = rot_trans_align_flip;
1020 result->process_inplace(
"xform.flip",
Dict(
"axis",
"x"));
1027 const string & cmp_name,
const Dict& cmp_params)
const
1043 const string & cmp_name,
const Dict& cmp_params)
const
1045 if (cmp_name !=
"dot" && cmp_name !=
"ccc")
throw InvalidParameterException(
"Resample aligner only works for dot and ccc");
1052 if(this_img->get_xsize()/2 - 1 - r2 - maxtx <= 0 || (r2 == -1 && maxtx > 0)){
1053 cout <<
"\nRunTimeError: nx/2 - 1 - r2 - tx must be greater than or = 0\n" << endl;
1056 if(this_img->get_ysize()/2 - 1 - r2 - maxty <= 0 || (r2 == -1 && maxty > 0)){
1057 cout <<
"\nRunTimeError:ny/2 - 1 - r2 - ty must be greater than or = 0\n" << endl;
1062 float best_peak = -1.0e37;
1063 int best_peak_index = 0;
1069 for(
int x = -maxtx;
x <= maxtx;
x++){
1070 for(
int y = -maxty;
y <= maxty;
y++){
1074 EMData * cfflip = this_img_polar->
calc_ccfx(to_polar, 0, this_img_polar->get_ysize(),
false,
true);
1075 EMData * cf = this_img_polar->
calc_ccfx(to_polar, 0, this_img_polar->get_ysize());
1077 polarxsize = this_img_polar->get_xsize();
1080 delete to_polar; to_polar = 0;
1081 delete this_img_polar; this_img_polar = 0;
1083 float *data = cf->get_data();
1089 if(peak > best_peak) {
1091 best_peak_index = peak_index;
1097 data = cfflip->get_data();
1099 delete cfflip; cfflip = 0;
1101 if(peak > best_peak) {
1103 best_peak_index = peak_index;
1111 float rot_angle = (float) (best_peak_index * 360.0f / polarxsize);
1114 Transform tmptt(
Dict(
"type",
"2d",
"alpha",0,
"tx",-best_tx,
"ty",-best_ty));
1115 Transform tmprot(
Dict(
"type",
"2d",
"alpha",rot_angle,
"tx",0,
"ty",0));
1118 rotimg->set_attr(
"xform.align2d",&total);
1120 rotimg->process_inplace(
"xform.flip",
Dict(
"axis",
"x"));
1128 const string& cmp_name,
const Dict& cmp_params)
const
1131 EMData *r1 = this_img->align(
"rotational", to, rot_params,cmp_name, cmp_params);
1134 EMData* flipped =to->process(
"xform.flip",
Dict(
"axis",
"x"));
1135 EMData *r2 = this_img->align(
"rotational", flipped,rot_params, cmp_name, cmp_params);
1136 Transform* t = r2->get_attr(
"xform.align2d");
1138 r2->set_attr(
"xform.align2d",t);
1141 float cmp1 = r1->cmp(cmp_name, to, cmp_params);
1142 float cmp2 = r2->cmp(cmp_name, flipped, cmp_params);
1144 delete flipped; flipped = 0;
1163 result->process_inplace(
"xform.flip",
Dict(
"axis",
"x"));
1170 const string& cmp_name,
const Dict& cmp_params)
const
1173 EMData * r1 = this_img->align(
"rotational_iterative", to, rot_params,cmp_name, cmp_params);
1175 EMData * flipped =to->process(
"xform.flip",
Dict(
"axis",
"x"));
1176 EMData * r2 = this_img->align(
"rotational_iterative", flipped,rot_params, cmp_name, cmp_params);
1177 Transform* t = r2->get_attr(
"xform.align2d");
1179 r2->set_attr(
"xform.align2d",t);
1182 float cmp1 = r1->cmp(cmp_name, to, cmp_params);
1183 float cmp2 = r2->cmp(cmp_name, flipped, cmp_params);
1185 delete flipped; flipped = 0;
1204 result->process_inplace(
"xform.flip",
Dict(
"axis",
"x"));
1225 const string & cmp_name,
const Dict& cmp_params)
const
1231 int ny = this_img->get_ysize();
1232 int xst = (int) floor(2 * M_PI * ny);
1236 EMData *to_shrunk_unwrapped = to->process(
"math.medianshrink",d);
1238 int to_copy_r2 = to_shrunk_unwrapped->get_ysize() / 2 - 2 - maxshift / 2;
1239 EMData *tmp = to_shrunk_unwrapped->
unwrap(4, to_copy_r2, xst / 2, 0, 0,
true);
1240 if( to_shrunk_unwrapped )
1242 delete to_shrunk_unwrapped;
1243 to_shrunk_unwrapped = 0;
1245 to_shrunk_unwrapped = tmp;
1247 EMData *to_shrunk_unwrapped_copy = to_shrunk_unwrapped->copy();
1248 EMData* to_unwrapped = to->
unwrap(4, to->get_ysize() / 2 - 2 - maxshift, xst, 0, 0,
true);
1249 EMData *to_unwrapped_copy = to_unwrapped->copy();
1251 bool delete_flipped =
true;
1254 delete_flipped =
false;
1258 flipped = to->process(
"xform.flip",
Dict(
"axis",
"x"));
1260 EMData *to_shrunk_flipped_unwrapped = flipped->process(
"math.medianshrink",d);
1261 tmp = to_shrunk_flipped_unwrapped->
unwrap(4, to_copy_r2, xst / 2, 0, 0,
true);
1262 if( to_shrunk_flipped_unwrapped )
1264 delete to_shrunk_flipped_unwrapped;
1265 to_shrunk_flipped_unwrapped = 0;
1267 to_shrunk_flipped_unwrapped = tmp;
1268 EMData *to_shrunk_flipped_unwrapped_copy = to_shrunk_flipped_unwrapped->copy();
1269 EMData* to_flip_unwrapped = flipped->
unwrap(4, to->get_ysize() / 2 - 2 - maxshift, xst, 0, 0,
true);
1270 EMData* to_flip_unwrapped_copy = to_flip_unwrapped->copy();
1272 if (delete_flipped && flipped != 0) {
1277 EMData *this_shrunk_2 = this_img->process(
"math.medianshrink",d);
1279 float bestval = FLT_MAX;
1285 int half_maxshift = maxshift / 2;
1287 int ur2 = this_shrunk_2->get_ysize() / 2 - 2 - half_maxshift;
1288 for (
int dy = -half_maxshift; dy <= half_maxshift; dy += 1) {
1289 for (
int dx = -half_maxshift; dx <= half_maxshift; dx += 1) {
1290 if (hypot(dx, dy) <= half_maxshift) {
1291 EMData *uw = this_shrunk_2->
unwrap(4, ur2, xst / 2, dx, dy,
true);
1292 EMData *uwc = uw->copy();
1295 uwc->
rotate_x(a->calc_max_index());
1296 float cm = uwc->cmp(cmp_name, to_shrunk_unwrapped_copy, cmp_params);
1299 bestang = (float) (2.0 * M_PI * a->calc_max_index() / a->get_xsize());
1321 uw = this_shrunk_2->
unwrap(4, ur2, xst / 2, dx, dy,
true);
1323 a = uw->
calc_ccfx(to_shrunk_flipped_unwrapped);
1325 uwc->
rotate_x(a->calc_max_index());
1326 cm = uwc->cmp(cmp_name, to_shrunk_flipped_unwrapped_copy, cmp_params);
1329 bestang = (float) (2.0 * M_PI * a->calc_max_index() / a->get_xsize());
1356 delete this_shrunk_2;
1359 if( to_shrunk_unwrapped )
1361 delete to_shrunk_unwrapped;
1362 to_shrunk_unwrapped = 0;
1364 if( to_shrunk_unwrapped_copy )
1366 delete to_shrunk_unwrapped_copy;
1367 to_shrunk_unwrapped_copy = 0;
1369 if( to_shrunk_flipped_unwrapped )
1371 delete to_shrunk_flipped_unwrapped;
1372 to_shrunk_flipped_unwrapped = 0;
1374 if( to_shrunk_flipped_unwrapped_copy )
1376 delete to_shrunk_flipped_unwrapped_copy;
1377 to_shrunk_flipped_unwrapped_copy = 0;
1383 float bestdx2 = bestdx;
1384 float bestdy2 = bestdy;
1388 for (
float dy = bestdy2 - 3; dy <= bestdy2 + 3; dy += 1.0 ) {
1389 for (
float dx = bestdx2 - 3; dx <= bestdx2 + 3; dx += 1.0 ) {
1391 if (hypot(dx, dy) <= maxshift) {
1392 EMData *uw = this_img->
unwrap(4, this_img->get_ysize() / 2 - 2 - maxshift, xst, (int)dx, (
int)dy,
true);
1393 EMData *uwc = uw->copy();
1396 uwc->
rotate_x(a->calc_max_index());
1397 float cm = uwc->cmp(cmp_name, to_unwrapped_copy, cmp_params);
1401 bestang = (float)(2.0 * M_PI * a->calc_max_index() / a->get_xsize());
1422 uw = this_img->
unwrap(4, this_img->get_ysize() / 2 - 2 - maxshift, xst, (int)dx, (
int)dy,
true);
1426 uwc->
rotate_x(a->calc_max_index());
1427 cm = uwc->cmp(cmp_name, to_flip_unwrapped_copy, cmp_params);
1431 bestang = (float)(2.0 * M_PI * a->calc_max_index() / a->get_xsize());
1455 if( to_unwrapped ) {
delete to_unwrapped;to_unwrapped = 0;}
1456 if( to_shrunk_unwrapped ) {
delete to_shrunk_unwrapped; to_shrunk_unwrapped = 0;}
1457 if (to_unwrapped_copy) {
delete to_unwrapped_copy; to_unwrapped_copy = 0; }
1458 if (to_flip_unwrapped) {
delete to_flip_unwrapped; to_flip_unwrapped = 0; }
1459 if (to_flip_unwrapped_copy) {
delete to_flip_unwrapped_copy; to_flip_unwrapped_copy = 0;}
1468 EMData* ret = this_img->process(
"xform",
Dict(
"transform",&t));
1469 ret->set_attr(
"xform.align2d",&t);
1476 const string & cmp_name,
const Dict& cmp_params)
const
1484 bool delete_flipped =
true;
1486 delete_flipped =
false;
1490 flipped = to->process(
"xform.flip",
Dict(
"axis",
"x"));
1493 int nx = this_img->get_xsize();
1500 if ( angle_step == 0 ) angle_step = atan2(2.0f, (
float)nx);
1510 Dict shrinkfactor(
"n",2);
1511 EMData *this_img_shrink = this_img->process(
"math.medianshrink",shrinkfactor);
1512 EMData *to_shrunk = to->process(
"math.medianshrink",shrinkfactor);
1513 EMData *flipped_shrunk = flipped->process(
"math.medianshrink",shrinkfactor);
1520 float bestval = FLT_MAX;
1522 int half_maxshift = maxshift / 2;
1525 for (
int dy = -half_maxshift; dy <= half_maxshift; ++dy) {
1526 for (
int dx = -half_maxshift; dx <= half_maxshift; ++dx) {
1527 if (hypot(dx, dy) <= maxshift) {
1528 for (
float ang = -angle_step * 2.0f; ang <= (float)2 * M_PI; ang += angle_step * 4.0f) {
1529 EMData v(*this_img_shrink);
1535 float lc = v.cmp(cmp_name, to_shrunk, cmp_params);
1545 lc = v.cmp(cmp_name,flipped_shrunk , cmp_params);
1563 if( flipped_shrunk )
1565 delete flipped_shrunk;
1568 if( this_img_shrink )
1570 delete this_img_shrink;
1571 this_img_shrink = 0;
1578 float bestdx2 = bestdx;
1579 float bestdy2 = bestdy;
1580 float bestang2 = bestang;
1582 for (
float dy = bestdy2 - 3; dy <= bestdy2 + 3; dy += trans_step) {
1583 for (
float dx = bestdx2 - 3; dx <= bestdx2 + 3; dx += trans_step) {
1584 if (hypot(dx, dy) <= maxshift) {
1585 for (
float ang = bestang2 - angle_step * 6.0f; ang <= bestang2 + angle_step * 6.0f; ang += angle_step) {
1592 float lc = v.cmp(cmp_name, to, cmp_params);
1602 lc = v.cmp(cmp_name, flipped, cmp_params);
1616 if (delete_flipped) {
delete flipped; flipped = 0; }
1626 EMData* rslt = this_img->process(
"xform",
Dict(
"transform",&t));
1627 rslt->set_attr(
"xform.align2d",&t);
1641 d[
"inc_mirror"] =
true;
1651 float bestquality = 0.0f;
1653 for(vector<Transform>::const_iterator trans_it = transforms.begin(); trans_it != transforms.end(); trans_it++) {
1654 Dict tparams = trans_it->get_params(
"eman");
1656 for(
float phi = lphi; phi < uphi; phi += dphi ) {
1657 tparams[
"phi"] = phi;
1663 for ( vector<Transform>::const_iterator it = syms.begin(); it != syms.end(); ++it ) {
1665 EMData* transformed = this_img->process(
"xform",
Dict(
"transform",&sympos));
1673 float quality = symptcl->get_attr(
"sigma");
1674 cout << quality <<
" " << phi << endl;
1675 if(quality > bestquality) {
1676 bestquality = quality;
1677 bestimage = symptcl;
1683 if(sym != 0)
delete sym;
1688static double refalifn(
const gsl_vector * v,
void *params)
1692 double x = gsl_vector_get(v, 0);
1693 double y = gsl_vector_get(v, 1);
1694 double a = gsl_vector_get(v, 2);
1696 EMData *this_img = (*dict)[
"this"];
1697 EMData *with = (*dict)[
"with"];
1698 bool mirror = (*dict)[
"mirror"];
1700 Transform t(
Dict(
"type",
"2d",
"alpha",
static_cast<float>(a)));
1704 float sca=(float)gsl_vector_get(v, 3);
1705 if (sca<.7 || sca>1.3)
return 1.0e20;
1706 t.
set_scale((
float)gsl_vector_get(v, 3));
1708 EMData *tmp = this_img->process(
"xform",
Dict(
"transform",&t));
1709 if (dict->
has_key(
"mask")) tmp->mult(*(
EMData *)((*dict)[
"mask"]));
1712 Cmp* c = (
Cmp*) ((
void*)(*dict)[
"cmp"]);
1713 double result = c->
cmp(tmp,with);
1715 if (tmp != 0)
delete tmp;
1720static void refalidf(
const gsl_vector * v,
void *params,gsl_vector * df) {
1724 static double lstep[4] = { 0.05, 0.05, 0.1, 0.01 };
1726 gsl_vector *vc = gsl_vector_alloc(v->size);
1727 gsl_vector_memcpy(vc,v);
1730 for (
unsigned int i=0; i<v->size; i++) {
1732 double vp = gsl_vector_get(vc,i);
1734 gsl_vector_set(vc,i,
vp+lstep[i]);
1737 gsl_vector_set(vc,i,
vp);
1739 gsl_vector_set(df,i,(f2-f)/lstep[i]);
1742 gsl_vector_free(vc);
1746static void refalifdf(
const gsl_vector * v,
void *params,
double * f, gsl_vector * df) {
1750 static double lstep[4] = { 0.05, 0.05, 0.1, 0.01 };
1752 gsl_vector *vc = gsl_vector_alloc(v->size);
1753 gsl_vector_memcpy(vc,v);
1756 for (
unsigned int i=0; i<v->size; i++) {
1758 double vp = gsl_vector_get(vc,i);
1760 gsl_vector_set(vc,i,
vp+lstep[i]);
1763 gsl_vector_set(vc,i,
vp);
1765 gsl_vector_set(df,i,(f2-*f)/lstep[i]);
1768 gsl_vector_free(vc);
1775 EMData *this_img = (*dict)[
"this"];
1776 EMData *img_to = (*dict)[
"with"];
1777 bool mirror = (*dict)[
"mirror"];
1779 double x = gsl_vector_get(v, 0);
1780 double y = gsl_vector_get(v, 1);
1781 double a = gsl_vector_get(v, 2);
1784 int nsec = this_img->get_xsize() * this_img->get_ysize();
1785 double result = 1.0 - r / nsec;
1792 const string & cmp_name,
const Dict& cmp_params)
const
1805 bool mirror =
false;
1808 t =
params[
"xform.align2d"];
1813 mirror =
params[
"mirror"];
1814 sscale =
params[
"scale"];
1820 if ((
float)(this_img->get_attr(
"sigma"))==0.0 || (
float)(to->get_attr(
"sigma"))==0.0) {
1821 result = this_img->process(
"xform",
Dict(
"transform",t));
1822 result->set_attr(
"xform.align2d",t);
1834 if (stepscale!=0.0) np++;
1836 gsl_params[
"this"] = this_img;
1837 gsl_params[
"with"] = to;
1838 gsl_params[
"snr"] =
params[
"snr"];
1839 gsl_params[
"mirror"] = mirror;
1842 const gsl_multimin_fminimizer_type *T = gsl_multimin_fminimizer_nmsimplex;
1843 gsl_vector *ss = gsl_vector_alloc(np);
1846 gsl_vector_set(ss, 0, stepx);
1847 gsl_vector_set(ss, 1, stepy);
1848 gsl_vector_set(ss, 2, stepaz);
1849 if (stepscale!=0.0) gsl_vector_set(ss,3,stepscale);
1851 gsl_vector *
x = gsl_vector_alloc(np);
1852 gsl_vector_set(
x, 0, sdx);
1853 gsl_vector_set(
x, 1, sdy);
1854 gsl_vector_set(
x, 2, saz);
1855 if (stepscale!=0.0) gsl_vector_set(
x,3,1.0);
1859 gsl_multimin_function minex_func;
1865 gsl_params[
"cmp"] = (
void *) c;
1870 minex_func.params = (
void *) &gsl_params;
1872 gsl_multimin_fminimizer *s = gsl_multimin_fminimizer_alloc(T, np);
1873 gsl_multimin_fminimizer_set(s, &minex_func,
x, ss);
1875 int rval = GSL_CONTINUE;
1876 int status = GSL_SUCCESS;
1885 while (rval == GSL_CONTINUE && iter < maxiter) {
1887 status = gsl_multimin_fminimizer_iterate(s);
1891 rval = gsl_multimin_test_size(gsl_multimin_fminimizer_size(s), precision);
1896 if (maxshift <= 0) {
1897 maxshift = this_img->get_xsize() / 4;
1899 float fmaxshift =
static_cast<float>(maxshift);
1900 if ( fmaxshift >= fabs((
float)gsl_vector_get(s->x, 0)) && fmaxshift >= fabs((
float)gsl_vector_get(s->x, 1)) && (stepscale==0 || (((float)gsl_vector_get(s->x, 3))<1.3 && ((
float)gsl_vector_get(s->x, 3))<0.7)) )
1903 Transform tsoln(
Dict(
"type",
"2d",
"alpha",(
float)gsl_vector_get(s->x, 2)));
1904 tsoln.set_mirror(mirror);
1905 tsoln.set_trans((
float)gsl_vector_get(s->x, 0),(
float)gsl_vector_get(s->x, 1));
1906 if (stepscale!=0.0) tsoln.set_scale((
float)gsl_vector_get(s->x, 3));
1907 result = this_img->process(
"xform",
Dict(
"transform",&tsoln));
1908 result->set_attr(
"xform.align2d",&tsoln);
1911 result = this_img->process(
"xform",
Dict(
"transform",t));
1912 result->set_attr(
"xform.align2d",t);
1919 gsl_vector_free(ss);
1920 gsl_multimin_fminimizer_free(s);
1922 if (c != 0)
delete c;
1927 const string & cmp_name,
const Dict& cmp_params)
const
1940 bool mirror =
false;
1943 t =
params[
"xform.align2d"];
1948 mirror =
params[
"mirror"];
1949 sscale =
params[
"scale"];
1955 if ((
float)(this_img->get_attr(
"sigma"))==0.0 || (
float)(to->get_attr(
"sigma"))==0.0) {
1956 result = this_img->process(
"xform",
Dict(
"transform",t));
1957 result->set_attr(
"xform.align2d",t);
1966 if (stepscale!=0.0) np++;
1968 gsl_params[
"this"] = this_img;
1969 gsl_params[
"with"] = to;
1970 gsl_params[
"snr"] =
params[
"snr"];
1971 gsl_params[
"mirror"] = mirror;
1974 const gsl_multimin_fdfminimizer_type *T = gsl_multimin_fdfminimizer_vector_bfgs;
1976 gsl_vector *
x = gsl_vector_alloc(np);
1977 gsl_vector_set(
x, 0, sdx);
1978 gsl_vector_set(
x, 1, sdy);
1979 gsl_vector_set(
x, 2, saz);
1980 if (stepscale!=0.0) gsl_vector_set(
x,3,1.0);
1984 gsl_multimin_function_fdf minex_func;
1990 gsl_params[
"cmp"] = (
void *) c;
1997 minex_func.params = (
void *) &gsl_params;
1999 gsl_multimin_fdfminimizer *s = gsl_multimin_fdfminimizer_alloc(T, np);
2000 gsl_multimin_fdfminimizer_set(s, &minex_func,
x, step, 0.001f);
2002 int rval = GSL_CONTINUE;
2003 int status = GSL_SUCCESS;
2013 while (rval == GSL_CONTINUE && iter < maxiter) {
2015 status = gsl_multimin_fdfminimizer_iterate(s);
2019 rval = gsl_multimin_test_gradient (s->gradient, precision);
2025 if (maxshift <= 0) {
2026 maxshift = this_img->get_xsize() / 4;
2028 float fmaxshift =
static_cast<float>(maxshift);
2029 if ( fmaxshift >= fabs((
float)gsl_vector_get(s->x, 0)) && fmaxshift >= fabs((
float)gsl_vector_get(s->x, 1)) && (stepscale==0 || (((float)gsl_vector_get(s->x, 3))<1.3 && ((
float)gsl_vector_get(s->x, 3))<0.7)) )
2031 if (verbose>0) printf(
" Refine good (%d) %1.2f %1.2f %1.1f\n",iter,(
float)gsl_vector_get(s->x, 0),(
float)gsl_vector_get(s->x, 1),(
float)gsl_vector_get(s->x, 2));
2032 Transform tsoln(
Dict(
"type",
"2d",
"alpha",(
float)gsl_vector_get(s->x, 2)));
2033 tsoln.set_mirror(mirror);
2034 tsoln.set_trans((
float)gsl_vector_get(s->x, 0),(
float)gsl_vector_get(s->x, 1));
2035 if (stepscale!=0.0) tsoln.set_scale((
float)gsl_vector_get(s->x, 3));
2036 result = this_img->process(
"xform",
Dict(
"transform",&tsoln));
2037 result->set_attr(
"xform.align2d",&tsoln);
2039 if (verbose>1) printf(
" Refine Failed %1.2f %1.2f %1.1f\n",(
float)gsl_vector_get(s->x, 0),(
float)gsl_vector_get(s->x, 1),(
float)gsl_vector_get(s->x, 2));
2040 result = this_img->process(
"xform",
Dict(
"transform",t));
2041 result->set_attr(
"xform.align2d",t);
2048 gsl_multimin_fdfminimizer_free(s);
2050 if (c != 0)
delete c;
2056 Vec3f normal(n0,n1,n2);
2059 float omega = spincoeff*
sqrt(n0*n0 + n1*n1 + n2*n2);
2063 d[
"n1"] = normal[0];
2064 d[
"n2"] = normal[1];
2065 d[
"n3"] = normal[2];
2076static double symquat(
const gsl_vector * v,
void *params)
2080 double n0 = gsl_vector_get(v, 0);
2081 double n1 = gsl_vector_get(v, 1);
2082 double n2 = gsl_vector_get(v, 2);
2083 double x = gsl_vector_get(v, 3);
2084 double y = gsl_vector_get(v, 4);
2085 double z = gsl_vector_get(v, 5);
2087 EMData* volume = (*dict)[
"volume"];
2088 float spincoeff = (*dict)[
"spincoeff"];
2093 EMData *tmp = volume->process(
"xform",
Dict(
"transform",&soln));
2094 EMData *symtmp = tmp->process(
"xform.applysym",
Dict(
"sym",(*dict)[
"sym"]));
2095 Cmp* c = (
Cmp*) ((
void*)(*dict)[
"cmp"]);
2096 double result = c->
cmp(symtmp,tmp);
2108 double n0 = gsl_vector_get(v, 0);
2109 double n1 = gsl_vector_get(v, 1);
2110 double n2 = gsl_vector_get(v, 2);
2111 double x = gsl_vector_get(v, 3);
2112 double y = gsl_vector_get(v, 4);
2113 double z = gsl_vector_get(v, 5);
2115 EMData *this_img = (*dict)[
"this"];
2116 EMData *with = (*dict)[
"with"];
2119 float spincoeff = (*dict)[
"spincoeff"];
2123 EMData *tmp = this_img->process(
"xform",
Dict(
"transform",&soln));
2124 Cmp* c = (
Cmp*) ((
void*)(*dict)[
"cmp"]);
2125 double result = c->
cmp(tmp,with);
2126 if ( tmp != 0 )
delete tmp;
2137 t =
params[
"xform.align3d"];
2153 gsl_params[
"volume"] = volume;
2154 gsl_params[
"transform"] = t;
2156 gsl_params[
"spincoeff"] = spincoeff;
2158 const gsl_multimin_fminimizer_type *T = gsl_multimin_fminimizer_nmsimplex;
2159 gsl_vector *ss = gsl_vector_alloc(np);
2168 gsl_vector_set(ss, 0, stepi);
2169 gsl_vector_set(ss, 1, stepj);
2170 gsl_vector_set(ss, 2, stepk);
2171 gsl_vector_set(ss, 3, stepx);
2172 gsl_vector_set(ss, 4, stepy);
2173 gsl_vector_set(ss, 5, stepz);
2175 gsl_vector *
x = gsl_vector_alloc(np);
2176 gsl_vector_set(
x, 0, sdi);
2177 gsl_vector_set(
x, 1, sdj);
2178 gsl_vector_set(
x, 2, sdk);
2179 gsl_vector_set(
x, 3, sdx);
2180 gsl_vector_set(
x, 4, sdy);
2181 gsl_vector_set(
x, 5, sdz);
2183 gsl_multimin_function minex_func;
2185 gsl_params[
"cmp"] = (
void *) c;
2188 minex_func.params = (
void *) &gsl_params;
2189 gsl_multimin_fminimizer *s = gsl_multimin_fminimizer_alloc(T, np);
2190 gsl_multimin_fminimizer_set(s, &minex_func,
x, ss);
2192 int rval = GSL_CONTINUE;
2193 int status = GSL_SUCCESS;
2198 while (rval == GSL_CONTINUE && iter < maxiter) {
2200 status = gsl_multimin_fminimizer_iterate(s);
2204 rval = gsl_multimin_test_size(gsl_multimin_fminimizer_size(s), precision);
2209 if (maxshift <= 0) {
2210 maxshift = volume->get_xsize() / 4;
2212 float fmaxshift =
static_cast<float>(maxshift);
2215 if ( fmaxshift >= (
float)gsl_vector_get(s->x, 0) && fmaxshift >= (float)gsl_vector_get(s->x, 1) && fmaxshift >= (float)gsl_vector_get(s->x, 2))
2217 float n0 = (float)gsl_vector_get(s->x, 0);
2218 float n1 = (float)gsl_vector_get(s->x, 1);
2219 float n2 = (float)gsl_vector_get(s->x, 2);
2220 float x = (float)gsl_vector_get(s->x, 3);
2221 float y = (float)gsl_vector_get(s->x, 4);
2222 float z = (float)gsl_vector_get(s->x, 5);
2226 result = volume->process(
"xform",
Dict(
"transform",&tsoln));
2227 result->set_attr(
"xform.align3d",&tsoln);
2228 EMData *tmpsym = result->process(
"xform.applysym",
Dict(
"sym",gsl_params[
"sym"]));
2229 result->set_attr(
"score", result->cmp(cmp_name,tmpsym,cmp_params));
2232 result = volume->process(
"xform",
Dict(
"transform",t));
2233 result->set_attr(
"xform.align3d",t);
2234 result->set_attr(
"score",0.0);
2238 gsl_vector_free(ss);
2239 gsl_multimin_fminimizer_free(s);
2241 if (c != 0)
delete c;
2248 const string & cmp_name,
const Dict& cmp_params)
const
2253 if (to->get_ndim() != 3 || this_img->get_ndim() != 3)
throw ImageDimensionException(
"The Refine3D aligner only works for 3D images");
2255#ifdef EMAN2_USING_CUDA
2256 if(EMData::usecuda == 1) {
2257 if(!this_img->getcudarwdata()) this_img->copy_to_cuda();
2258 if(!to->getcudarwdata()) to->copy_to_cuda();
2268 bool mirror =
false;
2276 t =
params[
"xform.align3d"];
2285 gsl_params[
"this"] = this_img;
2286 gsl_params[
"with"] = to;
2287 gsl_params[
"snr"] =
params[
"snr"];
2288 gsl_params[
"mirror"] = mirror;
2289 gsl_params[
"transform"] = t;
2290 gsl_params[
"spincoeff"] = spincoeff;
2291 Dict altered_cmp_params(cmp_params);
2293 const gsl_multimin_fminimizer_type *T = gsl_multimin_fminimizer_nmsimplex;
2294 gsl_vector *ss = gsl_vector_alloc(np);
2304 gsl_vector_set(ss, 0, stepi);
2305 gsl_vector_set(ss, 1, stepj);
2306 gsl_vector_set(ss, 2, stepk);
2307 gsl_vector_set(ss, 3, stepx);
2308 gsl_vector_set(ss, 4, stepy);
2309 gsl_vector_set(ss, 5, stepz);
2311 gsl_vector *
x = gsl_vector_alloc(np);
2312 gsl_vector_set(
x, 0, sdi);
2313 gsl_vector_set(
x, 1, sdj);
2314 gsl_vector_set(
x, 2, sdk);
2315 gsl_vector_set(
x, 3, sdx);
2316 gsl_vector_set(
x, 4, sdy);
2317 gsl_vector_set(
x, 5, sdz);
2319 gsl_multimin_function minex_func;
2322 gsl_params[
"cmp"] = (
void *) c;
2326 minex_func.params = (
void *) &gsl_params;
2328 gsl_multimin_fminimizer *s = gsl_multimin_fminimizer_alloc(T, np);
2329 gsl_multimin_fminimizer_set(s, &minex_func,
x, ss);
2331 int rval = GSL_CONTINUE;
2332 int status = GSL_SUCCESS;
2337 while (rval == GSL_CONTINUE && iter < maxiter) {
2339 status = gsl_multimin_fminimizer_iterate(s);
2343 rval = gsl_multimin_test_size(gsl_multimin_fminimizer_size(s), precision);
2348 if (maxshift <= 0) {
2349 maxshift = this_img->get_xsize() / 4;
2351 float fmaxshift =
static_cast<float>(maxshift);
2354 if ( fmaxshift >= (
float)gsl_vector_get(s->x, 0) && fmaxshift >= (float)gsl_vector_get(s->x, 1) && fmaxshift >= (float)gsl_vector_get(s->x, 2))
2356 float n0 = (float)gsl_vector_get(s->x, 0);
2357 float n1 = (float)gsl_vector_get(s->x, 1);
2358 float n2 = (float)gsl_vector_get(s->x, 2);
2359 float x = (float)gsl_vector_get(s->x, 3);
2360 float y = (float)gsl_vector_get(s->x, 4);
2361 float z = (float)gsl_vector_get(s->x, 5);
2365 result = this_img->process(
"xform",
Dict(
"transform",&tsoln));
2366 result->set_attr(
"xform.align3d",&tsoln);
2367 result->set_attr(
"score", result->cmp(cmp_name,to,cmp_params));
2371 result = this_img->process(
"xform",
Dict(
"transform",t));
2372 result->set_attr(
"xform.align3d",t);
2373 result->set_attr(
"score",0.0);
2379 gsl_vector_free(ss);
2380 gsl_multimin_fminimizer_free(s);
2382 if (c != 0)
delete c;
2388 const string & cmp_name,
const Dict& cmp_params)
const
2390 if ( this_img->get_ndim() != 3 || to->get_ndim() != 3 ) {
2400 t =
params[
"xform.align3d"];
2410 vector<string> check;
2411 check.push_back(
"searchx");
2412 check.push_back(
"searchy");
2413 check.push_back(
"searchz");
2414 for(vector<string>::const_iterator cit = check.begin(); cit != check.end(); ++cit) {
2417 int search =
params[
"search"];
2431 bool tomography = (cmp_name ==
"ccc.tomo") ? 1 : 0;
2433 if(dotrans || tomography){
2434 tofft = to->do_fft();
2437#ifdef EMAN2_USING_CUDA
2438 if(EMData::usecuda == 1) {
2439 if(!this_img->getcudarodata()) this_img->copy_to_cudaro();
2440 if(!to->getcudarwdata()) to->copy_to_cuda();
2441 if(to->getcudarwdata()){
if(tofft) tofft->copy_to_cuda();}
2449 best[
"score"] = 1.0e37;
2450 bool use_cpu =
true;
2454 for (
float alt = 0; alt < range; alt += delta) {
2457 if(alt != 0) saz = delta/sin(alt*M_PI/180.0f);
2458 for (
float az = 0; az < 360; az += saz ){
2460 cout <<
"Trying angle alt " << alt <<
" az " << az << endl;
2463 for(
float phi = -range-az; phi < range-az; phi += delta ) {
2472 transformed = this_img->process(
"xform",
Dict(
"transform",&tr));
2476 if(dotrans || tomography){
2478#ifdef EMAN2_USING_CUDA
2479 if(EMData::usecuda == 1){
2487 float2 stats =
get_stats_cuda(ccf->getcudarwdata(), ccf->get_xsize(), ccf->get_ysize(), ccf->get_zsize());
2488 score = -(data->
peak - stats.x)/
sqrt(stats.y);
2490 score = -data->
peak;
2496 if(tomography) ccf->process_inplace(
"normalize");
2500 IntPoint point = ccf->calc_max_location_wrap(searchx,searchy,searchz);
2501 tran.
set_trans((
float)-point[0], (float)-point[1], (
float)-point[2]);
2502 score = -ccf->get_value_at_wrap(point[0], point[1], point[2]);
2507 delete transformed; transformed = 0;
2511 if(!transformed) transformed = this_img->process(
"xform",
Dict(
"transform",&tr));
2512 score = c->
cmp(to,transformed);
2513 delete transformed; transformed = 0;
2516 if(score <
float(best[
"score"])) {
2518 best[
"score"] = score;
2519 best[
"xform.align3d"] = &tr;
2525 if(tofft) {
delete tofft; tofft = 0;}
2526 if (c != 0)
delete c;
2529 EMData* best_match = this_img->process(
"xform",
Dict(
"transform", best[
"xform.align3d"]));
2530 best_match->set_attr(
"xform.align3d", best[
"xform.align3d"]);
2531 best_match->set_attr(
"score",
float(best[
"score"]));
2544 t[
"transform"] = tr;
2545 EMData* soln = this_img->process(
"xform",t);
2546 soln->set_attr(
"xform.align3d",tr);
2555 if ( this_img->get_ndim() != 3 || to->get_ndim() != 3 ) {
2565 vector<string> check;
2566 check.push_back(
"searchx");
2567 check.push_back(
"searchy");
2568 check.push_back(
"searchz");
2569 for(vector<string>::const_iterator cit = check.begin(); cit != check.end(); ++cit) {
2572 int search =
params[
"search"];
2588 initxform =
params[
"initxform"];
2605 Dict altered_cmp_params(cmp_params);
2606 if (cmp_name ==
"ccc.tomo") {
2607 altered_cmp_params.
set_default(
"searchx", searchx);
2608 altered_cmp_params.
set_default(
"searchy", searchy);
2609 altered_cmp_params.
set_default(
"searchz", searchz);
2614 if (nsoln == 0)
return solns;
2615 for (
unsigned int i = 0; i < nsoln; ++i ) {
2619 d[
"xform.align3d"] = &t;
2623 bool tomography = (cmp_name ==
"ccc.tomo") ? 1 : 0;
2625 if(dotrans || tomography){
2626 tofft = to->do_fft();
2629#ifdef EMAN2_USING_CUDA
2630 if(EMData::usecuda == 1) {
2631 if(!this_img->getcudarodata()) this_img->copy_to_cudaro();
2632 if(!to->getcudarwdata()) to->copy_to_cuda();
2633 if(to->getcudarwdata()){
if(tofft) tofft->copy_to_cuda();}
2641 bool use_cpu =
true;
2642 for (
float alt = lalt; alt <= ualt; alt += dalt) {
2645 for (
float az = laz; az < uaz; az += daz ){
2647 cout <<
"Trying angle alt " << alt <<
" az " << az << endl;
2649 for(
float phi = lphi; phi < uphi; phi += dphi ) {
2655 EMData* transformed = this_img->process(
"xform",
Dict(
"transform",&t));
2658 float best_score = 0.0f;
2659 if(dotrans || tomography){
2661#ifdef EMAN2_USING_CUDA
2662 if(EMData::usecuda == 1){
2665 trans.
set_trans((
float)-data->
px, (
float)-data->
py, (
float)-data->
pz);
2668 float2 stats =
get_stats_cuda(ccf->getcudarwdata(), ccf->get_xsize(), ccf->get_ysize(), ccf->get_zsize());
2669 best_score = -(data->
peak - stats.x)/
sqrt(stats.y);
2671 best_score = -data->
peak;
2677 if(tomography) ccf->process_inplace(
"normalize");
2678 IntPoint point = ccf->calc_max_location_wrap(searchx,searchy,searchz);
2679 trans.
set_trans((
float)-point[0], (float)-point[1], (
float)-point[2]);
2681 best_score = -ccf->get_value_at_wrap(point[0], point[1], point[2]);
2684 delete transformed; transformed = 0;
2688 if(!transformed) transformed = this_img->process(
"xform",
Dict(
"transform",&t));
2689 best_score = c->
cmp(to,transformed);
2690 delete transformed; transformed = 0;
2694 for ( vector<Dict>::iterator it = solns.begin(); it != solns.end(); ++it, ++j ) {
2695 if ( (
float)(*it)[
"score"] > best_score ) {
2696 vector<Dict>::reverse_iterator rit = solns.rbegin();
2697 copy(rit+1,solns.rend()-j,rit);
2699 d[
"score"] = best_score;
2700 d[
"xform.align3d"] = &t;
2708 if(tofft) {
delete tofft; tofft = 0;}
2709 if (c != 0)
delete c;
2723 t[
"transform"] = tr;
2724 EMData* soln = this_img->process(
"xform",t);
2725 soln->set_attr(
"xform.align2d",tr);
2734 int nsoln = nrsoln*2;
2735 if (nrsoln<8) nsoln=8;
2741 if (this_img->is_complex()) base_this=this_img->copy();
2743 base_this=this_img->do_fft();
2744 base_this->process_inplace(
"xform.phaseorigin.tocorner");
2747 if (to->is_complex()) base_to=to->copy();
2749 base_to=to->do_fft();
2750 base_to->process_inplace(
"xform.phaseorigin.tocorner");
2757 if (maxres<0.1) maxres=0.1;
2759 if (base_this->get_xsize()!=base_this->get_ysize()+2 || base_to->get_xsize()!=base_to->get_ysize()+2 )
throw InvalidCallException(
"ERROR (RT2DTreeAligner): requires cubic images with even numbered box sizes");
2761 base_this->process_inplace(
"xform.fourierorigin.tocenter");
2762 base_to->process_inplace(
"xform.fourierorigin.tocenter");
2764 float apix=(float)this_img->get_attr(
"apix_x");
2765 int ny=this_img->get_ysize();
2766 if (maxshift<0) maxshift=ny*3/8;
2767 float maxs = ny*apix/maxres;
2771 vector<float> s_score(nsoln,0.0f);
2772 vector<Transform> s_xform(nsoln);
2774 if (verbose>0) printf(
"%d solutions\n",nsoln);
2777 for (
int sexp=5; sexp<10; sexp++) {
2778 int ss=pow(2.0,sexp);
2781 rescale=(float)ny/pow(2.0,sexp-1);
2784 if (verbose>0) printf(
"\nSize %d\n",ss);
2789 EMData *small_to= base_to-> get_clip(
Region(0,(ny-ss)/2,ss+2,ss));
2790 small_this->process_inplace(
"xform.fourierorigin.tocorner");
2792 if (maxs<cut2) cut2=maxs;
2793 small_this->process_inplace(
"filter.highpass.gauss",
Dict(
"cutoff_pixels",3));
2794 small_this->process_inplace(
"filter.lowpass.gauss",
Dict(
"cutoff_pixels",cut2));
2795 small_to->process_inplace(
"xform.fourierorigin.tocorner");
2796 small_to->process_inplace(
"filter.highpass.gauss",
Dict(
"cutoff_pixels",3));
2797 small_to->process_inplace(
"filter.lowpass.gauss",
Dict(
"cutoff_pixels",cut2));
2800 float astep = 360.0/int(M_PI/atan(1.25/ss));
2803 for (
int i=0; i<nsoln; i++) {
2811 if (verbose>1) printf(
"stage 1 - ang step %1.2f, filter %1.3f\n",astep,cut2/(apix*ny));
2812 vector<Transform> transforms;
2813 for (
float a=astep/2.0; a<359.9; a+=astep) {
2814 transforms.push_back(
Transform(
Dict(
"type",
"2d",
"alpha",a,
"mirror",0)));
2815 if (flip) transforms.push_back(
Transform(
Dict(
"type",
"2d",
"alpha",a,
"mirror",1)));
2817 if (verbose>0) printf(
"%lu orientations to test\n",transforms.size());
2820 for (
unsigned int it=0; it<transforms.size(); it++) {
2824 EMData *stt=small_this->process(
"xform",
Dict(
"transform",
EMObject(&t),
"zerocorners",1));
2827 int lmaxs=maxshift/ss;
2829 float sim=ccf->get_attr(
"minimum");
2831 for (
int y=-lmaxs;
y<=lmaxs;
y++) {
2832 for (
int x=-lmaxs;
x<=lmaxs;
x++) {
2833 float v=ccf->get_value_at_wrap(
x,
y);
2850 t.
set_params(
Dict(
"tx",(
int)ml[0],
"ty",(
int)ml[1],
"tz",(
int)ml[2]));
2862 for (
int i=0; i<nsoln; i++) {
2863 if (s_score[i]==-1.0e24) { worst=i;
break; }
2864 if (s_score[i]<s_score[worst]) worst=i;
2869 if (sim>s_score[worst]) {
2877 for (
int i=0; i<nsoln; i++) {
2878 Dict aap=s_xform[i].get_params(
"2d");
2879 printf(
"%d) %d\t%1.1f\t%1.1f\t%1.2f\t%1.1f\n",i,(
int)aap[
"mirror"],(
float)aap[
"tx"],(
float)aap[
"ty"],(
float)aap[
"alpha"],s_score[i]);
2887 if (verbose>1) printf(
"stage 2 (%1.2f, %1.2f, %d) filter: %1.3f\n",astep,rescale,nsoln,cut2/(apix*ny));
2888 for (
int i=0; i<nsoln; i++) {
2890 Dict aap=s_xform[i].get_params(
"2d");
2891 aap[
"tx"]=(float)aap[
"tx"]*rescale;
2892 aap[
"ty"]=(float)aap[
"ty"]*rescale;
2893 float alpha=aap[
"alpha"];
2894 for (
float a=alpha-astep; a<=alpha+astep; a+=astep) {
2896 EMData *stt=small_this->process(
"xform",
Dict(
"transform",
EMObject(&t),
"zerocorners",1));
2904 for (
int y=-4+ty;
y<=4+ty;
y++) {
2905 for (
int x=-4+tx;
x<=4+tx;
x++) {
2906 float v=ccf->get_value_at_wrap(
x,
y);
2919 aap=s_xform[i].get_params(
"2d");
2920 printf(
"%d) %d\t%1.1f\t%1.1f\t%1.2f\t%1.1f\n",i,(
int)aap[
"mirror"],(
float)aap[
"tx"],(
float)aap[
"ty"],(
float)aap[
"alpha"],s_score[i]);
2927 for (
unsigned int i=0; i<nsoln-1; i++) {
2928 for (
unsigned int j=i+1; j<nsoln; j++) {
2929 if (s_score[i]<s_score[j]) {
2930 float t=s_score[i]; s_score[i]=s_score[j]; s_score[j]=t;
2931 Transform tt=s_xform[i]; s_xform[i]=s_xform[j]; s_xform[j]=tt;
2939 if (nsoln<nrsoln) nsoln=nrsoln;
2953 for (
unsigned int i = 0; i < nrsoln; ++i ) {
2955 d[
"score"] = -s_score[i];
2957 if (s_xform[i].get_mirror()) {
2958 Vec3f t=s_xform[i].get_trans();
2960 s_xform[i].set_trans(t);
2962 d[
"xform.align2d"] = &s_xform[i];
2966 Dict aap=s_xform[0].get_params(
"2d");
2967 printf(
"Final: %d\t%1.1f\t%1.1f\t%1.2f\n",(
int)aap[
"mirror"],(
float)aap[
"tx"],(
float)aap[
"ty"],(
float)aap[
"alpha"]);
2980 const vector< Transform > xfs=
params[
"initxform"];
2989 EMData* soln = this_img->copy();
2990 soln->set_attr(
"xform.align3d",tr);
2991 soln->set_attr(
"xform.projection",tr);
2992 soln->set_attr(
"score",alis[0][
"score"]);
2999 if (this_img->get_zsize()!=1 || to->get_zsize()==1)
throw InvalidParameterException(
"ERROR (RT2Dto3DTreeAligner): first image must be 2D and second 3D");
3005 int nsoln = nrsoln*2;
3006 if (nrsoln<16) nsoln=32;
3008 const vector< Transform > xfs=
params[
"initxform"];
3012 vector<float> s_score(nsoln,1.0e24);
3013 vector<float> s_step(nsoln*3,7.5f);
3014 vector<Transform> s_xform(nsoln);
3018 int ny=this_img->get_ysize();
3021 float apix=(float)this_img->get_attr(
"apix_x");
3025 maxrescut=int(ny*apix/maxres);
3026 maxny=maxrescut*3/2*2;
3027 if(maxny>ny) maxny=ny;
3030 printf(
"\n\n*******\nmax resolution %1.2f, box size %d\n", maxres, maxny);
3037 const vector< Transform > xfs=
params[
"initxform"];
3039 for (
unsigned int i=0; i<nsoln; i++){
3040 s_xform[i].set_params(xfs[i].
get_params(
"eman"));
3047 if ((maxang>0) && (s>maxang/2)){
3050 std::random_device rd;
3051 std::uniform_int_distribution<int> dist(0, 1);
3052 for (
int i=0; i<nsoln*3; i++) {
3053 s_step[i]=s*(dist(rd))?1.0:-1.0;
3057 if (verbose>0) printf(
"%d solutions\n",nsoln);
3062 if (this_img->is_complex()) base_to=this_img->copy();
3064 base_to=this_img->do_fft();
3065 base_to->process_inplace(
"xform.phaseorigin.tocorner");
3068 if (to->is_complex()) base_this=to->copy();
3070 base_this=to->do_fft();
3071 base_this->process_inplace(
"xform.phaseorigin.tocorner");
3076 if (base_this->get_xsize()!=base_this->get_ysize()+2 || base_this->get_ysize()!=base_this->get_zsize()
3077 || base_to->get_xsize()!=base_to->get_ysize()+2 )
throw InvalidCallException(
"ERROR (RT3DTreeAligner): requires cubic images with even numbered box sizes");
3079 base_this->process_inplace(
"xform.fourierorigin.tocenter");
3080 base_to->process_inplace(
"xform.fourierorigin.tocenter");
3085 string axname[] = {
"az",
"alt",
"phi"};
3089 for (
int sexp=sexp_start; sexp<10; sexp++) {
3091 int ss=pow(2.0,sexp);
3094 if (ss>maxny) ss=maxny;
3096 int maxshift=maxshift00*ss/ny;
3097 if (maxshift00<0) maxshift=-1;
3098 if (verbose>0) printf(
"\nSize %d, maxshift %d\n",ss, maxshift);
3101 EMData *small_to= base_to-> get_clip(
Region(0,(ny-ss)/2,0,ss+2,ss,1));
3102 small_this->process_inplace(
"xform.fourierorigin.tocorner");
3103 small_this->process_inplace(
"filter.highpass.gauss",
Dict(
"cutoff_pixels",4));
3105 small_to->process_inplace(
"xform.fourierorigin.tocorner");
3106 small_to->process_inplace(
"filter.highpass.gauss",
Dict(
"cutoff_pixels",4));
3109 small_to->process_inplace(
"filter.lowpass.gauss",
Dict(
"cutoff_abs",0.375f));
3110 small_this->process_inplace(
"filter.lowpass.gauss",
Dict(
"cutoff_abs",0.375f));
3113 small_this->process_inplace(
"xform.fourierorigin.tocenter");
3118 float astep = 89.999/floor(pi/(1.5*2.0*atan(2.0/ss)));
3119 if ((maxang>0) && (astep>maxang/2)){
3128 for (
int i=0; i<nsoln; i++) {
3130 if (fabs(s_step[i*3+0])<astep/4.0) s_step[i*3+0]*=2.0;
3131 if (fabs(s_step[i*3+1])<astep/4.0) s_step[i*3+1]*=2.0;
3132 if (fabs(s_step[i*3+2])<astep/4.0) s_step[i*3+2]*=2.0;
3138 if (verbose>1) printf(
"stage 1 - ang step %1.2f\n",astep);
3140 d[
"inc_mirror"] = 1;
3145 if (verbose>0) printf(
"%d orientations to test (%lu)\n",(
int)(transforms.size()*(360.0/astep)),transforms.size());
3147 for (
unsigned int it=0; it<transforms.size(); it++) {
3149 printf(
" %d/%lu \r",it,transforms.size());
3152 for (
float phi=0; phi<360.0; phi+=astep) {
3164 EMData *stt=small_this->project(
"gauss_fft",
Dict(
"transform",
EMObject(&t),
"returnfft", 1));
3168 IntPoint ml=ccf->calc_max_location_wrap(maxshift,maxshift,0);
3170 aap[
"tx"]=(int)ml[0];
3171 aap[
"ty"]=(int)ml[1];
3177 stt=small_this->project(
"gauss_fft",
Dict(
"transform",
EMObject(&t),
"returnfft", 1));
3183 float sim=stt->cmp(
"frc",small_to);
3190 float worstv=1.0e20;
3191 for (
int i=0; i<nsoln; i++) {
3192 if (s_score[i]>1.0e20)
continue;
3206 for (
int i=0; i<nsoln; i++) {
3207 if (s_score[i]>1.0e20) { worst=i;
break; }
3208 if (s_score[i]<worstv) {worst=i; worstv=s_score[i];}
3215 if (sim<s_score[worst]) {
3223 if (verbose>2) printf(
"\n");
3230 if (verbose>1) printf(
"stage 2 (%1.2f)\n",astep);
3231 for (
int i=0; i<nsoln; i++) {
3234 printf(
" %d\t%d\r",i,nsoln);
3240 int r=
testort(small_this,small_to,s_score,s_xform,i,upd0,initxf,maxshift, maxang);
3243 for (
int axis=0; axis<3; axis++) {
3244 if (fabs(s_step[i*3+axis])<astep/4.0)
continue;
3246 upd[axname[axis]]=s_step[i*3+axis];
3249 if (axis==0) upd[axname[2]]=-s_step[i*3+axis];
3251 int r=
testort(small_this,small_to,s_score,s_xform,i,upd,initxf,maxshift, maxang);
3257 s_step[i*3+axis]*=-0.75;
3258 upd[axname[axis]]=s_step[i*3+axis];
3259 r=
testort(small_this,small_to,s_score,s_xform,i,upd,initxf,maxshift, maxang);
3262 if (verbose>4) printf(
"\nX %1.3f\t%1.3f\t%1.3f\t%d\t",s_step[i*3],s_step[i*3+1],s_step[i*3+2],changed);
3265 Dict aap=s_xform[i].get_params(
"eman");
3266 printf(
"\n%1.3f\t%1.3f\t%1.3f\t%1.3f\t%1.3f\t%1.3f\t(%1.3f)",s_step[i*3],s_step[i*3+1],s_step[i*3+2],
float(aap[
"az"]),
float(aap[
"alt"]),
float(aap[
"phi"]),s_score[i]);
3273 if (fabs(s_step[i*3])<astep/4 && fabs(s_step[i*3+1])<astep/4 && fabs(s_step[i*3+2])<astep/4) changed=0;
3293 for (
unsigned int i=0; i<nsoln-1; i++) {
3294 for (
unsigned int j=i+1; j<nsoln; j++) {
3295 if (s_score[i]>s_score[j]) {
3296 float t=s_score[i]; s_score[i]=s_score[j]; s_score[j]=t;
3297 Transform tt=s_xform[i]; s_xform[i]=s_xform[j]; s_xform[j]=tt;
3301 for (
unsigned int i=0; i<nsoln-1; i++) {
3310 if (nsoln<nrsoln) nsoln=nrsoln;
3315 if (ss>=maxny && curiter>0)
break;
3324 for (
unsigned int i = 0; i < nrsoln; ++i ) {
3326 d[
"score"] = s_score[i];
3329 d[
"xform.align3d"] = &s_xform[i];
3330 d[
"xform.projection"] = &s_xform[i];
3341 Dict aap=s_xform[i].get_params(
"eman");
3343 int ny=small_this->get_ysize();
3346 const vector< Transform > xfs=
params[
"initxform"];
3347 Dict xf0=xfs[i].get_params(
"eman");
3348 aap[
"tx"]=(float)xf0[
"tx"]*ny/(
float)
params[
"boxsize"];
3349 aap[
"ty"]=(float)xf0[
"ty"]*ny/(
float)
params[
"boxsize"];
3358 aap[p->first]=(float)aap[p->first]+(
float)p->second;
3374 EMData *stt=small_this->project(
"gauss_fft",
Dict(
"transform",
EMObject(&t),
"returnfft", 1));
3378 IntPoint ml=ccf->calc_max_location_wrap(maxshift,maxshift,0);
3379 aap[
"tx"]=(int)aap[
"tx"]+(
int)ml[0];
3380 aap[
"ty"]=(int)aap[
"ty"]+(
int)ml[1];
3387 sim=stt->cmp(
"frc",small_to,
Dict(
"pmin",(
float)ny*0.125f,
"pmax", (float)ny*0.33f));
3393 if (sim<s_score[i]) {
3410 t[
"transform"] = tr;
3411 EMData* soln = this_img->process(
"xform",t);
3412 soln->set_attr(
"xform.align3d",tr);
3413 soln->set_attr(
"score",alis[0][
"score"]);
3414 soln->set_attr(
"coverage",alis[0][
"coverage"]);
3426 int nsoln = nrsoln*2;
3427 if (nrsoln<32) nsoln=64;
3440 if (this_img->is_complex()) {
3441 EMData *tmp = this_img->do_ift();
3442 tmp->process_inplace(
"xform.phaseorigin.tocenter");
3443 tmp->process_inplace(
"normalize.mask",
Dict(
"mask",mask,
"apply_mask",1));
3444 base_to=tmp->do_fft();
3445 base_to->process_inplace(
"xform.phaseorigin.tocorner");
3449 EMData *tmp = this_img->process(
"normalize.mask",
Dict(
"mask",mask,
"apply_mask",1));
3450 base_to=tmp->do_fft();
3451 base_to->process_inplace(
"xform.phaseorigin.tocorner");
3455 if (to->is_complex()) {
3456 base_this=to->copy();
3459 base_this=to->do_fft();
3460 base_this->process_inplace(
"xform.phaseorigin.tocorner");
3464 if (this_img->is_complex()) base_to=this_img->copy();
3466 base_to=this_img->do_fft();
3467 base_to->process_inplace(
"xform.phaseorigin.tocorner");
3470 if (to->is_complex()) base_this=to->copy();
3472 base_this=to->do_fft();
3473 base_this->process_inplace(
"xform.phaseorigin.tocorner");
3478 if (base_this->get_xsize()!=base_this->get_ysize()+2 || base_this->get_ysize()!=base_this->get_zsize()
3479 || base_to->get_xsize()!=base_to->get_ysize()+2 || base_to->get_ysize()!=base_to->get_zsize())
throw InvalidCallException(
"ERROR (RT3DTreeAligner): requires cubic images with even numbered box sizes");
3485 base_this->process_inplace(
"xform.fourierorigin.tocenter");
3486 base_to->process_inplace(
"xform.fourierorigin.tocenter");
3488 float apix=(float)this_img->get_attr(
"apix_x");
3489 int ny=this_img->get_ysize();
3494 maxny=4*int(ny*apix/maxres/2+1);
3496 printf(
"\n\n*******\nmax resolution %1.2f, box size %d\n", maxres, maxny);
3503 vector<float> s_score(nsoln,0.0f);
3504 vector<float> s_coverage(nsoln,0.0f);
3505 vector<float> s_step(nsoln*3,7.5f);
3506 vector<Transform> s_xform(nsoln);
3507 if (verbose>0) printf(
"%d solutions\n",nsoln);
3513 const vector< Transform > xfs=
params[
"initxform"];
3516 for (
unsigned int i=0; i<nsoln; i++){
3517 s_xform[i].set_params(xfs[i].
get_params(
"eman"));
3535 string axname[] = {
"az",
"alt",
"phi"};
3538 for (
int sexp=sexp_start; sexp<10; sexp++) {
3541 int ss=pow(2.0,sexp);
3542 if (ss>maxny) ss=maxny;
3544 else if (ss<48) ss=48;
3545 if (verbose>0) printf(
"\nSize %d\n",ss);
3547 int maxshift=maxshift00*ss/ny;
3548 if (maxshift00<0) maxshift=-1;
3552 EMData *small_to= base_to-> get_clip(
Region(0,(ny-ss)/2,(ny-ss)/2,ss+2,ss,ss));
3553 small_this->process_inplace(
"xform.fourierorigin.tocorner");
3554 small_this->process_inplace(
"filter.highpass.gauss",
Dict(
"cutoff_pixels",4));
3555 small_to->process_inplace(
"xform.fourierorigin.tocorner");
3556 small_to->process_inplace(
"filter.highpass.gauss",
Dict(
"cutoff_pixels",4));
3560 small_this->process_inplace(
"filter.lowpass.gauss",
Dict(
"cutoff_abs",0.33f));
3561 small_to->process_inplace(
"filter.lowpass.gauss",
Dict(
"cutoff_abs",0.33f));
3567 for (
int i=0; i<ss/2; i++) {
3568 sigmathisv[i]*=sigmathisv[i]*sigmathis;
3569 sigmatov[i]*=sigmatov[i]*sigmato;
3575 float astep = 89.999/floor(pi/(1.5*2.0*atan(2.0/ss)));
3582 for (
int i=0; i<s_score.size(); i++) {
3584 if (fabs(s_step[i*3+0])<astep/4.0) s_step[i*3+0]*=2.0;
3585 if (fabs(s_step[i*3+1])<astep/4.0) s_step[i*3+1]*=2.0;
3586 if (fabs(s_step[i*3+2])<astep/4.0) s_step[i*3+2]*=2.0;
3592 if (verbose>1) printf(
"stage 1 - ang step %1.2f\n",astep);
3594 d[
"inc_mirror"] =
true;
3599 if (verbose>0) printf(
"%d orientations to test (%lu)\n",(
int)(transforms.size()*(360.0/astep)),transforms.size());
3600 if (transforms.size()<30)
continue;
3604 for (
unsigned int it=0; it<transforms.size(); it++) {
3607 printf(
" %d/%lu \r",it,transforms.size());
3610 for (
float phi=0; phi<360.0; phi+=astep) {
3622 EMData *stt=small_this->process(
"xform",
Dict(
"transform",
EMObject(&t),
"zerocorners",1));
3624 IntPoint ml=ccf->calc_max_location_wrap();
3626 aap[
"tx"]=(int)ml[0];
3627 aap[
"ty"]=(int)ml[1];
3628 aap[
"tz"]=(int)ml[2];
3632 stt=small_this->process(
"xform",
Dict(
"transform",
EMObject(&t),
"zerocorners",1));
3635 float sim=stt->cmp(
"ccc.tomo.thresh",small_to);
3643 float worstv=1.0e20;
3644 for (
int i=0; i<nsoln; i++) {
3645 if (s_coverage[i]==0.0)
continue;
3649 if (adif<astep*2.5) {
3659 for (
int i=0; i<nsoln; i++) {
3660 if (s_coverage[i]==0.0) { worst=i;
break; }
3661 if (s_score[i]<worstv) {worst=i; worstv=s_score[i];}
3667 if (sim<s_score[worst]) {
3669 s_coverage[worst]=stt->get_attr(
"fft_overlap");
3676 if (verbose>2) printf(
"\n");
3686 float res=float(ny)/float(ss)*apix*2;
3687 if (verbose>1) printf(
"stage 2 - maxres %1.2f, astep %1.2f\n",res, astep);
3690 s_xform[nsoln]=initxf;
3694 for (
int i=0; i<nsoln; i++) {
3697 printf(
" %d\t%d\r",i,nsoln);
3703 testort(small_this,small_to,sigmathisv,sigmatov,s_score,s_coverage,s_xform,i,upd, initxf, maxshift,mask);
3706 for (
int axis=0; axis<3; axis++) {
3707 if (fabs(s_step[i*3+axis])<astep/4.0)
continue;
3708 upd[axname[axis]]=s_step[i*3+axis];
3711 if (axis==0) upd[axname[2]]=-s_step[i*3+axis];
3713 int r=
testort(small_this,small_to,sigmathisv,sigmatov,s_score,s_coverage,s_xform,i,upd, initxf, maxshift,mask);
3719 s_step[i*3+axis]*=-0.75;
3720 upd[axname[axis]]=s_step[i*3+axis];
3721 r=
testort(small_this,small_to,sigmathisv,sigmatov,s_score,s_coverage,s_xform,i,upd, initxf, maxshift,mask);
3724 if (verbose>4) printf(
"\nX %1.3f\t%1.3f\t%1.3f\t%d\t",s_step[i*3],s_step[i*3+1],s_step[i*3+2],changed);
3727 Dict aap=s_xform[i].get_params(
"eman");
3728 printf(
"\n%1.3f\t%1.3f\t%1.3f\t%1.3f\t%1.3f\t%1.3f\t(%1.3f)",s_step[i*3],s_step[i*3+1],s_step[i*3+2],
float(aap[
"az"]),
float(aap[
"alt"]),
float(aap[
"phi"]),s_score[i]);
3735 if (fabs(s_step[i*3])<astep/4 && fabs(s_step[i*3+1])<astep/4 && fabs(s_step[i*3+2])<astep/4) changed=0;
3755 for (
unsigned int i=0; i<nsoln-1; i++) {
3756 for (
unsigned int j=i+1; j<nsoln; j++) {
3757 if (s_score[i]>s_score[j]) {
3758 float t=s_score[i]; s_score[i]=s_score[j]; s_score[j]=t;
3759 t=s_coverage[i]; s_coverage[i]=s_coverage[j]; s_coverage[j]=t;
3760 Transform tt=s_xform[i]; s_xform[i]=s_xform[j]; s_xform[j]=tt;
3768 if (nsoln<nrsoln) nsoln=nrsoln;
3775 if (ss>=maxny && curiter>0)
break;
3783 for (
unsigned int i = 0; i < nrsoln; ++i ) {
3795 for (
unsigned int i = 0; i < nrsoln; ++i ) {
3797 d[
"score"] = s_score[i];
3798 d[
"coverage"] = s_coverage[i];
3799 s_xform[i].invert();
3800 d[
"xform.align3d"] = &s_xform[i];
3809bool RT3DTreeAligner::testort(
EMData *small_this,
EMData *small_to,vector<float> &sigmathisv,vector<float> &sigmatov,vector<float> &s_score, vector<float> &s_coverage,vector<Transform> &s_xform,
int i,
Dict &upd,
Transform initxf,
int maxshift,
EMData* mask)
const {
3811 Dict aap=s_xform[i].get_params(
"eman");
3816 aap[p->first]=(float)aap[p->first]+(
float)p->second;
3831 td[
"phi"]=ti[
"phi"];
3845 int ny=small_this->get_ysize();
3853 EMData *stt=small_this->process(
"xform",
Dict(
"transform",
EMObject(&t),
"zerocorners",1));
3856 IntPoint ml=ccf->calc_max_location_wrap(maxshift, maxshift, maxshift);
3859 aap[
"tx"]=int(aap[
"tx"])+(int)ml[0];
3860 aap[
"ty"]=int(aap[
"ty"])+(int)ml[1];
3861 aap[
"tz"]=int(aap[
"tz"])+(int)ml[2];
3863 EMData *st2=small_this->process(
"xform",
Dict(
"transform",
EMObject(&t),
"zerocorners",1));
3868 float sim=st2->cmp(
"fsc.tomo.auto",small_to,
Dict(
"sigmaimg",sigmathisv,
"sigmawith",sigmatov,
"pmin", 4,
"pmax",ny/3));
3875 if (sim<s_score[i]) {
3877 s_coverage[i]=st2->get_attr(
"fft_overlap");
3895 t[
"transform"] = tr;
3896 EMData* soln = this_img->process(
"xform",t);
3897 soln->set_attr(
"xform.align3d",tr);
3898 soln->set_attr(
"score",alis[0][
"score"]);
3899 soln->set_attr(
"coverage",alis[0][
"coverage"]);
3911 int nsoln = nrsoln*2;
3912 if (nrsoln<32) nsoln=64;
3921 if (this_img->is_complex()) {
3922 base_to=this_img->copy();
3923 EMData *tmp = base_to->do_ift();
3924 tmp->process_inplace(
"threshold.notzero");
3925 base_mask=tmp->do_fft();
3929 base_to=this_img->do_fft();
3930 base_to->process_inplace(
"xform.phaseorigin.tocorner");
3931 EMData *tmp = this_img->process(
"threshold.notzero");
3932 base_mask=tmp->do_fft();
3936 if (to->is_complex()) {
3937 base_this=to->copy();
3938 EMData *tmp = base_this->do_ift();
3939 tmp->process_inplace(
"math.squared");
3940 base_thissq = tmp->do_fft();
3944 base_this=to->do_fft();
3945 base_this->process_inplace(
"xform.phaseorigin.tocorner");
3946 EMData *tmp = base_this->process(
"math.squared");
3947 base_thissq = tmp->do_fft();
3956 if (base_this->get_xsize()!=base_this->get_ysize()+2 || base_this->get_ysize()!=base_this->get_zsize()
3957 || base_to->get_xsize()!=base_to->get_ysize()+2 || base_to->get_ysize()!=base_to->get_zsize())
throw InvalidCallException(
"ERROR (RT3DTreeAligner): requires cubic images with even numbered box sizes");
3963 base_this->process_inplace(
"xform.fourierorigin.tocenter");
3964 base_to->process_inplace(
"xform.fourierorigin.tocenter");
3965 base_thissq->process_inplace(
"xform.fourierorigin.tocenter");
3966 base_mask->process_inplace(
"xform.fourierorigin.tocenter");
3968 float apix=(float)this_img->get_attr(
"apix_x");
3969 int ny=this_img->get_ysize();
3975 maxny=4*int(ny*apix/maxres/2+1);
3977 printf(
"\n\n*******\nmax resolution %1.2f, box size %d\n", maxres, maxny);
3984 vector<float> s_score(nsoln,0.0f);
3985 vector<float> s_coverage(nsoln,0.0f);
3986 vector<float> s_step(nsoln*3,7.5f);
3987 vector<Transform> s_xform(nsoln);
3988 if (verbose>0) printf(
"%d solutions\n",nsoln);
3994 const vector< Transform > xfs=
params[
"initxform"];
3997 for (
unsigned int i=0; i<nsoln; i++){
3998 s_xform[i].set_params(xfs[i].
get_params(
"eman"));
4009 string axname[] = {
"az",
"alt",
"phi"};
4012 for (
int sexp=sexp_start; sexp<10; sexp++) {
4015 int ss=pow(2.0,sexp);
4016 if (ss>maxny) ss=maxny;
4018 else if (ss<48) ss=48;
4019 if (verbose>0) printf(
"\nSize %d\n",ss);
4021 int maxshift=maxshift00*ss/ny;
4022 if (maxshift00<0) maxshift=-1;
4026 EMData *small_to= base_to-> get_clip(
Region(0,(ny-ss)/2,(ny-ss)/2,ss+2,ss,ss));
4028 EMData *small_mask= base_mask-> get_clip(
Region(0,(ny-ss)/2,(ny-ss)/2,ss+2,ss,ss));
4029 small_this->process_inplace(
"xform.fourierorigin.tocorner");
4030 small_this->process_inplace(
"filter.highpass.gauss",
Dict(
"cutoff_pixels",4));
4031 small_to->process_inplace(
"xform.fourierorigin.tocorner");
4032 small_to->process_inplace(
"filter.highpass.gauss",
Dict(
"cutoff_pixels",4));
4033 small_mask->process_inplace(
"xform.fourierorigin.tocorner");
4034 small_mask->process_inplace(
"filter.highpass.gauss",
Dict(
"cutoff_pixels",4));
4035 small_thissq->process_inplace(
"xform.fourierorigin.tocorner");
4036 small_thissq->process_inplace(
"filter.highpass.gauss",
Dict(
"cutoff_pixels",4));
4040 small_this->process_inplace(
"filter.lowpass.gauss",
Dict(
"cutoff_abs",0.33f));
4041 small_to->process_inplace(
"filter.lowpass.gauss",
Dict(
"cutoff_abs",0.33f));
4047 for (
int i=0; i<ss/2; i++) {
4048 sigmathisv[i]*=sigmathisv[i]*sigmathis;
4049 sigmatov[i]*=sigmatov[i]*sigmato;
4055 float astep = 89.999/floor(pi/(1.5*2.0*atan(2.0/ss)));
4062 for (
int i=0; i<s_score.size(); i++) {
4064 if (fabs(s_step[i*3+0])<astep/4.0) s_step[i*3+0]*=2.0;
4065 if (fabs(s_step[i*3+1])<astep/4.0) s_step[i*3+1]*=2.0;
4066 if (fabs(s_step[i*3+2])<astep/4.0) s_step[i*3+2]*=2.0;
4072 if (verbose>1) printf(
"stage 1 - ang step %1.2f\n",astep);
4074 d[
"inc_mirror"] =
true;
4079 if (verbose>0) printf(
"%d orientations to test (%lu)\n",(
int)(transforms.size()*(360.0/astep)),transforms.size());
4080 if (transforms.size()<30)
continue;
4084 for (
unsigned int it=0; it<transforms.size(); it++) {
4087 printf(
" %d/%lu \r",it,transforms.size());
4090 for (
float phi=0; phi<360.0; phi+=astep) {
4102 EMData *stt=small_this->process(
"xform",
Dict(
"transform",
EMObject(&t),
"zerocorners",1));
4103 EMData *sttsq=small_thissq->process(
"xform",
Dict(
"transform",
EMObject(&t),
"zerocorners",1));
4106 IntPoint ml=ccf->calc_max_location_wrap();
4108 aap[
"tx"]=(int)ml[0];
4109 aap[
"ty"]=(int)ml[1];
4110 aap[
"tz"]=(int)ml[2];
4115 stt=small_this->process(
"xform",
Dict(
"transform",
EMObject(&t),
"zerocorners",1));
4118 float sim=stt->cmp(
"ccc.tomo.thresh",small_to);
4126 float worstv=1.0e20;
4127 for (
int i=0; i<nsoln; i++) {
4128 if (s_coverage[i]==0.0)
continue;
4132 if (adif<astep*2.5) {
4142 for (
int i=0; i<nsoln; i++) {
4143 if (s_coverage[i]==0.0) { worst=i;
break; }
4144 if (s_score[i]<worstv) {worst=i; worstv=s_score[i];}
4150 if (sim<s_score[worst]) {
4152 s_coverage[worst]=stt->get_attr(
"fft_overlap");
4159 if (verbose>2) printf(
"\n");
4169 float res=float(ny)/float(ss)*apix*2;
4170 if (verbose>1) printf(
"stage 2 - maxres %1.2f, astep %1.2f\n",res, astep);
4173 s_xform[nsoln]=initxf;
4177 for (
int i=0; i<nsoln; i++) {
4180 printf(
" %d\t%d\r",i,nsoln);
4186 testort(small_this,small_to,small_mask,small_thissq,sigmathisv,sigmatov,s_score,s_coverage,s_xform,i,upd, initxf, maxshift);
4189 for (
int axis=0; axis<3; axis++) {
4190 if (fabs(s_step[i*3+axis])<astep/4.0)
continue;
4191 upd[axname[axis]]=s_step[i*3+axis];
4194 if (axis==0) upd[axname[2]]=-s_step[i*3+axis];
4196 int r=
testort(small_this,small_to,small_mask,small_thissq,sigmathisv,sigmatov,s_score,s_coverage,s_xform,i,upd, initxf, maxshift);
4202 s_step[i*3+axis]*=-0.75;
4203 upd[axname[axis]]=s_step[i*3+axis];
4204 r=
testort(small_this,small_to,small_mask,small_thissq,sigmathisv,sigmatov,s_score,s_coverage,s_xform,i,upd, initxf, maxshift);
4207 if (verbose>4) printf(
"\nX %1.3f\t%1.3f\t%1.3f\t%d\t",s_step[i*3],s_step[i*3+1],s_step[i*3+2],changed);
4210 Dict aap=s_xform[i].get_params(
"eman");
4211 printf(
"\n%1.3f\t%1.3f\t%1.3f\t%1.3f\t%1.3f\t%1.3f\t(%1.3f)",s_step[i*3],s_step[i*3+1],s_step[i*3+2],
float(aap[
"az"]),
float(aap[
"alt"]),
float(aap[
"phi"]),s_score[i]);
4218 if (fabs(s_step[i*3])<astep/4 && fabs(s_step[i*3+1])<astep/4 && fabs(s_step[i*3+2])<astep/4) changed=0;
4238 for (
unsigned int i=0; i<nsoln-1; i++) {
4239 for (
unsigned int j=i+1; j<nsoln; j++) {
4240 if (s_score[i]>s_score[j]) {
4241 float t=s_score[i]; s_score[i]=s_score[j]; s_score[j]=t;
4242 t=s_coverage[i]; s_coverage[i]=s_coverage[j]; s_coverage[j]=t;
4243 Transform tt=s_xform[i]; s_xform[i]=s_xform[j]; s_xform[j]=tt;
4251 if (nsoln<nrsoln) nsoln=nrsoln;
4256 delete small_thissq;
4260 if (ss>=maxny && curiter>0)
break;
4270 for (
unsigned int i = 0; i < nrsoln; ++i ) {
4282 for (
unsigned int i = 0; i < nrsoln; ++i ) {
4284 d[
"score"] = s_score[i];
4285 d[
"coverage"] = s_coverage[i];
4286 s_xform[i].invert();
4287 d[
"xform.align3d"] = &s_xform[i];
4296bool RT3DLocalTreeAligner::testort(
EMData *small_this,
EMData *small_to,
EMData *small_mask,
EMData *small_thissq,vector<float> &sigmathisv,vector<float> &sigmatov,vector<float> &s_score, vector<float> &s_coverage,vector<Transform> &s_xform,
int i,
Dict &upd,
Transform initxf,
int maxshift)
const {
4298 Dict aap=s_xform[i].get_params(
"eman");
4303 aap[p->first]=(float)aap[p->first]+(
float)p->second;
4318 td[
"phi"]=ti[
"phi"];
4332 int ny=small_this->get_ysize();
4340 EMData *stt=small_this->process(
"xform",
Dict(
"transform",
EMObject(&t),
"zerocorners",1));
4341 EMData *sttsq=small_thissq->process(
"xform",
Dict(
"transform",
EMObject(&t),
"zerocorners",1));
4344 IntPoint ml=ccf->calc_max_location_wrap(maxshift, maxshift, maxshift);
4347 aap[
"tx"]=int(aap[
"tx"])+(int)ml[0];
4348 aap[
"ty"]=int(aap[
"ty"])+(int)ml[1];
4349 aap[
"tz"]=int(aap[
"tz"])+(int)ml[2];
4351 EMData *st2=small_this->process(
"xform",
Dict(
"transform",
EMObject(&t),
"zerocorners",1));
4356 float sim=st2->cmp(
"fsc.tomo.auto",small_to,
Dict(
"sigmaimg",sigmathisv,
"sigmawith",sigmatov,
"pmin", 4,
"pmax",ny/3));
4363 if (sim<s_score[i]) {
4365 s_coverage[i]=st2->get_attr(
"fft_overlap");
4385 t[
"transform"] = tr;
4386 EMData* soln = this_img->process(
"xform",t);
4387 soln->set_attr(
"xform.align3d",tr);
4396 if ( this_img->get_ndim() != 3 || to->get_ndim() != 3 ) {
4406 vector<string> check;
4407 check.push_back(
"searchx");
4408 check.push_back(
"searchy");
4409 check.push_back(
"searchz");
4410 for(vector<string>::const_iterator cit = check.begin(); cit != check.end(); ++cit) {
4413 int search =
params[
"search"];
4429 initxform =
params[
"initxform"];
4442 Dict altered_cmp_params(cmp_params);
4443 if (cmp_name ==
"ccc.tomo") {
4444 altered_cmp_params.
set_default(
"searchx", searchx);
4445 altered_cmp_params.
set_default(
"searchy", searchy);
4446 altered_cmp_params.
set_default(
"searchz", searchz);
4451 if (nsoln == 0)
return solns;
4452 for (
unsigned int i = 0; i < nsoln; ++i ) {
4456 d[
"xform.align3d"] = &t;
4461 d[
"inc_mirror"] =
true;
4475 bool tomography = (cmp_name ==
"ccc.tomo") ? 1 : 0;
4478 EMData * this_imgfft = 0;
4479 if(dotrans || tomography){
4480 this_imgfft = this_img->do_fft();
4483#ifdef EMAN2_USING_CUDA
4484 if(EMData::usecuda == 1) {
4485 cout <<
"Using CUDA for 3D alignment" << endl;
4486 if(!to->getcudarodata()) to->copy_to_cudaro();
4487 if(!this_img->getcudarwdata()) this_img->copy_to_cuda();
4488 if(this_imgfft) this_imgfft->copy_to_cuda();
4495 bool use_cpu =
true;
4496 for(vector<Transform>::const_iterator trans_it = transforms.begin(); trans_it != transforms.end(); trans_it++) {
4500 float alt =
params[
"alt"];
4502 cout <<
"Trying angle alt: " << alt <<
" az: " << az << endl;
4505 for(
float phi = lphi; phi < uphi; phi += dphi ) {
4511 transformed = to->process(
"xform",
Dict(
"transform",&t));
4514 float best_score = 0.0f;
4516 if(dotrans || tomography){
4518#ifdef EMAN2_USING_CUDA
4519 if(EMData::usecuda == 1){
4523 trans.
set_trans((
float)-data->
px, (
float)-data->
py, (
float)-data->
pz);
4526 float2 stats =
get_stats_cuda(ccf->getcudarwdata(), ccf->get_xsize(), ccf->get_ysize(), ccf->get_zsize());
4527 best_score = -(data->
peak - stats.x)/
sqrt(stats.y);
4529 best_score = -data->
peak;
4536 if(tomography) ccf->process_inplace(
"normalize");
4537 IntPoint point = ccf->calc_max_location_wrap(searchx,searchy,searchz);
4538 trans.
set_trans((
float)-point[0], (float)-point[1], (
float)-point[2]);
4540 best_score = -ccf->get_value_at_wrap(point[0], point[1], point[2]);
4543 delete transformed; transformed = 0;
4547 if(!transformed) transformed = to->process(
"xform",
Dict(
"transform",&t));
4548 best_score = c->
cmp(this_img,transformed);
4549 delete transformed; transformed = 0;
4554 for ( vector<Dict>::iterator it = solns.begin(); it != solns.end(); ++it, ++j ) {
4555 if ( (
float)(*it)[
"score"] > best_score ) {
4556 vector<Dict>::reverse_iterator rit = solns.rbegin();
4557 copy(rit+1,solns.rend()-j,rit);
4559 d[
"score"] = best_score;
4561 d[
"xform.align3d"] = &t;
4569 if(this_imgfft) {
delete this_imgfft; this_imgfft = 0;}
4570 if(sym!=0)
delete sym;
4571 if (c != 0)
delete c;
4584 EMData* soln = this_img->process(
"xform",
Dict(
"transform",tr));
4585 soln->set_attr(
"xform.align3d",tr);
4598 ixform =
params[
"transform"];
4605 if (nsoln == 0)
return solns;
4606 for (
unsigned int i = 0; i < nsoln; ++i ) {
4610 d[
"xform.align3d"] = &t;
4614 #ifdef EMAN2_USING_CUDA
4615 if(EMData::usecuda == 1) {
4616 cout <<
"Using CUDA for 3D sym alignment" << endl;
4617 if(!this_img->getcudarwdata()) this_img->copy_to_cudaro();
4618 if(!to->getcudarwdata()) to->copy_to_cuda();
4627 for ( vector<Transform>::const_iterator symit = syms.begin(); symit != syms.end(); ++symit ) {
4630 EMData* transformed = this_img->process(
"xform",
Dict(
"transform", &sympos));
4631 score = c->
cmp(transformed,to);
4632 delete transformed; transformed = 0;
4636 cout <<
"Score is: " << score <<
" az " << float(rots[
"az"]) <<
" alt " << float(rots[
"alt"]) <<
" phi " << float(rots[
"phi"]) << endl;
4640 for ( vector<Dict>::iterator it = solns.begin(); it != solns.end(); ++it, ++j ) {
4641 if ( (
float)(*it)[
"score"] > score ) {
4642 vector<Dict>::reverse_iterator rit = solns.rbegin();
4643 copy(rit+1,solns.rend()-j,rit);
4646 d[
"xform.align3d"] = &sympos;
4652 if (c != 0)
delete c;
4658float frm_2d_Align(
EMData *this_img,
EMData *to,
float *frm2dhhat,
EMData* selfpcsfft,
int p_max_input,
int rsize,
float &com_this_x,
float &com_this_y,
float &com_with_x,
float &com_with_y,
const string & cmp_name,
const Dict& cmp_params)
4663 int MAXR=this_img->get_ysize()/2;
4665 unsigned long tsize=2*size;
4666 unsigned long ind1=0, ind2=0, ind3=0, ind4=0, ind41=0;
4667 unsigned long index0=0;
4668 int i=0, j=0, m=0, n=0, r=0;
4669 int loop_rho=0, rho_best=0;
4671 float* gnr2 =
new float[size*2];
4672 float* maxcor =
new float[size+1];
4674 int p_max=p_max_input;
4675 float* result =
new float[5*(p_max+1)];
4676 float* cr=
new float[size*(bw+1)];
4677 float* ci=
new float[size*(bw+1)];
4679 data_in->set_complex(
true);
4680 data_in->set_fftodd(
false);
4681 data_in->set_ri(
true);
4682 data_in->set_size(size+2,size,1);
4683 float *in=data_in->get_data();
4685 float *self_sampl_fft = selfpcsfft->get_data();
4687 float maxcor_sofar=0.0f;
4690 for(p=0; p<=p_max; ++p){
4692 for (i=0;i<size;++i)
4693 for (j=0;j<bw+1;++j){
4700 for(r=0;r<=MAXR;++r) {
4701 ind3=(ind2+r*bw)*size;
4702 for(m=0;m<size;m++){
4705 gnr2[2*m]=frm2dhhat[ind4];
4706 gnr2[2*m+1]=frm2dhhat[ind41];
4709 float tempr=self_sampl_fft[2*m+r*(size+2)]*r;
4710 float tempi=self_sampl_fft[2*m+1+r*(size+2)]*r;
4711 float gnr2_r=gnr2[2*m];
4712 float gnr2_i=gnr2[2*m+1];
4713 cr[n*(bw+1)+m]+=gnr2_r*tempr+gnr2_i*tempi;
4714 ci[n*(bw+1)+m]+=gnr2_i*tempr-gnr2_r*tempi;
4717 int ssize=tsize-2*m;
4719 float gnr2_r=gnr2[ssize];
4720 float gnr2_i=gnr2[ssize1];
4721 cr[(size-n)*(bw+1)+m]+=gnr2_r*tempr-gnr2_i*tempi;
4722 ci[(size-n)*(bw+1)+m]-=gnr2_i*tempr+gnr2_r*tempi;
4725 cr[(size-n)*(bw+1)+m]+=*(gnr2)*tempr-*(gnr2+1)*tempi;
4726 ci[(size-n)*(bw+1)+m]-=*(gnr2+1)*tempr+*(gnr2)*tempi;
4732 for (
int cii=0; cii<size*(bw+1);++cii){
4734 in[2*cii+1]=ci[cii];
4739 data_out=data_in->do_ift();
4740 float *c=data_out->get_data();
4741 float tempr=0.0f, corre_fcs=999.0f;
4743 int n_best=0, m_best=0;
4745 for(n=0;n<size;++n){
4746 for(m=0;m<size;++m){
4757 float corre,Phi2,Phi,Tx,Ty,Vx, Vy;
4763 Phi2=n_best*M_PI/bw;
4767 Tx=Vx+(floor(com_this_x+0.5f)-floor(com_with_x+0.5f));
4768 Ty=Vy+(floor(com_this_y+0.5f)-floor(com_with_y+0.5f));
4773 EMData *this_tmp=this_img->copy();
4774 this_tmp->
rotate(-(Phi2-Phi)*180.0f,0.0f,0.0f);
4777 corre=this_tmp->cmp(cmp_name,to,cmp_params);
4780 if(corre<=corre_fcs) {
4782 result[0+5*p] = float(p);
4783 result[1+5*p] = corre;
4784 result[2+5*p] = (Phi2-Phi)*180.0f;
4788 maxcor[p]=corre_fcs;
4789 if(corre_fcs<maxcor_sofar) {
4790 maxcor_sofar=corre_fcs;
4794 if(maxcor[p] < maxcor[p-1] && maxcor[p-1] < maxcor[p-2]&& maxcor[p-2] < maxcor[p-3] && maxcor[p-3] < maxcor[p-4]){
4804 float fsc = result[1+rb5];
4805 float ang_keep = result[2+rb5];
4806 float Tx = result[3+rb5];
4807 float Ty = result[4+rb5];
4818 this_img->
rotate(-ang_keep,0,0);
4824 this_img->set_attr(
"xform.align2d",&tsoln);
4826 float fsc_best=this_img->cmp(cmp_name,to,cmp_params);
4827 printf(
"rho_best=%d fsc=%f fsc_best=%f dx=%f dy=%f ang_keep=%f com_withx=%f com_selfx=%f com_selfy=%f\n",rho_best,fsc,fsc_best,dx,dy,ang_keep,com_with_x,com_this_x,com_this_y);
4835 const string & cmp_name,
const Dict& cmp_params)
const
4843 int nx=this_img->get_xsize();
4844 int ny=this_img->get_ysize();
4845 int size =(int)floor(M_PI*ny/4.0);
4849 EMData *this_temp=this_img->copy();
4851 com_test=this_temp->calc_center_of_mass();
4852 float com_this_x=com_test[0];
4853 float com_this_y=com_test[1];
4857 EMData *that_temp=to->copy();
4858 com_test1=that_temp->calc_center_of_mass();
4859 float com_with_x=com_test1[0];
4860 float com_with_y=com_test1[1];
4863 EMData *avg_frm=to->copy();
4872 float *sampl_fft=withpcsfft->get_data();
4877 unsigned long ind1=0, ind2=0, ind3=0, ind4=0, ind41=0;
4878 float pi2=2.0*M_PI, r2;
4881 data_in->set_complex(
true);
4883 data_in->set_size(2*size,1,1);
4884 float * comp_in=data_in->get_data();
4889 if( (frm2dhhat=(
float *)malloc((p_max+1)*(size+2)*bw*size*2*
sizeof(
float)))==NULL){
4890 cout <<
"Error in allocating memory 13. \n";
4895 if((sb=
new float[size])==NULL||(cb=
new float[size])==NULL) {
4896 cout <<
"can't allocate more memory, terminating. \n";
4899 for(
int i=0;i<size;++i) {
4900 float beta=i*M_PI/bw;
4905 for(
int p=0; p<=p_max; ++p){
4907 float pp2=(float)(p*p);
4908 for(
int n=0;n<bw;++n){
4910 for(
int r=0;r<=MAXR;++r) {
4911 ind3=(ind2+r*bw)*size;
4912 float rr2=(float)(r*r);
4913 float rp2=(float)(r*p);
4914 for(
int i=0;i<size;++i){
4915 r2=
std::sqrt((
float)(rr2+pp2-2.0*rp2*cb[i]));
4916 int r1=(int)floor(r2+0.5f);
4919 comp_in[2*i+1]=0.0f;
4922 float gn_r=sampl_fft[2*n+r1*(size+2)];
4923 float gn_i=sampl_fft[2*n+1+r1*(size+2)];
4924 float sb2, cb2, cn, sn;
4934 if(sb2>1.0) sb2= 1.0f;
4935 if(sb2<-1.0)sb2=-1.0f;
4936 if(cb2>1.0) cb2= 1.0f;
4937 if(cb2<-1.0)cb2=-1.0f;
4938 float beta2=atan2(sb2,cb2);
4939 if(beta2<0.0) beta2+=pi2;
4947 comp_in[2*i]=cn*gn_r-sn*gn_i;
4948 comp_in[2*i+1]=-(cn*gn_i+sn*gn_r);
4952 data_out=data_in->do_fft();
4953 float * comp_out=data_out->get_data();
4954 for(
int m=0;m<size;m++){
4957 frm2dhhat[ind4]=comp_out[2*m];
4958 frm2dhhat[ind41]=comp_out[2*m+1];
4970 float dot_frm0=0.0f, dot_frm1=0.0f;
4971 EMData *da_nFlip=0, *da_yFlip=0, *dr_frm=0;
4973 for (
int iFlip=0;iFlip<=1;++iFlip){
4974 if (iFlip==0){dr_frm=this_img->copy(); da_nFlip=this_img->copy();}
4975 else {dr_frm=this_img->copy(); da_yFlip=this_img->copy();}
4976 if(iFlip==1) {com_this_x=nx-com_this_x; }
4978 dx=-(com_this_x-nx/2);
4979 dy=-(com_this_y-ny/2);
4987 dot_frm0=frm_2d_Align(da_nFlip,to, frm2dhhat, selfpcsfft, p_max, size, com_this_x, com_this_y, com_with_x, com_with_y,cmp_name,cmp_params);
4989 dot_frm1=frm_2d_Align(da_yFlip,to, frm2dhhat, selfpcsfft, p_max, size, com_this_x, com_this_y, com_with_x, com_with_y,cmp_name,cmp_params);
4994 if(dot_frm0 <=dot_frm1) {
4996 printf(
"best_corre=%f, no flip\n",dot_frm0);
5003 printf(
"best_corre=%f, flipped\n",dot_frm1);
5010#ifdef SPARX_USING_CUDA
5016 if (
id != -1) cudasetup(
id);
5028void CUDA_Aligner::setup(
int nima,
int nx,
int ny,
int ring_length,
int nring,
int ou,
float step,
int kx,
int ky,
bool ctf) {
5048 int base_address = num*
NX*
NY;
5050 for (
int y=0;
y<
NY;
y++)
5051 for (
int x=0;
x<
NX;
x++)
5059 params = (
float *)malloc(
NIMA*6*
sizeof(
float));
5061 for (
int i=0; i<
NIMA*6; i++) params[i] = ctf_params[i];
5070 float *ctf_p, *ali_p, *av1, *av2;
5072 ctf_p = (
float *)malloc(
NIMA*6*
sizeof(
float));
5073 ali_p = (
float *)malloc(
NIMA*4*
sizeof(
float));
5076 for (
int i=0; i<
NIMA*6; i++) ctf_p[i] = ctf_params[i];
5078 for (
int i=0; i<
NIMA*4; i++) ali_p[i] = ali_params[i];
5080 av1 = ave1->get_data();
5081 av2 = ave2->get_data();
5091 float *ref_image, max_ccf;
5092 int base_address, ccf_offset;
5094 float ang, sx = 0, sy = 0, mirror, co, so, sxs, sys;
5096 vector<float> align_result;
5098 sx2 = (
float *)malloc(
NIMA*
sizeof(
float));
5099 sy2 = (
float *)malloc(
NIMA*
sizeof(
float));
5101 ref_image = ref_image_em->get_data();
5103 for (
int i=0; i<
NIMA; i++) {
5104 sx2[i] = sx_list[i];
5105 sy2[i] = sy_list[i];
5109 calculate_ccf(
image_stack_filtered, ref_image,
ccf,
NIMA,
NX,
NY,
RING_LENGTH,
NRING,
OU,
STEP,
KX,
KY, sx2, sy2, silent);
5111 calculate_ccf(
image_stack, ref_image,
ccf,
NIMA,
NX,
NY,
RING_LENGTH,
NRING,
OU,
STEP,
KX,
KY, sx2, sy2, silent);
5116 for (
int im=0; im<
NIMA; im++) {
5118 for (
int kx=-
KX; kx<=
KX; kx++) {
5119 for (
int ky=-
KY; ky<=
KY; ky++) {
5122 ts =
ccf[base_address+l];
5123 tm =
ccf[base_address+l+ccf_offset];
5141 co = cos(ang*M_PI/180.0);
5142 so = -sin(ang*M_PI/180.0);
5143 sxs = sx*co - sy*so;
5144 sys = sx*so + sy*co;
5146 align_result.push_back(ang);
5147 align_result.push_back(sxs);
5148 align_result.push_back(sys);
5149 align_result.push_back(mirror);
5155 return align_result;
5161 float *ref_image, max_ccf;
5162 int base_address, ccf_offset;
5164 float ang = 0.0, sx = 0.0, sy = 0.0, co, so, sxs, sys;
5167 vector<float> align_result;
5169 sx2 = (
float *)malloc(
NIMA*
sizeof(
float));
5170 sy2 = (
float *)malloc(
NIMA*
sizeof(
float));
5172 ref_image = ref_image_em->get_data();
5174 for (
int i=0; i<
NIMA; i++) {
5175 ang = ali_params[i*4]/180.0*M_PI;
5176 sx = (ali_params[i*4+3] < 0.5)?(ali_params[i*4+1]-csx):(ali_params[i*4+1]+csx);
5177 sy = ali_params[i*4+2]-csy;
5180 sx2[i] = -(sx*co-sy*so);
5181 sy2[i] = -(sx*so+sy*co);
5185 calculate_ccf(
image_stack_filtered, ref_image,
ccf,
NIMA,
NX,
NY,
RING_LENGTH,
NRING,
OU,
STEP,
KX,
KY, sx2, sy2, silent);
5187 calculate_ccf(
image_stack, ref_image,
ccf,
NIMA,
NX,
NY,
RING_LENGTH,
NRING,
OU,
STEP,
KX,
KY, sx2, sy2, silent);
5192 float sx_sum = 0.0f;
5193 float sy_sum = 0.0f;
5197 if (dl<1) { dl = 1; }
5199 for (
int im=0; im<
NIMA; im++) {
5201 for (
int kx=-
KX; kx<=
KX; kx++) {
5202 for (
int ky=-
KY; ky<=
KY; ky++) {
5205 ts =
ccf[base_address+l];
5206 tm =
ccf[base_address+l+ccf_offset];
5224 co = cos(ang*M_PI/180.0);
5225 so = -sin(ang*M_PI/180.0);
5227 sxs = (sx-sx2[im])*co-(sy-sy2[im])*so;
5228 sys = (sx-sx2[im])*so+(sy-sy2[im])*co;
5232 align_result.push_back(ang);
5233 align_result.push_back(sxs);
5234 align_result.push_back(sys);
5235 align_result.push_back(mirror);
5237 if (mirror == 0) { sx_sum += sxs; }
else { sx_sum -= sxs; }
5241 align_result.push_back(sx_sum);
5242 align_result.push_back(sy_sum);
5247 return align_result;
5277void CUDA_multiref_aligner::setup(
int nima,
int nref,
int nx,
int ny,
int ring_length,
int nring,
int ou,
float step,
int kx,
int ky,
bool ctf) {
5312 int base_address = num*
NX*
NY;
5314 for (
int y=0;
y<
NY;
y++)
5315 for (
int x=0;
x<
NX;
x++)
5321 int base_address = num*
NX*
NY;
5323 for (
int y=0;
y<
NY;
y++)
5324 for (
int x=0;
x<
NX;
x++)
5330 float *ctf_params_ref = (
float *)malloc(
NREF*6*
sizeof(
float));
5331 float *sx2 = (
float *)malloc(
NIMA*
sizeof(
float));
5332 float *sy2 = (
float *)malloc(
NIMA*
sizeof(
float));
5333 vector<float> align_results;
5336 vector<int> batch_size;
5337 vector<int> batch_begin;
5341 int current_size = 1;
5342 for (
int i=1; i<
NIMA; i++) {
5344 batch_size.push_back(current_size);
5347 }
else current_size++;
5349 batch_size.push_back(current_size);
5354 int num_batch = batch_size.size();
5355 batch_begin.resize(num_batch, 0);
5356 for (
int i=1; i<num_batch; i++) batch_begin[i] = batch_size[i-1]+batch_begin[i-1];
5357 assert(batch_begin[num_batch-1]+batch_size[num_batch-1] ==
NIMA-1);
5359 for (
int i=0; i<
NIMA; i++) {
5363 float co = cos(ang);
5364 float so = sin(ang);
5365 sx2[i] = -(sx*co-sy*so);
5366 sy2[i] = -(sx*so+sy*co);
5369 for (
int i=0; i<num_batch; i++) {
5371 for (
int p=0; p<
NREF; p++)
5372 for (
int q=0; q<6; q++)
5373 ctf_params_ref[p*6+q] =
ctf_params[batch_begin[i]*6+q];
5375 calculate_multiref_ccf(
image_stack+batch_begin[i]*
NX*
NY,
ref_image_stack_filtered,
ccf, batch_size[i],
NREF,
NX,
NY,
RING_LENGTH,
NRING,
OU,
STEP,
KX,
KY,
5376 sx2+batch_begin[i], sy2+batch_begin[i], silent);
5378 calculate_multiref_ccf(
image_stack+batch_begin[i]*
NX*
NY,
ref_image_stack,
ccf, batch_size[i],
NREF,
NX,
NY,
RING_LENGTH,
NRING,
OU,
STEP,
KX,
KY,
5379 sx2+batch_begin[i], sy2+batch_begin[i], silent);
5382 for (
int j=0; j<batch_size[i]; j++) {
5383 for (
int im=0; im<
NREF; im++) {
5384 float max_ccf = -1.0e22;
5385 float ang = 0.0, sx = 0.0, sy = 0.0;
5387 for (
int kx=-
KX; kx<=
KX; kx++) {
5388 for (
int ky=-
KY; ky<=
KY; ky++) {
5391 float ts =
ccf[base_address+l];
5392 float tm =
ccf[base_address+l+ccf_offset];
5410 float co = cos(ang*M_PI/180.0);
5411 float so = -sin(ang*M_PI/180.0);
5413 int img_num = batch_begin[i]+j;
5414 float sxs = (sx-sx2[img_num])*co-(sy-sy2[img_num])*so;
5415 float sys = (sx-sx2[img_num])*so+(sy-sy2[img_num])*co;
5417 align_results.push_back(max_ccf);
5418 align_results.push_back(ang);
5419 align_results.push_back(sxs);
5420 align_results.push_back(sys);
5421 align_results.push_back(mirror);
5426 free(ctf_params_ref);
5430 return align_results;
5438 dump_factory < Aligner > ();
5443 return dump_factory_list < Aligner > ();
static double refalifn3dquat(const gsl_vector *v, void *params)
static double refalifn(const gsl_vector *v, void *params)
static Transform refalin3d_perturbquat(const Transform *const t, const float &spincoeff, const float &n0, const float &n1, const float &n2, const float &x, const float &y, const float &z)
static double symquat(const gsl_vector *v, void *params)
static void refalidf(const gsl_vector *v, void *params, gsl_vector *df)
static double refalifnfast(const gsl_vector *v, void *params)
static void refalifdf(const gsl_vector *v, void *params, double *f, gsl_vector *df)
virtual Dict get_params() const
Get the Aligner parameters in a key/value dictionary.
Averager class defines a way to do averaging on a set of images.
virtual EMData * finish()=0
Finish up the averaging and return the result.
virtual void add_image(EMData *image)
To add an image to the Averager.
void setup(int nima, int nx, int ny, int ring_length, int nring, int ou, float step, int kx, int ky, bool ctf)
vector< float > alignment_2d(EMData *ref_image, vector< float > sx, vector< float > sy, int silent)
float * image_stack_filtered
void insert_image(EMData *image, int num)
vector< float > ali2d_single_iter(EMData *ref_image, vector< float > ali_params, float csx, float csy, int silent, float delta)
void filter_stack(vector< float > ctf_params)
void sum_oe(vector< float > ctf_params, vector< float > ali_params, EMData *ave1, EMData *ave2)
void insert_ref_image(EMData *image, int num)
CUDA_multiref_aligner(int id)
void insert_image(EMData *image, int num)
vector< float > multiref_ali2d(int silent)
float * ref_image_stack_filtered
void setup(int nima, int nref, int nx, int ny, int ring_length, int nring, int ou, float step, int kx, int ky, bool ctf)
void setup_params(vector< float > all_ali_params, vector< float > all_ctf_params)
Cmp class defines image comparison method.
virtual float cmp(EMData *image, EMData *with) const =0
To compare 'image' with another image passed in through its parameters.
Const iterator support for the Dict object This is just a wrapper, everything is inherited from the m...
Dict is a dictionary to store <string, EMObject> pair.
size_t size() const
Ask the Dictionary for its size.
type set_default(const string &key, type val)
Default setting behavior This can be achieved using a template - d.woolford Jan 2008 (before there wa...
bool has_key(const string &key) const
Ask the Dictionary if it as a particular key.
static const double rad2deg
static const double deg2rad
EMData stores an image's data and defines core image processing routines.
void translate(float dx, float dy, float dz)
Translate this image.
void rotate(const Transform &t)
Rotate this image.
EMData * calc_flcf(EMData *with)
Calculates the cross correlation with local normalization between 2 images.
EMData * make_rotational_footprint_cmc(bool unwrap=true)
void zero_corner_circulant(const int radius=0)
Zero the pixels in the bottom left corner of the image If radius is greater than 1,...
double dot_rotate_translate(EMData *with, float dx, float dy, float da, const bool mirror=false)
dot product of 2 images.
EMData * calc_ccf_masked(EMData *with, EMData *withsq=0, EMData *mask=0)
Calculate cross correlation between this and with where this is assumed to have had a mask applied to...
void rotate_x(int dx)
This performs a translation of each line along x with wraparound.
EMData * get_clip(const Region &area, const float fill=0) const
Get an inclusive clip.
EMData * make_rotational_footprint_e1(bool unwrap=true)
vector< float > calc_radial_dist(int n, float x0, float dx, int inten)
calculates radial distribution.
EMData * oneDfftPolar(int size, float rmax, float MAXR)
EMData * unwrap_largerR(int r1, int r2, int xs, float rmax_f)
EMObject is a wrapper class for types including int, float, double, etc as defined in ObjectType.
static bool is_same_size(const EMData *image1, const EMData *image2)
Check whether two EMData images are of the same size.
virtual EMData * align(EMData *this_img, EMData *to_img, const string &cmp_name, const Dict &cmp_params=Dict()) const
To align 'this_img' with another image passed in through its parameters.
Factory is used to store objects to create new instances.
static T * get(const string &instance_name)
FloatPoint defines a float-coordinate point in a 1D/2D/3D space.
IntPoint defines an integer-coordinate point in a 1D/2D/3D space.
Typical usage of Processors are as follows:
virtual vector< Dict > xform_align_nbest(EMData *this_img, EMData *to_img, const unsigned int nsoln, const string &cmp_name, const Dict &cmp_params) const
See Aligner comments for more details.
virtual EMData * align(EMData *this_img, EMData *to_img, const string &cmp_name="sqeuclidean", const Dict &cmp_params=Dict()) const
See Aligner comments for more details.
virtual EMData * align(EMData *this_img, EMData *to_img, const string &cmp_name="sqeuclidean", const Dict &cmp_params=Dict()) const
See Aligner comments for more details.
virtual vector< Dict > xform_align_nbest(EMData *this_img, EMData *to_img, const unsigned int nsoln, const string &cmp_name, const Dict &cmp_params) const
See Aligner comments for more details.
bool testort(EMData *small_this, EMData *small_to, vector< float > &s_score, vector< Transform > &s_xform, int i, Dict &upd, Transform initxf, int maxshift, int maxang) const
virtual EMData * align(EMData *this_img, EMData *to_img, const string &cmp_name="ccc.tomo", const Dict &cmp_params=Dict()) const
See Aligner comments for more details.
virtual vector< Dict > xform_align_nbest(EMData *this_img, EMData *to_img, const unsigned int nsoln, const string &cmp_name, const Dict &cmp_params) const
See Aligner comments for more details.
virtual EMData * align(EMData *this_img, EMData *to_img, const string &cmp_name="sqeuclidean", const Dict &cmp_params=Dict()) const
See Aligner comments for more details.
virtual vector< Dict > xform_align_nbest(EMData *this_img, EMData *to_img, const unsigned int nsoln, const string &cmp_name, const Dict &cmp_params) const
See Aligner comments for more details.
bool testort(EMData *small_this, EMData *small_to, EMData *small_mask, EMData *small_thissq, vector< float > &sigmathisv, vector< float > &sigmatov, vector< float > &s_score, vector< float > &s_coverage, vector< Transform > &s_xform, int i, Dict &upd, Transform initxf, int maxshift) const
virtual EMData * align(EMData *this_img, EMData *to_img, const string &cmp_name="sqeuclidean", const Dict &cmp_params=Dict()) const
See Aligner comments for more details.
virtual vector< Dict > xform_align_nbest(EMData *this_img, EMData *to_img, const unsigned int nsoln, const string &cmp_name, const Dict &cmp_params) const
See Aligner comments for more details.
virtual EMData * align(EMData *this_img, EMData *to_img, const string &cmp_name="ccc.tomo", const Dict &cmp_params=Dict()) const
See Aligner comments for more details.
virtual vector< Dict > xform_align_nbest(EMData *this_img, EMData *to_img, const unsigned int nsoln, const string &cmp_name, const Dict &cmp_params) const
See Aligner comments for more details.
virtual EMData * align(EMData *this_img, EMData *to_img, const string &cmp_name="sqeuclidean", const Dict &cmp_params=Dict()) const
See Aligner comments for more details.
virtual vector< Dict > xform_align_nbest(EMData *this_img, EMData *to_img, const unsigned int nsoln, const string &cmp_name, const Dict &cmp_params) const
See Aligner comments for more details.
bool testort(EMData *small_this, EMData *small_to, vector< float > &sigmathisv, vector< float > &sigmatov, vector< float > &s_score, vector< float > &s_coverage, vector< Transform > &s_xform, int i, Dict &upd, Transform initxf, int maxshift, EMData *mask) const
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 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 string &cmp_name="sqeuclidean", 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 string &cmp_name="sqeuclidean", 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 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 string &cmp_name="dot", const Dict &cmp_params=Dict()) const
To align 'this_img' with another image passed in through its parameters.
Region defines a 2D or 3D rectangular region specified by its origin coordinates and all edges' sizes...
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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 string &cmp_name="dot", const Dict &cmp_params=Dict()) const
To align 'this_img' with another image passed in through its parameters.
static EMData * align_180_ambiguous(EMData *this_img, EMData *to_img, int rfp_mode=2, int zscore=0)
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.
EMData * align_using_base(EMData *this_img, EMData *to_img, const string &cmp_name="dot", const Dict &cmp_params=Dict()) const
implmentation of the scale alignment using the base aligner set in set_base_aligner
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 string &cmp_name="ccc", 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 string &cmp_name="ccc", const Dict &cmp_params=Dict()) const
To align 'this_img' with another image passed in through its parameters.
Symmetry3D - A base class for 3D Symmetry objects.
static vector< Transform > get_symmetries(const string &symmetry)
vector< Transform > gen_orientations(const string &generatorname="eman", const Dict &parms=Dict())
Ask the Symmetry3D object to generate a set of orientations in its asymmetric unit using an Orientati...
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.
static void find_max(const float *data, size_t nitems, float *p_max_val, int *p_max_index=0)
Find the maximum value and (optional) its index in an array.
static int calc_best_fft_size(int low)
Search the best FFT size with good primes.
float normalize()
Normalize the vector and return its length before the normalization.
float2 get_stats_cuda(const float *data, const int nx, const int ny, const int nz)
CudaPeakInfo * calc_max_location_wrap_cuda(const float *in, const int nx, const int ny, const int nz, const int maxdx, const int maxdy, const int maxdz)
EMData * copy() const
This file is a part of "emdata.h", to use functions in this file, you should "#include "emdata....
EMData * sqrt() const
return square root of current image
vector< Dict > xform_align_nbest(const string &aligner_name, EMData *to_img, const Dict ¶ms=Dict(), const unsigned int nsoln=1, const string &cmp_name="dot", const Dict &cmp_params=Dict())
Align this image with another image, return the parameters of the "n best" solutions See Aligner::xfo...
#define InvalidParameterException(desc)
#define ImageDimensionException(desc)
#define UnexpectedBehaviorException(desc)
#define InvalidCallException(desc)
#define NullPointerException(desc)
EMData * calc_ccf(EMData *with=0, fp_flag fpflag=CIRCULANT, bool center=false)
Calculate Cross-Correlation Function (CCF).
EMData * unwrap(int r1=-1, int r2=-1, int xs=-1, int dx=0, int dy=0, bool do360=false, bool weight_radial=true) const
Maps to polar coordinates from Cartesian coordinates.
EMData * calc_ccfx(EMData *const with, int y0=0, int y1=-1, bool nosum=false, bool flip=false, bool usez=false)
Calculate Cross-Correlation Function (CCF) in the x-direction and adds them up, result in 1D.
EMData * make_rotational_footprint(bool unwrap=true)
Makes a 'rotational footprint', which is an 'unwound' autocorrelation function.
map< string, vector< string > > dump_aligners_list()