#include <aligner.h>
Inheritance diagram for EMAN::TranslationalAligner:
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 = "translational" |
It calculates the shift for a translational alignment, then do the translation.
intonly | Integer pixel translations only | |
maxshift | Maximum translation in pixels | |
nozero | Zero translation not permitted (useful for CCD images) |
Definition at line 173 of file aligner.h.
virtual EMData* EMAN::TranslationalAligner::align | ( | EMData * | this_img, | |
EMData * | to_img | |||
) | const [inline, virtual] |
Implements EMAN::Aligner.
Definition at line 179 of file aligner.h.
References align().
00180 { 00181 return align(this_img, to_img, "", Dict()); 00182 }
EMData * TranslationalAligner::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 94 of file aligner.cpp.
References EMAN::EMData::calc_ccf(), EMAN::EMData::calc_flcf(), EMAN::EMData::calc_max_location_wrap(), calc_max_location_wrap_cuda(), EMAN::EMData::get_data(), ImageDimensionException, EMAN::EMUtil::is_same_size(), nx, ny, EMAN::Aligner::params, EMAN::EMData::process(), EMAN::EMData::process_inplace(), EMAN::EMData::set_attr(), EMAN::Dict::set_default(), t, EMAN::EMData::update(), and EMAN::EMData::zero_corner_circulant().
Referenced by align().
00096 { 00097 if (!this_img) { 00098 return 0; 00099 } 00100 00101 if (to && !EMUtil::is_same_size(this_img, to)) 00102 throw ImageDimensionException("Images must be the same size to perform translational alignment"); 00103 00104 EMData *cf = 0; 00105 int nx = this_img->get_xsize(); 00106 int ny = this_img->get_ysize(); 00107 int nz = this_img->get_zsize(); 00108 00109 int masked = params.set_default("masked",0); 00110 int useflcf = params.set_default("useflcf",0); 00111 bool use_cpu = true; 00112 #ifdef EMAN2_USING_CUDA 00113 if (this_img->gpu_operation_preferred() ) { 00114 // cout << "Translate on GPU" << endl; 00115 use_cpu = false; 00116 cf = this_img->calc_ccf_cuda(to,false,false); 00117 } 00118 #endif // EMAN2_USING_CUDA 00119 if (use_cpu) { 00120 if (useflcf) cf = this_img->calc_flcf(to); 00121 else cf = this_img->calc_ccf(to); 00122 } 00123 00124 // This is too expensive 00125 if (masked) { 00126 EMData *msk=this_img->process("threshold.notzero"); 00127 EMData *sqr=to->process("math.squared"); 00128 EMData *cfn=msk->calc_ccf(sqr); 00129 cfn->process_inplace("math.sqrt"); 00130 float *d1=cf->get_data(); 00131 float *d2=cfn->get_data(); 00132 for (int i=0; i<nx*ny*nz; i++) { 00133 if (d2[i]!=0) d1[i]/=d2[i]; 00134 } 00135 cf->update(); 00136 delete msk; 00137 delete sqr; 00138 delete cfn; 00139 } 00140 00141 // 00142 00143 int maxshiftx = params.set_default("maxshift",-1); 00144 int maxshifty = params["maxshift"]; 00145 int maxshiftz = params["maxshift"]; 00146 int nozero = params["nozero"]; 00147 00148 if (maxshiftx <= 0) { 00149 maxshiftx = nx / 4; 00150 maxshifty = ny / 4; 00151 maxshiftz = nz / 4; 00152 } 00153 00154 if (maxshiftx > nx / 2 - 1) maxshiftx = nx / 2 - 1; 00155 if (maxshifty > ny / 2 - 1) maxshifty = ny / 2 - 1; 00156 if (maxshiftz > nz / 2 - 1) maxshiftz = nz / 2 - 1; 00157 00158 if (nx == 1) maxshiftx = 0; // This is justhere for completeness really... plus it saves errors 00159 if (ny == 1) maxshifty = 0; 00160 if (nz == 1) maxshiftz = 0; 00161 00162 // If nozero the portion of the image in the center (and its 8-connected neighborhood) is zeroed 00163 if (nozero) { 00164 cf->zero_corner_circulant(1); 00165 } 00166 00167 IntPoint peak; 00168 #ifdef EMAN2_USING_CUDA 00169 if (!use_cpu) { 00170 EMDataForCuda tmp = cf->get_data_struct_for_cuda(); 00171 int* p = calc_max_location_wrap_cuda(&tmp,maxshiftx, maxshifty, maxshiftz); 00172 peak = IntPoint(p[0],p[1],p[2]); 00173 free(p); 00174 } 00175 #endif // EMAN2_USING_CUDA 00176 if (use_cpu) { 00177 peak = cf->calc_max_location_wrap(maxshiftx, maxshifty, maxshiftz); 00178 } 00179 Vec3f cur_trans = Vec3f ( (float)-peak[0], (float)-peak[1], (float)-peak[2]); 00180 00181 if (!to) { 00182 cur_trans /= 2.0f; // If aligning theimage to itself then only go half way - 00183 int intonly = params.set_default("intonly",false); 00184 if (intonly) { 00185 cur_trans[0] = floor(cur_trans[0] + 0.5f); 00186 cur_trans[1] = floor(cur_trans[1] + 0.5f); 00187 cur_trans[2] = floor(cur_trans[2] + 0.5f); 00188 } 00189 } 00190 00191 if( cf ){ 00192 delete cf; 00193 cf = 0; 00194 } 00195 Dict params("trans",static_cast< vector<int> >(cur_trans)); 00196 cf=this_img->process("math.translate.int",params); 00197 Transform t; 00198 t.set_trans(cur_trans); 00199 if ( nz != 1 ) { 00200 // Transform* t = get_set_align_attr("xform.align3d",cf,this_img); 00201 // t->set_trans(cur_trans); 00202 cf->set_attr("xform.align3d",&t); 00203 } else if ( ny != 1 ) { 00204 //Transform* t = get_set_align_attr("xform.align2d",cf,this_img); 00205 cur_trans[2] = 0; // just make sure of it 00206 t.set_trans(cur_trans); 00207 cf->set_attr("xform.align2d",&t); 00208 } 00209 00210 return cf; 00211 }
virtual string EMAN::TranslationalAligner::get_desc | ( | ) | const [inline, virtual] |
virtual string EMAN::TranslationalAligner::get_name | ( | ) | const [inline, virtual] |
virtual TypeDict EMAN::TranslationalAligner::get_param_types | ( | ) | const [inline, virtual] |
Implements EMAN::Aligner.
Definition at line 199 of file aligner.h.
References EMAN::EMObject::INT, and EMAN::TypeDict::put().
00200 { 00201 TypeDict d; 00202 d.put("intonly", EMObject::INT,"Integer pixel translations only"); 00203 d.put("useflcf", EMObject::INT,"Use Fast Local Correlation Function rather than CCF"); 00204 d.put("maxshift", EMObject::INT,"Maximum translation in pixels"); 00205 d.put("masked", EMObject::INT,"Treat zero pixels in 'this' as a mask for normalization (default false)"); 00206 d.put("nozero", EMObject::INT,"Zero translation not permitted (useful for CCD images)"); 00207 return d; 00208 }
static Aligner* EMAN::TranslationalAligner::NEW | ( | ) | [inline, static] |
const string TranslationalAligner::NAME = "translational" [static] |