EMAN2
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | List of all members
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]

Public Member Functions

string get_name () const
 Get the processor's name. More...
 
string get_desc () const
 Get the descrition of this specific processor. More...
 
virtual TypeDict get_param_types () const
 Get processor parameter information in a dictionary. More...
 
- Public Member Functions inherited from EMAN::FourierAnlProcessor
void process_inplace (EMData *image)
 To process an image in-place. More...
 
- Public Member Functions inherited from EMAN::Processor
virtual ~Processor ()
 
virtual EMDataprocess (const EMData *const image)
 To proccess an image out-of-place. More...
 
virtual void process_list_inplace (vector< EMData * > &images)
 To process multiple images using the same algorithm. More...
 
virtual Dict get_params () const
 Get the processor parameters in a key/value dictionary. More...
 
virtual void set_params (const Dict &new_params)
 Set the processor parameters using a key/value dictionary. More...
 

Static Public Member Functions

static ProcessorNEW ()
 
- Static Public Member Functions inherited from EMAN::FourierAnlProcessor
static string get_group_desc ()
 
- Static Public Member Functions inherited from EMAN::Processor
static string get_group_desc ()
 Get the description of this group of processors. More...
 
static void EMFourierFilterInPlace (EMData *fimage, Dict params)
 Compute a Fourier-filter processed image in place. More...
 
static EMDataEMFourierFilter (EMData *fimage, Dict params)
 Compute a Fourier-processor processed image without altering the original image. More...
 

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
 

Additional Inherited Members

- Public Types inherited from EMAN::Processor
enum  fourier_filter_types {
  TOP_HAT_LOW_PASS , TOP_HAT_HIGH_PASS , TOP_HAT_BAND_PASS , TOP_HOMOMORPHIC ,
  GAUSS_LOW_PASS , GAUSS_HIGH_PASS , GAUSS_BAND_PASS , GAUSS_INVERSE ,
  GAUSS_HOMOMORPHIC , BUTTERWORTH_LOW_PASS , BUTTERWORTH_HIGH_PASS , BUTTERWORTH_HOMOMORPHIC ,
  KAISER_I0 , KAISER_SINH , KAISER_I0_INVERSE , KAISER_SINH_INVERSE ,
  SHIFT , TANH_LOW_PASS , TANH_HIGH_PASS , TANH_HOMOMORPHIC ,
  TANH_BAND_PASS , RADIAL_TABLE , CTF_
}
 Fourier filter Processor type enum. More...
 
- Protected Attributes inherited from EMAN::Processor
Dict params
 

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 1943 of file processor.h.

Member Function Documentation

◆ create_radial_func()

void LowpassAutoBProcessor::create_radial_func ( vector< float > &  radial_mask,
EMData image 
) const
protectedvirtual

Implements EMAN::FourierAnlProcessor.

Definition at line 1143 of file processor.cpp.

1143 {
1144 float apix=(float)image->get_attr("apix_x");
1145 int verbose=(int)params["verbose"];
1146// int adaptnoise=params.set_default("adaptnoise",0);
1147 float noisecutoff=(float)params.set_default("noisecutoff",1.0/6.0);
1148 if (apix<=0 || apix>7.0f) throw ImageFormatException("apix_x > 7.0 or <0");
1149 float ds=1.0f/(apix*image->get_ysize()); // 0.5 is because radial mask is 2x oversampled
1150 unsigned int start=(int)floor(1.0/(15.0*ds));
1151 unsigned int end=radial_mask.size()-2;
1152 if (noisecutoff>0) end=(int)floor(noisecutoff/ds);
1153 if (end>radial_mask.size()-2) {
1154 if (verbose) printf("WARNING: specified noisecutoff too close to Nyquist, reset !");
1155 end=radial_mask.size()-2;
1156 }
1157 if (end<start+2) {
1158 printf("WARNING: noise cutoff too close to 15 A ! Results will not be good...");
1159 start=end-5;
1160 }
1161
1162 FILE *out=NULL;
1163 if (verbose>2) {
1164 printf("Autob -> %d - %d ds=%g apix=%g rdlmsk=%d\n",start,end,ds,apix,int(radial_mask.size()));
1165 out=fopen("fitplot.txt","w");
1166 }
1167 int N=(radial_mask.size()-start-2);
1168 float *x=(float *)malloc(N*sizeof(float));
1169 float *y=(float *)malloc(N*sizeof(float));
1170 float *dy=(float *)malloc(N*sizeof(float));
1171 for (unsigned int i=start; i<radial_mask.size()-2; i++ ) { // -2 is arbitrary because sometimes the last pixel or two have funny values
1172 x[i-start]=ds*ds*i*i;
1173 if (radial_mask[i]>0) y[i-start]=log(radial_mask[i]); // ok
1174 else if (i>start) y[i-start]=y[i-start-1]; // not good
1175 else y[i-start]=0.0; // bad
1176 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
1177 if (out) fprintf(out,"%f\t%f\n",x[i-start],y[i-start]);
1178 }
1179 if (out) fclose(out);
1180
1181 float slope=0,intercept=0;
1182 Util::calc_least_square_fit(end-start, x,y,&slope,&intercept,1);
1183
1184 if (verbose) printf("slope=%f intercept=%f\n",slope,intercept);
1185
1186 float B=(float)params["bfactor"]+slope*4.0f/2.0f; // *4 is for Henderson definition, 2.0 is for intensity vs amplitude
1187 float B2=(float)params["bfactor"];
1188
1189 if (verbose) printf("User B = %1.2f Corrective B = %1.2f Total B=%1.3f\n",(float)params["bfactor"],slope*2.0,B);
1190
1191 float cutval=exp(-B*pow(end*ds,2.0f)/4.0f)/exp(-B2*pow(end*ds,2.0f)/4.0f);
1192 for (unsigned int i=0; i<radial_mask.size(); i++) {
1193 if (i<=end) radial_mask[i]=exp(-B*pow(i*ds,2.0f)/4.0f);
1194 else radial_mask[i]=cutval*exp(-B2*pow(i*ds,2.0f)/4.0f);
1195 }
1196 if (verbose>1) Util::save_data(0,ds,radial_mask,"filter.txt");
1197
1198 free(x);
1199 free(y);
1200 free(dy);
1201 }
type set_default(const string &key, type val)
Default setting behavior This can be achieved using a template - d.woolford Jan 2008 (before there wa...
Definition: emobject.h:569
static void calc_least_square_fit(size_t nitems, const float *data_x, const float *data_y, float *p_slope, float *p_intercept, bool ignore_zero, float absmax=0)
calculate the least square fit value.
Definition: util.cpp:538
static void save_data(const vector< float > &x_array, const vector< float > &y_array, const string &filename)
Save (x y) data array into a file.
Definition: util.cpp:604
EMData * log() const
return natural logarithm image for a image
#define ImageFormatException(desc)
Definition: exception.h:147
#define y(i, j)
Definition: projector.cpp:1516
#define x(i)
Definition: projector.cpp:1517

References EMAN::Util::calc_least_square_fit(), ImageFormatException, log(), EMAN::Processor::params, EMAN::Util::save_data(), EMAN::Dict::set_default(), x, and y.

◆ get_desc()

string EMAN::LowpassAutoBProcessor::get_desc ( ) const
inlinevirtual

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 1956 of file processor.h.

1957 {
1958 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.";
1959 }

◆ get_name()

string EMAN::LowpassAutoBProcessor::get_name ( ) const
inlinevirtual

Get the processor's name.

Each processor is identified by a unique name.

Returns
The processor's name.

Implements EMAN::Processor.

Definition at line 1946 of file processor.h.

1947 {
1948 return NAME;
1949 }
static const string NAME
Definition: processor.h:1961

References NAME.

◆ get_param_types()

virtual TypeDict EMAN::LowpassAutoBProcessor::get_param_types ( ) const
inlinevirtual

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 1963 of file processor.h.

1964 {
1966 d.put("bfactor", EMObject::FLOAT, "B-factor in terms of e^-(B s^2/4)");
1967 d.put("noisecutoff", EMObject::FLOAT, "Spatial frequency past which inverse-B will not be applied, default=1/6A");
1968// d.put("adaptnoise", EMObject::INT, "Dual linear fit separating lower resolution signal from higher resolution noise. Noise region not upweighted.");
1969 d.put("return_radial", EMObject::BOOL, "Return the radial filter function as an attribute (filter_curve)");
1970 d.put("verbose", EMObject::INT, "Print information about the determined B-factor");
1971 return d;
1972 }
TypeDict get_param_types() const
Get processor parameter information in a dictionary.
Definition: processor.h:400
TypeDict is a dictionary to store <string, EMObject::ObjectType> pair.
Definition: emobject.h:305
void put(const string &key, EMObject::ObjectType o, const string &desc="")
Definition: emobject.h:330

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

◆ NEW()

static Processor * EMAN::LowpassAutoBProcessor::NEW ( )
inlinestatic

Definition at line 1951 of file processor.h.

1952 {
1953 return new LowpassAutoBProcessor();
1954 }
processor radial function: if lowpass > 0, f(x) = exp(-x*x/(lowpass*lowpass)); else f(x) = exp(x*x/(l...
Definition: processor.h:1944

◆ preprocess()

virtual void EMAN::LowpassAutoBProcessor::preprocess ( EMData image)
inlineprotectedvirtual

Reimplemented from EMAN::FourierAnlProcessor.

Definition at line 1975 of file processor.h.

1975 {
1976 if(params.has_key("apix")) {
1977 image->set_attr("apix_x", (float)params["apix"]);
1978 image->set_attr("apix_y", (float)params["apix"]);
1979 image->set_attr("apix_z", (float)params["apix"]);
1980 }
1981 float apix=(float)image->get_attr("apix_x");
1982 params["bfactor"] = pow(apix/(float)params["cutoff_abs"],0.0f);
1983
1984 const Dict dict = image->get_attr_dict();
1985 if (params.has_key("cutoff_abs")) {
1986 params["bfactor"] = pow(apix/(float)params["cutoff_abs"],2.0f);
1987 }
1988 else if( params.has_key("cutoff_freq") ) {
1989 float val = (float)params["cutoff_freq"] * apix;
1990 params["cutoff_abs"] = val;
1991 params["bfactor"] = pow(apix/(float)params["cutoff_abs"],2.0f);
1992 }
1993 else if( params.has_key("cutoff_pixels") ) {
1994 float val = (float)params["cutoff_pixels"] / (float)dict["nx"];
1995 params["cutoff_abs"] = val;
1996 params["bfactor"] = pow(apix/(float)params["cutoff_abs"],2.0f);
1997 }
1998 }
Dict is a dictionary to store <string, EMObject> pair.
Definition: emobject.h:385
bool has_key(const string &key) const
Ask the Dictionary if it as a particular key.
Definition: emobject.h:511

References EMAN::Dict::has_key(), and EMAN::Processor::params.

Member Data Documentation

◆ NAME

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

Definition at line 1961 of file processor.h.

Referenced by get_name().


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