#include <aligner.h>
Inheritance diagram for EMAN::RotateTranslateFlipAlignerPawel:
Public Member Functions | |
virtual EMData * | align (EMData *this_img, EMData *to_img, const string &cmp_name="dot", 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 |
virtual string | get_name () const |
Get the Aligner's name. | |
virtual string | get_desc () const |
virtual TypeDict | get_param_types () const |
Static Public Member Functions | |
static Aligner * | NEW () |
Static Public Attributes | |
static const string | NAME = "rotate_translate_flip_resample" |
translation if found by varing to origin using for polar coordinate resampling in real space
tx | maximum transltion in x direction, must by less than (n/2 - 1 - r2) | |
tu | maximum transltion in y direction, must by less than (n/2 - 1 - r2) | |
r1 | inner ring | |
r2 | outer ring |
Definition at line 1032 of file aligner.h.
virtual EMData* EMAN::RotateTranslateFlipAlignerPawel::align | ( | EMData * | this_img, | |
EMData * | to_img | |||
) | const [inline, virtual] |
Implements EMAN::Aligner.
Definition at line 1038 of file aligner.h.
References align().
01039 { 01040 return align(this_img, to_img, "sqeuclidean", Dict()); 01041 }
EMData * RotateTranslateFlipAlignerPawel::align | ( | EMData * | this_img, | |
EMData * | to_img, | |||
const string & | cmp_name = "dot" , |
|||
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 915 of file aligner.cpp.
References EMAN::EMData::calc_ccfx(), data, EMAN::Util::find_max(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), InvalidParameterException, EMAN::Aligner::params, EMAN::EMData::process(), EMAN::EMData::process_inplace(), EMAN::EMData::set_attr(), EMAN::Dict::set_default(), EMAN::EMData::unwrap(), x, and y.
Referenced by align().
00917 { 00918 if (cmp_name != "dot" && cmp_name != "ccc") throw InvalidParameterException("Resample aligner only works for dot and ccc"); 00919 00920 int maxtx = params.set_default("tx", 0); 00921 int maxty = params.set_default("ty", 0); 00922 int r1 = params.set_default("r1",-1); 00923 int r2 = params.set_default("r2",-1); 00924 00925 if(this_img->get_xsize()/2 - 1 - r2 - maxtx <= 0 || (r2 == -1 && maxtx > 0)){ 00926 cout << "\nRunTimeError: nx/2 - 1 - r2 - tx must be greater than or = 0\n" << endl; // For some reason the expection message is not being print, stupid C++ 00927 throw InvalidParameterException("nx/2 - 1 - r2 - tx must be greater than or = 0"); 00928 } 00929 if(this_img->get_ysize()/2 - 1 - r2 - maxty <= 0 || (r2 == -1 && maxty > 0)){ 00930 cout << "\nRunTimeError:ny/2 - 1 - r2 - ty must be greater than or = 0\n" << endl; // For some reason the expection message is not being print, stupid C++ 00931 throw InvalidParameterException("ny/2 - 1 - r2 - ty must be greater than or = 0"); 00932 } 00933 00934 // float best_peak = -numeric_limits<float>::infinity(); 00935 float best_peak = -1.0e37; 00936 int best_peak_index = 0; 00937 int best_tx = 0; 00938 int best_ty = 0; 00939 int polarxsize = 0; 00940 bool flip = false; 00941 00942 for(int x = -maxtx; x <= maxtx; x++){ 00943 for(int y = -maxty; y <= maxty; y++){ 00944 00945 EMData * to_polar = to->unwrap(r1,r2,-1,0,0,true); 00946 EMData * this_img_polar = this_img->unwrap(r1,r2,-1,x,y,true); 00947 EMData * cfflip = this_img_polar->calc_ccfx(to_polar, 0, this_img_polar->get_ysize(), false, true); 00948 EMData * cf = this_img_polar->calc_ccfx(to_polar, 0, this_img_polar->get_ysize()); 00949 00950 polarxsize = this_img_polar->get_xsize(); 00951 00952 //take out the garbage 00953 delete to_polar; to_polar = 0; 00954 delete this_img_polar; this_img_polar = 0; 00955 00956 float *data = cf->get_data(); 00957 float peak = 0; 00958 int peak_index = 0; 00959 Util::find_max(data, polarxsize, &peak, &peak_index); 00960 delete cf; cf = 0; 00961 00962 if(peak > best_peak) { 00963 best_peak = peak; 00964 best_peak_index = peak_index; 00965 best_tx = x; 00966 best_ty = y; 00967 flip = false; 00968 } 00969 00970 data = cfflip->get_data(); 00971 Util::find_max(data, polarxsize, &peak, &peak_index); 00972 delete cfflip; cfflip = 0; 00973 00974 if(peak > best_peak) { 00975 best_peak = peak; 00976 best_peak_index = peak_index; 00977 best_tx = x; 00978 best_ty = y; 00979 flip = true; 00980 } 00981 } 00982 } 00983 00984 float rot_angle = (float) (best_peak_index * 360.0f / polarxsize); 00985 00986 //return the result 00987 Transform tmptt(Dict("type","2d","alpha",0,"tx",-best_tx,"ty",-best_ty)); 00988 Transform tmprot(Dict("type","2d","alpha",rot_angle,"tx",0,"ty",0)); 00989 Transform total = tmprot*tmptt; 00990 EMData * rotimg=this_img->process("xform",Dict("transform",(Transform*)&total)); 00991 rotimg->set_attr("xform.align2d",&total); 00992 if(flip == true) { 00993 rotimg->process_inplace("xform.flip",Dict("axis", "x")); 00994 } 00995 00996 return rotimg; 00997 00998 }
virtual string EMAN::RotateTranslateFlipAlignerPawel::get_desc | ( | ) | const [inline, virtual] |
Implements EMAN::Aligner.
Definition at line 1048 of file aligner.h.
01049 { 01050 return "Performs rotational alignment, translation align, and flip by resampling to polar coordinates in real space."; 01051 }
virtual string EMAN::RotateTranslateFlipAlignerPawel::get_name | ( | ) | const [inline, virtual] |
virtual TypeDict EMAN::RotateTranslateFlipAlignerPawel::get_param_types | ( | ) | const [inline, virtual] |
Implements EMAN::Aligner.
Definition at line 1058 of file aligner.h.
References EMAN::EMObject::INT, and EMAN::TypeDict::put().
01059 { 01060 TypeDict d; 01061 //d.put("usedot", EMObject::INT); 01062 d.put("tx", EMObject::INT, "Maximum x translation in pixels, Default = 0"); 01063 d.put("ty", EMObject::INT, "Maximum y translation in pixels, Default = 0"); 01064 d.put("r1", EMObject::INT, "Inner ring, pixels"); 01065 d.put("r2", EMObject::INT, "Outer ring, pixels"); 01066 return d; 01067 }
static Aligner* EMAN::RotateTranslateFlipAlignerPawel::NEW | ( | ) | [inline, static] |
const string RotateTranslateFlipAlignerPawel::NAME = "rotate_translate_flip_resample" [static] |