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

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


Constructor & Destructor Documentation

CtfCAutoAverager::CtfCAutoAverager (  ) 

Definition at line 699 of file averager.cpp.

Referenced by NEW().

00700         : nimg(0)
00701 {
00702 
00703 }


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

00707 {
00708         if (!image) {
00709                 return;
00710         }
00711 
00712 
00713 
00714         EMData *fft=image->do_fft();
00715 
00716         if (nimg >= 1 && !EMUtil::is_same_size(fft, result)) {
00717                 LOGERR("%s Averager can only process images of the same size", get_name().c_str());
00718                 return;
00719         }
00720 
00721         nimg++;
00722         if (nimg == 1) {
00723                 result = fft->copy_head();
00724                 result->to_zero();
00725         }
00726 
00727         Ctf *ctf = (Ctf *)image->get_attr("ctf");
00728         float b=ctf->bfactor;
00729         ctf->bfactor=0;                 // NO B-FACTOR CORRECTION !
00730 
00731         EMData *snr = result -> copy();
00732         ctf->compute_2d_complex(snr,Ctf::CTF_SNR);
00733         EMData *ctfi = result-> copy();
00734         ctf->compute_2d_complex(ctfi,Ctf::CTF_AMP);
00735 
00736         ctf->bfactor=b; // return to its original value
00737 
00738         float *outd = result->get_data();
00739         float *ind = fft->get_data();
00740         float *snrd = snr->get_data();
00741         float *ctfd = ctfi->get_data();
00742 
00743         size_t sz=snr->get_xsize()*snr->get_ysize();
00744         for (size_t i = 0; i < sz; i+=2) {
00745                 if (snrd[i]<0) snrd[i]=0;
00746                 ctfd[i]=fabs(ctfd[i]);
00747                 
00748                 // This limits the maximum possible amplification in CTF correction to 10x
00749                 if (ctfd[i]<.05)  ctfd[i]=0.05f;
00750 //              {
00751 //                      if (snrd[i]<=0) ctfd[i]=.05f;
00752 //                      else ctfd[i]=snrd[i]*10.0f;
00753 //              }
00754                 
00755                 // SNR weight and CTF correction
00756                 outd[i]+=ind[i]*snrd[i]/ctfd[i];
00757                 outd[i+1]+=ind[i+1]*snrd[i]/ctfd[i];
00758         }
00759 
00760         if (nimg==1) {
00761                 snrsum=snr->copy_head();
00762                 float *ssnrd=snrsum->get_data();
00763                 // we're only using the real component, for Wiener filter we put 1.0 in R, but for just SNR weight we use 0
00764                 for (size_t i = 0; i < sz; i+=2) { ssnrd[i]=0.0; ssnrd[i+1]=0.0; }
00765         }
00766         snr->process_inplace("math.absvalue");
00767         snrsum->add(*snr);
00768 
00769         delete ctf;
00770         delete fft;
00771         delete snr;
00772         delete ctfi;
00773 }

EMData * CtfCAutoAverager::finish (  )  [virtual]

Finish up the averaging and return the result.

Returns:
The averaged image.

Implements EMAN::Averager.

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

00776 {
00777 /*      EMData *tmp=result->do_ift();
00778         tmp->write_image("ctfcw.hdf",0);
00779         delete tmp;
00780 
00781         tmp=snrsum->do_ift();
00782         tmp->write_image("ctfcw.hdf",1);
00783         delete tmp;*/
00784 
00785 //      snrsum->write_image("snrsum.hdf",-1);
00786         //size_t sz=result->get_xsize()*result->get_ysize();
00787         int nx=result->get_xsize();
00788         int ny=result->get_ysize();     
00789         float *snrsd=snrsum->get_data();
00790         float *outd=result->get_data();
00791 
00792         int rm=(ny-2)*(ny-2)/4;
00793         for (int j=0; j<ny; j++) {
00794                 for (int i=0; i<nx; i+=2) {
00795                         size_t ii=i+j*nx;
00796                         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; }
00797                         // we aren't wiener filtering, but if the total SNR is too low, we don't want TOO much exaggeration of noise
00798                         if (snrsd[ii]<.05) {            
00799                                 outd[ii]*=20.0;         // 1/0.05
00800                                 outd[ii+1]*=20.0;
00801                         }
00802                         else {
00803                                 outd[ii]/=snrsd[ii];            // snrsd contains total SNR
00804                                 outd[ii+1]/=snrsd[ii];
00805                         }
00806                 }
00807         }
00808         result->update();
00809         result->set_attr("ptcl_repr",nimg);
00810         result->set_attr("ctf_snr_total",snrsum->calc_radial_dist(snrsum->get_ysize()/2,0,1,false));
00811         result->set_attr("ctf_wiener_filtered",0);
00812         
00813 /*      snrsum->write_image("snr.hdf",-1);
00814         result->write_image("avg.hdf",-1);*/
00815         
00816         delete snrsum;
00817         EMData *ret=result->do_ift();
00818         delete result;
00819         result=NULL;
00820         return ret;
00821 }

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

Implements EMAN::Averager.

Definition at line 484 of file averager.h.

00485                 {
00486                         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";
00487                 }

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

References NAME.

Referenced by add_image().

00480                 {
00481                         return NAME;
00482                 }

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

Definition at line 489 of file averager.h.

References CtfCAutoAverager().

00490                 {
00491                         return new CtfCAutoAverager();
00492                 }

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

References EMAN::Averager::params.

00495                 {
00496                         params = new_params;
00497 //                      outfile = params["outfile"];
00498                 }


Member Data Documentation

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

Definition at line 500 of file averager.h.

Referenced by get_name().

int EMAN::CtfCAutoAverager::nimg [protected]

Definition at line 504 of file averager.h.

Referenced by add_image(), and finish().

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

Definition at line 503 of file averager.h.

Referenced by add_image(), and finish().


The documentation for this class was generated from the following files:
Generated on Tue Jul 12 13:48:05 2011 for EMAN2 by  doxygen 1.4.7