#include <processor.h>
Inheritance diagram for EMAN::LowpassAutoBProcessor:
Public Member Functions | |
string | get_name () const |
Get the processor's name. | |
string | get_desc () const |
Get the descrition of this specific processor. | |
virtual TypeDict | get_param_types () const |
Get processor parameter information in a dictionary. | |
Static Public Member Functions | |
static Processor * | NEW () |
Static Public Attributes | |
static const string | NAME = "filter.lowpass.autob" |
Protected Member Functions | |
virtual void | preprocess (EMData *image) |
void | create_radial_func (vector< float > &radial_mask, EMData *image) const |
Definition at line 834 of file processor.h.
void LowpassAutoBProcessor::create_radial_func | ( | vector< float > & | radial_mask, | |
EMData * | image | |||
) | const [protected, virtual] |
Implements EMAN::FourierAnlProcessor.
Definition at line 628 of file processor.cpp.
References B, EMAN::Util::calc_least_square_fit(), EMAN::EMData::get_attr(), EMAN::EMData::get_xsize(), ImageFormatException, log(), EMAN::Processor::params, EMAN::Util::save_data(), EMAN::Dict::set_default(), x, and y.
00628 { 00629 float apix=(float)image->get_attr("apix_x"); 00630 int verbose=(int)params["verbose"]; 00631 // int adaptnoise=params.set_default("adaptnoise",0); 00632 float noisecutoff=(float)params.set_default("noisecutoff",0.0); 00633 if (apix<=0 || apix>7.0f) throw ImageFormatException("0 < apix_x < 7.0"); 00634 float ds=1.0f/(apix*image->get_xsize()); // 0.5 is because radial mask is 2x oversampled 00635 unsigned int start=(int)floor(1.0/(15.0*ds)); 00636 unsigned int end=radial_mask.size()-2; 00637 if (noisecutoff>0) end=(int)floor(noisecutoff/ds); 00638 if (end>radial_mask.size()-2) { 00639 printf("WARNING: specified noisecutoff too close to Nyquist, reset !"); 00640 end=radial_mask.size()-2; 00641 } 00642 if (end<start+2) { 00643 printf("WARNING: noise cutoff too close to 15 A ! Results will not be good..."); 00644 start=end-5; 00645 } 00646 00647 FILE *out=NULL; 00648 if (verbose>2) out=fopen("fitplot.txt","w"); 00649 int N=(radial_mask.size()-start-2); 00650 float *x=(float *)malloc(N*sizeof(float)); 00651 float *y=(float *)malloc(N*sizeof(float)); 00652 float *dy=(float *)malloc(N*sizeof(float)); 00653 for (unsigned int i=start; i<radial_mask.size()-2; i++ ) { // -2 is arbitrary because sometimes the last pixel or two have funny values 00654 x[i-start]=ds*ds*i*i; 00655 if (radial_mask[i]>0) y[i-start]=log(radial_mask[i]); // ok 00656 else if (i>start) y[i-start]=y[i-start-1]; // not good 00657 else y[i-start]=0.0; // bad 00658 if (i<radial_mask.size()-3) dy[i-start]=y[i-start]-y[i-start-1]; // creates a 'derivative' of sorts, for use in adaptnoise 00659 if (out) fprintf(out,"%f\t%f\n",x[i-start],y[i-start]); 00660 } 00661 if (out) fclose(out); 00662 00663 float slope=0,intercept=0; 00664 Util::calc_least_square_fit(end-start, x,y,&slope,&intercept,1); 00665 00666 if (verbose) printf("slope=%f intercept=%f\n",slope,intercept); 00667 00668 float B=(float)params["bfactor"]+slope*4.0f/2.0f; // *4 is for Henderson definition, 2.0 is for intensity vs amplitude 00669 float B2=(float)params["bfactor"]; 00670 00671 if (verbose) printf("User B = %1.2f Corrective B = %1.2f Total B=%1.3f\n",(float)params["bfactor"],slope*2.0,B); 00672 00673 float cutval=exp(-B*pow(end*ds,2.0f)/4.0f)/exp(-B2*pow(end*ds,2.0f)/4.0f); 00674 for (unsigned int i=0; i<radial_mask.size(); i++) { 00675 if (i<=end) radial_mask[i]=exp(-B*pow(i*ds,2.0f)/4.0f); 00676 else radial_mask[i]=cutval*exp(-B2*pow(i*ds,2.0f)/4.0f); 00677 } 00678 if (verbose>1) Util::save_data(0,ds,radial_mask,"filter.txt"); 00679 00680 free(x); 00681 free(y); 00682 free(dy); 00683 }
string EMAN::LowpassAutoBProcessor::get_desc | ( | ) | const [inline, virtual] |
Get the descrition of this specific processor.
This function must be overwritten by a subclass.
Implements EMAN::Processor.
Definition at line 847 of file processor.h.
00848 { 00849 return "This processor sharpens a map based on the concept that the power spectrum should be roughly flat over the ~15 A-Nyquist resolution range, then combines this inverse B-factor with the specified low-pass Gaussian filter parameters to produce a single aggregate Gaussian filter."; 00850 }
string EMAN::LowpassAutoBProcessor::get_name | ( | ) | const [inline, virtual] |
Get the processor's name.
Each processor is identified by a unique name.
Implements EMAN::Processor.
Definition at line 837 of file processor.h.
References NAME.
00838 { 00839 return NAME; 00840 }
virtual TypeDict EMAN::LowpassAutoBProcessor::get_param_types | ( | ) | const [inline, virtual] |
Get processor parameter information in a dictionary.
Each parameter has one record in the dictionary. Each record contains its name, data-type, and description.
Reimplemented from EMAN::FourierAnlProcessor.
Definition at line 854 of file processor.h.
References EMAN::EMObject::FLOAT, EMAN::FourierAnlProcessor::get_param_types(), EMAN::EMObject::INT, and EMAN::TypeDict::put().
00855 { 00856 TypeDict d = FourierAnlProcessor::get_param_types(); 00857 d.put("bfactor", EMObject::FLOAT, "B-factor in terms of e^-(B s^2/4)"); 00858 d.put("noisecutoff", EMObject::FLOAT, "Spatial frequency past which inverse-B will not be applied"); 00859 // d.put("adaptnoise", EMObject::INT, "Dual linear fit separating lower resolution signal from higher resolution noise. Noise region not upweighted."); 00860 d.put("verbose", EMObject::INT, "Print information about the determined B-factor"); 00861 return d; 00862 }
static Processor* EMAN::LowpassAutoBProcessor::NEW | ( | ) | [inline, static] |
Definition at line 842 of file processor.h.
00843 { 00844 return new LowpassAutoBProcessor(); 00845 }
virtual void EMAN::LowpassAutoBProcessor::preprocess | ( | EMData * | image | ) | [inline, protected, virtual] |
Reimplemented from EMAN::FourierAnlProcessor.
Definition at line 865 of file processor.h.
References EMAN::EMData::get_attr(), EMAN::EMData::get_attr_dict(), EMAN::Dict::has_key(), EMAN::Processor::params, and EMAN::EMData::set_attr().
00865 { 00866 if(params.has_key("apix")) { 00867 image->set_attr("apix_x", (float)params["apix"]); 00868 image->set_attr("apix_y", (float)params["apix"]); 00869 image->set_attr("apix_z", (float)params["apix"]); 00870 } 00871 float apix=(float)image->get_attr("apix_x"); 00872 00873 const Dict dict = image->get_attr_dict(); 00874 if (params.has_key("cutoff_abs")) { 00875 params["bfactor"] = pow(apix/(float)params["cutoff_abs"],2.0f); 00876 } 00877 else if( params.has_key("cutoff_freq") ) { 00878 float val = (float)params["cutoff_freq"] * apix; 00879 params["cutoff_abs"] = val; 00880 params["bfactor"] = pow(apix/(float)params["cutoff_abs"],2.0f); 00881 } 00882 else if( params.has_key("cutoff_pixels") ) { 00883 float val = 0.5f*(float)params["cutoff_pixels"] / (float)dict["nx"]; 00884 params["cutoff_abs"] = val; 00885 params["bfactor"] = pow(apix/(float)params["cutoff_abs"],2.0f); 00886 } 00887 }
const string LowpassAutoBProcessor::NAME = "filter.lowpass.autob" [static] |