#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 | |
Aligner * | NEW () |
Static Public Attributes | |
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.
|
Implements EMAN::Aligner. Definition at line 179 of file aligner.h. References align(). 00180 { 00181 return align(this_img, to_img, "dot", Dict()); 00182 }
|
|
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.
Implements EMAN::Aligner. Definition at line 99 of file aligner.cpp. References EMAN::EMData::calc_ccf(), EMAN::EMData::calc_flcf(), EMAN::EMData::calc_max_location_wrap(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), 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(), EMAN::Transform::set_trans(), t, EMAN::EMData::update(), EMAN::Vec3f, and EMAN::EMData::zero_corner_circulant(). 00101 { 00102 if (!this_img) { 00103 return 0; 00104 } 00105 00106 if (to && !EMUtil::is_same_size(this_img, to)) 00107 throw ImageDimensionException("Images must be the same size to perform translational alignment"); 00108 00109 EMData *cf = 0; 00110 int nx = this_img->get_xsize(); 00111 int ny = this_img->get_ysize(); 00112 int nz = this_img->get_zsize(); 00113 00114 int masked = params.set_default("masked",0); 00115 int useflcf = params.set_default("useflcf",0); 00116 bool use_cpu = true; 00117 //#ifdef EMAN2_USING_CUDA 00118 // if (this_img->gpu_operation_preferred() ) { 00119 // cout << "Translate on GPU" << endl; 00120 // use_cpu = false; 00121 // cf = this_img->calc_ccf_cuda(to,false,false); 00122 // } 00123 //#endif // EMAN2_USING_CUDA 00124 if (use_cpu) { 00125 if (useflcf) cf = this_img->calc_flcf(to); 00126 else cf = this_img->calc_ccf(to); 00127 } 00128 00129 // This is too expensive 00130 if (masked) { 00131 EMData *msk=this_img->process("threshold.notzero"); 00132 EMData *sqr=to->process("math.squared"); 00133 EMData *cfn=msk->calc_ccf(sqr); 00134 cfn->process_inplace("math.sqrt"); 00135 float *d1=cf->get_data(); 00136 float *d2=cfn->get_data(); 00137 for (int i=0; i<nx*ny*nz; i++) { 00138 if (d2[i]!=0) d1[i]/=d2[i]; 00139 } 00140 cf->update(); 00141 delete msk; 00142 delete sqr; 00143 delete cfn; 00144 } 00145 00146 // 00147 00148 int maxshiftx = params.set_default("maxshift",-1); 00149 int maxshifty = params["maxshift"]; 00150 int maxshiftz = params["maxshift"]; 00151 int nozero = params["nozero"]; 00152 00153 if (maxshiftx <= 0) { 00154 maxshiftx = nx / 4; 00155 maxshifty = ny / 4; 00156 maxshiftz = nz / 4; 00157 } 00158 00159 if (maxshiftx > nx / 2 - 1) maxshiftx = nx / 2 - 1; 00160 if (maxshifty > ny / 2 - 1) maxshifty = ny / 2 - 1; 00161 if (maxshiftz > nz / 2 - 1) maxshiftz = nz / 2 - 1; 00162 00163 if (nx == 1) maxshiftx = 0; // This is justhere for completeness really... plus it saves errors 00164 if (ny == 1) maxshifty = 0; 00165 if (nz == 1) maxshiftz = 0; 00166 00167 // If nozero the portion of the image in the center (and its 8-connected neighborhood) is zeroed 00168 if (nozero) { 00169 cf->zero_corner_circulant(1); 00170 } 00171 00172 IntPoint peak; 00173 //#ifdef EMAN2_USING_CUDA 00174 // if (!use_cpu) { 00175 // EMDataForCuda tmp = cf->get_data_struct_for_cuda(); 00176 // int* p = calc_max_location_wrap_cuda(&tmp,maxshiftx, maxshifty, maxshiftz); 00177 // peak = IntPoint(p[0],p[1],p[2]); 00178 // free(p); 00179 // } 00180 //#endif // EMAN2_USING_CUDA 00181 if (use_cpu) { 00182 peak = cf->calc_max_location_wrap(maxshiftx, maxshifty, maxshiftz); 00183 } 00184 Vec3f cur_trans = Vec3f ( (float)-peak[0], (float)-peak[1], (float)-peak[2]); 00185 00186 if (!to) { 00187 cur_trans /= 2.0f; // If aligning theimage to itself then only go half way - 00188 int intonly = params.set_default("intonly",false); 00189 if (intonly) { 00190 cur_trans[0] = floor(cur_trans[0] + 0.5f); 00191 cur_trans[1] = floor(cur_trans[1] + 0.5f); 00192 cur_trans[2] = floor(cur_trans[2] + 0.5f); 00193 } 00194 } 00195 00196 if( cf ){ 00197 delete cf; 00198 cf = 0; 00199 } 00200 Dict params("trans",static_cast< vector<int> >(cur_trans)); 00201 cf=this_img->process("math.translate.int",params); 00202 Transform t; 00203 t.set_trans(cur_trans); 00204 if ( nz != 1 ) { 00205 // Transform* t = get_set_align_attr("xform.align3d",cf,this_img); 00206 // t->set_trans(cur_trans); 00207 cf->set_attr("xform.align3d",&t); 00208 } else if ( ny != 1 ) { 00209 //Transform* t = get_set_align_attr("xform.align2d",cf,this_img); 00210 cur_trans[2] = 0; // just make sure of it 00211 t.set_trans(cur_trans); 00212 cf->set_attr("xform.align2d",&t); 00213 } 00214 00215 return cf; 00216 }
|
|
Implements EMAN::Aligner. Definition at line 189 of file aligner.h. 00190 { 00191 return "Translational 2D and 3D alignment by cross-correlation"; 00192 }
|
|
Get the Aligner's name. Each Aligner is identified by a unique name.
Implements EMAN::Aligner. Definition at line 184 of file aligner.h. 00185 {
00186 return NAME;
00187 }
|
|
Implements EMAN::Aligner. Definition at line 199 of file aligner.h. References 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 }
|
|
Definition at line 194 of file aligner.h. 00195 { 00196 return new TranslationalAligner(); 00197 }
|
|
Definition at line 53 of file aligner.cpp. |