Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

EMAN::CtfCAutoAverager Class Reference

CtfCWautoAverager averages the images with CTF correction with a Wiener filter. More...

#include <averager.h>

Inheritance diagram for EMAN::CtfCAutoAverager:

Inheritance graph
[legend]
Collaboration diagram for EMAN::CtfCAutoAverager:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 CtfCAutoAverager ()
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

AveragerNEW ()

Static Public Attributes

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

CtfCAutoAverager::CtfCAutoAverager  ) 
 

Definition at line 598 of file averager.cpp.

00599         : nimg(0)
00600 {
00601 
00602 }


Member Function Documentation

void CtfCAutoAverager::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 605 of file averager.cpp.

References EMAN::EMData::add(), b, EMAN::Ctf::bfactor, EMAN::Ctf::compute_2d_complex(), copy(), EMAN::EMData::copy_head(), 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(), snrsum, and EMAN::EMData::to_zero().

00606 {
00607         if (!image) {
00608                 return;
00609         }
00610 
00611 
00612 
00613         EMData *fft=image->do_fft();
00614 
00615         if (nimg >= 1 && !EMUtil::is_same_size(fft, result)) {
00616                 LOGERR("%s Averager can only process images of the same size", get_name().c_str());
00617                 return;
00618         }
00619 
00620         nimg++;
00621         if (nimg == 1) {
00622                 result = fft->copy_head();
00623                 result->to_zero();
00624         }
00625 
00626         Ctf *ctf = (Ctf *)image->get_attr("ctf");
00627         float b=ctf->bfactor;
00628         ctf->bfactor=0;                 // NO B-FACTOR CORRECTION !
00629 
00630         EMData *snr = result -> copy();
00631         ctf->compute_2d_complex(snr,Ctf::CTF_SNR);
00632         EMData *ctfi = result-> copy();
00633         ctf->compute_2d_complex(ctfi,Ctf::CTF_AMP);
00634 
00635         ctf->bfactor=b; // return to its original value
00636 
00637         float *outd = result->get_data();
00638         float *ind = fft->get_data();
00639         float *snrd = snr->get_data();
00640         float *ctfd = ctfi->get_data();
00641 
00642         size_t sz=snr->get_xsize()*snr->get_ysize();
00643         for (size_t i = 0; i < sz; i+=2) {
00644                 if (snrd[i]<0) snrd[i]=0;
00645                 ctfd[i]=fabs(ctfd[i]);
00646                 
00647                 // This limits the maximum possible amplification in CTF correction to 10x
00648                 if (ctfd[i]<.05)  ctfd[i]=0.05f;
00649 //              {
00650 //                      if (snrd[i]<=0) ctfd[i]=.05f;
00651 //                      else ctfd[i]=snrd[i]*10.0f;
00652 //              }
00653                 
00654                 // SNR weight and CTF correction
00655                 outd[i]+=ind[i]*snrd[i]/ctfd[i];
00656                 outd[i+1]+=ind[i+1]*snrd[i]/ctfd[i];
00657         }
00658 
00659         if (nimg==1) {
00660                 snrsum=snr->copy_head();
00661                 float *ssnrd=snrsum->get_data();
00662                 // we're only using the real component, for Wiener filter we put 1.0 in R, but for just SNR weight we use 0
00663                 for (size_t i = 0; i < sz; i+=2) { ssnrd[i]=0.0; ssnrd[i+1]=0.0; }
00664         }
00665         snr->process_inplace("math.absvalue");
00666         snrsum->add(*snr);
00667 
00668         delete ctf;
00669         delete fft;
00670         delete snr;
00671         delete ctfi;
00672 }

EMData * CtfCAutoAverager::finish  )  [virtual]
 

Finish up the averaging and return the result.

Returns:
The averaged image.

Implements EMAN::Averager.

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

00675 {
00676 /*      EMData *tmp=result->do_ift();
00677         tmp->write_image("ctfcw.hdf",0);
00678         delete tmp;
00679 
00680         tmp=snrsum->do_ift();
00681         tmp->write_image("ctfcw.hdf",1);
00682         delete tmp;*/
00683 
00684 //      snrsum->write_image("snrsum.hdf",-1);
00685         //size_t sz=result->get_xsize()*result->get_ysize();
00686         int nx=result->get_xsize();
00687         int ny=result->get_ysize();     
00688         float *snrsd=snrsum->get_data();
00689         float *outd=result->get_data();
00690 
00691         int rm=(ny-2)*(ny-2)/4;
00692         for (int j=0; j<ny; j++) {
00693                 for (int i=0; i<nx; i+=2) {
00694                         size_t ii=i+j*nx;
00695                         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; }
00696                         // we aren't wiener filtering, but if the total SNR is too low, we don't want TOO much exaggeration of noise
00697                         if (snrsd[ii]<.05) {            
00698                                 outd[ii]*=20.0;         // 1/0.05
00699                                 outd[ii+1]*=20.0;
00700                         }
00701                         else {
00702                                 outd[ii]/=snrsd[ii];            // snrsd contains total SNR
00703                                 outd[ii+1]/=snrsd[ii];
00704                         }
00705                 }
00706         }
00707         result->update();
00708         result->set_attr("ptcl_repr",nimg);
00709         result->set_attr("ctf_snr_total",snrsum->calc_radial_dist(snrsum->get_ysize()/2,0,1,false));
00710         result->set_attr("ctf_wiener_filtered",0);
00711         
00712 /*      snrsum->write_image("snr.hdf",-1);
00713         result->write_image("avg.hdf",-1);*/
00714         
00715         delete snrsum;
00716         EMData *ret=result->do_ift();
00717         delete result;
00718         result=NULL;
00719         return ret;
00720 }

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

Implements EMAN::Averager.

Definition at line 439 of file averager.h.

00440                 {
00441                         return "Averaging with automatic CTF correction and SNR weight. No B-factor correction (as this is best done in 3-D). Does not require a structure factor, but only works with EMAN2's CTF model";
00442                 }

string EMAN::CtfCAutoAverager::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.

Referenced by add_image().

00435                 {
00436                         return NAME;
00437                 }

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

Definition at line 444 of file averager.h.

00445                 {
00446                         return new CtfCAutoAverager();
00447                 }

void EMAN::CtfCAutoAverager::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.

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


Member Data Documentation

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

Definition at line 52 of file averager.cpp.

int EMAN::CtfCAutoAverager::nimg [protected]
 

Definition at line 459 of file averager.h.

Referenced by add_image(), and finish().

EMData* EMAN::CtfCAutoAverager::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 Thu Dec 9 13:47:16 2010 for EMAN2 by  doxygen 1.3.9.1