EMAN2
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions
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 984 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 661 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.

                                                                                              {
        float apix=(float)image->get_attr("apix_x");
        int verbose=(int)params["verbose"];
//      int adaptnoise=params.set_default("adaptnoise",0);
        float noisecutoff=(float)params.set_default("noisecutoff",1.0/6.0);
        if (apix<=0 || apix>7.0f) throw ImageFormatException("apix_x > 7.0 or <0");
        float ds=1.0f/(apix*image->get_xsize());        // 0.5 is because radial mask is 2x oversampled
        unsigned int start=(int)floor(1.0/(15.0*ds));
        unsigned int end=radial_mask.size()-2;
        if (noisecutoff>0) end=(int)floor(noisecutoff/ds);
        if (end>radial_mask.size()-2) {
                if (verbose) printf("WARNING: specified noisecutoff too close to Nyquist, reset !");
                end=radial_mask.size()-2;
        }
        if (end<start+2) {
                printf("WARNING: noise cutoff too close to 15 A ! Results will not be good...");
                start=end-5;
        }

        FILE *out=NULL;
        if (verbose>2)  {
                printf("Autob -> %d - %d  ds=%g apix=%g rdlmsk=%d\n",start,end,ds,apix,int(radial_mask.size()));
                out=fopen("fitplot.txt","w");
        }
        int N=(radial_mask.size()-start-2);
        float *x=(float *)malloc(N*sizeof(float));
        float *y=(float *)malloc(N*sizeof(float));
        float *dy=(float *)malloc(N*sizeof(float));
        for (unsigned int i=start; i<radial_mask.size()-2; i++ ) {              // -2 is arbitrary because sometimes the last pixel or two have funny values
                x[i-start]=ds*ds*i*i;
                if (radial_mask[i]>0) y[i-start]=log(radial_mask[i]); // ok
                else if (i>start) y[i-start]=y[i-start-1];              // not good
                else y[i-start]=0.0;                                                    // bad
                if (i>start &&i<radial_mask.size()-3) dy[i-start]=y[i-start]-y[i-start-1];      // creates a 'derivative' of sorts, for use in adaptnoise
                if (out) fprintf(out,"%f\t%f\n",x[i-start],y[i-start]);
        }
        if (out) fclose(out);

        float slope=0,intercept=0;
        Util::calc_least_square_fit(end-start, x,y,&slope,&intercept,1);

        if (verbose) printf("slope=%f  intercept=%f\n",slope,intercept);

        float B=(float)params["bfactor"]+slope*4.0f/2.0f;               // *4 is for Henderson definition, 2.0 is for intensity vs amplitude
        float B2=(float)params["bfactor"];

        if (verbose) printf("User B = %1.2f  Corrective B = %1.2f  Total B=%1.3f\n",(float)params["bfactor"],slope*2.0,B);

        float cutval=exp(-B*pow(end*ds,2.0f)/4.0f)/exp(-B2*pow(end*ds,2.0f)/4.0f);
        for (unsigned int i=0; i<radial_mask.size(); i++) {
                if (i<=end) radial_mask[i]=exp(-B*pow(i*ds,2.0f)/4.0f);
                else radial_mask[i]=cutval*exp(-B2*pow(i*ds,2.0f)/4.0f);
        }
        if (verbose>1) Util::save_data(0,ds,radial_mask,"filter.txt");

        free(x);
        free(y);
        free(dy);
 }
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 997 of file processor.h.

                {
                        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.";
                }
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 987 of file processor.h.

References NAME.

                {
                        return NAME;
                }
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 1004 of file processor.h.

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

                {
                        TypeDict d = FourierAnlProcessor::get_param_types();
                        d.put("bfactor", EMObject::FLOAT, "B-factor in terms of e^-(B s^2/4)");
                        d.put("noisecutoff", EMObject::FLOAT, "Spatial frequency past which inverse-B will not be applied, default=1/6A");
//                      d.put("adaptnoise", EMObject::INT, "Dual linear fit separating lower resolution signal from higher resolution noise. Noise region not upweighted.");
                        d.put("return_radial", EMObject::BOOL, "Return the radial filter function as an attribute (filter_curve)");
                        d.put("verbose", EMObject::INT, "Print information about the determined B-factor");
                        return d;
                }
static Processor* EMAN::LowpassAutoBProcessor::NEW ( ) [inline, static]

Definition at line 992 of file processor.h.

                {
                        return new LowpassAutoBProcessor();
                }
virtual void EMAN::LowpassAutoBProcessor::preprocess ( EMData image) [inline, protected, virtual]

Reimplemented from EMAN::FourierAnlProcessor.

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

                                                        {
                        if(params.has_key("apix")) {
                                image->set_attr("apix_x", (float)params["apix"]);
                                image->set_attr("apix_y", (float)params["apix"]);
                                image->set_attr("apix_z", (float)params["apix"]);
                        }
                        float apix=(float)image->get_attr("apix_x");

                        const Dict dict = image->get_attr_dict();
                        if (params.has_key("cutoff_abs")) {
                                params["bfactor"] = pow(apix/(float)params["cutoff_abs"],2.0f);
                        }
                        else if( params.has_key("cutoff_freq") ) {
                                float val =  (float)params["cutoff_freq"] * apix;
                                params["cutoff_abs"] = val;
                                params["bfactor"] = pow(apix/(float)params["cutoff_abs"],2.0f);
                        }
                        else if( params.has_key("cutoff_pixels") ) {
                                float val = 0.5f*(float)params["cutoff_pixels"] / (float)dict["nx"];
                                params["cutoff_abs"] = val;
                                params["bfactor"] = pow(apix/(float)params["cutoff_abs"],2.0f);
                        }
                }

Member Data Documentation

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

Definition at line 1002 of file processor.h.

Referenced by get_name().


The documentation for this class was generated from the following files: