Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File 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]
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 465 of file averager.h.


Constructor & Destructor Documentation

CtfCWautoAverager::CtfCWautoAverager  ) 
 

Definition at line 475 of file averager.cpp.

Referenced by NEW().

00476         : nimg(0)
00477 {
00478 
00479 }


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 482 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, snrsum, and EMAN::EMData::to_zero().

00483 {
00484         if (!image) {
00485                 return;
00486         }
00487 
00488 
00489 
00490         EMData *fft=image->do_fft();
00491 
00492         if (nimg >= 1 && !EMUtil::is_same_size(fft, result)) {
00493                 LOGERR("%s Averager can only process images of the same size", get_name().c_str());
00494                 return;
00495         }
00496 
00497         nimg++;
00498         if (nimg == 1) {
00499                 result = fft->copy_head();
00500                 result->to_zero();
00501         }
00502 
00503         Ctf *ctf = (Ctf *)image->get_attr("ctf");
00504         float b=ctf->bfactor;
00505         ctf->bfactor=100.0;                     // FIXME - this is a temporary fixed B-factor which does a (very) little sharpening
00506 
00507         EMData *snr = result -> copy();
00508         ctf->compute_2d_complex(snr,Ctf::CTF_SNR);
00509         EMData *ctfi = result-> copy();
00510         ctf->compute_2d_complex(ctfi,Ctf::CTF_AMP);
00511 
00512         ctf->bfactor=b; // return to its original value
00513 
00514         float *outd = result->get_data();
00515         float *ind = fft->get_data();
00516         float *snrd = snr->get_data();
00517         float *ctfd = ctfi->get_data();
00518 
00519         size_t sz=snr->get_xsize()*snr->get_ysize();
00520         for (size_t i = 0; i < sz; i+=2) {
00521                 if (snrd[i]<0) snrd[i]=0;
00522                 ctfd[i]=fabs(ctfd[i]);
00523                 if (ctfd[i]<.05) {
00524                         if (snrd[i]<=0) ctfd[i]=.05f;
00525                         else ctfd[i]=snrd[i]*10.0f;
00526                 }
00527                 outd[i]+=ind[i]*snrd[i]/ctfd[i];
00528                 outd[i+1]+=ind[i+1]*snrd[i]/ctfd[i];
00529         }
00530 
00531         if (nimg==1) {
00532                 snrsum=snr->copy_head();
00533                 float *ssnrd=snrsum->get_data();
00534                 // we're only using the real component, and we need to start with 1.0
00535                 for (size_t i = 0; i < sz; i+=2) { ssnrd[i]=1.0; ssnrd[i+1]=0.0; }
00536         }
00537         snrsum->add(*snr);
00538 
00539         delete ctf;
00540         delete fft;
00541         delete snr;
00542         delete ctfi;
00543 }

EMData * CtfCWautoAverager::finish  )  [virtual]
 

Finish up the averaging and return the result.

Returns:
The averaged image.

Implements EMAN::Averager.

Definition at line 545 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::EMData::set_attr(), snrsum, and EMAN::EMData::update().

00546 {
00547 /*      EMData *tmp=result->do_ift();
00548         tmp->write_image("ctfcw.hdf",0);
00549         delete tmp;
00550 
00551         tmp=snrsum->do_ift();
00552         tmp->write_image("ctfcw.hdf",1);
00553         delete tmp;*/
00554 
00555 //      snrsum->write_image("snrsum.hdf",-1);
00556         size_t sz=result->get_xsize()*result->get_ysize();
00557         float *snrsd=snrsum->get_data();
00558         float *outd=result->get_data();
00559 
00560         for (size_t i=0; i<sz; i+=2) {
00561                 outd[i]/=snrsd[i];              // snrsd contains total SNR+1
00562                 outd[i+1]/=snrsd[i];
00563         }
00564         result->update();
00565         result->set_attr("ptcl_repr",nimg);
00566         result->set_attr("ctf_snr_total",snrsum->calc_radial_dist(snrsum->get_ysize()/2,0,1,false));
00567         result->set_attr("ctf_wiener_filtered",1);
00568         
00569         delete snrsum;
00570         EMData *ret=result->do_ift();
00571         delete result;
00572         result=NULL;
00573         return ret;
00574 }

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

Implements EMAN::Averager.

Definition at line 478 of file averager.h.

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

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

References NAME.

Referenced by add_image().

00474                 {
00475                         return NAME;
00476                 }

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

Definition at line 483 of file averager.h.

References CtfCWautoAverager().

00484                 {
00485                         return new CtfCWautoAverager();
00486                 }

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

References EMAN::Averager::params.

00489                 {
00490                         params = new_params;
00491 //                      outfile = params["outfile"];
00492                 }


Member Data Documentation

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

Definition at line 494 of file averager.h.

Referenced by get_name().

int EMAN::CtfCWautoAverager::nimg [protected]
 

Definition at line 498 of file averager.h.

Referenced by add_image(), and finish().

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

Definition at line 497 of file averager.h.

Referenced by add_image(), and finish().


The documentation for this class was generated from the following files:
Generated on Mon Jul 19 13:05:55 2010 for EMAN2 by  doxygen 1.4.4