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


Constructor & Destructor Documentation

CtfCWautoAverager::CtfCWautoAverager (  ) 

Definition at line 716 of file averager.cpp.

Referenced by NEW().

00717         : nimg(0)
00718 {
00719 
00720 }


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

00724 {
00725         if (!image) {
00726                 return;
00727         }
00728 
00729 
00730 
00731         EMData *fft=image->do_fft();
00732 
00733         if (nimg >= 1 && !EMUtil::is_same_size(fft, result)) {
00734                 LOGERR("%s Averager can only process images of the same size", get_name().c_str());
00735                 return;
00736         }
00737 
00738         nimg++;
00739         if (nimg == 1) {
00740                 result = fft->copy_head();
00741                 result->to_zero();
00742         }
00743 
00744         Ctf *ctf = (Ctf *)image->get_attr("ctf");
00745 //string cc=ctf->to_string();
00746 //FILE *out=fopen("ctf.txt","a");
00747 //fprintf(out,"%s\n",cc.c_str());
00748 //fclose(out);
00749         float b=ctf->bfactor;
00750         ctf->bfactor=100.0;                     // FIXME - this is a temporary fixed B-factor which does a (very) little sharpening
00751 
00752 //      if (nimg==1) unlink("snr.hdf");
00753 
00754         EMData *snr = result -> copy();
00755         ctf->compute_2d_complex(snr,Ctf::CTF_SNR);
00756 //      snr->write_image("snr.hdf",-1);
00757         EMData *ctfi = result-> copy();
00758         ctf->compute_2d_complex(ctfi,Ctf::CTF_AMP);
00759 
00760         ctf->bfactor=b; // return to its original value
00761 
00762         float *outd = result->get_data();
00763         float *ind = fft->get_data();
00764         float *snrd = snr->get_data();
00765         float *ctfd = ctfi->get_data();
00766 
00767         size_t sz=snr->get_xsize()*snr->get_ysize();
00768         for (size_t i = 0; i < sz; i+=2) {
00769                 if (snrd[i]<0) snrd[i]=0.001;   // Used to be 0. See ctfcauto averager
00770                 ctfd[i]=fabs(ctfd[i]);
00771                 if (ctfd[i]<.05) ctfd[i]=0.05f;
00772 //              {
00773 //                      if (snrd[i]<=0) ctfd[i]=.05f;
00774 //                      else ctfd[i]=snrd[i]*10.0f;
00775 //              }
00776                 outd[i]+=ind[i]*snrd[i]/ctfd[i];
00777                 outd[i+1]+=ind[i+1]*snrd[i]/ctfd[i];
00778         }
00779 
00780         if (nimg==1) {
00781                 snrsum=snr->copy_head();
00782                 float *ssnrd=snrsum->get_data();
00783                 // we're only using the real component, and we need to start with 1.0
00784                 for (size_t i = 0; i < sz; i+=2) { ssnrd[i]=1.0; ssnrd[i+1]=0.0; }
00785         }
00786 //      snr->write_image("snr.hdf",-1);
00787         snr->process_inplace("math.absvalue");
00788         snrsum->add(*snr);
00789 
00790         delete ctf;
00791         delete fft;
00792         delete snr;
00793         delete ctfi;
00794 }

EMData * CtfCWautoAverager::finish (  )  [virtual]

Finish up the averaging and return the result.

Returns:
The averaged image.

Implements EMAN::Averager.

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

00797 {
00798 /*      EMData *tmp=result->do_ift();
00799         tmp->write_image("ctfcw.hdf",0);
00800         delete tmp;
00801 
00802         tmp=snrsum->do_ift();
00803         tmp->write_image("ctfcw.hdf",1);
00804         delete tmp;*/
00805 
00806 //snrsum->write_image("snrsum.hdf",-1);
00807         //size_t sz=result->get_xsize()*result->get_ysize();
00808         int nx=result->get_xsize();
00809         int ny=result->get_ysize();     
00810         float *snrsd=snrsum->get_data();
00811         float *outd=result->get_data();
00812 
00813         int rm=(ny-2)*(ny-2)/4;
00814         for (int j=0; j<ny; j++) {
00815                 for (int i=0; i<nx; i+=2) {
00816                         size_t ii=i+j*nx;
00817                         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; }
00818                         outd[ii]/=snrsd[ii];            // snrsd contains total SNR
00819                         outd[ii+1]/=snrsd[ii];
00820                 }
00821         }
00822 
00823         result->update();
00824         result->set_attr("ptcl_repr",nimg);
00825         result->set_attr("ctf_snr_total",snrsum->calc_radial_dist(snrsum->get_ysize()/2,0,1,false));
00826         result->set_attr("ctf_wiener_filtered",1);
00827         
00828         delete snrsum;
00829         EMData *ret=result->do_ift();
00830         delete result;
00831         result=NULL;
00832         return ret;
00833 }

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

Implements EMAN::Averager.

Definition at line 474 of file averager.h.

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

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

References NAME.

Referenced by add_image().

00470                 {
00471                         return NAME;
00472                 }

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

Definition at line 479 of file averager.h.

References CtfCWautoAverager().

00480                 {
00481                         return new CtfCWautoAverager();
00482                 }

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

References EMAN::Averager::params.

00485                 {
00486                         params = new_params;
00487 //                      outfile = params["outfile"];
00488                 }


Member Data Documentation

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

Definition at line 490 of file averager.h.

Referenced by get_name().

int EMAN::CtfCWautoAverager::nimg [protected]

Definition at line 494 of file averager.h.

Referenced by add_image(), and finish().

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

Definition at line 493 of file averager.h.

Referenced by add_image(), and finish().


The documentation for this class was generated from the following files:
Generated on Tue Jun 11 12:42:55 2013 for EMAN2 by  doxygen 1.4.7