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


Constructor & Destructor Documentation

CtfCWautoAverager::CtfCWautoAverager (  ) 

Definition at line 637 of file averager.cpp.

Referenced by NEW().

00638         : nimg(0)
00639 {
00640 
00641 }


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 644 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().

00645 {
00646         if (!image) {
00647                 return;
00648         }
00649 
00650 
00651 
00652         EMData *fft=image->do_fft();
00653 
00654         if (nimg >= 1 && !EMUtil::is_same_size(fft, result)) {
00655                 LOGERR("%s Averager can only process images of the same size", get_name().c_str());
00656                 return;
00657         }
00658 
00659         nimg++;
00660         if (nimg == 1) {
00661                 result = fft->copy_head();
00662                 result->to_zero();
00663         }
00664 
00665         Ctf *ctf = (Ctf *)image->get_attr("ctf");
00666 //string cc=ctf->to_string();
00667 //FILE *out=fopen("ctf.txt","a");
00668 //fprintf(out,"%s\n",cc.c_str());
00669 //fclose(out);
00670         float b=ctf->bfactor;
00671         ctf->bfactor=100.0;                     // FIXME - this is a temporary fixed B-factor which does a (very) little sharpening
00672 
00673 //      if (nimg==1) unlink("snr.hdf");
00674 
00675         EMData *snr = result -> copy();
00676         ctf->compute_2d_complex(snr,Ctf::CTF_SNR);
00677 //      snr->write_image("snr.hdf",-1);
00678         EMData *ctfi = result-> copy();
00679         ctf->compute_2d_complex(ctfi,Ctf::CTF_AMP);
00680 
00681         ctf->bfactor=b; // return to its original value
00682 
00683         float *outd = result->get_data();
00684         float *ind = fft->get_data();
00685         float *snrd = snr->get_data();
00686         float *ctfd = ctfi->get_data();
00687 
00688         size_t sz=snr->get_xsize()*snr->get_ysize();
00689         for (size_t i = 0; i < sz; i+=2) {
00690                 if (snrd[i]<0) snrd[i]=0;
00691                 ctfd[i]=fabs(ctfd[i]);
00692                 if (ctfd[i]<.05) ctfd[i]=0.05f;
00693 //              {
00694 //                      if (snrd[i]<=0) ctfd[i]=.05f;
00695 //                      else ctfd[i]=snrd[i]*10.0f;
00696 //              }
00697                 outd[i]+=ind[i]*snrd[i]/ctfd[i];
00698                 outd[i+1]+=ind[i+1]*snrd[i]/ctfd[i];
00699         }
00700 
00701         if (nimg==1) {
00702                 snrsum=snr->copy_head();
00703                 float *ssnrd=snrsum->get_data();
00704                 // we're only using the real component, and we need to start with 1.0
00705                 for (size_t i = 0; i < sz; i+=2) { ssnrd[i]=1.0; ssnrd[i+1]=0.0; }
00706         }
00707 //      snr->write_image("snr.hdf",-1);
00708         snr->process_inplace("math.absvalue");
00709         snrsum->add(*snr);
00710 
00711         delete ctf;
00712         delete fft;
00713         delete snr;
00714         delete ctfi;
00715 }

EMData * CtfCWautoAverager::finish (  )  [virtual]

Finish up the averaging and return the result.

Returns:
The averaged image.

Implements EMAN::Averager.

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

00718 {
00719 /*      EMData *tmp=result->do_ift();
00720         tmp->write_image("ctfcw.hdf",0);
00721         delete tmp;
00722 
00723         tmp=snrsum->do_ift();
00724         tmp->write_image("ctfcw.hdf",1);
00725         delete tmp;*/
00726 
00727 //snrsum->write_image("snrsum.hdf",-1);
00728         //size_t sz=result->get_xsize()*result->get_ysize();
00729         int nx=result->get_xsize();
00730         int ny=result->get_ysize();     
00731         float *snrsd=snrsum->get_data();
00732         float *outd=result->get_data();
00733 
00734         int rm=(ny-2)*(ny-2)/4;
00735         for (int j=0; j<ny; j++) {
00736                 for (int i=0; i<nx; i+=2) {
00737                         size_t ii=i+j*nx;
00738                         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; }
00739                         outd[ii]/=snrsd[ii];            // snrsd contains total SNR
00740                         outd[ii+1]/=snrsd[ii];
00741                 }
00742         }
00743 
00744         result->update();
00745         result->set_attr("ptcl_repr",nimg);
00746         result->set_attr("ctf_snr_total",snrsum->calc_radial_dist(snrsum->get_ysize()/2,0,1,false));
00747         result->set_attr("ctf_wiener_filtered",1);
00748         
00749         delete snrsum;
00750         EMData *ret=result->do_ift();
00751         delete result;
00752         result=NULL;
00753         return ret;
00754 }

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

Implements EMAN::Averager.

Definition at line 564 of file averager.h.

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

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

References NAME.

Referenced by add_image().

00560                 {
00561                         return NAME;
00562                 }

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

Definition at line 569 of file averager.h.

References CtfCWautoAverager().

00570                 {
00571                         return new CtfCWautoAverager();
00572                 }

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

References EMAN::Averager::params.

00575                 {
00576                         params = new_params;
00577 //                      outfile = params["outfile"];
00578                 }


Member Data Documentation

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

Definition at line 580 of file averager.h.

Referenced by get_name().

int EMAN::CtfCWautoAverager::nimg [protected]

Definition at line 584 of file averager.h.

Referenced by add_image(), and finish().

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

Definition at line 583 of file averager.h.

Referenced by add_image(), and finish().


The documentation for this class was generated from the following files:
Generated on Fri Aug 10 16:32:11 2012 for EMAN2 by  doxygen 1.4.7