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 = "ctf.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 426 of file averager.h.


Constructor & Destructor Documentation

CtfCWautoAverager::CtfCWautoAverager (  ) 

Definition at line 473 of file averager.cpp.

Referenced by NEW().

00474         : nimg(0)
00475 {
00476 
00477 }


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

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

EMData * CtfCWautoAverager::finish (  )  [virtual]

Finish up the averaging and return the result.

Returns:
The averaged image.

Implements EMAN::Averager.

Definition at line 543 of file averager.cpp.

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

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

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

Implements EMAN::Averager.

Definition at line 439 of file averager.h.

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

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

References NAME.

Referenced by add_image().

00435                 {
00436                         return NAME;
00437                 }

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

Definition at line 444 of file averager.h.

References CtfCWautoAverager().

00445                 {
00446                         return new CtfCWautoAverager();
00447                 }

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

References EMAN::Averager::params.

00450                 {
00451                         params = new_params;
00452 //                      outfile = params["outfile"];
00453                 }


Member Data Documentation

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

Definition at line 455 of file averager.h.

Referenced by get_name().

int EMAN::CtfCWautoAverager::nimg [protected]

Definition at line 459 of file averager.h.

Referenced by add_image(), and finish().

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

Definition at line 458 of file averager.h.

Referenced by add_image(), and finish().


The documentation for this class was generated from the following files:
Generated on Tue May 25 17:15:50 2010 for EMAN2 by  doxygen 1.4.7