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]
List of all members.

Public Member Functions

 CtfCWautoAverager ()
void add_image (EMData *image)
 To add an image to the Averager.
EMDatafinish ()
 Finish up the averaging and return the result.
string get_name () const
 Get the Averager's name.
string get_desc () const
void set_params (const Dict &new_params)
 Set the Averager parameters using a key/value dictionary.

Static Public Member Functions

static AveragerNEW ()

Static Public Attributes

static const string NAME = "ctfw.auto"

Protected Attributes

EMDatasnrsum
int nimg

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 510 of file averager.h.


Constructor & Destructor Documentation

CtfCWautoAverager::CtfCWautoAverager (  ) 

Definition at line 580 of file averager.cpp.

Referenced by NEW().

00581         : nimg(0)
00582 {
00583 
00584 }


Member Function Documentation

void CtfCWautoAverager::add_image ( EMData image  )  [virtual]

To add an image to the Averager.

This image will be averaged in this function.

Parameters:
image The image to be averaged.

Implements EMAN::Averager.

Definition at line 587 of file averager.cpp.

References EMAN::EMData::add(), b, EMAN::Ctf::bfactor, EMAN::Ctf::compute_2d_complex(), copy(), EMAN::EMData::copy_head(), EMAN::Ctf::CTF_AMP, EMAN::Ctf::CTF_SNR, EMAN::EMData::do_fft(), EMAN::EMData::get_attr(), EMAN::EMData::get_data(), get_name(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMUtil::is_same_size(), LOGERR, nimg, EMAN::EMData::process_inplace(), EMAN::Averager::result, snrsum, and EMAN::EMData::to_zero().

00588 {
00589         if (!image) {
00590                 return;
00591         }
00592 
00593 
00594 
00595         EMData *fft=image->do_fft();
00596 
00597         if (nimg >= 1 && !EMUtil::is_same_size(fft, result)) {
00598                 LOGERR("%s Averager can only process images of the same size", get_name().c_str());
00599                 return;
00600         }
00601 
00602         nimg++;
00603         if (nimg == 1) {
00604                 result = fft->copy_head();
00605                 result->to_zero();
00606         }
00607 
00608         Ctf *ctf = (Ctf *)image->get_attr("ctf");
00609 //string cc=ctf->to_string();
00610 //FILE *out=fopen("ctf.txt","a");
00611 //fprintf(out,"%s\n",cc.c_str());
00612 //fclose(out);
00613         float b=ctf->bfactor;
00614         ctf->bfactor=100.0;                     // FIXME - this is a temporary fixed B-factor which does a (very) little sharpening
00615 
00616 //      if (nimg==1) unlink("snr.hdf");
00617 
00618         EMData *snr = result -> copy();
00619         ctf->compute_2d_complex(snr,Ctf::CTF_SNR);
00620 //      snr->write_image("snr.hdf",-1);
00621         EMData *ctfi = result-> copy();
00622         ctf->compute_2d_complex(ctfi,Ctf::CTF_AMP);
00623 
00624         ctf->bfactor=b; // return to its original value
00625 
00626         float *outd = result->get_data();
00627         float *ind = fft->get_data();
00628         float *snrd = snr->get_data();
00629         float *ctfd = ctfi->get_data();
00630 
00631         size_t sz=snr->get_xsize()*snr->get_ysize();
00632         for (size_t i = 0; i < sz; i+=2) {
00633                 if (snrd[i]<0) snrd[i]=0;
00634                 ctfd[i]=fabs(ctfd[i]);
00635                 if (ctfd[i]<.05) ctfd[i]=0.05f;
00636 //              {
00637 //                      if (snrd[i]<=0) ctfd[i]=.05f;
00638 //                      else ctfd[i]=snrd[i]*10.0f;
00639 //              }
00640                 outd[i]+=ind[i]*snrd[i]/ctfd[i];
00641                 outd[i+1]+=ind[i+1]*snrd[i]/ctfd[i];
00642         }
00643 
00644         if (nimg==1) {
00645                 snrsum=snr->copy_head();
00646                 float *ssnrd=snrsum->get_data();
00647                 // we're only using the real component, and we need to start with 1.0
00648                 for (size_t i = 0; i < sz; i+=2) { ssnrd[i]=1.0; ssnrd[i+1]=0.0; }
00649         }
00650 //      snr->write_image("snr.hdf",-1);
00651         snr->process_inplace("math.absvalue");
00652         snrsum->add(*snr);
00653 
00654         delete ctf;
00655         delete fft;
00656         delete snr;
00657         delete ctfi;
00658 }

EMData * CtfCWautoAverager::finish (  )  [virtual]

Finish up the averaging and return the result.

Returns:
The averaged image.

Implements EMAN::Averager.

Definition at line 660 of file averager.cpp.

References EMAN::EMData::calc_radial_dist(), EMAN::EMData::do_ift(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), nimg, EMAN::Averager::result, EMAN::EMData::set_attr(), snrsum, and EMAN::EMData::update().

00661 {
00662 /*      EMData *tmp=result->do_ift();
00663         tmp->write_image("ctfcw.hdf",0);
00664         delete tmp;
00665 
00666         tmp=snrsum->do_ift();
00667         tmp->write_image("ctfcw.hdf",1);
00668         delete tmp;*/
00669 
00670 //snrsum->write_image("snrsum.hdf",-1);
00671         //size_t sz=result->get_xsize()*result->get_ysize();
00672         int nx=result->get_xsize();
00673         int ny=result->get_ysize();     
00674         float *snrsd=snrsum->get_data();
00675         float *outd=result->get_data();
00676 
00677         int rm=(ny-2)*(ny-2)/4;
00678         for (int j=0; j<ny; j++) {
00679                 for (int i=0; i<nx; i+=2) {
00680                         size_t ii=i+j*nx;
00681                         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; }
00682                         outd[ii]/=snrsd[ii];            // snrsd contains total SNR
00683                         outd[ii+1]/=snrsd[ii];
00684                 }
00685         }
00686 
00687         result->update();
00688         result->set_attr("ptcl_repr",nimg);
00689         result->set_attr("ctf_snr_total",snrsum->calc_radial_dist(snrsum->get_ysize()/2,0,1,false));
00690         result->set_attr("ctf_wiener_filtered",1);
00691         
00692         delete snrsum;
00693         EMData *ret=result->do_ift();
00694         delete result;
00695         result=NULL;
00696         return ret;
00697 }

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

Implements EMAN::Averager.

Definition at line 523 of file averager.h.

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

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

Get the Averager's name.

Each Averager is identified by a unique name.

Returns:
The Averager's name.

Implements EMAN::Averager.

Definition at line 518 of file averager.h.

References NAME.

Referenced by add_image().

00519                 {
00520                         return NAME;
00521                 }

static Averager* EMAN::CtfCWautoAverager::NEW (  )  [inline, static]

Definition at line 528 of file averager.h.

References CtfCWautoAverager().

00529                 {
00530                         return new CtfCWautoAverager();
00531                 }

void EMAN::CtfCWautoAverager::set_params ( const Dict new_params  )  [inline, virtual]

Set the Averager parameters using a key/value dictionary.

Parameters:
new_params A dictionary containing the new parameters.

Reimplemented from EMAN::Averager.

Definition at line 533 of file averager.h.

References EMAN::Averager::params.

00534                 {
00535                         params = new_params;
00536 //                      outfile = params["outfile"];
00537                 }


Member Data Documentation

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

Definition at line 539 of file averager.h.

Referenced by get_name().

int EMAN::CtfCWautoAverager::nimg [protected]

Definition at line 543 of file averager.h.

Referenced by add_image(), and finish().

EMData* EMAN::CtfCWautoAverager::snrsum [protected]

Definition at line 542 of file averager.h.

Referenced by add_image(), and finish().


The documentation for this class was generated from the following files:
Generated on Tue Jul 12 13:48:06 2011 for EMAN2 by  doxygen 1.4.7