#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 1716 of file aligner.h.
virtual EMData* EMAN::FRM2DAligner::align | ( | EMData * | this_img, | |
EMData * | to_img | |||
) | const [inline, virtual] |
Implements EMAN::Aligner.
Definition at line 1722 of file aligner.h.
References align().
01723 { 01724 return align(this_img, to_img, "frc", Dict()); 01725 }
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 3047 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().
03049 { 03050 if (!this_img) { 03051 return 0; 03052 } 03053 if (to && !EMUtil::is_same_size(this_img, to)) 03054 throw ImageDimensionException("Images must be the same size to perform translational alignment"); 03055 03056 int nx=this_img->get_xsize(); 03057 int ny=this_img->get_ysize(); 03058 int size =(int)floor(M_PI*ny/4.0); 03059 size =Util::calc_best_fft_size(size);//ming bestfftsize(size); 03060 int MAXR=ny/2; 03061 //int MAXR=size; 03062 EMData *this_temp=this_img->copy(); // ming change avg to to 03063 FloatPoint com_test,com_test1; 03064 com_test=this_temp->calc_center_of_mass();//ming add 03065 float com_this_x=com_test[0]; 03066 float com_this_y=com_test[1]; 03067 delete this_temp; 03068 03069 03070 EMData *that_temp=to->copy(); 03071 com_test1=that_temp->calc_center_of_mass(); 03072 float com_with_x=com_test1[0]; 03073 float com_with_y=com_test1[1]; 03074 delete that_temp; 03075 03076 EMData *avg_frm=to->copy(); 03077 float dx,dy; 03078 //float dx=-(com_with_x-nx/2); //ming 03079 //float dy=-(com_with_y-ny/2); //ming 03080 //avg_frm->translate(dx,dy,0.0); 03081 EMData *withpcs=avg_frm->unwrap_largerR(0,MAXR,size,float(MAXR)); // ming, something wrong inside this subroutine 03082 //EMData *withpcs=avg_frm->unwrap(-1,-1,-1,0,0,1); 03083 EMData *withpcsfft=withpcs->oneDfftPolar(size, float(MAXR), float(MAXR)); 03084 03085 float *sampl_fft=withpcsfft->get_data(); // 03086 delete avg_frm; 03087 delete withpcs; 03088 03089 int bw=size/2; 03090 unsigned long ind1=0, ind2=0, ind3=0, ind4=0, ind41=0; 03091 float pi2=2.0*M_PI, r2; 03092 03093 EMData *data_in=new EMData; 03094 data_in->set_complex(true); 03095 data_in->set_ri(1); 03096 data_in->set_size(2*size,1,1); 03097 float * comp_in=data_in->get_data(); 03098 03099 int p_max=3; 03100 float *frm2dhhat=0; 03101 03102 if( (frm2dhhat=(float *)malloc((p_max+1)*(size+2)*bw*size*2* sizeof(float)))==NULL){ 03103 cout <<"Error in allocating memory 13. \n"; 03104 exit(1); 03105 } 03106 //printf("p_max=%d\n",p_max); 03107 float *sb=0, *cb=0; // sin(beta) and cos(beta) for get h_hat, 300>size 03108 if((sb=new float[size])==NULL||(cb=new float[size])==NULL) { 03109 cout <<"can't allocate more memory, terminating. \n"; 03110 exit(1); 03111 } 03112 for(int i=0;i<size;++i) { // beta sampling, to calculate beta' and r' 03113 float beta=i*M_PI/bw; 03114 sb[i]=sin(beta); 03115 cb[i]=cos(beta); 03116 } 03117 03118 for(int p=0; p<=p_max; ++p){ 03119 ind1=p*size*bw; 03120 float pp2=(float)(p*p); 03121 for(int n=0;n<bw;++n){ /* loop for n */ 03122 ind2=ind1+n; 03123 for(int r=0;r<=MAXR;++r) { 03124 ind3=(ind2+r*bw)*size; 03125 float rr2=(float)(r*r); 03126 float rp2=(float)(r*p); 03127 for(int i=0;i<size;++i){ // beta sampling, to get beta' and r' 03128 r2=std::sqrt((float)(rr2+pp2-2.0*rp2*cb[i])); // r2->r' 03129 int r1=(int)floor(r2+0.5f); // for computing gn(r') 03130 if(r1>MAXR){ 03131 comp_in[2*i]=0.0f; 03132 comp_in[2*i+1]=0.0f; 03133 } 03134 else{ 03135 float gn_r=sampl_fft[2*n+r1*(size+2)]; // real part of gn(r') 03136 float gn_i=sampl_fft[2*n+1+r1*(size+2)]; // imaginary part of gn(r') 03137 float sb2, cb2, cn, sn; 03138 if(n!=0){ 03139 if(r2 != 0.0){ 03140 sb2=r*sb[i]/r2; 03141 cb2=(r*cb[i]-p)/r2; 03142 } 03143 else{ 03144 sb2=0.0; 03145 cb2=1.0; 03146 } 03147 if(sb2>1.0) sb2= 1.0f; 03148 if(sb2<-1.0)sb2=-1.0f; 03149 if(cb2>1.0) cb2= 1.0f; 03150 if(cb2<-1.0)cb2=-1.0f; 03151 float beta2=atan2(sb2,cb2); 03152 if(beta2<0.0) beta2+=pi2; 03153 float nb2=n*beta2; 03154 cn=cos(nb2); 03155 sn=sin(nb2); 03156 } 03157 else{ 03158 cn=1.0f; sn=0.0f; 03159 } 03160 comp_in[2*i]=cn*gn_r-sn*gn_i; 03161 comp_in[2*i+1]=-(cn*gn_i+sn*gn_r); 03162 } 03163 } 03164 EMData *data_out; 03165 data_out=data_in->do_fft(); 03166 float * comp_out=data_out->get_data(); 03167 for(int m=0;m<size;m++){ // store hat{h(n,r,p)}(m) 03168 ind4=(ind3+m)*2; 03169 ind41=ind4+1; 03170 frm2dhhat[ind4]=comp_out[2*m]; 03171 frm2dhhat[ind41]=comp_out[2*m+1]; 03172 } 03173 delete data_out; 03174 } 03175 } 03176 } 03177 03178 delete[] sb; 03179 delete[] cb; 03180 delete data_in; 03181 delete withpcsfft; 03182 03183 float dot_frm0=0.0f, dot_frm1=0.0f; 03184 EMData *da_nFlip=0, *da_yFlip=0, *dr_frm=0; 03185 //dr_frm=this_img->copy(); 03186 for (int iFlip=0;iFlip<=1;++iFlip){ 03187 if (iFlip==0){dr_frm=this_img->copy(); da_nFlip=this_img->copy();} 03188 else {dr_frm=this_img->copy(); da_yFlip=this_img->copy();} 03189 if(iFlip==1) {com_this_x=nx-com_this_x; } //ming // image mirror about Y axis, so y keeps the same 03190 03191 dx=-(com_this_x-nx/2); //ming 03192 dy=-(com_this_y-ny/2); //ming 03193 dr_frm->translate(dx,dy,0.0); // this 03194 EMData *selfpcs = dr_frm->unwrap_largerR(0,MAXR,size, (float)MAXR); 03195 //EMData *selfpcs=dr_frm->unwrap(-1,-1,-1,0,0,1); 03196 EMData *selfpcsfft = selfpcs->oneDfftPolar(size, (float)MAXR, (float)MAXR); 03197 delete selfpcs; 03198 delete dr_frm; 03199 if(iFlip==0) 03200 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); 03201 else 03202 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); 03203 delete selfpcsfft; 03204 } 03205 03206 delete[] frm2dhhat; 03207 if(dot_frm0 <=dot_frm1) { 03208 #ifdef DEBUG 03209 printf("best_corre=%f, no flip\n",dot_frm0); 03210 #endif 03211 delete da_yFlip; 03212 return da_nFlip; 03213 } 03214 else { 03215 #ifdef DEBUG 03216 printf("best_corre=%f, flipped\n",dot_frm1); 03217 #endif 03218 delete da_nFlip; 03219 return da_yFlip; 03220 } 03221 }
string EMAN::FRM2DAligner::get_desc | ( | ) | const [inline, virtual] |
Implements EMAN::Aligner.
Definition at line 1732 of file aligner.h.
01733 { 01734 return "FRM2D uses two rotational parameters and one translational parameter"; 01735 }
string EMAN::FRM2DAligner::get_name | ( | ) | const [inline, virtual] |
virtual TypeDict EMAN::FRM2DAligner::get_param_types | ( | ) | const [inline, virtual] |
Implements EMAN::Aligner.
Definition at line 1741 of file aligner.h.
References EMAN::EMObject::INT, and EMAN::TypeDict::put().
01742 { 01743 TypeDict d; 01744 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."); 01745 01746 //d.put("p_max", EMObject::FLOAT,"p_max is"); 01747 return d; 01748 }
static Aligner* EMAN::FRM2DAligner::NEW | ( | ) | [inline, static] |
const string FRM2DAligner::NAME = "frm2d" [static] |