EMAN::LowpassAutoBProcessor Class Reference

processor radial function: if lowpass > 0, f(x) = exp(-x*x/(lowpass*lowpass)); else f(x) = exp(x*x/(lowpass*lowpass)) More...

#include <processor.h>

Inheritance diagram for EMAN::LowpassAutoBProcessor:

Inheritance graph
[legend]
Collaboration diagram for EMAN::LowpassAutoBProcessor:

Collaboration graph
[legend]
List of all members.

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 ProcessorNEW ()

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

Detailed Description

processor radial function: if lowpass > 0, f(x) = exp(-x*x/(lowpass*lowpass)); else f(x) = exp(x*x/(lowpass*lowpass))

Definition at line 933 of file processor.h.


Member Function Documentation

void LowpassAutoBProcessor::create_radial_func ( vector< float > &  radial_mask,
EMData image 
) const [protected, virtual]

Implements EMAN::FourierAnlProcessor.

Definition at line 629 of file processor.cpp.

References 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.

00629                                                                                               {
00630         float apix=(float)image->get_attr("apix_x");
00631         int verbose=(int)params["verbose"];
00632 //      int adaptnoise=params.set_default("adaptnoise",0);
00633         float noisecutoff=(float)params.set_default("noisecutoff",0.0);
00634         if (apix<=0 || apix>7.0f) throw ImageFormatException("0 < apix_x < 7.0");
00635         float ds=1.0f/(apix*image->get_xsize());        // 0.5 is because radial mask is 2x oversampled
00636         unsigned int start=(int)floor(1.0/(15.0*ds));
00637         unsigned int end=radial_mask.size()-2;
00638         if (noisecutoff>0) end=(int)floor(noisecutoff/ds);
00639         if (end>radial_mask.size()-2) {
00640                 printf("WARNING: specified noisecutoff too close to Nyquist, reset !");
00641                 end=radial_mask.size()-2;
00642         }
00643         if (end<start+2) {
00644                 printf("WARNING: noise cutoff too close to 15 A ! Results will not be good...");
00645                 start=end-5;
00646         }
00647 
00648         FILE *out=NULL;
00649         if (verbose>2)  out=fopen("fitplot.txt","w");
00650         int N=(radial_mask.size()-start-2);
00651         float *x=(float *)malloc(N*sizeof(float));
00652         float *y=(float *)malloc(N*sizeof(float));
00653         float *dy=(float *)malloc(N*sizeof(float));
00654         for (unsigned int i=start; i<radial_mask.size()-2; i++ ) {              // -2 is arbitrary because sometimes the last pixel or two have funny values
00655                 x[i-start]=ds*ds*i*i;
00656                 if (radial_mask[i]>0) y[i-start]=log(radial_mask[i]); // ok
00657                 else if (i>start) y[i-start]=y[i-start-1];              // not good
00658                 else y[i-start]=0.0;                                                    // bad
00659                 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
00660                 if (out) fprintf(out,"%f\t%f\n",x[i-start],y[i-start]);
00661         }
00662         if (out) fclose(out);
00663 
00664         float slope=0,intercept=0;
00665         Util::calc_least_square_fit(end-start, x,y,&slope,&intercept,1);
00666 
00667         if (verbose) printf("slope=%f  intercept=%f\n",slope,intercept);
00668 
00669         float B=(float)params["bfactor"]+slope*4.0f/2.0f;               // *4 is for Henderson definition, 2.0 is for intensity vs amplitude
00670         float B2=(float)params["bfactor"];
00671 
00672         if (verbose) printf("User B = %1.2f  Corrective B = %1.2f  Total B=%1.3f\n",(float)params["bfactor"],slope*2.0,B);
00673 
00674         float cutval=exp(-B*pow(end*ds,2.0f)/4.0f)/exp(-B2*pow(end*ds,2.0f)/4.0f);
00675         for (unsigned int i=0; i<radial_mask.size(); i++) {
00676                 if (i<=end) radial_mask[i]=exp(-B*pow(i*ds,2.0f)/4.0f);
00677                 else radial_mask[i]=cutval*exp(-B2*pow(i*ds,2.0f)/4.0f);
00678         }
00679         if (verbose>1) Util::save_data(0,ds,radial_mask,"filter.txt");
00680 
00681         free(x);
00682         free(y);
00683         free(dy);
00684  }

string EMAN::LowpassAutoBProcessor::get_desc (  )  const [inline, virtual]

Get the descrition of this specific processor.

This function must be overwritten by a subclass.

Returns:
The description of this processor.

Implements EMAN::Processor.

Definition at line 946 of file processor.h.

00947                 {
00948                         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.";
00949                 }

string EMAN::LowpassAutoBProcessor::get_name (  )  const [inline, virtual]

Get the processor's name.

Each processor is identified by a unique name.

Returns:
The processor's name.

Implements EMAN::Processor.

Definition at line 936 of file processor.h.

References NAME.

00937                 {
00938                         return NAME;
00939                 }

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.

Returns:
A dictionary containing the parameter info.

Reimplemented from EMAN::FourierAnlProcessor.

Definition at line 953 of file processor.h.

References EMAN::EMObject::FLOAT, EMAN::FourierAnlProcessor::get_param_types(), EMAN::EMObject::INT, and EMAN::TypeDict::put().

00954                 {
00955                         TypeDict d = FourierAnlProcessor::get_param_types();
00956                         d.put("bfactor", EMObject::FLOAT, "B-factor in terms of e^-(B s^2/4)");
00957                         d.put("noisecutoff", EMObject::FLOAT, "Spatial frequency past which inverse-B will not be applied");
00958 //                      d.put("adaptnoise", EMObject::INT, "Dual linear fit separating lower resolution signal from higher resolution noise. Noise region not upweighted.");
00959                         d.put("verbose", EMObject::INT, "Print information about the determined B-factor");
00960                         return d;
00961                 }

static Processor* EMAN::LowpassAutoBProcessor::NEW (  )  [inline, static]

Definition at line 941 of file processor.h.

00942                 {
00943                         return new LowpassAutoBProcessor();
00944                 }

virtual void EMAN::LowpassAutoBProcessor::preprocess ( EMData image  )  [inline, protected, virtual]

Reimplemented from EMAN::FourierAnlProcessor.

Definition at line 964 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().

00964                                                         {
00965                         if(params.has_key("apix")) {
00966                                 image->set_attr("apix_x", (float)params["apix"]);
00967                                 image->set_attr("apix_y", (float)params["apix"]);
00968                                 image->set_attr("apix_z", (float)params["apix"]);
00969                         }
00970                         float apix=(float)image->get_attr("apix_x");
00971 
00972                         const Dict dict = image->get_attr_dict();
00973                         if (params.has_key("cutoff_abs")) {
00974                                 params["bfactor"] = pow(apix/(float)params["cutoff_abs"],2.0f);
00975                         }
00976                         else if( params.has_key("cutoff_freq") ) {
00977                                 float val =  (float)params["cutoff_freq"] * apix;
00978                                 params["cutoff_abs"] = val;
00979                                 params["bfactor"] = pow(apix/(float)params["cutoff_abs"],2.0f);
00980                         }
00981                         else if( params.has_key("cutoff_pixels") ) {
00982                                 float val = 0.5f*(float)params["cutoff_pixels"] / (float)dict["nx"];
00983                                 params["cutoff_abs"] = val;
00984                                 params["bfactor"] = pow(apix/(float)params["cutoff_abs"],2.0f);
00985                         }
00986                 }


Member Data Documentation

const string LowpassAutoBProcessor::NAME = "filter.lowpass.autob" [static]

Definition at line 951 of file processor.h.

Referenced by get_name().


The documentation for this class was generated from the following files:
Generated on Tue Jun 11 12:43:32 2013 for EMAN2 by  doxygen 1.4.7