#include "emfft.h"
#include "cmp.h"
#include "aligner.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) |
double | refalifn3d (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 49 of file aligner.cpp. |
|
Definition at line 1876 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(). 01877 { 01878 int size=rsize; 01879 float dx,dy; 01880 int bw=size/2; 01881 int MAXR=this_img->get_ysize()/2; 01882 //int MAXR=size; 01883 unsigned long tsize=2*size; 01884 unsigned long ind1=0, ind2=0, ind3=0, ind4=0, ind41=0; 01885 unsigned long index0=0; 01886 int i=0, j=0, m=0, n=0, r=0; 01887 int loop_rho=0, rho_best=0; 01888 01889 float* gnr2 = new float[size*2]; 01890 float* maxcor = new float[size+1]; // MAXR need change 01891 01892 int p_max=p_max_input; 01893 float* result = new float[5*(p_max+1)]; 01894 float* cr=new float[size*(bw+1)]; 01895 float* ci=new float[size*(bw+1)]; 01896 EMData *data_in=new EMData; 01897 data_in->set_complex(true); 01898 data_in->set_fftodd(false); 01899 data_in->set_ri(true); 01900 data_in->set_size(size+2,size,1); 01901 float *in=data_in->get_data(); 01902 01903 float *self_sampl_fft = selfpcsfft->get_data(); // ming f(r) 01904 01905 float maxcor_sofar=0.0f; 01906 int p=0; 01907 01908 for(p=0; p<=p_max; ++p){ 01909 ind1=p*size*bw; 01910 for (i=0;i<size;++i) 01911 for (j=0;j<bw+1;++j){ 01912 cr[i*(bw+1)+j]=0.0; 01913 ci[i*(bw+1)+j]=0.0; 01914 } 01915 for(n=0;n<bw;++n){ // loop for n 01916 ind2=(ind1+n); 01917 index0=n*(bw+1); 01918 for(r=0;r<=MAXR;++r) { 01919 ind3=(ind2+r*bw)*size; 01920 for(m=0;m<size;m++){ // take back hat{h(n,r,p)}(m) 01921 ind4=(ind3+m)*2; 01922 ind41=ind4+1; 01923 gnr2[2*m]=frm2dhhat[ind4]; 01924 gnr2[2*m+1]=frm2dhhat[ind41]; 01925 } 01926 for(m=0;m<bw;++m){ 01927 float tempr=self_sampl_fft[2*m+r*(size+2)]*r; 01928 float tempi=self_sampl_fft[2*m+1+r*(size+2)]*r; 01929 float gnr2_r=gnr2[2*m]; 01930 float gnr2_i=gnr2[2*m+1]; 01931 cr[n*(bw+1)+m]+=gnr2_r*tempr+gnr2_i*tempi; 01932 ci[n*(bw+1)+m]+=gnr2_i*tempr-gnr2_r*tempi; 01933 if(n!=0){ // m,-n 01934 if(m!= 0){ 01935 int ssize=tsize-2*m; // ssize = 2*size-2m 01936 int ssize1=ssize+1; 01937 float gnr2_r=gnr2[ssize]; 01938 float gnr2_i=gnr2[ssize1]; 01939 cr[(size-n)*(bw+1)+m]+=gnr2_r*tempr-gnr2_i*tempi; 01940 ci[(size-n)*(bw+1)+m]-=gnr2_i*tempr+gnr2_r*tempi; 01941 } 01942 else{ 01943 cr[(size-n)*(bw+1)+m]+=*(gnr2)*tempr-*(gnr2+1)*tempi; 01944 ci[(size-n)*(bw+1)+m]-=*(gnr2+1)*tempr+*(gnr2)*tempi; 01945 } 01946 } 01947 } 01948 } 01949 } 01950 for (int cii=0; cii<size*(bw+1);++cii){ 01951 in[2*cii]=cr[cii]; 01952 in[2*cii+1]=ci[cii]; 01953 //printf("cii=%d,in[2i+1]=%f\n",cii, cr[cii]); 01954 } 01955 01956 EMData *data_out; 01957 data_out=data_in->do_ift(); 01958 float *c=data_out->get_data(); 01959 float tempr=0.0f, corre_fcs=999.0f; 01960 01961 int n_best=0, m_best=0; 01962 float temp=-100.0f; 01963 for(n=0;n<size;++n){// move Tri_2D to Tri = c(phi,phi';rho) 01964 for(m=0;m<size;++m){ 01965 temp=c[n*size+m]; 01966 if(temp>tempr) { 01967 tempr=temp; 01968 n_best=n; 01969 m_best=m; 01970 } 01971 } 01972 } 01973 delete data_out; 01974 01975 float corre,Phi2,Phi,Tx,Ty,Vx, Vy; 01976 01977 //for (n_best=0;n_best<bw;n_best++) 01978 // for (m_best=0;m_best<2*bw;m_best++){ 01979 //n_best=0; 01980 //m_best=70; 01981 Phi2=n_best*M_PI/bw; // ming this is reference image rotation angle 01982 Phi=m_best*M_PI/bw; // ming this is particle image rotation angle 01983 Vx=p*cos(Phi);//should use the angle of the centered one 01984 Vy=-p*sin(Phi); 01985 Tx=Vx+(floor(com_this_x+0.5f)-floor(com_with_x+0.5f)); 01986 Ty=Vy+(floor(com_this_y+0.5f)-floor(com_with_y+0.5f)); 01987 01988 dx=-Tx; // the Rota & Trans value (Tx,Ty, ang_keep) are for the projection image, 01989 dy=-Ty; // need to convert to raw image 01990 01991 EMData *this_tmp=this_img->copy();//ming change to to 01992 this_tmp->rotate(-(Phi2-Phi)*180.0f,0.0f,0.0f); 01993 this_tmp->translate(dx,dy,0.0); 01994 01995 corre=this_tmp->cmp(cmp_name,to,cmp_params); 01996 //printf("corre=%f\n",corre); 01997 delete this_tmp; 01998 if(corre<=corre_fcs) { //ming, cmp use smaller value stands for more similarity 01999 corre_fcs=corre; 02000 result[0+5*p] = float(p); // rho 02001 result[1+5*p] = corre; // correlation_fcs 02002 result[2+5*p] = (Phi2-Phi)*180.0f; // rotation angle 02003 result[3+5*p] = Tx; // Translation_x 02004 result[4+5*p] = Ty; // Translation_y 02005 } 02006 maxcor[p]=corre_fcs; // maximum correlation for current rho 02007 if(corre_fcs<maxcor_sofar) { 02008 maxcor_sofar=corre_fcs; // max correlation up to current rho 02009 rho_best=p; // the rho value with maxinum correlation value 02010 } 02011 if(p>=4){ 02012 if(maxcor[p] < maxcor[p-1] && maxcor[p-1] < maxcor[p-2]&& maxcor[p-2] < maxcor[p-3] && maxcor[p-3] < maxcor[p-4]){ 02013 loop_rho=1; 02014 break; //exit p loop 02015 } 02016 } 02017 } // end for p 02018 //}//test my method 02019 if(loop_rho == 1) 02020 p=p+1; 02021 int rb5=5*rho_best; 02022 float fsc = result[1+rb5]; 02023 float ang_keep = result[2+rb5]; 02024 float Tx = result[3+rb5]; 02025 float Ty = result[4+rb5]; 02026 delete[] gnr2; 02027 delete[] maxcor; 02028 delete[] result; 02029 delete cr; 02030 cr=0; 02031 delete ci; 02032 ci=0; 02033 delete data_in; // ming add 02034 dx = -Tx; // the Rota & Trans value (Tx,Ty, ang_keep) are for the projection image, 02035 dy = -Ty; // need to convert to raw image 02036 this_img->rotate(-ang_keep,0,0); // ming change this to this_img?? 02037 this_img->translate(dx,dy,0.0); // ming change this to this_img 02038 02039 02040 Transform tsoln(Dict("type","2d","alpha",ang_keep)); 02041 tsoln.set_trans(dx,dy); 02042 this_img->set_attr("xform.align2d",&tsoln); 02043 #ifdef DEBUG 02044 float fsc_best=this_img->cmp(cmp_name,to,cmp_params); 02045 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); 02046 #endif 02047 return fsc; // return the fsc coefficients 02048 } // FRM2D aligner sub_class
|
|
Definition at line 1127 of file aligner.cpp. References EMAN::Cmp::cmp(), EMAN::EMData::process(), EMAN::Transform::set_mirror(), EMAN::Transform::set_trans(), t, v, x, and y. 01128 { 01129 Dict *dict = (Dict *) params; 01130 01131 double x = gsl_vector_get(v, 0); 01132 double y = gsl_vector_get(v, 1); 01133 double a = gsl_vector_get(v, 2); 01134 01135 EMData *this_img = (*dict)["this"]; 01136 EMData *with = (*dict)["with"]; 01137 bool mirror = (*dict)["mirror"]; 01138 01139 // float mean = (float)this_img->get_attr("mean"); 01140 // if ( Util::goodf(&mean) ) { 01141 // //cout << "tmps mean is nan even before rotation" << endl; 01142 // } 01143 01144 Transform t(Dict("type","2d","alpha",static_cast<float>(a))); 01145 // Transform3D t3d(Transform3D::EMAN, (float)a, 0.0f, 0.0f); 01146 // t3d.set_posttrans( (float) x, (float) y); 01147 // tmp->rotate_translate(t3d); 01148 t.set_trans((float)x,(float)y); 01149 t.set_mirror(mirror); 01150 EMData *tmp = this_img->process("xform",Dict("transform",&t)); 01151 01152 Cmp* c = (Cmp*) ((void*)(*dict)["cmp"]); 01153 double result = c->cmp(tmp,with); 01154 01155 // DELETE AT SOME STAGE, USEFUL FOR PRERELEASE STUFF 01156 // float test_result = (float)result; 01157 // if ( Util::goodf(&test_result) ) { 01158 // cout << "result " << result << " " << x << " " << y << " " << a << endl; 01159 // cout << (float)this_img->get_attr("mean") << " " << (float)tmp->get_attr("mean") << " " << (float)with->get_attr("mean") << endl; 01160 // tmp->write_image("tmp.hdf"); 01161 // with->write_image("with.hdf"); 01162 // this_img->write_image("this_img.hdf"); 01163 // EMData* t = this_img->copy(); 01164 // cout << (float)t->get_attr("mean") << endl; 01165 // t->rotate_translate( t3d ); 01166 // cout << (float)t->get_attr("mean") << endl; 01167 // cout << "exit" << endl; 01169 // cout << (float)t->get_attr("mean") << endl; 01170 // cout << "now exit" << endl; 01171 // delete t; 01172 // } 01173 01174 01175 if ( tmp != 0 ) delete tmp; 01176 01177 return result; 01178 }
|
|
Definition at line 1417 of file aligner.cpp. References EMAN::Cmp::cmp(), phi, EMAN::EMData::process(), EMAN::Transform::set_trans(), t, v, x, and y. 01418 { 01419 Dict *dict = (Dict *) params; 01420 01421 double x = gsl_vector_get(v, 0); 01422 double y = gsl_vector_get(v, 1); 01423 double z = gsl_vector_get(v, 2); 01424 double az = gsl_vector_get(v, 3); 01425 double alt = gsl_vector_get(v, 4); 01426 double phi = gsl_vector_get(v, 5); 01427 EMData *this_img = (*dict)["this"]; 01428 EMData *with = (*dict)["with"]; 01429 //bool mirror = (*dict)["mirror"]; 01430 01431 Dict d("type","eman","az",static_cast<float>(az)); 01432 d["alt"] = static_cast<float>(alt); 01433 d["phi"] = static_cast<float>(phi); 01434 Transform t(d); 01435 t.set_trans((float)x,(float)y,(float)z); 01436 //t.set_mirror(mirror); 01437 EMData *tmp = this_img->process("xform",Dict("transform",&t)); 01438 01439 Cmp* c = (Cmp*) ((void*)(*dict)["cmp"]); 01440 double result = c->cmp(tmp,with); 01441 //cout << result << " x " << x << " y " << y << " z " << z << " az " << az << " alt " << alt << " phi " << phi << endl; 01442 if ( tmp != 0 ) delete tmp; 01443 01444 return result; 01445 }
|
|
Definition at line 1180 of file aligner.cpp. References EMAN::EMData::dot_rotate_translate(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), v, x, and y. 01181 { 01182 Dict *dict = (Dict *) params; 01183 EMData *this_img = (*dict)["this"]; 01184 EMData *img_to = (*dict)["with"]; 01185 bool mirror = (*dict)["mirror"]; 01186 01187 double x = gsl_vector_get(v, 0); 01188 double y = gsl_vector_get(v, 1); 01189 double a = gsl_vector_get(v, 2); 01190 01191 double r = this_img->dot_rotate_translate(img_to, (float)x, (float)y, (float)a, mirror); 01192 int nsec = this_img->get_xsize() * this_img->get_ysize(); 01193 double result = 1.0 - r / nsec; 01194 01195 // cout << result << " x " << x << " y " << y << " az " << a << endl; 01196 return result; 01197 }
|