#include "emfft.h"
#include "cmp.h"
#include "aligner.h"
#include "averager.h"
#include "emdata.h"
#include "processor.h"
#include "util.h"
#include "symmetry.h"
#include <gsl/gsl_multimin.h>
#include "plugins/aligner_template.h"
Include dependency graph for aligner.cpp:
Go to the source code of this file.
Defines | |
#define | EMAN2_ALIGNER_DEBUG 0 |
| |
Functions | |
double | refalifn (const gsl_vector *v, void *params) |
double | refalifnfast (const gsl_vector *v, void *params) |
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) |
double | symquat (const gsl_vector *v, void *params) |
double | refalifn3dquat (const gsl_vector *v, void *params) |
float | 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) |
|
Definition at line 55 of file aligner.cpp. |
|
Definition at line 2527 of file aligner.cpp. References EMAN::EMData::cmp(), EMAN::EMData::copy(), EMAN::EMData::do_ift(), EMAN::EMData::get_data(), EMAN::EMData::get_ysize(), in, EMAN::EMData::rotate(), EMAN::EMData::set_attr(), EMAN::EMData::set_complex(), EMAN::EMData::set_fftodd(), EMAN::EMData::set_ri(), EMAN::EMData::set_size(), EMAN::Transform::set_trans(), and EMAN::EMData::translate(). Referenced by EMAN::FRM2DAligner::align(). 02528 { 02529 int size=rsize; 02530 float dx,dy; 02531 int bw=size/2; 02532 int MAXR=this_img->get_ysize()/2; 02533 //int MAXR=size; 02534 unsigned long tsize=2*size; 02535 unsigned long ind1=0, ind2=0, ind3=0, ind4=0, ind41=0; 02536 unsigned long index0=0; 02537 int i=0, j=0, m=0, n=0, r=0; 02538 int loop_rho=0, rho_best=0; 02539 02540 float* gnr2 = new float[size*2]; 02541 float* maxcor = new float[size+1]; // MAXR need change 02542 02543 int p_max=p_max_input; 02544 float* result = new float[5*(p_max+1)]; 02545 float* cr=new float[size*(bw+1)]; 02546 float* ci=new float[size*(bw+1)]; 02547 EMData *data_in=new EMData; 02548 data_in->set_complex(true); 02549 data_in->set_fftodd(false); 02550 data_in->set_ri(true); 02551 data_in->set_size(size+2,size,1); 02552 float *in=data_in->get_data(); 02553 02554 float *self_sampl_fft = selfpcsfft->get_data(); // ming f(r) 02555 02556 float maxcor_sofar=0.0f; 02557 int p=0; 02558 02559 for(p=0; p<=p_max; ++p){ 02560 ind1=p*size*bw; 02561 for (i=0;i<size;++i) 02562 for (j=0;j<bw+1;++j){ 02563 cr[i*(bw+1)+j]=0.0; 02564 ci[i*(bw+1)+j]=0.0; 02565 } 02566 for(n=0;n<bw;++n){ // loop for n 02567 ind2=(ind1+n); 02568 index0=n*(bw+1); 02569 for(r=0;r<=MAXR;++r) { 02570 ind3=(ind2+r*bw)*size; 02571 for(m=0;m<size;m++){ // take back hat{h(n,r,p)}(m) 02572 ind4=(ind3+m)*2; 02573 ind41=ind4+1; 02574 gnr2[2*m]=frm2dhhat[ind4]; 02575 gnr2[2*m+1]=frm2dhhat[ind41]; 02576 } 02577 for(m=0;m<bw;++m){ 02578 float tempr=self_sampl_fft[2*m+r*(size+2)]*r; 02579 float tempi=self_sampl_fft[2*m+1+r*(size+2)]*r; 02580 float gnr2_r=gnr2[2*m]; 02581 float gnr2_i=gnr2[2*m+1]; 02582 cr[n*(bw+1)+m]+=gnr2_r*tempr+gnr2_i*tempi; 02583 ci[n*(bw+1)+m]+=gnr2_i*tempr-gnr2_r*tempi; 02584 if(n!=0){ // m,-n 02585 if(m!= 0){ 02586 int ssize=tsize-2*m; // ssize = 2*size-2m 02587 int ssize1=ssize+1; 02588 float gnr2_r=gnr2[ssize]; 02589 float gnr2_i=gnr2[ssize1]; 02590 cr[(size-n)*(bw+1)+m]+=gnr2_r*tempr-gnr2_i*tempi; 02591 ci[(size-n)*(bw+1)+m]-=gnr2_i*tempr+gnr2_r*tempi; 02592 } 02593 else{ 02594 cr[(size-n)*(bw+1)+m]+=*(gnr2)*tempr-*(gnr2+1)*tempi; 02595 ci[(size-n)*(bw+1)+m]-=*(gnr2+1)*tempr+*(gnr2)*tempi; 02596 } 02597 } 02598 } 02599 } 02600 } 02601 for (int cii=0; cii<size*(bw+1);++cii){ 02602 in[2*cii]=cr[cii]; 02603 in[2*cii+1]=ci[cii]; 02604 //printf("cii=%d,in[2i+1]=%f\n",cii, cr[cii]); 02605 } 02606 02607 EMData *data_out; 02608 data_out=data_in->do_ift(); 02609 float *c=data_out->get_data(); 02610 float tempr=0.0f, corre_fcs=999.0f; 02611 02612 int n_best=0, m_best=0; 02613 float temp=-100.0f; 02614 for(n=0;n<size;++n){// move Tri_2D to Tri = c(phi,phi';rho) 02615 for(m=0;m<size;++m){ 02616 temp=c[n*size+m]; 02617 if(temp>tempr) { 02618 tempr=temp; 02619 n_best=n; 02620 m_best=m; 02621 } 02622 } 02623 } 02624 delete data_out; 02625 02626 float corre,Phi2,Phi,Tx,Ty,Vx, Vy; 02627 02628 //for (n_best=0;n_best<bw;n_best++) 02629 // for (m_best=0;m_best<2*bw;m_best++){ 02630 //n_best=0; 02631 //m_best=70; 02632 Phi2=n_best*M_PI/bw; // ming this is reference image rotation angle 02633 Phi=m_best*M_PI/bw; // ming this is particle image rotation angle 02634 Vx=p*cos(Phi);//should use the angle of the centered one 02635 Vy=-p*sin(Phi); 02636 Tx=Vx+(floor(com_this_x+0.5f)-floor(com_with_x+0.5f)); 02637 Ty=Vy+(floor(com_this_y+0.5f)-floor(com_with_y+0.5f)); 02638 02639 dx=-Tx; // the Rota & Trans value (Tx,Ty, ang_keep) are for the projection image, 02640 dy=-Ty; // need to convert to raw image 02641 02642 EMData *this_tmp=this_img->copy();//ming change to to 02643 this_tmp->rotate(-(Phi2-Phi)*180.0f,0.0f,0.0f); 02644 this_tmp->translate(dx,dy,0.0); 02645 02646 corre=this_tmp->cmp(cmp_name,to,cmp_params); 02647 //printf("corre=%f\n",corre); 02648 delete this_tmp; 02649 if(corre<=corre_fcs) { //ming, cmp use smaller value stands for more similarity 02650 corre_fcs=corre; 02651 result[0+5*p] = float(p); // rho 02652 result[1+5*p] = corre; // correlation_fcs 02653 result[2+5*p] = (Phi2-Phi)*180.0f; // rotation angle 02654 result[3+5*p] = Tx; // Translation_x 02655 result[4+5*p] = Ty; // Translation_y 02656 } 02657 maxcor[p]=corre_fcs; // maximum correlation for current rho 02658 if(corre_fcs<maxcor_sofar) { 02659 maxcor_sofar=corre_fcs; // max correlation up to current rho 02660 rho_best=p; // the rho value with maxinum correlation value 02661 } 02662 if(p>=4){ 02663 if(maxcor[p] < maxcor[p-1] && maxcor[p-1] < maxcor[p-2]&& maxcor[p-2] < maxcor[p-3] && maxcor[p-3] < maxcor[p-4]){ 02664 loop_rho=1; 02665 break; //exit p loop 02666 } 02667 } 02668 } // end for p 02669 //}//test my method 02670 if(loop_rho == 1) 02671 p=p+1; 02672 int rb5=5*rho_best; 02673 float fsc = result[1+rb5]; 02674 float ang_keep = result[2+rb5]; 02675 float Tx = result[3+rb5]; 02676 float Ty = result[4+rb5]; 02677 delete[] gnr2; 02678 delete[] maxcor; 02679 delete[] result; 02680 delete cr; 02681 cr=0; 02682 delete ci; 02683 ci=0; 02684 delete data_in; // ming add 02685 dx = -Tx; // the Rota & Trans value (Tx,Ty, ang_keep) are for the projection image, 02686 dy = -Ty; // need to convert to raw image 02687 this_img->rotate(-ang_keep,0,0); // ming change this to this_img?? 02688 this_img->translate(dx,dy,0.0); // ming change this to this_img 02689 02690 02691 Transform tsoln(Dict("type","2d","alpha",ang_keep)); 02692 tsoln.set_trans(dx,dy); 02693 this_img->set_attr("xform.align2d",&tsoln); 02694 #ifdef DEBUG 02695 float fsc_best=this_img->cmp(cmp_name,to,cmp_params); 02696 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); 02697 #endif 02698 return fsc; // return the fsc coefficients 02699 } // FRM2D aligner sub_class
|
|
Definition at line 1380 of file aligner.cpp. References EMAN::Cmp::cmp(), EMAN::EMData::process(), EMAN::Transform::set_mirror(), EMAN::Transform::set_scale(), EMAN::Transform::set_trans(), t, v, x, and y. 01381 { 01382 Dict *dict = (Dict *) params; 01383 01384 double x = gsl_vector_get(v, 0); 01385 double y = gsl_vector_get(v, 1); 01386 double a = gsl_vector_get(v, 2); 01387 01388 EMData *this_img = (*dict)["this"]; 01389 EMData *with = (*dict)["with"]; 01390 bool mirror = (*dict)["mirror"]; 01391 01392 // float mean = (float)this_img->get_attr("mean"); 01393 // if ( Util::goodf(&mean) ) { 01394 // //cout << "tmps mean is nan even before rotation" << endl; 01395 // } 01396 01397 Transform t(Dict("type","2d","alpha",static_cast<float>(a))); 01398 // Transform3D t3d(Transform3D::EMAN, (float)a, 0.0f, 0.0f); 01399 // t3d.set_posttrans( (float) x, (float) y); 01400 // tmp->rotate_translate(t3d); 01401 t.set_trans((float)x,(float)y); 01402 t.set_mirror(mirror); 01403 if (v->size>3) { 01404 float sca=(float)gsl_vector_get(v, 3); 01405 if (sca<.7 || sca>1.3) return 1.0e20; 01406 t.set_scale((float)gsl_vector_get(v, 3)); 01407 } 01408 EMData *tmp = this_img->process("xform",Dict("transform",&t)); 01409 01410 // printf("GSL %f %f %f %d %f\n",x,y,a,mirror,(float)gsl_vector_get(v, 3)); 01411 Cmp* c = (Cmp*) ((void*)(*dict)["cmp"]); 01412 double result = c->cmp(tmp,with); 01413 01414 // DELETE AT SOME STAGE, USEFUL FOR PRERELEASE STUFF 01415 // float test_result = (float)result; 01416 // if ( Util::goodf(&test_result) ) { 01417 // cout << "result " << result << " " << x << " " << y << " " << a << endl; 01418 // cout << (float)this_img->get_attr("mean") << " " << (float)tmp->get_attr("mean") << " " << (float)with->get_attr("mean") << endl; 01419 // tmp->write_image("tmp.hdf"); 01420 // with->write_image("with.hdf"); 01421 // this_img->write_image("this_img.hdf"); 01422 // EMData* t = this_img->copy(); 01423 // cout << (float)t->get_attr("mean") << endl; 01424 // t->rotate_translate( t3d ); 01425 // cout << (float)t->get_attr("mean") << endl; 01426 // cout << "exit" << endl; 01428 // cout << (float)t->get_attr("mean") << endl; 01429 // cout << "now exit" << endl; 01430 // delete t; 01431 // } 01432 01433 01434 if ( tmp != 0 ) delete tmp; 01435 01436 return result; 01437 }
|
|
Definition at line 1642 of file aligner.cpp. References EMAN::Cmp::cmp(), EMAN::EMData::process(), refalin3d_perturbquat(), t, v, x, and y. 01643 { 01644 Dict *dict = (Dict *) params; 01645 01646 double n0 = gsl_vector_get(v, 0); 01647 double n1 = gsl_vector_get(v, 1); 01648 double n2 = gsl_vector_get(v, 2); 01649 double x = gsl_vector_get(v, 3); 01650 double y = gsl_vector_get(v, 4); 01651 double z = gsl_vector_get(v, 5); 01652 01653 EMData *this_img = (*dict)["this"]; 01654 EMData *with = (*dict)["with"]; 01655 01656 Transform* t = (*dict)["transform"]; 01657 float spincoeff = (*dict)["spincoeff"]; 01658 01659 Transform soln = refalin3d_perturbquat(t,spincoeff,(float)n0,(float)n1,(float)n2,(float)x,(float)y,(float)z); 01660 01661 EMData *tmp = this_img->process("xform",Dict("transform",&soln)); 01662 Cmp* c = (Cmp*) ((void*)(*dict)["cmp"]); 01663 double result = c->cmp(tmp,with); 01664 if ( tmp != 0 ) delete tmp; 01665 delete t; t = 0; 01666 //cout << result << endl; 01667 return result; 01668 }
|
|
Definition at line 1439 of file aligner.cpp. References EMAN::EMData::dot_rotate_translate(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), v, x, and y. 01440 { 01441 Dict *dict = (Dict *) params; 01442 EMData *this_img = (*dict)["this"]; 01443 EMData *img_to = (*dict)["with"]; 01444 bool mirror = (*dict)["mirror"]; 01445 01446 double x = gsl_vector_get(v, 0); 01447 double y = gsl_vector_get(v, 1); 01448 double a = gsl_vector_get(v, 2); 01449 01450 double r = this_img->dot_rotate_translate(img_to, (float)x, (float)y, (float)a, mirror); 01451 int nsec = this_img->get_xsize() * this_img->get_ysize(); 01452 double result = 1.0 - r / nsec; 01453 01454 // cout << result << " x " << x << " y " << y << " az " << a << endl; 01455 return result; 01456 }
|
|
Definition at line 1592 of file aligner.cpp. References EMAN::Vec3< Type >::normalize(), q, EMAN::Transform::set_trans(), sqrt(), EMAN::Vec3f, x, and y. Referenced by EMAN::Refine3DAlignerQuaternion::align(), EMAN::SymAlignProcessorQuat::align(), refalifn3dquat(), and symquat(). 01593 { 01594 Vec3f normal(n0,n1,n2); 01595 normal.normalize(); 01596 01597 float omega = spincoeff*sqrt(n0*n0 + n1*n1 + n2*n2); // Here we compute the spin by the rotation axis vector length 01598 Dict d; 01599 d["type"] = "spin"; 01600 d["Omega"] = omega; 01601 d["n1"] = normal[0]; 01602 d["n2"] = normal[1]; 01603 d["n3"] = normal[2]; 01604 //cout << omega << " " << normal[0] << " " << normal[1] << " " << normal[2] << " " << n0 << " " << n1 << " " << n2 << endl; 01605 01606 Transform q(d); 01607 q.set_trans((float)x,(float)y,(float)z); 01608 01609 q = q*(*t); //compose transforms 01610 01611 return q; 01612 }
|
|
Definition at line 1614 of file aligner.cpp. References EMAN::Cmp::cmp(), EMAN::EMData::process(), refalin3d_perturbquat(), t, v, x, and y. 01615 { 01616 Dict *dict = (Dict *) params; 01617 01618 double n0 = gsl_vector_get(v, 0); 01619 double n1 = gsl_vector_get(v, 1); 01620 double n2 = gsl_vector_get(v, 2); 01621 double x = gsl_vector_get(v, 3); 01622 double y = gsl_vector_get(v, 4); 01623 double z = gsl_vector_get(v, 5); 01624 01625 EMData* volume = (*dict)["volume"]; 01626 float spincoeff = (*dict)["spincoeff"]; 01627 Transform* t = (*dict)["transform"]; 01628 01629 Transform soln = refalin3d_perturbquat(t,spincoeff,(float)n0,(float)n1,(float)n2,(float)x,(float)y,(float)z); 01630 01631 EMData *tmp = volume->process("xform",Dict("transform",&soln)); 01632 EMData *symtmp = tmp->process("xform.applysym",Dict("sym",(*dict)["sym"])); 01633 Cmp* c = (Cmp*) ((void*)(*dict)["cmp"]); 01634 double result = c->cmp(symtmp,tmp); 01635 delete tmp; 01636 delete symtmp; 01637 delete t; t = 0; 01638 //cout << result << endl; 01639 return result; 01640 }
|