Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

EMAN::FRM2DAligner Class Reference

#include <aligner.h>

Inheritance diagram for EMAN::FRM2DAligner:

Inheritance graph
[legend]
Collaboration diagram for EMAN::FRM2DAligner:

Collaboration graph
[legend]
List of all members.

Public Member Functions

virtual EMDataalign (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 EMDataalign (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

AlignerNEW ()

Static Public Attributes

const string NAME = "frm2d"

Member Function Documentation

virtual EMData* EMAN::FRM2DAligner::align EMData this_img,
EMData to_img
const [inline, virtual]
 

Implements EMAN::Aligner.

Definition at line 1182 of file aligner.h.

References align().

01183                                         {
01184                                                 return align(this_img, to_img, "frc", Dict());
01185                                         }

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.

Parameters:
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.
Returns:
The aligned image.

Implements EMAN::Aligner.

Definition at line 2354 of file aligner.cpp.

References EMAN::EMData::calc_center_of_mass(), EMAN::EMData::copy(), EMAN::EMData::do_fft(), frm_2d_Align(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), ImageDimensionException, nx, ny, EMAN::EMData::oneDfftPolar(), EMAN::EMData::set_complex(), EMAN::EMData::set_ri(), EMAN::EMData::set_size(), sqrt(), EMAN::EMData::translate(), and EMAN::EMData::unwrap_largerR().

02356 {
02357         if (!this_img) {
02358                 return 0;
02359         }
02360         if (to && !EMUtil::is_same_size(this_img, to))
02361                 throw ImageDimensionException("Images must be the same size to perform translational alignment");
02362 
02363         int nx=this_img->get_xsize();
02364         int ny=this_img->get_ysize();
02365         int size =(int)floor(M_PI*ny/4.0);
02366         size =Util::calc_best_fft_size(size);//ming   bestfftsize(size);
02367         int MAXR=ny/2;
02368         //int MAXR=size;
02369         EMData *this_temp=this_img->copy(); // ming change avg to to
02370         FloatPoint com_test,com_test1;
02371         com_test=this_temp->calc_center_of_mass();//ming add
02372         float com_this_x=com_test[0];
02373         float com_this_y=com_test[1];
02374         delete this_temp;
02375 
02376 
02377         EMData *that_temp=to->copy();
02378         com_test1=that_temp->calc_center_of_mass();
02379         float com_with_x=com_test1[0];
02380         float com_with_y=com_test1[1];
02381         delete that_temp;
02382 
02383         EMData *avg_frm=to->copy();
02384         float dx,dy;
02385         //float dx=-(com_with_x-nx/2); //ming
02386         //float dy=-(com_with_y-ny/2); //ming
02387         //avg_frm->translate(dx,dy,0.0);
02388         EMData *withpcs=avg_frm->unwrap_largerR(0,MAXR,size,float(MAXR)); // ming, something wrong inside this subroutine
02389         //EMData *withpcs=avg_frm->unwrap(-1,-1,-1,0,0,1);
02390         EMData *withpcsfft=withpcs->oneDfftPolar(size, float(MAXR), float(MAXR));
02391 
02392         float *sampl_fft=withpcsfft->get_data(); //
02393         delete avg_frm;
02394         delete withpcs;
02395 
02396         int bw=size/2;
02397         unsigned long ind1=0, ind2=0, ind3=0, ind4=0, ind41=0;
02398         float pi2=2.0*M_PI, r2;
02399 
02400         EMData *data_in=new EMData;
02401         data_in->set_complex(true);
02402         data_in->set_ri(1);
02403         data_in->set_size(2*size,1,1);
02404         float * comp_in=data_in->get_data();
02405 
02406         int p_max=3;
02407         float *frm2dhhat=0;
02408 
02409         if( (frm2dhhat=(float *)malloc((p_max+1)*(size+2)*bw*size*2* sizeof(float)))==NULL){
02410                 cout <<"Error in allocating memory 13. \n";
02411                 exit(1);
02412         }
02413         //printf("p_max=%d\n",p_max);
02414         float *sb=0, *cb=0;             // sin(beta) and cos(beta) for get h_hat, 300>size
02415         if((sb=new float[size])==NULL||(cb=new float[size])==NULL) {
02416                 cout <<"can't allocate more memory, terminating. \n";
02417                 exit(1);
02418         }
02419         for(int i=0;i<size;++i) {        // beta sampling, to calculate beta' and r'
02420                 float beta=i*M_PI/bw;
02421                 sb[i]=sin(beta);
02422                 cb[i]=cos(beta);
02423         }
02424 
02425         for(int p=0; p<=p_max; ++p){
02426                 ind1=p*size*bw;
02427         float pp2=(float)(p*p);
02428                 for(int n=0;n<bw;++n){         /* loop for n */
02429                 ind2=ind1+n;
02430                 for(int r=0;r<=MAXR;++r) {
02431                                 ind3=(ind2+r*bw)*size;
02432                         float rr2=(float)(r*r);
02433                                 float rp2=(float)(r*p);
02434                         for(int i=0;i<size;++i){                            // beta sampling, to get beta' and r'
02435                                 r2=std::sqrt((float)(rr2+pp2-2.0*rp2*cb[i]));   // r2->r'
02436                                 int r1=(int)floor(r2+0.5f);                        // for computing gn(r')
02437                                 if(r1>MAXR){
02438                                         comp_in[2*i]=0.0f;
02439                                         comp_in[2*i+1]=0.0f;
02440                                 }
02441                                 else{
02442                                         float gn_r=sampl_fft[2*n+r1*(size+2)];           // real part of gn(r')
02443                                         float gn_i=sampl_fft[2*n+1+r1*(size+2)];           // imaginary part of gn(r')
02444                                                 float sb2, cb2, cn, sn;
02445                                                 if(n!=0){
02446                                                         if(r2 != 0.0){
02447                                                                 sb2=r*sb[i]/r2;
02448                                                                 cb2=(r*cb[i]-p)/r2;
02449                                                         }
02450                                                 else{
02451                                                                 sb2=0.0;
02452                                                                 cb2=1.0;
02453                                                         }
02454                                                 if(sb2>1.0) sb2= 1.0f;
02455                                                 if(sb2<-1.0)sb2=-1.0f;
02456                                                 if(cb2>1.0) cb2= 1.0f;
02457                                                 if(cb2<-1.0)cb2=-1.0f;
02458                                                 float beta2=atan2(sb2,cb2);
02459                                                 if(beta2<0.0) beta2+=pi2;
02460                                                 float nb2=n*beta2;
02461                                                 cn=cos(nb2);
02462                                                         sn=sin(nb2);
02463                                                 }
02464                                         else{
02465                                                         cn=1.0f; sn=0.0f;
02466                                                 }
02467                                                 comp_in[2*i]=cn*gn_r-sn*gn_i;
02468                                                 comp_in[2*i+1]=-(cn*gn_i+sn*gn_r);
02469                                 }
02470                         }
02471                         EMData *data_out;
02472                         data_out=data_in->do_fft();
02473                         float * comp_out=data_out->get_data();
02474                         for(int m=0;m<size;m++){                                     // store hat{h(n,r,p)}(m)
02475                                         ind4=(ind3+m)*2;
02476                                         ind41=ind4+1;
02477                                         frm2dhhat[ind4]=comp_out[2*m];
02478                                         frm2dhhat[ind41]=comp_out[2*m+1];
02479                                 }
02480                         delete data_out;
02481                         }
02482                 }
02483         }
02484 
02485         delete[] sb;
02486         delete[] cb;
02487         delete data_in;
02488         delete withpcsfft;
02489 
02490         float dot_frm0=0.0f, dot_frm1=0.0f;
02491         EMData *da_nFlip=0, *da_yFlip=0, *dr_frm=0;
02492         //dr_frm=this_img->copy();
02493         for (int iFlip=0;iFlip<=1;++iFlip){
02494                 if (iFlip==0){dr_frm=this_img->copy();  da_nFlip=this_img->copy();}
02495                 else {dr_frm=this_img->copy(); da_yFlip=this_img->copy();}
02496                 if(iFlip==1) {com_this_x=nx-com_this_x; } //ming   // image mirror about Y axis, so y keeps the same
02497 
02498                 dx=-(com_this_x-nx/2); //ming
02499                 dy=-(com_this_y-ny/2); //ming
02500                 dr_frm->translate(dx,dy,0.0); // this
02501                 EMData *selfpcs = dr_frm->unwrap_largerR(0,MAXR,size, (float)MAXR);
02502                 //EMData *selfpcs=dr_frm->unwrap(-1,-1,-1,0,0,1);
02503                 EMData *selfpcsfft = selfpcs->oneDfftPolar(size, (float)MAXR, (float)MAXR);
02504                 delete selfpcs;
02505                 delete dr_frm;
02506                 if(iFlip==0)
02507                         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);
02508                 else
02509                         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);
02510                 delete selfpcsfft;
02511         }
02512 
02513         delete[] frm2dhhat;
02514         if(dot_frm0 <=dot_frm1) {
02515 #ifdef DEBUG
02516                 printf("best_corre=%f, no flip\n",dot_frm0);
02517 #endif
02518                 delete da_yFlip;
02519                 return da_nFlip;
02520         }
02521         else {
02522 #ifdef DEBUG
02523                 printf("best_corre=%f, flipped\n",dot_frm1);
02524 #endif
02525                 delete da_nFlip;
02526                 return da_yFlip;
02527         }
02528 }

string EMAN::FRM2DAligner::get_desc  )  const [inline, virtual]
 

Implements EMAN::Aligner.

Definition at line 1192 of file aligner.h.

01193                                         {
01194                                                 return "FRM2D uses two rotational parameters and one translational parameter";
01195                                         }

string EMAN::FRM2DAligner::get_name  )  const [inline, virtual]
 

Get the Aligner's name.

Each Aligner is identified by a unique name.

Returns:
The Aligner's name.

Implements EMAN::Aligner.

Definition at line 1187 of file aligner.h.

01188                                         {
01189                                                 return NAME;
01190                                         }

virtual TypeDict EMAN::FRM2DAligner::get_param_types  )  const [inline, virtual]
 

Implements EMAN::Aligner.

Definition at line 1201 of file aligner.h.

References EMAN::TypeDict::put().

01202                                         {
01203                                                         TypeDict d;
01204                                                         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.");
01205 
01206                                                         //d.put("p_max", EMObject::FLOAT,"p_max is");
01207                                                         return d;
01208                                         }

Aligner* EMAN::FRM2DAligner::NEW  )  [inline, static]
 

Definition at line 1197 of file aligner.h.

01198                                         {
01199                                                 return new FRM2DAligner();
01200                                         }


Member Data Documentation

const string FRM2DAligner::NAME = "frm2d" [static]
 

Definition at line 78 of file aligner.cpp.


The documentation for this class was generated from the following files:
Generated on Mon Mar 7 18:16:48 2011 for EMAN2 by  doxygen 1.3.9.1