#include <aligner.h>
Inheritance diagram for EMAN::FRM2DAligner:
Public Member Functions | |
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. | |
virtual EMData * | align (EMData *this_img, EMData *to_img) const |
string | get_name () const |
Get the Aligner's name. | |
string | get_desc () const |
virtual TypeDict | get_param_types () const |
Static Public Member Functions | |
static Aligner * | NEW () |
Static Public Attributes | |
static const string | NAME = "frm2d" |
Definition at line 1650 of file aligner.h.
virtual EMData* EMAN::FRM2DAligner::align | ( | EMData * | this_img, | |
EMData * | to_img | |||
) | const [inline, virtual] |
Implements EMAN::Aligner.
Definition at line 1656 of file aligner.h.
References align().
01657 { 01658 return align(this_img, to_img, "frc", Dict()); 01659 }
EMData * FRM2DAligner::align | ( | EMData * | this_img, | |
EMData * | to_img, | |||
const string & | cmp_name, | |||
const Dict & | cmp_params = Dict() | |||
) | const [virtual] |
To align 'this_img' with another image passed in through its parameters.
The alignment uses a user-given comparison method to compare the two images. If none is given, a default one is used.
this_img | The image to be compared. | |
to_img | 'this_img" is aligned with 'to_img'. | |
cmp_name | The comparison method to compare the two images. | |
cmp_params | The parameter dictionary for comparison method. |
Implements EMAN::Aligner.
Definition at line 2888 of file aligner.cpp.
References EMAN::Util::calc_best_fft_size(), EMAN::EMData::calc_center_of_mass(), EMAN::EMData::copy(), EMAN::EMData::do_fft(), frm_2d_Align(), EMAN::EMData::get_data(), ImageDimensionException, EMAN::EMUtil::is_same_size(), nx, EMAN::EMData::oneDfftPolar(), EMAN::EMData::set_complex(), EMAN::EMData::set_ri(), EMAN::EMData::set_size(), sqrt(), EMAN::EMData::translate(), and EMAN::EMData::unwrap_largerR().
Referenced by align().
02890 { 02891 if (!this_img) { 02892 return 0; 02893 } 02894 if (to && !EMUtil::is_same_size(this_img, to)) 02895 throw ImageDimensionException("Images must be the same size to perform translational alignment"); 02896 02897 int nx=this_img->get_xsize(); 02898 int ny=this_img->get_ysize(); 02899 int size =(int)floor(M_PI*ny/4.0); 02900 size =Util::calc_best_fft_size(size);//ming bestfftsize(size); 02901 int MAXR=ny/2; 02902 //int MAXR=size; 02903 EMData *this_temp=this_img->copy(); // ming change avg to to 02904 FloatPoint com_test,com_test1; 02905 com_test=this_temp->calc_center_of_mass();//ming add 02906 float com_this_x=com_test[0]; 02907 float com_this_y=com_test[1]; 02908 delete this_temp; 02909 02910 02911 EMData *that_temp=to->copy(); 02912 com_test1=that_temp->calc_center_of_mass(); 02913 float com_with_x=com_test1[0]; 02914 float com_with_y=com_test1[1]; 02915 delete that_temp; 02916 02917 EMData *avg_frm=to->copy(); 02918 float dx,dy; 02919 //float dx=-(com_with_x-nx/2); //ming 02920 //float dy=-(com_with_y-ny/2); //ming 02921 //avg_frm->translate(dx,dy,0.0); 02922 EMData *withpcs=avg_frm->unwrap_largerR(0,MAXR,size,float(MAXR)); // ming, something wrong inside this subroutine 02923 //EMData *withpcs=avg_frm->unwrap(-1,-1,-1,0,0,1); 02924 EMData *withpcsfft=withpcs->oneDfftPolar(size, float(MAXR), float(MAXR)); 02925 02926 float *sampl_fft=withpcsfft->get_data(); // 02927 delete avg_frm; 02928 delete withpcs; 02929 02930 int bw=size/2; 02931 unsigned long ind1=0, ind2=0, ind3=0, ind4=0, ind41=0; 02932 float pi2=2.0*M_PI, r2; 02933 02934 EMData *data_in=new EMData; 02935 data_in->set_complex(true); 02936 data_in->set_ri(1); 02937 data_in->set_size(2*size,1,1); 02938 float * comp_in=data_in->get_data(); 02939 02940 int p_max=3; 02941 float *frm2dhhat=0; 02942 02943 if( (frm2dhhat=(float *)malloc((p_max+1)*(size+2)*bw*size*2* sizeof(float)))==NULL){ 02944 cout <<"Error in allocating memory 13. \n"; 02945 exit(1); 02946 } 02947 //printf("p_max=%d\n",p_max); 02948 float *sb=0, *cb=0; // sin(beta) and cos(beta) for get h_hat, 300>size 02949 if((sb=new float[size])==NULL||(cb=new float[size])==NULL) { 02950 cout <<"can't allocate more memory, terminating. \n"; 02951 exit(1); 02952 } 02953 for(int i=0;i<size;++i) { // beta sampling, to calculate beta' and r' 02954 float beta=i*M_PI/bw; 02955 sb[i]=sin(beta); 02956 cb[i]=cos(beta); 02957 } 02958 02959 for(int p=0; p<=p_max; ++p){ 02960 ind1=p*size*bw; 02961 float pp2=(float)(p*p); 02962 for(int n=0;n<bw;++n){ /* loop for n */ 02963 ind2=ind1+n; 02964 for(int r=0;r<=MAXR;++r) { 02965 ind3=(ind2+r*bw)*size; 02966 float rr2=(float)(r*r); 02967 float rp2=(float)(r*p); 02968 for(int i=0;i<size;++i){ // beta sampling, to get beta' and r' 02969 r2=std::sqrt((float)(rr2+pp2-2.0*rp2*cb[i])); // r2->r' 02970 int r1=(int)floor(r2+0.5f); // for computing gn(r') 02971 if(r1>MAXR){ 02972 comp_in[2*i]=0.0f; 02973 comp_in[2*i+1]=0.0f; 02974 } 02975 else{ 02976 float gn_r=sampl_fft[2*n+r1*(size+2)]; // real part of gn(r') 02977 float gn_i=sampl_fft[2*n+1+r1*(size+2)]; // imaginary part of gn(r') 02978 float sb2, cb2, cn, sn; 02979 if(n!=0){ 02980 if(r2 != 0.0){ 02981 sb2=r*sb[i]/r2; 02982 cb2=(r*cb[i]-p)/r2; 02983 } 02984 else{ 02985 sb2=0.0; 02986 cb2=1.0; 02987 } 02988 if(sb2>1.0) sb2= 1.0f; 02989 if(sb2<-1.0)sb2=-1.0f; 02990 if(cb2>1.0) cb2= 1.0f; 02991 if(cb2<-1.0)cb2=-1.0f; 02992 float beta2=atan2(sb2,cb2); 02993 if(beta2<0.0) beta2+=pi2; 02994 float nb2=n*beta2; 02995 cn=cos(nb2); 02996 sn=sin(nb2); 02997 } 02998 else{ 02999 cn=1.0f; sn=0.0f; 03000 } 03001 comp_in[2*i]=cn*gn_r-sn*gn_i; 03002 comp_in[2*i+1]=-(cn*gn_i+sn*gn_r); 03003 } 03004 } 03005 EMData *data_out; 03006 data_out=data_in->do_fft(); 03007 float * comp_out=data_out->get_data(); 03008 for(int m=0;m<size;m++){ // store hat{h(n,r,p)}(m) 03009 ind4=(ind3+m)*2; 03010 ind41=ind4+1; 03011 frm2dhhat[ind4]=comp_out[2*m]; 03012 frm2dhhat[ind41]=comp_out[2*m+1]; 03013 } 03014 delete data_out; 03015 } 03016 } 03017 } 03018 03019 delete[] sb; 03020 delete[] cb; 03021 delete data_in; 03022 delete withpcsfft; 03023 03024 float dot_frm0=0.0f, dot_frm1=0.0f; 03025 EMData *da_nFlip=0, *da_yFlip=0, *dr_frm=0; 03026 //dr_frm=this_img->copy(); 03027 for (int iFlip=0;iFlip<=1;++iFlip){ 03028 if (iFlip==0){dr_frm=this_img->copy(); da_nFlip=this_img->copy();} 03029 else {dr_frm=this_img->copy(); da_yFlip=this_img->copy();} 03030 if(iFlip==1) {com_this_x=nx-com_this_x; } //ming // image mirror about Y axis, so y keeps the same 03031 03032 dx=-(com_this_x-nx/2); //ming 03033 dy=-(com_this_y-ny/2); //ming 03034 dr_frm->translate(dx,dy,0.0); // this 03035 EMData *selfpcs = dr_frm->unwrap_largerR(0,MAXR,size, (float)MAXR); 03036 //EMData *selfpcs=dr_frm->unwrap(-1,-1,-1,0,0,1); 03037 EMData *selfpcsfft = selfpcs->oneDfftPolar(size, (float)MAXR, (float)MAXR); 03038 delete selfpcs; 03039 delete dr_frm; 03040 if(iFlip==0) 03041 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); 03042 else 03043 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); 03044 delete selfpcsfft; 03045 } 03046 03047 delete[] frm2dhhat; 03048 if(dot_frm0 <=dot_frm1) { 03049 #ifdef DEBUG 03050 printf("best_corre=%f, no flip\n",dot_frm0); 03051 #endif 03052 delete da_yFlip; 03053 return da_nFlip; 03054 } 03055 else { 03056 #ifdef DEBUG 03057 printf("best_corre=%f, flipped\n",dot_frm1); 03058 #endif 03059 delete da_nFlip; 03060 return da_yFlip; 03061 } 03062 }
string EMAN::FRM2DAligner::get_desc | ( | ) | const [inline, virtual] |
Implements EMAN::Aligner.
Definition at line 1666 of file aligner.h.
01667 { 01668 return "FRM2D uses two rotational parameters and one translational parameter"; 01669 }
string EMAN::FRM2DAligner::get_name | ( | ) | const [inline, virtual] |
virtual TypeDict EMAN::FRM2DAligner::get_param_types | ( | ) | const [inline, virtual] |
Implements EMAN::Aligner.
Definition at line 1675 of file aligner.h.
References EMAN::EMObject::INT, and EMAN::TypeDict::put().
01676 { 01677 TypeDict d; 01678 d.put("maxshift", EMObject::INT,"Maximum translation in pixels in any direction. If the solution yields a shift beyond this value in any direction, then the refinement is judged a failure and the original alignment is used as the solution."); 01679 01680 //d.put("p_max", EMObject::FLOAT,"p_max is"); 01681 return d; 01682 }
static Aligner* EMAN::FRM2DAligner::NEW | ( | ) | [inline, static] |
const string FRM2DAligner::NAME = "frm2d" [static] |