#include <aligner.h>
Inheritance diagram for EMAN::Refine3DAlignerGrid:
Public Member Functions | |
virtual EMData * | align (EMData *this_img, EMData *to_img, const string &cmp_name="sqeuclidean", 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 = "refine_3d_grid" |
Refines a preliminary 3D alignment using a sampling grid. This is a port from tomohunter, but the az sampling scheme is altered cuch that the points on the sphere are equidistant (Improves speed several hundered times). The distance between the points on the sphere is 'delta' and the range(distance from the pole, 0,0,0 position) is given as 'range'. IN general this refinement scheme is a bit slower than the Quaternion Simplex aligner, but perfroms better in the presence of noise(according to current dogma).
xform.align3d | The Transform from the previous course alignment. If unspecified the identity matrix is used | |
delta | The angluar distance bewteen points on the spehere used in the grid | |
range | The size of the grid. Measured in angluar distance from the north pole | |
dotrans | Do a translational search | |
search | The maximum length of the detectable translational shift - if you supply this parameter you can not supply the maxshiftx, maxshifty or maxshiftz parameters. Each approach is mutually exclusive | |
searchx | The maximum length of the detectable translational shift in the x direction- if you supply this parameter you can not supply the maxshift parameters | |
searchy | The maximum length of the detectable translational shift in the y direction- if you supply this parameter you can not supply the maxshift parameters | |
searchz | The maximum length of the detectable translational shift in the z direction- if you supply this parameter you can not supply the maxshift parameters | |
verbose | Turn this on to have useful information printed to standard out |
Definition at line 916 of file aligner.h.
|
Implements EMAN::Aligner. Definition at line 922 of file aligner.h. References align(). 00923 { 00924 return align(this_img, to_img, "sqeuclidean", Dict()); 00925 }
|
|
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 1714 of file aligner.cpp. References EMAN::EMData::calc_ccf(), EMAN::EMData::calc_max_location_wrap(), calc_max_location_wrap_cuda(), EMAN::EMData::cmp(), data, EMAN::EMData::do_fft(), EMAN::Dict::end(), EMAN::EMData::get_attr(), EMAN::EMData::get_ndim(), get_stats_cuda(), EMAN::Transform::get_trans(), EMAN::EMData::get_value_at_wrap(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), EMAN::Dict::has_key(), ImageDimensionException, InvalidParameterException, CudaPeakInfo::peak, phi, EMAN::EMData::process(), EMAN::EMData::process_inplace(), CudaPeakInfo::px, CudaPeakInfo::py, CudaPeakInfo::pz, EMAN::EMData::set_attr(), EMAN::Dict::set_default(), EMAN::Transform::set_trans(), sqrt(), t, and EMAN::Vec3f. 01716 { 01717 if ( this_img->get_ndim() != 3 || to->get_ndim() != 3 ) { 01718 throw ImageDimensionException("This aligner only works for 3D images"); 01719 } 01720 01721 Transform* t; 01722 if (params.has_key("xform.align3d") ) { 01723 // Unlike the 2d refine aligner, this class doesn't require the starting transform's 01724 // parameters to form the starting guess. Instead the Transform itself 01725 // is perturbed carefully (using quaternion rotation) to overcome problems that arise 01726 // when you use orthogonally-based Euler angles 01727 t = params["xform.align3d"]; 01728 }else { 01729 t = new Transform(); // is the identity 01730 } 01731 01732 int searchx = 0; 01733 int searchy = 0; 01734 int searchz = 0; 01735 01736 bool dotrans = params.set_default("dotrans",1); 01737 if (params.has_key("search")) { 01738 vector<string> check; 01739 check.push_back("searchx"); 01740 check.push_back("searchy"); 01741 check.push_back("searchz"); 01742 for(vector<string>::const_iterator cit = check.begin(); cit != check.end(); ++cit) { 01743 if (params.has_key(*cit)) throw InvalidParameterException("The search parameter is mutually exclusive of the searchx, searchy, and searchz parameters"); 01744 } 01745 int search = params["search"]; 01746 searchx = search; 01747 searchy = search; 01748 searchz = search; 01749 } else { 01750 searchx = params.set_default("searchx",3); 01751 searchy = params.set_default("searchy",3); 01752 searchz = params.set_default("searchz",3); 01753 } 01754 01755 float delta = params.set_default("delta",1.0f); 01756 float range = params.set_default("range",10.0f); 01757 bool verbose = params.set_default("verbose",false); 01758 01759 bool tomography = (cmp_name == "ccc.tomo") ? 1 : 0; 01760 EMData * tofft = 0; 01761 if(dotrans || tomography){ 01762 tofft = to->do_fft(); 01763 } 01764 01765 #ifdef EMAN2_USING_CUDA 01766 if(EMData::usecuda == 1) { 01767 if(!this_img->isrodataongpu()) this_img->copy_to_cudaro(); 01768 if(!to->getcudarwdata()) to->copy_to_cuda(); 01769 if(to->getcudarwdata()){if(tofft) tofft->copy_to_cuda();} 01770 } 01771 #endif 01772 01773 Dict d; 01774 d["type"] = "eman"; // d is used in the loop below 01775 Dict best; 01776 best["score"] = 0.0f; 01777 bool use_cpu = true; 01778 Transform tran = Transform(); 01779 for ( float alt = 0; alt < range; alt += delta) { 01780 // now compute a sane az step size 01781 float saz = 360; 01782 if(alt != 0) saz = delta/sin(alt*M_PI/180.0f); // This gives consistent az step sizes(arc lengths) 01783 for ( float az = 0; az < 360; az += saz ){ 01784 if (verbose) { 01785 cout << "Trying angle alt " << alt << " az " << az << endl; 01786 } 01787 // account for any changes in az 01788 for( float phi = -range-az; phi < range-az; phi += delta ) { 01789 d["alt"] = alt; 01790 d["phi"] = phi; 01791 d["az"] = az; 01792 Transform tr(d); 01793 tr = tr*(*t); // compose transforms, this moves to the pole (aprox) 01794 01795 EMData* transformed = this_img->process("xform",Dict("transform",&tr)); 01796 01797 //need to do things a bit diffrent if we want to compare two tomos 01798 float score = 0.0f; 01799 if(dotrans || tomography){ 01800 EMData* ccf = transformed->calc_ccf(tofft); 01801 #ifdef EMAN2_USING_CUDA 01802 if(to->getcudarwdata()){ 01803 use_cpu = false; 01804 CudaPeakInfo* data = calc_max_location_wrap_cuda(ccf->getcudarwdata(), ccf->get_xsize(), ccf->get_ysize(), ccf->get_zsize(), searchx, searchy, searchz); 01805 tran.set_trans((float)-data->px, (float)-data->py, (float)-data->pz); 01806 //CudaPeakInfoFloat* data = calc_max_location_wrap_intp_cuda(ccf->getcudarwdata(), ccf->get_xsize(), ccf->get_ysize(), ccf->get_zsize(), searchx, searchy, searchz); 01807 //tran.set_trans(-data->xintp, -data->yintp, -data->zintp); 01808 tr = tran*tr; 01809 if (tomography) { 01810 float2 stats = get_stats_cuda(ccf->getcudarwdata(), ccf->get_xsize(), ccf->get_ysize(), ccf->get_zsize()); 01811 score = -(data->peak - stats.x)/sqrt(stats.y); // Normalize, this is better than calling the norm processor since we only need to normalize one point 01812 } else { 01813 score = -data->peak; 01814 } 01815 delete data; 01816 } 01817 #endif 01818 if(use_cpu){ 01819 if(tomography) ccf->process_inplace("normalize"); 01820 //vector<float> fpoint = ccf->calc_max_location_wrap_intp(searchx,searchy,searchz); 01821 //tran.set_trans(-fpoint[0], -fpoint[1], -fpoint[2]); 01822 //score = -fpoint[3]; 01823 IntPoint point = ccf->calc_max_location_wrap(searchx,searchy,searchz); 01824 tran.set_trans((float)-point[0], (float)-point[1], (float)-point[2]); 01825 score = -ccf->get_value_at_wrap(point[0], point[1], point[2]); 01826 tr = tran*tr; 01827 01828 } 01829 delete ccf; ccf =0; 01830 delete transformed; transformed = 0;// this is to stop a mem leak 01831 } 01832 01833 if(!tomography){ 01834 if(!transformed) transformed = this_img->process("xform",Dict("transform",&tr)); // we are returning a map 01835 score = transformed->cmp(cmp_name,to,cmp_params); //this is not very efficient as it creates a new cmp object for each iteration 01836 delete transformed; transformed = 0;// this is to stop a mem leak 01837 } 01838 01839 if(score < float(best["score"])) { 01840 best["score"] = score; 01841 best["xform.align3d"] = &tr; // I wonder if this will cause a mem leak? 01842 } 01843 } 01844 } 01845 } 01846 01847 if(tofft) {delete tofft; tofft = 0;} 01848 01849 //make aligned map; 01850 EMData* best_match = this_img->process("xform",Dict("transform", best["xform.align3d"])); // we are returning a map 01851 best_match->set_attr("xform.align3d", best["xform.align3d"]); 01852 best_match->set_attr("score", float(best["score"])); 01853 01854 //debug.... 01855 Transform* zz = best_match->get_attr("xform.align3d"); 01856 Vec3f zzz = zz->get_trans(); 01857 cout << "x " << float(zzz[0]) << " y " << float(zzz[1]) << " z " << float(zzz[2]) << endl; 01858 01859 return best_match; 01860 01861 }
|
|
Implements EMAN::Aligner. Definition at line 932 of file aligner.h. 00933 { 00934 return "Refines a preliminary 3D alignment using a simplex algorithm. Subpixel precision."; 00935 }
|
|
Get the Aligner's name. Each Aligner is identified by a unique name.
Implements EMAN::Aligner. Definition at line 927 of file aligner.h. 00928 {
00929 return NAME;
00930 }
|
|
Implements EMAN::Aligner. Definition at line 942 of file aligner.h. References EMAN::TypeDict::put(). 00943 { 00944 TypeDict d; 00945 d.put("xform.align3d", EMObject::TRANSFORM,"The Transform storing the starting guess. If unspecified the identity matrix is used"); 00946 d.put("delta", EMObject::FLOAT, "The angular step size. Default is 1." ); 00947 d.put("range", EMObject::FLOAT, "The angular range size. Default is 10." ); 00948 d.put("dotrans", EMObject::BOOL,"Do a translational search. Default is True(1)"); 00949 d.put("search", EMObject::INT,"The maximum length of the detectable translational shift - if you supply this parameter you can not supply the maxshiftx, maxshifty or maxshiftz parameters. Each approach is mutually exclusive."); 00950 d.put("searchx", EMObject::INT,"The maximum length of the detectable translational shift in the x direction- if you supply this parameter you can not supply the maxshift parameters. Default is 3."); 00951 d.put("searchy", EMObject::INT,"The maximum length of the detectable translational shift in the y direction- if you supply this parameter you can not supply the maxshift parameters. Default is 3."); 00952 d.put("searchz", EMObject::INT,"The maximum length of the detectable translational shift in the z direction- if you supply this parameter you can not supply the maxshift parameters. Default is 3"); 00953 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."); 00954 d.put("verbose", EMObject::BOOL,"Turn this on to have useful information printed to standard out."); 00955 return d; 00956 }
|
|
Definition at line 937 of file aligner.h. 00938 { 00939 return new Refine3DAlignerGrid(); 00940 }
|
|
Definition at line 74 of file aligner.cpp. |