EMAN2
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Attributes | List of all members
EMAN::CtfCWautoAverager Class Reference

CtfCWautoAverager averages the images with CTF correction with a Wiener filter. More...

#include <averager.h>

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

Public Member Functions

 CtfCWautoAverager ()
 
void add_image (EMData *image)
 To add an image to the Averager. More...
 
EMDatafinish ()
 Finish up the averaging and return the result. More...
 
string get_name () const
 Get the Averager's name. More...
 
string get_desc () const
 
void set_params (const Dict &new_params)
 Set the Averager parameters using a key/value dictionary. More...
 
- Public Member Functions inherited from EMAN::Averager
 Averager ()
 
virtual ~Averager ()
 
virtual void add_image_list (const vector< EMData * > &images)
 To add multiple images to the Averager. More...
 
virtual void mult (const float &s)
 Multiply the result image by some floating point constant This is useful when weighting the input images prior to calling add_image - a situation where it is likely you want to divide by the sum of the weights. More...
 
virtual TypeDict get_param_types () const
 Get Averager parameter information in a dictionary. More...
 

Static Public Member Functions

static AveragerNEW ()
 

Static Public Attributes

static const string NAME = "ctfw.auto"
 

Protected Attributes

EMDatasnrsum
 
int nimg
 
- Protected Attributes inherited from EMAN::Averager
Dict params
 
EMDataresult
 

Detailed Description

CtfCWautoAverager averages the images with CTF correction with a Wiener filter.

The Weiner filter is estimated directly from the data.

Definition at line 604 of file averager.h.

Constructor & Destructor Documentation

◆ CtfCWautoAverager()

CtfCWautoAverager::CtfCWautoAverager ( )

Definition at line 1012 of file averager.cpp.

1013 : nimg(0)
1014{
1015
1016}

Referenced by NEW().

Member Function Documentation

◆ add_image()

void CtfCWautoAverager::add_image ( EMData image)
virtual

To add an image to the Averager.

This image will be averaged in this function.

Parameters
imageThe image to be averaged.

Reimplemented from EMAN::Averager.

Definition at line 1019 of file averager.cpp.

1020{
1021 if (!image) {
1022 return;
1023 }
1024
1025
1026
1027 EMData *fft=image->do_fft();
1028
1029 if (nimg >= 1 && !EMUtil::is_same_size(fft, result)) {
1030 LOGERR("%s Averager can only process images of the same size", get_name().c_str());
1031 return;
1032 }
1033
1034 nimg++;
1035 if (nimg == 1) {
1036 result = fft->copy_head();
1037 result->to_zero();
1038 }
1039
1040 Ctf *ctf = (Ctf *)image->get_attr("ctf");
1041//string cc=ctf->to_string();
1042//FILE *out=fopen("ctf.txt","a");
1043//fprintf(out,"%s\n",cc.c_str());
1044//fclose(out);
1045 float b=ctf->bfactor;
1046 ctf->bfactor=100.0; // FIXME - this is a temporary fixed B-factor which does a (very) little sharpening
1047
1048// if (nimg==1) unlink("snr.hdf");
1049
1050 EMData *snr = result -> copy();
1052// snr->write_image("snr.hdf",-1);
1053 EMData *ctfi = result-> copy();
1055
1056 ctf->bfactor=b; // return to its original value
1057
1058 float *outd = result->get_data();
1059 float *ind = fft->get_data();
1060 float *snrd = snr->get_data();
1061 float *ctfd = ctfi->get_data();
1062
1063 size_t sz=snr->get_xsize()*snr->get_ysize();
1064 for (size_t i = 0; i < sz; i+=2) {
1065 if (snrd[i]<0) snrd[i]=0.001; // Used to be 0. See ctfcauto averager
1066 ctfd[i]=fabs(ctfd[i]);
1067 if (ctfd[i]<.05) ctfd[i]=0.05f;
1068// {
1069// if (snrd[i]<=0) ctfd[i]=.05f;
1070// else ctfd[i]=snrd[i]*10.0f;
1071// }
1072 outd[i]+=ind[i]*snrd[i]/ctfd[i];
1073 outd[i+1]+=ind[i+1]*snrd[i]/ctfd[i];
1074 }
1075
1076 if (nimg==1) {
1077 snrsum=snr->copy_head();
1078 float *ssnrd=snrsum->get_data();
1079 // we're only using the real component, and we need to start with 1.0
1080 for (size_t i = 0; i < sz; i+=2) { ssnrd[i]=1.0; ssnrd[i+1]=0.0; }
1081 }
1082// snr->write_image("snr.hdf",-1);
1083 snr->process_inplace("math.absvalue");
1084 snrsum->add(*snr);
1085
1086 delete ctf;
1087 delete fft;
1088 delete snr;
1089 delete ctfi;
1090}
EMData * result
Definition: averager.h:158
string get_name() const
Get the Averager's name.
Definition: averager.h:612
Ctf is the base class for all CTF model.
Definition: ctf.h:60
virtual void compute_2d_complex(EMData *img, CtfType t, XYData *struct_factor=0)=0
float bfactor
Definition: ctf.h:85
@ CTF_AMP
Definition: ctf.h:65
@ CTF_SNR
Definition: ctf.h:68
EMData stores an image's data and defines core image processing routines.
Definition: emdata.h:82
static bool is_same_size(const EMData *image1, const EMData *image2)
Check whether two EMData images are of the same size.
Definition: emutil.cpp:1224
EMData * copy() const
This file is a part of "emdata.h", to use functions in this file, you should "#include "emdata....
#define LOGERR
Definition: log.h:51

References EMAN::Ctf::bfactor, EMAN::Ctf::compute_2d_complex(), copy(), EMAN::Ctf::CTF_AMP, EMAN::Ctf::CTF_SNR, get_name(), EMAN::EMUtil::is_same_size(), LOGERR, nimg, EMAN::Averager::result, and snrsum.

◆ finish()

EMData * CtfCWautoAverager::finish ( )
virtual

Finish up the averaging and return the result.

Returns
The averaged image.

Implements EMAN::Averager.

Definition at line 1092 of file averager.cpp.

1093{
1094/* EMData *tmp=result->do_ift();
1095 tmp->write_image("ctfcw.hdf",0);
1096 delete tmp;
1097
1098 tmp=snrsum->do_ift();
1099 tmp->write_image("ctfcw.hdf",1);
1100 delete tmp;*/
1101
1102//snrsum->write_image("snrsum.hdf",-1);
1103 //size_t sz=result->get_xsize()*result->get_ysize();
1104 int nx=result->get_xsize();
1105 int ny=result->get_ysize();
1106 float *snrsd=snrsum->get_data();
1107 float *outd=result->get_data();
1108
1109 int rm=(ny-2)*(ny-2)/4;
1110 for (int j=0; j<ny; j++) {
1111 for (int i=0; i<nx; i+=2) {
1112 size_t ii=i+j*nx;
1113 if ((j<ny/2 && i*i/4+j*j>rm) ||(j>=ny/2 && i*i/4+(ny-j)*(ny-j)>rm) || snrsd[ii]==0) { outd[ii]=outd[ii+1]=0; continue; }
1114 outd[ii]/=snrsd[ii]; // snrsd contains total SNR
1115 outd[ii+1]/=snrsd[ii];
1116 }
1117 }
1118
1119 result->update();
1120 result->set_attr("ptcl_repr",nimg);
1121 result->set_attr("ctf_snr_total",snrsum->calc_radial_dist(snrsum->get_ysize()/2,0,1,false));
1122 result->set_attr("ctf_wiener_filtered",1);
1123
1124 delete snrsum;
1125 EMData *ret=result->do_ift();
1126 delete result;
1127 result=NULL;
1128 return ret;
1129}
vector< float > calc_radial_dist(int n, float x0, float dx, int inten)
calculates radial distribution.
Definition: emdata.cpp:2781

References EMAN::EMData::calc_radial_dist(), nimg, EMAN::Averager::result, and snrsum.

◆ get_desc()

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

Implements EMAN::Averager.

Definition at line 617 of file averager.h.

618 {
619 return "Averaging with autmatic CTF correction. Does not require a structure factor, but only works with EMAN2's CTF model";
620 }

◆ get_name()

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

Get the Averager's name.

Each Averager is identified by a unique name.

Returns
The Averager's name.

Implements EMAN::Averager.

Definition at line 612 of file averager.h.

613 {
614 return NAME;
615 }
static const string NAME
Definition: averager.h:633

References NAME.

Referenced by add_image().

◆ NEW()

static Averager * EMAN::CtfCWautoAverager::NEW ( )
inlinestatic

Definition at line 622 of file averager.h.

623 {
624 return new CtfCWautoAverager();
625 }

References CtfCWautoAverager().

◆ set_params()

void EMAN::CtfCWautoAverager::set_params ( const Dict new_params)
inlinevirtual

Set the Averager parameters using a key/value dictionary.

Parameters
new_paramsA dictionary containing the new parameters.

Reimplemented from EMAN::Averager.

Definition at line 627 of file averager.h.

628 {
629 params = new_params;
630// outfile = params["outfile"];
631 }

References EMAN::Averager::params.

Member Data Documentation

◆ NAME

const string CtfCWautoAverager::NAME = "ctfw.auto"
static

Definition at line 633 of file averager.h.

Referenced by get_name().

◆ nimg

int EMAN::CtfCWautoAverager::nimg
protected

Definition at line 637 of file averager.h.

Referenced by add_image(), and finish().

◆ snrsum

EMData* EMAN::CtfCWautoAverager::snrsum
protected

Definition at line 636 of file averager.h.

Referenced by add_image(), and finish().


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